aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
authorStefan Monnier2025-06-22 22:25:03 -0400
committerStefan Monnier2025-06-27 23:11:39 -0400
commit6c0bbf0f921682a185ebd57efef1e9d4f8ced788 (patch)
treea07e91ca4549ce6b5c273aa0cbd1e0b19a4b7540 /test/src
parentcb484ead91cb20f1cad31ac878a65ea1e9354871 (diff)
downloademacs-6c0bbf0f921682a185ebd57efef1e9d4f8ced788.tar.gz
emacs-6c0bbf0f921682a185ebd57efef1e9d4f8ced788.zip
(Finsert_file_contents): Refine commit d07af40d8826
* src/fileio.c (Finsert_file_contents): Inhibit ask-supersession only if we're VISITing in a non-narrowed buffer (bug#78866). * test/src/fileio-tests.el (ert--tests-dir): New var. (fileio-tests--insert-file-contents-supersession): New test.
Diffstat (limited to 'test/src')
-rw-r--r--test/src/fileio-tests.el26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el
index 13cc5de29e8..b6302c35fee 100644
--- a/test/src/fileio-tests.el
+++ b/test/src/fileio-tests.el
@@ -235,5 +235,31 @@ Also check that an encoding error can appear in a symlink."
235 "2025/02/01 23:15:59.123456700"))) 235 "2025/02/01 23:15:59.123456700")))
236 (delete-file tfile)))) 236 (delete-file tfile))))
237 237
238(defconst ert--tests-dir
239 (file-name-directory (macroexp-file-name)))
240
241(ert-deftest fileio-tests--insert-file-contents-supersession ()
242 (ert-with-temp-file file
243 (write-region "foo" nil file)
244 (let* ((asked nil)
245 (buf (find-file-noselect file))
246 (auast (lambda (&rest _) (setq asked t))))
247 (unwind-protect
248 (with-current-buffer buf
249 ;; Pretend someone else edited the file.
250 (write-region "bar" nil file 'append)
251 ;; Use `advice-add' rather than `cl-letf' because the function
252 ;; may not be defined yet.
253 (advice-add 'ask-user-about-supersession-threat :override auast)
254 ;; Modify the local buffer via `insert-file-contents'.
255 (insert-file-contents
256 (expand-file-name "lread-resources/somelib.el"
257 ert--tests-dir)
258 nil nil nil 'replace))
259 (advice-remove 'ask-user-about-supersession-threat auast)
260 (kill-buffer buf))
261 ;; We should have prompted about the supersession threat.
262 (should asked))))
263
238 264
239;;; fileio-tests.el ends here 265;;; fileio-tests.el ends here