On Thu, May 2, 2019 at 4:50 AM Michael Albinus wrote: > Jonathan Tomer writes: > > Hi Jonathan, > > > +(ert-deftest tramp-test46-file-precious-flag () > > Since this belongs rather to write-region, I would call it > `tramp-test10-write-region-file-precious-flag', and move it to the > repsective place in file. > > > + "Check that file-precious-flag is respected with Tramp in use." > > + (let* ((temp-file (make-temp-file "emacs")) > > + (remote-file (concat "/mock:localhost:" temp-file)) > > Please don't do this. The mock method does not work everywhere, for > example on an MS Windows machine. > > `file-precious-flag' is handled in the tramp-sh.el handler only. So you > might start with the test `tramp--test-sh-p', and skip otherwise. > > And then you could use the same mechanism like in the other > tests. Something like this: > > --8<---------------cut here---------------start------------->8--- > (ert-deftest tramp-test10-write-region-file-precious-flag () > "Check that `file-precious-flag' is respected with Tramp in use." > (skip-unless (tramp--test-enabled)) > (skip-unless (tramp--test-sh-p)) > > (let ((tmp-name (tramp--test-make-temp-name)) > (advice (lambda (_start _end filename &rest r) > (should-not (string= filename tmp-name))))) > > (unwind-protect > (with-current-buffer (find-file-noselect tmp-name) > ;; Write initial contents. Adapt `visited-file-modtime' > ;; in order to suppress confirmation. > (insert "foo") > (write-region nil nil tmp-name) > (set-visited-file-modtime) > ;; Run the test. > (advice-add 'write-region :before advice) > (setq-local file-precious-flag t) > (insert "bar") > (should (null (save-buffer)))) > > ;; Cleanup. > (ignore-errors (advice-remove 'write-region advice)) > (ignore-errors (delete-file tmp-name))))) > --8<---------------cut here---------------end--------------->8--- > > I haven't tested further, this gives an error for me. Don't know yet, > whether it is the test definition, or (more likely) a problem in Tramp. > Changing let to let* fixes the test. New patch incoming. > > Best regards, Michael. >