Prefer ert-with-temp-(directory|file) in most remaining tests

* test/lisp/auth-source-tests.el (auth-source-test-searches):
* test/lisp/autorevert-tests.el (auto-revert-test00-auto-revert-mode)
(auto-revert-test01-auto-revert-several-files)
(auto-revert-test02-auto-revert-deleted-file)
(auto-revert-test03-auto-revert-tail-mode)
(auto-revert-test04-auto-revert-mode-dired)
(auto-revert-test05-global-notify)
(auto-revert-test06-write-file)
(auto-revert-test07-auto-revert-several-buffers):
* test/lisp/calendar/icalendar-tests.el (icalendar-tests--do-test-cycle):
* test/lisp/custom-tests.el (custom-theme--load-path):
* test/lisp/dired-aux-tests.el (dired-test-bug27496)
(with-dired-bug28834-test):
* test/lisp/emacs-lisp/bytecomp-tests.el (test-byte-comp-compile-and-load)
(bytecomp-tests--dest-mountpoint)
(bytecomp-tests--target-file-no-directory):
* test/lisp/emacs-lisp/gv-tests.el (gv-tests--in-temp-dir):
* test/lisp/eshell/eshell-tests.el (with-temp-eshell)
(eshell-test-command-result):
* test/lisp/info-xref-tests.el (info-xref-test-makeinfo):
* test/lisp/vc/vc-tests.el (vc-test--create-repo)
(vc-test--register, vc-test--state, vc-test--working-revision)
(vc-test--checkout-model, vc-test--rename-file)
(vc-test--version-diff):
* test/src/buffer-tests.el (test-kill-buffer-auto-save-delete):
* test/src/comp-tests.el (comp-tests-bootstrap):
* test/src/process-tests.el (process-test-quoted-batfile): Prefer
'ert-with-temp-(directory|file)' to using 'make-temp-file' directly.
This commit is contained in:
Stefan Kangas 2021-11-08 01:21:06 +01:00
parent 6fa5f0cbbc
commit cdd7589330
14 changed files with 1060 additions and 1114 deletions

View file

@ -693,24 +693,19 @@ byte-compiled. Run with dynamic binding."
(defun test-byte-comp-compile-and-load (compile &rest forms)
(declare (indent 1))
(let ((elfile nil)
(elcfile nil))
(unwind-protect
(progn
(setf elfile (make-temp-file "test-bytecomp" nil ".el"))
(when compile
(setf elcfile (make-temp-file "test-bytecomp" nil ".elc")))
(with-temp-buffer
(dolist (form forms)
(print form (current-buffer)))
(write-region (point-min) (point-max) elfile nil 'silent))
(if compile
(let ((byte-compile-dest-file-function
(lambda (e) elcfile)))
(byte-compile-file elfile)))
(load elfile nil 'nomessage))
(when elfile (delete-file elfile))
(when elcfile (delete-file elcfile)))))
(ert-with-temp-file elfile
:suffix ".el"
(ert-with-temp-file elcfile
:suffix ".elc"
(with-temp-buffer
(dolist (form forms)
(print form (current-buffer)))
(write-region (point-min) (point-max) elfile nil 'silent))
(if compile
(let ((byte-compile-dest-file-function
(lambda (e) elcfile)))
(byte-compile-file elfile)))
(load elfile nil 'nomessage))))
(ert-deftest test-byte-comp-macro-expansion ()
(test-byte-comp-compile-and-load t
@ -1245,25 +1240,21 @@ literals (Bug#20852)."
(ert-deftest bytecomp-tests--not-writable-directory ()
"Test that byte compilation works if the output directory isn't
writable (Bug#44631)."
(let ((directory (make-temp-file "bytecomp-tests-" :directory)))
(unwind-protect
(let* ((input-file (expand-file-name "test.el" directory))
(output-file (expand-file-name "test.elc" directory))
(byte-compile-dest-file-function
(lambda (_) output-file))
(byte-compile-error-on-warn t))
(write-region "" nil input-file nil nil nil 'excl)
(write-region "" nil output-file nil nil nil 'excl)
(set-file-modes input-file #o400)
(set-file-modes output-file #o200)
(set-file-modes directory #o500)
(should (byte-compile-file input-file))
(should (file-regular-p output-file))
(should (cl-plusp (file-attribute-size
(file-attributes output-file)))))
(with-demoted-errors "Error cleaning up directory: %s"
(set-file-modes directory #o700)
(delete-directory directory :recursive)))))
(ert-with-temp-directory directory
(let* ((input-file (expand-file-name "test.el" directory))
(output-file (expand-file-name "test.elc" directory))
(byte-compile-dest-file-function
(lambda (_) output-file))
(byte-compile-error-on-warn t))
(write-region "" nil input-file nil nil nil 'excl)
(write-region "" nil output-file nil nil nil 'excl)
(set-file-modes input-file #o400)
(set-file-modes output-file #o200)
(set-file-modes directory #o500)
(should (byte-compile-file input-file))
(should (file-regular-p output-file))
(should (cl-plusp (file-attribute-size
(file-attributes output-file)))))))
(ert-deftest bytecomp-tests--dest-mountpoint ()
"Test that byte compilation works if the destination file is a
@ -1275,56 +1266,49 @@ mountpoint (Bug#44631)."
(skip-unless (not (file-remote-p bwrap)))
(skip-unless (file-executable-p emacs))
(skip-unless (not (file-remote-p emacs)))
(let ((directory (make-temp-file "bytecomp-tests-" :directory)))
(unwind-protect
(let* ((input-file (expand-file-name "test.el" directory))
(output-file (expand-file-name "test.elc" directory))
(unquoted-file (file-name-unquote output-file))
(byte-compile-dest-file-function
(lambda (_) output-file))
(byte-compile-error-on-warn t))
(should-not (file-remote-p input-file))
(should-not (file-remote-p output-file))
(write-region "" nil input-file nil nil nil 'excl)
(write-region "" nil output-file nil nil nil 'excl)
(set-file-modes input-file #o400)
(set-file-modes output-file #o200)
(set-file-modes directory #o500)
(with-temp-buffer
(let ((status (call-process
bwrap nil t nil
"--ro-bind" "/" "/"
"--bind" unquoted-file unquoted-file
emacs "--quick" "--batch" "--load=bytecomp"
(format "--eval=%S"
`(setq byte-compile-dest-file-function
(lambda (_) ,output-file)
byte-compile-error-on-warn t))
"--funcall=batch-byte-compile" input-file)))
(unless (eql status 0)
(ert-fail `((status . ,status)
(output . ,(buffer-string)))))))
(should (file-regular-p output-file))
(should (cl-plusp (file-attribute-size
(file-attributes output-file)))))
(with-demoted-errors "Error cleaning up directory: %s"
(set-file-modes directory #o700)
(delete-directory directory :recursive))))))
(ert-with-temp-directory directory
(let* ((input-file (expand-file-name "test.el" directory))
(output-file (expand-file-name "test.elc" directory))
(unquoted-file (file-name-unquote output-file))
(byte-compile-dest-file-function
(lambda (_) output-file))
(byte-compile-error-on-warn t))
(should-not (file-remote-p input-file))
(should-not (file-remote-p output-file))
(write-region "" nil input-file nil nil nil 'excl)
(write-region "" nil output-file nil nil nil 'excl)
(set-file-modes input-file #o400)
(set-file-modes output-file #o200)
(set-file-modes directory #o500)
(with-temp-buffer
(let ((status (call-process
bwrap nil t nil
"--ro-bind" "/" "/"
"--bind" unquoted-file unquoted-file
emacs "--quick" "--batch" "--load=bytecomp"
(format "--eval=%S"
`(setq byte-compile-dest-file-function
(lambda (_) ,output-file)
byte-compile-error-on-warn t))
"--funcall=batch-byte-compile" input-file)))
(unless (eql status 0)
(ert-fail `((status . ,status)
(output . ,(buffer-string)))))))
(should (file-regular-p output-file))
(should (cl-plusp (file-attribute-size
(file-attributes output-file))))))))
(ert-deftest bytecomp-tests--target-file-no-directory ()
"Check that Bug#45287 is fixed."
(let ((directory (make-temp-file "bytecomp-tests-" :directory)))
(unwind-protect
(let* ((default-directory directory)
(byte-compile-dest-file-function (lambda (_) "test.elc"))
(byte-compile-error-on-warn t))
(write-region "" nil "test.el" nil nil nil 'excl)
(should (byte-compile-file "test.el"))
(should (file-regular-p "test.elc"))
(should (cl-plusp (file-attribute-size
(file-attributes "test.elc")))))
(with-demoted-errors "Error cleaning up directory: %s"
(delete-directory directory :recursive)))))
(ert-with-temp-directory directory
(let* ((default-directory directory)
(byte-compile-dest-file-function (lambda (_) "test.elc"))
(byte-compile-error-on-warn t))
(write-region "" nil "test.el" nil nil nil 'excl)
(should (byte-compile-file "test.el"))
(should (file-regular-p "test.elc"))
(should (cl-plusp (file-attribute-size
(file-attributes "test.elc")))))))
(defun bytecomp-tests--get-vars ()
(list (ignore-errors (symbol-value 'bytecomp-tests--var1))

View file

@ -21,22 +21,21 @@
(require 'edebug)
(require 'ert)
(require 'ert-x)
(eval-when-compile (require 'cl-lib))
(cl-defmacro gv-tests--in-temp-dir ((elvar elcvar)
(&rest filebody)
&rest body)
(declare (indent 2))
`(let ((default-directory (make-temp-file "gv-test" t)))
(unwind-protect
(let ((,elvar "gv-test-deffoo.el")
(,elcvar "gv-test-deffoo.elc"))
(with-temp-file ,elvar
(insert ";; -*- lexical-binding: t; -*-\n")
(dolist (form ',filebody)
(pp form (current-buffer))))
,@body)
(delete-directory default-directory t))))
`(ert-with-temp-directory default-directory
(let ((,elvar "gv-test-deffoo.el")
(,elcvar "gv-test-deffoo.elc"))
(with-temp-file ,elvar
(insert ";; -*- lexical-binding: t; -*-\n")
(dolist (form ',filebody)
(pp form (current-buffer))))
,@body)))
(ert-deftest gv-define-expander-in-file ()
(gv-tests--in-temp-dir (el elc)