From 3c053ef14248742726e4a44dc4a809874ce76c72 Mon Sep 17 00:00:00 2001
From: Lars Ingebrigtsen <larsi@gnus.org>
Date: Sat, 14 Aug 2021 15:50:55 +0200
Subject: Filter out -L foo labels in diff-hunk-file-names

* lisp/vc/diff-mode.el (diff-hunk-file-names): Filter out "-L foo"
labels (bug#10160).
---
 test/lisp/vc/diff-mode-tests.el | 12 ++++++++++++
 1 file changed, 12 insertions(+)

(limited to 'test/lisp/vc/diff-mode-tests.el')

diff --git a/test/lisp/vc/diff-mode-tests.el b/test/lisp/vc/diff-mode-tests.el
index 5bc4ad6dace..521865906e7 100644
--- a/test/lisp/vc/diff-mode-tests.el
+++ b/test/lisp/vc/diff-mode-tests.el
@@ -468,4 +468,16 @@ baz"))))
                        (114 131 (diff-mode syntax face font-lock-string-face))
                        (134 140 (diff-mode syntax face font-lock-keyword-face))))))))
 
+(ert-deftest test-hunk-file-names ()
+  (with-temp-buffer
+    (insert "diff -c /tmp/ange-ftp13518wvE.el /tmp/ange-ftp1351895K.el\n")
+    (goto-char (point-min))
+    (should (equal (diff-hunk-file-names)
+                   '("/tmp/ange-ftp1351895K.el" "/tmp/ange-ftp13518wvE.el"))))
+  (with-temp-buffer
+    (insert "diff -c -L /ftp\:slbhao\:/home/albinus/src/tramp/lisp/tramp.el -L /ftp\:slbhao\:/home/albinus/src/emacs/lisp/net/tramp.el /tmp/ange-ftp13518wvE.el /tmp/ange-ftp1351895K.el\n")
+    (goto-char (point-min))
+    (should (equal (diff-hunk-file-names)
+                   '("/tmp/ange-ftp1351895K.el" "/tmp/ange-ftp13518wvE.el")))))
+
 (provide 'diff-mode-tests)
-- 
cgit v1.2.3


From 343dc9d41524cebfc88511a88df3969dbd766022 Mon Sep 17 00:00:00 2001
From: Mattias Engdegård <mattiase@acm.org>
Date: Mon, 16 Aug 2021 11:37:19 +0200
Subject: ; * test/lisp/vc/diff-mode-tests.el: Remove useless \

---
 test/lisp/vc/diff-mode-tests.el | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'test/lisp/vc/diff-mode-tests.el')

diff --git a/test/lisp/vc/diff-mode-tests.el b/test/lisp/vc/diff-mode-tests.el
index 521865906e7..fefe50d5173 100644
--- a/test/lisp/vc/diff-mode-tests.el
+++ b/test/lisp/vc/diff-mode-tests.el
@@ -475,7 +475,7 @@ baz"))))
     (should (equal (diff-hunk-file-names)
                    '("/tmp/ange-ftp1351895K.el" "/tmp/ange-ftp13518wvE.el"))))
   (with-temp-buffer
-    (insert "diff -c -L /ftp\:slbhao\:/home/albinus/src/tramp/lisp/tramp.el -L /ftp\:slbhao\:/home/albinus/src/emacs/lisp/net/tramp.el /tmp/ange-ftp13518wvE.el /tmp/ange-ftp1351895K.el\n")
+    (insert "diff -c -L /ftp:slbhao:/home/albinus/src/tramp/lisp/tramp.el -L /ftp:slbhao:/home/albinus/src/emacs/lisp/net/tramp.el /tmp/ange-ftp13518wvE.el /tmp/ange-ftp1351895K.el\n")
     (goto-char (point-min))
     (should (equal (diff-hunk-file-names)
                    '("/tmp/ange-ftp1351895K.el" "/tmp/ange-ftp13518wvE.el")))))
-- 
cgit v1.2.3


From 8bb28e740dd2cc8058d7833dd60b0ef9a8765c1b Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Sun, 26 Sep 2021 01:53:56 +0200
Subject: ; Minor stylistic checkdoc fixes in test/**/*.el

---
 test/lisp/autorevert-tests.el                      |  2 +-
 test/lisp/calc/calc-tests.el                       |  4 +--
 test/lisp/calculator-tests.el                      |  2 +-
 test/lisp/calendar/cal-french-tests.el             |  1 +
 test/lisp/calendar/icalendar-tests.el              |  2 +-
 test/lisp/calendar/solar-tests.el                  |  4 +++
 test/lisp/calendar/todo-mode-tests.el              |  2 +-
 test/lisp/cedet/semantic-utest-c.el                |  2 +-
 test/lisp/cedet/semantic-utest-ia.el               |  2 +-
 test/lisp/cedet/semantic-utest.el                  |  7 +++--
 test/lisp/cedet/semantic/fw-tests.el               |  2 +-
 test/lisp/comint-tests.el                          |  4 +--
 test/lisp/cus-edit-tests.el                        |  2 +-
 test/lisp/dabbrev-tests.el                         |  2 ++
 test/lisp/descr-text-tests.el                      |  2 +-
 test/lisp/dired-aux-tests.el                       |  2 +-
 test/lisp/dired-tests.el                           |  2 +-
 test/lisp/dired-x-tests.el                         |  2 +-
 test/lisp/electric-tests.el                        |  2 +-
 test/lisp/emacs-lisp/bytecomp-tests.el             |  4 +--
 test/lisp/emacs-lisp/cconv-tests.el                |  6 ++--
 .../eieio-tests/eieio-test-methodinvoke.el         | 20 +++++++-----
 .../emacs-lisp/eieio-tests/eieio-test-persist.el   |  6 ++--
 test/lisp/emacs-lisp/eieio-tests/eieio-tests.el    | 10 +++---
 .../faceup-test-this-file-directory.el             |  2 +-
 test/lisp/emacs-lisp/generator-tests.el            |  2 +-
 test/lisp/emacs-lisp/let-alist-tests.el            |  2 +-
 test/lisp/emacs-lisp/memory-report-tests.el        |  2 ++
 test/lisp/emacs-lisp/nadvice-tests.el              |  2 +-
 .../macro-problem-package-1.0/macro-aux.el         |  2 +-
 .../macro-problem-package-1.0/macro-problem.el     |  4 +--
 .../macro-problem-package-2.0/macro-aux.el         |  4 +--
 .../macro-problem-package-2.0/macro-problem.el     |  8 ++---
 .../newer-versions/simple-single-1.4.el            |  6 ++--
 .../package-resources/signed/signed-bad-1.0.el     |  6 ++--
 .../package-resources/signed/signed-good-1.0.el    |  6 ++--
 .../package-resources/simple-depend-1.0.el         |  2 +-
 .../package-resources/simple-single-1.3.el         |  6 ++--
 .../package-resources/simple-two-depend-1.1.el     |  2 +-
 test/lisp/emacs-lisp/package-tests.el              |  2 +-
 test/lisp/emacs-lisp/regexp-opt-tests.el           |  2 +-
 test/lisp/emacs-lisp/rx-tests.el                   |  4 +++
 test/lisp/emacs-lisp/shortdoc-tests.el             |  4 +++
 .../emacs-lisp/testcover-resources/testcases.el    | 10 +++---
 test/lisp/emacs-lisp/unsafep-tests.el              |  2 +-
 test/lisp/erc/erc-tests.el                         |  2 ++
 test/lisp/erc/erc-track-tests.el                   |  2 ++
 test/lisp/eshell/eshell-tests.el                   |  2 +-
 test/lisp/faces-resources/faces-test-dark-theme.el |  2 +-
 .../lisp/faces-resources/faces-test-light-theme.el |  2 +-
 test/lisp/faces-tests.el                           |  2 +-
 test/lisp/gnus/gnus-search-tests.el                |  2 +-
 test/lisp/gnus/gnus-util-tests.el                  |  2 +-
 test/lisp/gnus/message-tests.el                    |  2 +-
 test/lisp/htmlfontify-tests.el                     |  2 +-
 test/lisp/ibuffer-tests.el                         |  2 +-
 test/lisp/info-xref-tests.el                       |  2 +-
 test/lisp/international/ccl-tests.el               |  2 ++
 test/lisp/jit-lock-tests.el                        |  2 ++
 test/lisp/kmacro-tests.el                          |  2 +-
 test/lisp/mail/rmail-tests.el                      |  2 +-
 test/lisp/mail/rmailmm-tests.el                    |  2 +-
 test/lisp/mail/uudecode-tests.el                   |  4 +--
 test/lisp/net/shr-tests.el                         |  2 +-
 test/lisp/net/socks-tests.el                       |  2 +-
 test/lisp/net/tramp-tests.el                       |  2 +-
 test/lisp/newcomment-tests.el                      |  4 +--
 test/lisp/org/org-tests.el                         |  2 ++
 test/lisp/play/cookie1-tests.el                    |  2 +-
 test/lisp/progmodes/elisp-mode-tests.el            | 36 +++++++++++-----------
 test/lisp/progmodes/etags-tests.el                 |  2 ++
 test/lisp/progmodes/flymake-tests.el               |  2 +-
 test/lisp/progmodes/gdb-mi-tests.el                |  4 +++
 test/lisp/progmodes/opascal-tests.el               |  2 ++
 test/lisp/progmodes/pascal-tests.el                |  4 +++
 test/lisp/progmodes/sql-tests.el                   |  2 +-
 test/lisp/ps-print-tests.el                        |  2 ++
 test/lisp/saveplace-tests.el                       |  2 ++
 test/lisp/ses-tests.el                             |  2 ++
 test/lisp/shell-tests.el                           |  2 +-
 test/lisp/simple-tests.el                          |  2 +-
 test/lisp/so-long-tests/so-long-tests-helpers.el   |  4 +--
 test/lisp/tar-mode-tests.el                        |  2 +-
 test/lisp/term/tty-colors-tests.el                 |  2 +-
 test/lisp/textmodes/dns-mode-tests.el              |  2 ++
 test/lisp/thingatpt-tests.el                       |  4 +--
 test/lisp/time-stamp-tests.el                      |  6 ++--
 test/lisp/time-tests.el                            |  2 ++
 test/lisp/timezone-tests.el                        |  2 ++
 test/lisp/url/url-parse-tests.el                   |  2 +-
 test/lisp/vc/add-log-tests.el                      |  4 +--
 test/lisp/vc/diff-mode-tests.el                    |  1 +
 test/lisp/vc/smerge-mode-tests.el                  |  2 ++
 test/lisp/vc/vc-bzr-tests.el                       |  2 +-
 test/lisp/whitespace-tests.el                      |  2 +-
 test/lisp/xml-tests.el                             |  4 +--
 test/manual/biditest.el                            |  2 ++
 test/manual/cedet/ede-tests.el                     |  2 +-
 test/manual/cedet/semantic-tests.el                |  2 ++
 test/manual/cedet/tests/test.el                    | 32 +++++++++----------
 .../etags/el-src/emacs/lisp/progmodes/etags.el     |  2 +-
 test/manual/image-size-tests.el                    |  2 ++
 test/manual/image-transforms-tests.el              |  2 ++
 test/manual/redisplay-testsuite.el                 |  2 ++
 test/misc/test-custom-libs.el                      |  4 +--
 test/src/alloc-tests.el                            |  2 ++
 test/src/character-tests.el                        |  2 ++
 test/src/charset-tests.el                          |  4 ++-
 test/src/coding-tests.el                           |  2 +-
 test/src/comp-resources/comp-test-funcs.el         | 14 ++++-----
 test/src/comp-tests.el                             |  4 +--
 test/src/data-tests.el                             | 22 ++++++-------
 test/src/decompress-tests.el                       |  2 +-
 test/src/fileio-tests.el                           | 12 +++++---
 test/src/floatfns-tests.el                         |  4 +++
 test/src/fns-tests.el                              |  2 ++
 test/src/indent-tests.el                           |  2 ++
 test/src/inotify-tests.el                          |  2 +-
 test/src/lcms-tests.el                             |  4 +--
 test/src/marker-tests.el                           |  2 +-
 test/src/minibuf-tests.el                          |  4 +--
 test/src/process-tests.el                          |  2 +-
 test/src/regex-emacs-tests.el                      | 28 ++++++++---------
 test/src/textprop-tests.el                         |  2 +-
 test/src/thread-tests.el                           |  8 ++---
 test/src/timefns-tests.el                          |  2 ++
 test/src/xfaces-tests.el                           |  4 +++
 test/src/xml-tests.el                              |  2 +-
 128 files changed, 302 insertions(+), 209 deletions(-)

(limited to 'test/lisp/vc/diff-mode-tests.el')

diff --git a/test/lisp/autorevert-tests.el b/test/lisp/autorevert-tests.el
index a04610089c0..d0c52f6103f 100644
--- a/test/lisp/autorevert-tests.el
+++ b/test/lisp/autorevert-tests.el
@@ -688,4 +688,4 @@ This expects `auto-revert--messages' to be bound by
     (ert-run-tests-batch "^auto-revert-")))
 
 (provide 'auto-revert-tests)
-;;; auto-revert-tests.el ends here
+;;; autorevert-tests.el ends here
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el
index 13dd228d3b3..8a78a068242 100644
--- a/test/lisp/calc/calc-tests.el
+++ b/test/lisp/calc/calc-tests.el
@@ -53,7 +53,7 @@ A and B should be calc expressions."
 
 (defun calc-tests-simple (fun string &rest args)
   "Push STRING on the calc stack, then call FUN and return the new top.
-The result is a calc (i.e., lisp) expression, not its string representation.
+The result is a calc (i.e., Lisp) expression, not its string representation.
 Also pop the entire stack afterwards.
 An existing calc stack is reused, otherwise a new one is created."
   (calc-eval string 'push)
@@ -448,7 +448,7 @@ An existing calc stack is reused, otherwise a new one is created."
     ;; Generalisation for any n, integral k≥0: use falling product
     (/ (apply '* (number-sequence n (- n (1- k)) -1))
        (calc-tests--fac k)))
-   (t (error "case not covered"))))
+   (t (error "Case not covered"))))
 
 (defun calc-tests--calc-to-number (x)
   "Convert a Calc object to a Lisp number."
diff --git a/test/lisp/calculator-tests.el b/test/lisp/calculator-tests.el
index 9551b1a4c61..f24ca97310c 100644
--- a/test/lisp/calculator-tests.el
+++ b/test/lisp/calculator-tests.el
@@ -48,4 +48,4 @@
          (should (equal (calculator-string-to-number str) expected)))))))
 
 (provide 'calculator-tests)
-;; calculator-tests.el ends here
+;;; calculator-tests.el ends here
diff --git a/test/lisp/calendar/cal-french-tests.el b/test/lisp/calendar/cal-french-tests.el
index ab62c1e6fc1..1de5dea0882 100644
--- a/test/lisp/calendar/cal-french-tests.el
+++ b/test/lisp/calendar/cal-french-tests.el
@@ -111,3 +111,4 @@
     (should (equal (calendar-french-date-string (list m d y)) str))))
 
 (provide 'cal-french-tests)
+;;; cal-french-tests.el ends here
diff --git a/test/lisp/calendar/icalendar-tests.el b/test/lisp/calendar/icalendar-tests.el
index de2a8917581..a1853ff3d4e 100644
--- a/test/lisp/calendar/icalendar-tests.el
+++ b/test/lisp/calendar/icalendar-tests.el
@@ -1636,7 +1636,7 @@ SUMMARY:NNN Wwwwwwww Wwwww - Aaaaaa Pppppppp rrrrrr ddd oo Nnnnnnnn 30
     (format-time-string "%FT%T%z" (encode-time time) 0)))
 
 (defun icalendar-tests--decode-isodatetime (_ical-string)
-  "Test icalendar--decode-isodatetime."
+  "Test `icalendar--decode-isodatetime'."
   (should (equal (icalendar-test--format "20040917T050910-0200")
                  "2004-09-17T03:09:10+0000"))
   (should (equal (icalendar-test--format "20040917T050910")
diff --git a/test/lisp/calendar/solar-tests.el b/test/lisp/calendar/solar-tests.el
index 337deb8ce9a..921be1d2d48 100644
--- a/test/lisp/calendar/solar-tests.el
+++ b/test/lisp/calendar/solar-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Code:
+
 (require 'ert)
 (require 'solar)
 
@@ -42,3 +44,5 @@
       (should (< (abs (- sunset 17.72)) epsilon)))))
 
 (provide 'solar-tests)
+
+;;; solar-tests.el ends here
diff --git a/test/lisp/calendar/todo-mode-tests.el b/test/lisp/calendar/todo-mode-tests.el
index 6fa2b9d7c35..0538368fc82 100644
--- a/test/lisp/calendar/todo-mode-tests.el
+++ b/test/lisp/calendar/todo-mode-tests.el
@@ -35,7 +35,7 @@
   "Todo Archive mode test file.")
 
 (defmacro with-todo-test (&rest body)
-  "Set up an isolated todo-mode test environment."
+  "Set up an isolated `todo-mode' test environment."
   (declare (debug (body)))
   `(let* ((todo-test-home (make-temp-file "todo-test-home-" t))
           ;; Since we change HOME, clear this to avoid a conflict
diff --git a/test/lisp/cedet/semantic-utest-c.el b/test/lisp/cedet/semantic-utest-c.el
index d08c79cad3e..c5eb5b0ec06 100644
--- a/test/lisp/cedet/semantic-utest-c.el
+++ b/test/lisp/cedet/semantic-utest-c.el
@@ -60,7 +60,7 @@
 	      (semantic-fetch-tags))))
       (when (or (not tags-expected) (not tags-actual))
         (message "Tried to find test files in: %s" semantic-utest-c-test-directory)
-        (error "Failed:  Discovered no tags in test files or test file not found."))
+        (error "Failed:  Discovered no tags in test files or test file not found"))
 
       ;; Now that we have the tags, compare them for SPP accuracy.
       (dolist (tag tags-actual)
diff --git a/test/lisp/cedet/semantic-utest-ia.el b/test/lisp/cedet/semantic-utest-ia.el
index 122c431d472..6ea4ca1a16a 100644
--- a/test/lisp/cedet/semantic-utest-ia.el
+++ b/test/lisp/cedet/semantic-utest-ia.el
@@ -489,4 +489,4 @@ tag that contains point, and return that."
 
 (provide 'semantic-ia-utest)
 
-;;; semantic-ia-utest.el ends here
+;;; semantic-utest-ia.el ends here
diff --git a/test/lisp/cedet/semantic-utest.el b/test/lisp/cedet/semantic-utest.el
index 172ab62f895..3e4cfb0f0cb 100644
--- a/test/lisp/cedet/semantic-utest.el
+++ b/test/lisp/cedet/semantic-utest.el
@@ -29,6 +29,8 @@
 (require 'cedet)
 (require 'semantic)
 
+;;; Code:
+
 (defvar cedet-utest-directory
   (let* ((C (file-name-directory (locate-library "cedet")))
          (D (expand-file-name "../../test/manual/cedet/" C)))
@@ -103,7 +105,7 @@ int calc_sv(int);
 (defvar semantic-utest-C-filename-h
   (concat (file-name-sans-extension semantic-utest-C-filename)
 	  ".h")
-  "Header file filename for C")
+  "Header file filename for C.")
 
 
 (defvar semantic-utest-C-name-contents
@@ -424,8 +426,7 @@ class aClass {
      nil
      (overlay 135 262 "phptest.php"))
     )
-  "Expected results from the PHP Unit test"
-  )
+  "Expected results from the PHP Unit test.")
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
diff --git a/test/lisp/cedet/semantic/fw-tests.el b/test/lisp/cedet/semantic/fw-tests.el
index 7b1cd21bd1b..6a5f3c85fc6 100644
--- a/test/lisp/cedet/semantic/fw-tests.el
+++ b/test/lisp/cedet/semantic/fw-tests.el
@@ -42,4 +42,4 @@
       ;; retrieve cached data
       (should (equal (semantic-get-cache-data 'moose) data)))))
 
-;;; gw-tests.el ends here
+;;; fw-tests.el ends here
diff --git a/test/lisp/comint-tests.el b/test/lisp/comint-tests.el
index 8a9a41f452f..19d0cca88c8 100644
--- a/test/lisp/comint-tests.el
+++ b/test/lisp/comint-tests.el
@@ -1,4 +1,4 @@
-;;; comint-tests.el  -*- lexical-binding:t -*-
+;;; comint-tests.el --- Tests for comint.el  -*- lexical-binding:t -*-
 
 ;; Copyright (C) 2010-2021 Free Software Foundation, Inc.
 
@@ -94,4 +94,4 @@ password flow if it returns a nil value."
 ;; no-byte-compile: t
 ;; End:
 
-;;; comint-testsuite.el ends here
+;;; comint-tests.el ends here
diff --git a/test/lisp/cus-edit-tests.el b/test/lisp/cus-edit-tests.el
index 97b3349000c..f7d52834370 100644
--- a/test/lisp/cus-edit-tests.el
+++ b/test/lisp/cus-edit-tests.el
@@ -37,7 +37,7 @@
 
 ;;;; showing/hiding obsolete options
 
-(defgroup cus-edit-tests nil "test"
+(defgroup cus-edit-tests nil "Test."
   :group 'test-group)
 
 (defcustom cus-edit-tests--obsolete-option-tag nil
diff --git a/test/lisp/dabbrev-tests.el b/test/lisp/dabbrev-tests.el
index 0b20dcf9213..e4b78373915 100644
--- a/test/lisp/dabbrev-tests.el
+++ b/test/lisp/dabbrev-tests.el
@@ -70,3 +70,5 @@ multiple expansions."
         ;; C-u C-u C-M-/
         (execute-kbd-macro [21 21 201326639]))
       (should (string= (buffer-string) "abc\na")))))
+
+;;; dabbrev-tests.el ends here
diff --git a/test/lisp/descr-text-tests.el b/test/lisp/descr-text-tests.el
index 2052dc0e38c..715fafa44c3 100644
--- a/test/lisp/descr-text-tests.el
+++ b/test/lisp/descr-text-tests.el
@@ -91,4 +91,4 @@
 
 (provide 'descr-text-test)
 
-;;; descr-text-test.el ends here
+;;; descr-text-tests.el ends here
diff --git a/test/lisp/dired-aux-tests.el b/test/lisp/dired-aux-tests.el
index 7f1743f88d7..d5940ed8ca7 100644
--- a/test/lisp/dired-aux-tests.el
+++ b/test/lisp/dired-aux-tests.el
@@ -159,4 +159,4 @@
     (dired-test--check-highlighting (nth 0 lines) '(8))))
 
 (provide 'dired-aux-tests)
-;; dired-aux-tests.el ends here
+;;; dired-aux-tests.el ends here
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index aac78c64c69..83f7dc3cac7 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -518,4 +518,4 @@
         (delete-directory testdir t)))))
 
 (provide 'dired-tests)
-;; dired-tests.el ends here
+;;; dired-tests.el ends here
diff --git a/test/lisp/dired-x-tests.el b/test/lisp/dired-x-tests.el
index 003923d60fa..d00815e543c 100644
--- a/test/lisp/dired-x-tests.el
+++ b/test/lisp/dired-x-tests.el
@@ -63,4 +63,4 @@
                    nil))))
 
 (provide 'dired-x-tests)
-;; dired-x-tests.el ends here
+;;; dired-x-tests.el ends here
diff --git a/test/lisp/electric-tests.el b/test/lisp/electric-tests.el
index 46bcbfce307..4e7cbf5419b 100644
--- a/test/lisp/electric-tests.el
+++ b/test/lisp/electric-tests.el
@@ -871,7 +871,7 @@ baz\"\""
     (local-set-key (vector key) 'self-insert-command)))
 
 (defun electric-layout-for-c-style-du-jour (inserted)
-  "A function to use in `electric-layout-rules'"
+  "A function to use in `electric-layout-rules'."
   (when (memq inserted '(?\{ ?\}))
     (save-excursion
       (backward-char 2) (c-point-syntax) (forward-char) ; silly, but needed
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index 14df39bfd77..448c7be6219 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -1,4 +1,4 @@
-;;; bytecomp-tests.el  -*- lexical-binding:t -*-
+;;; bytecomp-tests.el --- Tests for bytecomp.el  -*- lexical-binding:t -*-
 
 ;; Copyright (C) 2008-2021 Free Software Foundation, Inc.
 
@@ -1498,4 +1498,4 @@ EXPECTED-POINT BINDINGS (MODES \\='\\='(ruby-mode js-mode python-mode)) \
 ;; End:
 
 (provide 'bytecomp-tests)
-;; bytecomp-tests.el ends here.
+;;; bytecomp-tests.el ends here
diff --git a/test/lisp/emacs-lisp/cconv-tests.el b/test/lisp/emacs-lisp/cconv-tests.el
index 5aeed0cc155..4290571735e 100644
--- a/test/lisp/emacs-lisp/cconv-tests.el
+++ b/test/lisp/emacs-lisp/cconv-tests.el
@@ -1,4 +1,4 @@
-;;; cconv-tests.el -*- lexical-binding: t -*-
+;;; cconv-tests.el --- Tests for cconv.el  -*- lexical-binding: t -*-
 
 ;; Copyright (C) 2018-2021 Free Software Foundation, Inc.
 
@@ -19,6 +19,8 @@
 
 ;;; Commentary:
 
+;;; Code:
+
 (require 'ert)
 (require 'cl-lib)
 
@@ -204,4 +206,4 @@
           42)))
 
 (provide 'cconv-tests)
-;; cconv-tests.el ends here.
+;;; cconv-tests.el ends here
diff --git a/test/lisp/emacs-lisp/eieio-tests/eieio-test-methodinvoke.el b/test/lisp/emacs-lisp/eieio-tests/eieio-test-methodinvoke.el
index 9f9bb73133c..d1da066dc45 100644
--- a/test/lisp/emacs-lisp/eieio-tests/eieio-test-methodinvoke.el
+++ b/test/lisp/emacs-lisp/eieio-tests/eieio-test-methodinvoke.el
@@ -22,22 +22,22 @@
 
 ;;; Commentary:
 ;;
-;; Test method invocation order.  From the common lisp reference
-;; manual:
+;; Test method invocation order.  From the Common Lisp Reference
+;; Manual:
 ;;
 ;; QUOTE:
 ;; - All the :before methods are called, in most-specific-first
 ;;   order.  Their values are ignored.  An error is signaled if
 ;;   call-next-method is used in a :before method.
 ;;
-;; - The most specific primary method is called. Inside the body of a
+;; - The most specific primary method is called.  Inside the body of a
 ;;   primary method, call-next-method may be used to call the next
-;;   most specific primary method. When that method returns, the
+;;   most specific primary method.  When that method returns, the
 ;;   previous primary method can execute more code, perhaps based on
-;;   the returned value or values. The generic function no-next-method
+;;   the returned value or values.  The generic function no-next-method
 ;;   is invoked if call-next-method is used and there are no more
-;;   applicable primary methods. The function next-method-p may be
-;;   used to determine whether a next method exists. If
+;;   applicable primary methods.  The function next-method-p may be
+;;   used to determine whether a next method exists.  If
 ;;   call-next-method is not used, only the most specific primary
 ;;   method is called.
 ;;
@@ -46,12 +46,14 @@
 ;;   call-next-method is used in a :after method.
 ;;
 ;;
-;; Also test behavior of `call-next-method'. From clos.org:
+;; Also test behavior of `call-next-method'.  From clos.org:
 ;;
 ;; QUOTE:
 ;; When call-next-method is called with no arguments, it passes the
 ;; current method's original arguments to the next method.
 
+;;; Code:
+
 (require 'eieio)
 (require 'ert)
 
@@ -403,3 +405,5 @@
   (should (equal (eieio-test--1 (make-instance 'CNM-2) 5)
                  '("CNM-1-1" "CNM-1-2" "CNM-0" 7 5)))
   (should (equal (eieio-test--1 'CNM-2 6) '("subclass CNM-1-2" CNM-2 6))))
+
+;;; eieio-test-methodinvoke.el ends here
diff --git a/test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el b/test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el
index ddbef02c35a..fd044ff3734 100644
--- a/test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el
+++ b/test/lisp/emacs-lisp/eieio-tests/eieio-test-persist.el
@@ -165,9 +165,9 @@ Assume SLOTVALUE is a symbol of some sort."
   ((slot1 :initarg :slot1
 	  :initform 1)
    (slot2 :initform 2))
-  "Class for testing persistent saving of an object that isn't
-persistent.  This class is instead used as a slot value in a
-persistent class.")
+  "Class for testing persistent saving of an object that isn't persistent.
+This class is instead used as a slot value in a persistent
+class.")
 
 (defclass persistent-with-objs-slot (eieio-persistent)
   ((pnp :initarg :pnp
diff --git a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
index 3ec42343443..9eb7fb02230 100644
--- a/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
+++ b/test/lisp/emacs-lisp/eieio-tests/eieio-tests.el
@@ -48,13 +48,13 @@
 	 :type (or null class-a)
 	 :documentation "Test self referencing types.")
    )
-  "Class A")
+  "Class A.")
 
 (defclass class-b ()
   ((land :initform "Sc"
 	 :type string
 	 :documentation "Detail about land."))
-  "Class B")
+  "Class B.")
 
 (defclass class-ab (class-a class-b)
   ((amphibian :initform "frog"
@@ -160,7 +160,7 @@
   ;; error
   (should-error (abstract-class)))
 
-(defgeneric generic1 () "First generic function")
+(defgeneric generic1 () "First generic function.")
 
 (ert-deftest eieio-test-03-generics ()
   (defun anormalfunction () "A plain function for error testing." nil)
@@ -901,12 +901,12 @@ Subclasses to override slot attributes.")
 
 (defclass opt-test1 ()
   ()
-  "Abstract base class"
+  "Abstract base class."
   :abstract t)
 
 (defclass opt-test2 (opt-test1)
   ()
-  "Instantiable child")
+  "Instantiable child.")
 
 (ert-deftest eieio-test-36-build-class-alist ()
   (should (= (length (eieio-build-class-alist 'opt-test1 nil)) 2))
diff --git a/test/lisp/emacs-lisp/faceup-resources/faceup-test-this-file-directory.el b/test/lisp/emacs-lisp/faceup-resources/faceup-test-this-file-directory.el
index 3303e7b178d..9fe5fe9218d 100644
--- a/test/lisp/emacs-lisp/faceup-resources/faceup-test-this-file-directory.el
+++ b/test/lisp/emacs-lisp/faceup-resources/faceup-test-this-file-directory.el
@@ -22,7 +22,7 @@
 
 ;;; Commentary:
 
-;; Support file for `faceup-test-basics.el'. This file is used to test
+;; Support file for `faceup-test-basics.el'.  This file is used to test
 ;; `faceup-this-file-directory' in various contexts.
 
 ;;; Code:
diff --git a/test/lisp/emacs-lisp/generator-tests.el b/test/lisp/emacs-lisp/generator-tests.el
index a1b9f64fdb1..c81d3d09e7d 100644
--- a/test/lisp/emacs-lisp/generator-tests.el
+++ b/test/lisp/emacs-lisp/generator-tests.el
@@ -271,7 +271,7 @@ identical output."
                      (unwind-protect
                           (progn
                             (iter-yield 1)
-                            (error "test")
+                            (error "Test")
                             (iter-yield 2))
                        (cl-incf nr-unwound))))))
     (should (equal (iter-next iter) 1))
diff --git a/test/lisp/emacs-lisp/let-alist-tests.el b/test/lisp/emacs-lisp/let-alist-tests.el
index d856696da24..88e689c80b8 100644
--- a/test/lisp/emacs-lisp/let-alist-tests.el
+++ b/test/lisp/emacs-lisp/let-alist-tests.el
@@ -100,4 +100,4 @@ See Bug#24641."
                    `[,(+ .a) ,(+ .a .b .b)])
                  [1 5])))
 
-;;; let-alist.el ends here
+;;; let-alist-tests.el ends here
diff --git a/test/lisp/emacs-lisp/memory-report-tests.el b/test/lisp/emacs-lisp/memory-report-tests.el
index e352dd165f3..d37f09b34f2 100644
--- a/test/lisp/emacs-lisp/memory-report-tests.el
+++ b/test/lisp/emacs-lisp/memory-report-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Code:
+
 (require 'ert)
 (require 'memory-report)
 
diff --git a/test/lisp/emacs-lisp/nadvice-tests.el b/test/lisp/emacs-lisp/nadvice-tests.el
index 358d9025ad5..ee33bb0fa40 100644
--- a/test/lisp/emacs-lisp/nadvice-tests.el
+++ b/test/lisp/emacs-lisp/nadvice-tests.el
@@ -208,4 +208,4 @@ function being an around advice."
 ;; no-byte-compile: t
 ;; End:
 
-;;; advice-tests.el ends here.
+;;; nadvice-tests.el ends here
diff --git a/test/lisp/emacs-lisp/package-resources/macro-problem-package-1.0/macro-aux.el b/test/lisp/emacs-lisp/package-resources/macro-problem-package-1.0/macro-aux.el
index f43232224af..ad20a3507a6 100644
--- a/test/lisp/emacs-lisp/package-resources/macro-problem-package-1.0/macro-aux.el
+++ b/test/lisp/emacs-lisp/package-resources/macro-problem-package-1.0/macro-aux.el
@@ -5,7 +5,7 @@
 ;;; Code:
 
 (defun macro-aux-1 ( &rest forms)
-  "Description"
+  "Description."
   `(progn ,@forms))
 
 (provide 'macro-aux)
diff --git a/test/lisp/emacs-lisp/package-resources/macro-problem-package-1.0/macro-problem.el b/test/lisp/emacs-lisp/package-resources/macro-problem-package-1.0/macro-problem.el
index 0533b1bd9c4..6e5e54e54fd 100644
--- a/test/lisp/emacs-lisp/package-resources/macro-problem-package-1.0/macro-problem.el
+++ b/test/lisp/emacs-lisp/package-resources/macro-problem-package-1.0/macro-problem.el
@@ -9,11 +9,11 @@
 (require 'macro-aux)
 
 (defmacro macro-problem-1 ( &rest forms)
-  "Description"
+  "Description."
   `(progn ,@forms))
 
 (defun macro-problem-func ()
-  ""
+  "Description."
   (macro-problem-1 'a 'b)
   (macro-aux-1 'a 'b))
 
diff --git a/test/lisp/emacs-lisp/package-resources/macro-problem-package-2.0/macro-aux.el b/test/lisp/emacs-lisp/package-resources/macro-problem-package-2.0/macro-aux.el
index 6a55a40e3b4..814d77183ab 100644
--- a/test/lisp/emacs-lisp/package-resources/macro-problem-package-2.0/macro-aux.el
+++ b/test/lisp/emacs-lisp/package-resources/macro-problem-package-2.0/macro-aux.el
@@ -5,11 +5,11 @@
 ;;; Code:
 
 (defmacro macro-aux-1 ( &rest forms)
-  "Description"
+  "Description."
   `(progn ,@forms))
 
 (defmacro macro-aux-3 ( &rest _)
-  "Description"
+  "Description."
   90)
 
 (provide 'macro-aux)
diff --git a/test/lisp/emacs-lisp/package-resources/macro-problem-package-2.0/macro-problem.el b/test/lisp/emacs-lisp/package-resources/macro-problem-package-2.0/macro-problem.el
index cad4ed93f19..aef5eda7c6c 100644
--- a/test/lisp/emacs-lisp/package-resources/macro-problem-package-2.0/macro-problem.el
+++ b/test/lisp/emacs-lisp/package-resources/macro-problem-package-2.0/macro-problem.el
@@ -9,21 +9,21 @@
 (require 'macro-aux)
 
 (defmacro macro-problem-1 ( &rest forms)
-  "Description"
+  "Description."
   `(progn ,(cadr (car forms))))
 
 
 (defun macro-problem-func ()
-  ""
+  "Description."
   (list (macro-problem-1 '1 'b)
         (macro-aux-1 'a 'b)))
 
 (defmacro macro-problem-3 (&rest _)
-  "Description"
+  "Description."
   10)
 
 (defun macro-problem-10-and-90 ()
-  ""
+  "Description."
   (list (macro-problem-3 haha) (macro-aux-3 hehe)))
 
 (provide 'macro-problem)
diff --git a/test/lisp/emacs-lisp/package-resources/newer-versions/simple-single-1.4.el b/test/lisp/emacs-lisp/package-resources/newer-versions/simple-single-1.4.el
index 301993deb30..be6bedf8a1c 100644
--- a/test/lisp/emacs-lisp/package-resources/newer-versions/simple-single-1.4.el
+++ b/test/lisp/emacs-lisp/package-resources/newer-versions/simple-single-1.4.el
@@ -7,14 +7,14 @@
 ;;; Commentary:
 
 ;; This package provides a minor mode to frobnicate and/or bifurcate
-;; any flanges you desire. To activate it, type "C-M-r M-3 butterfly"
+;; any flanges you desire.  To activate it, type "C-M-r M-3 butterfly"
 ;; and all your dreams will come true.
 ;;
 ;; This is a new, updated version.
 
 ;;; Code:
 
-(defgroup simple-single nil "Simply a file"
+(defgroup simple-single nil "Simply a file."
   :group 'lisp)
 
 (defcustom simple-single-super-sunday nil
@@ -29,7 +29,7 @@ Default changed to nil."
 
 ;;;###autoload
 (define-minor-mode simple-single-mode
-  "It does good things to stuff")
+  "It does good things to stuff.")
 
 (provide 'simple-single)
 
diff --git a/test/lisp/emacs-lisp/package-resources/signed/signed-bad-1.0.el b/test/lisp/emacs-lisp/package-resources/signed/signed-bad-1.0.el
index ff070c6526f..781077251e9 100644
--- a/test/lisp/emacs-lisp/package-resources/signed/signed-bad-1.0.el
+++ b/test/lisp/emacs-lisp/package-resources/signed/signed-bad-1.0.el
@@ -8,12 +8,12 @@
 ;;; Commentary:
 
 ;; This package provides a minor mode to frobnicate and/or bifurcate
-;; any flanges you desire. To activate it, type "C-M-r M-3 butterfly"
+;; any flanges you desire.  To activate it, type "C-M-r M-3 butterfly"
 ;; and all your dreams will come true.
 
 ;;; Code:
 
-(defgroup signed-bad nil "Simply a file"
+(defgroup signed-bad nil "Simply a file."
   :group 'lisp)
 
 (defcustom signed-bad-super-sunday t
@@ -26,7 +26,7 @@
 
 ;;;###autoload
 (define-minor-mode signed-bad-mode
-  "It does good things to stuff")
+  "It does good things to stuff.")
 
 (provide 'signed-bad)
 
diff --git a/test/lisp/emacs-lisp/package-resources/signed/signed-good-1.0.el b/test/lisp/emacs-lisp/package-resources/signed/signed-good-1.0.el
index 60b1b8663d9..8a408c1f301 100644
--- a/test/lisp/emacs-lisp/package-resources/signed/signed-good-1.0.el
+++ b/test/lisp/emacs-lisp/package-resources/signed/signed-good-1.0.el
@@ -8,12 +8,12 @@
 ;;; Commentary:
 
 ;; This package provides a minor mode to frobnicate and/or bifurcate
-;; any flanges you desire. To activate it, type "C-M-r M-3 butterfly"
+;; any flanges you desire.  To activate it, type "C-M-r M-3 butterfly"
 ;; and all your dreams will come true.
 
 ;;; Code:
 
-(defgroup signed-good nil "Simply a file"
+(defgroup signed-good nil "Simply a file."
   :group 'lisp)
 
 (defcustom signed-good-super-sunday t
@@ -26,7 +26,7 @@
 
 ;;;###autoload
 (define-minor-mode signed-good-mode
-  "It does good things to stuff")
+  "It does good things to stuff.")
 
 (provide 'signed-good)
 
diff --git a/test/lisp/emacs-lisp/package-resources/simple-depend-1.0.el b/test/lisp/emacs-lisp/package-resources/simple-depend-1.0.el
index cb003905bb5..f1ee8627610 100644
--- a/test/lisp/emacs-lisp/package-resources/simple-depend-1.0.el
+++ b/test/lisp/emacs-lisp/package-resources/simple-depend-1.0.el
@@ -12,6 +12,6 @@
 ;;; Code:
 
 (defvar simple-depend "Value"
-  "Some trivial code")
+  "Some trivial code.")
 
 ;;; simple-depend.el ends here
diff --git a/test/lisp/emacs-lisp/package-resources/simple-single-1.3.el b/test/lisp/emacs-lisp/package-resources/simple-single-1.3.el
index 9c3f427ff48..459801d78cf 100644
--- a/test/lisp/emacs-lisp/package-resources/simple-single-1.3.el
+++ b/test/lisp/emacs-lisp/package-resources/simple-single-1.3.el
@@ -8,12 +8,12 @@
 ;;; Commentary:
 
 ;; This package provides a minor mode to frobnicate and/or bifurcate
-;; any flanges you desire. To activate it, type "C-M-r M-3 butterfly"
+;; any flanges you desire.  To activate it, type "C-M-r M-3 butterfly"
 ;; and all your dreams will come true.
 
 ;;; Code:
 
-(defgroup simple-single nil "Simply a file"
+(defgroup simple-single nil "Simply a file."
   :group 'lisp)
 
 (defcustom simple-single-super-sunday t
@@ -26,7 +26,7 @@
 
 ;;;###autoload
 (define-minor-mode simple-single-mode
-  "It does good things to stuff")
+  "It does good things to stuff.")
 
 (provide 'simple-single)
 
diff --git a/test/lisp/emacs-lisp/package-resources/simple-two-depend-1.1.el b/test/lisp/emacs-lisp/package-resources/simple-two-depend-1.1.el
index a0a9607350a..8de6141d67a 100644
--- a/test/lisp/emacs-lisp/package-resources/simple-two-depend-1.1.el
+++ b/test/lisp/emacs-lisp/package-resources/simple-two-depend-1.1.el
@@ -12,6 +12,6 @@
 ;;; Code:
 
 (defvar simple-two-depend "Value"
-  "Some trivial code")
+  "Some trivial code.")
 
 ;;; simple-two-depend.el ends here
diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el
index 77bc8117cf2..1fd93bc1be7 100644
--- a/test/lisp/emacs-lisp/package-tests.el
+++ b/test/lisp/emacs-lisp/package-tests.el
@@ -180,7 +180,7 @@
   (replace-regexp-in-string "-pkg\\.el\\'" "" (package--description-file dir)))
 
 (defun package-test-suffix-matches (base suffix-list)
-  "Return file names matching BASE concatenated with each item in SUFFIX-LIST"
+  "Return file names matching BASE concatenated with each item in SUFFIX-LIST."
   (mapcan (lambda (item) (file-expand-wildcards (concat base item)))
           suffix-list))
 
diff --git a/test/lisp/emacs-lisp/regexp-opt-tests.el b/test/lisp/emacs-lisp/regexp-opt-tests.el
index 940feb5e828..65494e20df6 100644
--- a/test/lisp/emacs-lisp/regexp-opt-tests.el
+++ b/test/lisp/emacs-lisp/regexp-opt-tests.el
@@ -66,4 +66,4 @@
 
   (should (equal (regexp-opt-charset '()) regexp-unmatchable)))
 
-;;; regexp-tests.el ends here.
+;;; regexp-opt-tests.el ends here
diff --git a/test/lisp/emacs-lisp/rx-tests.el b/test/lisp/emacs-lisp/rx-tests.el
index 4828df0de92..3bc35feb6dd 100644
--- a/test/lisp/emacs-lisp/rx-tests.el
+++ b/test/lisp/emacs-lisp/rx-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Code:
+
 (require 'ert)
 (require 'rx)
 
@@ -583,3 +585,5 @@
            "\\(?3:.+$\\)")))
 
 (provide 'rx-tests)
+
+;;; rx-tests.el ends here
diff --git a/test/lisp/emacs-lisp/shortdoc-tests.el b/test/lisp/emacs-lisp/shortdoc-tests.el
index 3bb3185649b..cfb0b4244bc 100644
--- a/test/lisp/emacs-lisp/shortdoc-tests.el
+++ b/test/lisp/emacs-lisp/shortdoc-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Code:
+
 (require 'ert)
 (require 'shortdoc)
 
@@ -43,3 +45,5 @@
             (setq props (cddr props))))))))
 
 (provide 'shortdoc-tests)
+
+;;; shortdoc-tests.el ends here
diff --git a/test/lisp/emacs-lisp/testcover-resources/testcases.el b/test/lisp/emacs-lisp/testcover-resources/testcases.el
index 7ced257c6f9..29094526d7e 100644
--- a/test/lisp/emacs-lisp/testcover-resources/testcases.el
+++ b/test/lisp/emacs-lisp/testcover-resources/testcases.el
@@ -77,12 +77,12 @@
 "Testcover doesn't prevent testing of defcustom values."
 ;; ====
 (defgroup testcover-testcase nil
-  "Test case for testcover"
+  "Test case for testcover."
   :group 'lisp
   :prefix "testcover-testcase-"
   :version "26.0")
 (defcustom testcover-testcase-flag t
-  "Test value used by testcover-tests.el"
+  "Test value used by testcover-tests.el."
   :type 'boolean
   :group 'testcover-testcase)
 (defun testcover-testcase-get-flag ()
@@ -111,7 +111,7 @@
 "Wrapping a form with noreturn prevents splotching."
 ;; ====
 (defun testcover-testcase-cancel (spacecraft)
-  (error "no destination for %s" spacecraft))
+  (error "No destination for %s" spacecraft))
 (defun testcover-testcase-launch (spacecraft planet)
   (if (null planet)
       (noreturn (testcover-testcase-cancel spacecraft%%%))
@@ -220,7 +220,7 @@
 (defun testcover-testcase-cc (arg)
   (condition-case nil
       (if (null arg%%%)%%%
-        (error "foo")
+        (error "Foo")
         "0")!!!
         (error nil)))
 (should-not (testcover-testcase-cc nil))
@@ -510,4 +510,4 @@ regarding the odd-looking coverage result for the quoted form."
 (testcover-testcase-cyc2 1 2)
 (testcover-testcase-cyc2 1 4)
 
-;; testcases.el ends here.
+;;; testcases.el ends here
diff --git a/test/lisp/emacs-lisp/unsafep-tests.el b/test/lisp/emacs-lisp/unsafep-tests.el
index b2a48d80675..f0d9b032438 100644
--- a/test/lisp/emacs-lisp/unsafep-tests.el
+++ b/test/lisp/emacs-lisp/unsafep-tests.el
@@ -105,7 +105,7 @@
       . (variable (x)))
     ( (let (1) 2)
       . (variable 1))
-    ( (error "asdf")
+    ( (error "Asdf")
       . #'error)
     ( (signal 'error "asdf")
       . #'signal)
diff --git a/test/lisp/erc/erc-tests.el b/test/lisp/erc/erc-tests.el
index 22f62a35c7e..6ed26f68289 100644
--- a/test/lisp/erc/erc-tests.el
+++ b/test/lisp/erc/erc-tests.el
@@ -227,3 +227,5 @@
   (when noninteractive
     (kill-buffer "*erc-protocol*")
     (should-not erc-debug-irc-protocol)))
+
+;;; erc-tests.el ends here
diff --git a/test/lisp/erc/erc-track-tests.el b/test/lisp/erc/erc-track-tests.el
index 0ce93bd45c6..b2687a96ab3 100644
--- a/test/lisp/erc/erc-track-tests.el
+++ b/test/lisp/erc/erc-track-tests.el
@@ -119,3 +119,5 @@
                        '(bold erc-current-nick-face) str1)
     (should (erc-faces-in str0))
     (should (erc-faces-in str1)) ))
+
+;;; erc-track-tests.el ends here
diff --git a/test/lisp/eshell/eshell-tests.el b/test/lisp/eshell/eshell-tests.el
index 4f0cc9b6785..a460f45bf13 100644
--- a/test/lisp/eshell/eshell-tests.el
+++ b/test/lisp/eshell/eshell-tests.el
@@ -262,4 +262,4 @@ chars"
 
 (provide 'eshell-tests)
 
-;;; tests/eshell-tests.el ends here
+;;; eshell-tests.el ends here
diff --git a/test/lisp/faces-resources/faces-test-dark-theme.el b/test/lisp/faces-resources/faces-test-dark-theme.el
index f3ef6b67fa7..7e8871ec10a 100644
--- a/test/lisp/faces-resources/faces-test-dark-theme.el
+++ b/test/lisp/faces-resources/faces-test-dark-theme.el
@@ -22,7 +22,7 @@
 ;;; Code:
 
 (deftheme faces-test-dark
-  "")
+  "Dark test theme.")
 
 (custom-theme-set-faces
  'faces-test-dark
diff --git a/test/lisp/faces-resources/faces-test-light-theme.el b/test/lisp/faces-resources/faces-test-light-theme.el
index 390b8461644..70a75017614 100644
--- a/test/lisp/faces-resources/faces-test-light-theme.el
+++ b/test/lisp/faces-resources/faces-test-light-theme.el
@@ -22,7 +22,7 @@
 ;;; Code:
 
 (deftheme faces-test-light
-  "")
+  "Light test theme.")
 
 (custom-theme-set-faces
  'faces-test-light
diff --git a/test/lisp/faces-tests.el b/test/lisp/faces-tests.el
index c0db9c9de17..fe5f3ec95f8 100644
--- a/test/lisp/faces-tests.el
+++ b/test/lisp/faces-tests.el
@@ -25,7 +25,7 @@
 (require 'ert)
 (require 'ert-x)
 
-(defgroup faces--test nil ""
+(defgroup faces--test nil "Group to test faces."
   :group 'faces--test)
 
 (defface faces--test1
diff --git a/test/lisp/gnus/gnus-search-tests.el b/test/lisp/gnus/gnus-search-tests.el
index 6148da65621..9f012d4e888 100644
--- a/test/lisp/gnus/gnus-search-tests.el
+++ b/test/lisp/gnus/gnus-search-tests.el
@@ -97,4 +97,4 @@
                      "more bits"))))
 
 (provide 'gnus-search-tests)
-;;; search-tests.el ends here
+;;; gnus-search-tests.el ends here
diff --git a/test/lisp/gnus/gnus-util-tests.el b/test/lisp/gnus/gnus-util-tests.el
index f8d30f6373e..60a9cde0e7f 100644
--- a/test/lisp/gnus/gnus-util-tests.el
+++ b/test/lisp/gnus/gnus-util-tests.el
@@ -132,4 +132,4 @@
   (should (equal '("1") (gnus-setdiff '(2 "1" 2) '(2))))
   (should (equal '("1" "1") (gnus-setdiff '(2 "1" 2 "1") '(2)))))
 
-;;; gnustest-gnus-util.el ends here
+;;; gnus-util-tests.el ends here
diff --git a/test/lisp/gnus/message-tests.el b/test/lisp/gnus/message-tests.el
index b4f2b7f675d..0f42f62f386 100644
--- a/test/lisp/gnus/message-tests.el
+++ b/test/lisp/gnus/message-tests.el
@@ -185,4 +185,4 @@ Hello.
 
 (provide 'message-mode-tests)
 
-;;; message-mode-tests.el ends here
+;;; message-tests.el ends here
diff --git a/test/lisp/htmlfontify-tests.el b/test/lisp/htmlfontify-tests.el
index 879131cae32..15798319a13 100644
--- a/test/lisp/htmlfontify-tests.el
+++ b/test/lisp/htmlfontify-tests.el
@@ -43,4 +43,4 @@ available (Bug#25468)."
                  0)))
 
 (provide 'htmlfontify-tests)
-;; htmlfontify-tests.el ends here
+;;; htmlfontify-tests.el ends here
diff --git a/test/lisp/ibuffer-tests.el b/test/lisp/ibuffer-tests.el
index a51079180a5..9b0327b0ef0 100644
--- a/test/lisp/ibuffer-tests.el
+++ b/test/lisp/ibuffer-tests.el
@@ -826,4 +826,4 @@
   (should (equal (ibuffer-unary-operand '(not . a)) 'a)))
 
 (provide 'ibuffer-tests)
-;; ibuffer-tests.el ends here
+;;; ibuffer-tests.el ends here
diff --git a/test/lisp/info-xref-tests.el b/test/lisp/info-xref-tests.el
index ecba86146f1..0b8091f17af 100644
--- a/test/lisp/info-xref-tests.el
+++ b/test/lisp/info-xref-tests.el
@@ -161,4 +161,4 @@ text.
                                                (line-end-position)))))))
 
 
-;;; info-xref.el ends here
+;;; info-xref-tests.el ends here
diff --git a/test/lisp/international/ccl-tests.el b/test/lisp/international/ccl-tests.el
index 0f765e4ff88..f3da2d88732 100644
--- a/test/lisp/international/ccl-tests.el
+++ b/test/lisp/international/ccl-tests.el
@@ -246,3 +246,5 @@ At EOF:
            (registers [17 0 0 0 0 0 0 0]))
       (ccl-execute compiled registers)
       (should (equal registers [2 16 0 0 0 0 0 1])))))
+
+;;; ccl-tests.el ends here
diff --git a/test/lisp/jit-lock-tests.el b/test/lisp/jit-lock-tests.el
index 121966b2b77..a54aad8165c 100644
--- a/test/lisp/jit-lock-tests.el
+++ b/test/lisp/jit-lock-tests.el
@@ -58,3 +58,5 @@
     (with-silent-modifications
       (put-text-property (point-min) (point-max) 'fontified t))
     (jit-lock-fontify-now (point-min) (point-max))))
+
+;;; jit-lock-tests.el ends here
diff --git a/test/lisp/kmacro-tests.el b/test/lisp/kmacro-tests.el
index 8736f7fd2dc..ecd3d5fc22b 100644
--- a/test/lisp/kmacro-tests.el
+++ b/test/lisp/kmacro-tests.el
@@ -834,7 +834,7 @@ and `read-event' and `read-key-sequence' set up to return items from
 EVENTS and SEQUENCES respectively.  SEQUENCES may be nil, but
 EVENTS should not be.  EVENTS should be a list of symbols bound
 in `kmacro-step-edit-map' or `query-replace' map, and this function
-will do the keymap lookup for you. SEQUENCES should contain
+will do the keymap lookup for you.  SEQUENCES should contain
 return values for `read-key-sequence'.
 
 Before running the macro, the current buffer will be erased.
diff --git a/test/lisp/mail/rmail-tests.el b/test/lisp/mail/rmail-tests.el
index f533401496b..826a90455fb 100644
--- a/test/lisp/mail/rmail-tests.el
+++ b/test/lisp/mail/rmail-tests.el
@@ -32,4 +32,4 @@
      'rmail-edit-current-message))))
 
 (provide 'rmail-tests)
-;; rmail-tests.el ends here
+;;; rmail-tests.el ends here
diff --git a/test/lisp/mail/rmailmm-tests.el b/test/lisp/mail/rmailmm-tests.el
index a022008b534..d7b3775d6d0 100644
--- a/test/lisp/mail/rmailmm-tests.el
+++ b/test/lisp/mail/rmailmm-tests.el
@@ -114,4 +114,4 @@ This is the epilogue.  It is also to be ignored."))
 
 (provide 'rmailmm-tests)
 
-;; rmailmm-tests.el ends here
+;;; rmailmm-tests.el ends here
diff --git a/test/lisp/mail/uudecode-tests.el b/test/lisp/mail/uudecode-tests.el
index 6ff767562e3..981ce1c4ae0 100644
--- a/test/lisp/mail/uudecode-tests.el
+++ b/test/lisp/mail/uudecode-tests.el
@@ -35,11 +35,11 @@
 
 (defvar uudecode-tests-encoded-str
   (uudecode-tests-read-file (ert-resource-file "uuencoded.txt"))
-  "Uuencoded data for bookmark-tests.el
+  "Uuencoded data for bookmark-tests.el.
 Same as `uudecode-tests-decoded-str' but uuencoded.")
 (defvar uudecode-tests-decoded-str
   (uudecode-tests-read-file (ert-resource-file "uudecoded.txt"))
-  "Plain text data for bookmark-tests.el
+  "Plain text data for bookmark-tests.el.
 Same as `uudecode-tests-encoded-str' but plain text.")
 
 (ert-deftest uudecode-tests-decode-region-internal ()
diff --git a/test/lisp/net/shr-tests.el b/test/lisp/net/shr-tests.el
index ed532af657a..bfb83f25184 100644
--- a/test/lisp/net/shr-tests.el
+++ b/test/lisp/net/shr-tests.el
@@ -67,4 +67,4 @@
 
 (require 'shr)
 
-;;; shr-stream-tests.el ends here
+;;; shr-tests.el ends here
diff --git a/test/lisp/net/socks-tests.el b/test/lisp/net/socks-tests.el
index c0f90bc2d47..9079c1bef2a 100644
--- a/test/lisp/net/socks-tests.el
+++ b/test/lisp/net/socks-tests.el
@@ -128,7 +128,7 @@
 
 (defvar socks-tests-canned-server-patterns nil
   "Alist containing request/response cons pairs to be tried in order.
-Vectors must match verbatim. Strings are considered regex patterns.")
+Vectors must match verbatim.  Strings are considered regex patterns.")
 
 (defun socks-tests-canned-server-create ()
   "Create and return a fake SOCKS server."
diff --git a/test/lisp/net/tramp-tests.el b/test/lisp/net/tramp-tests.el
index 26a3ac7e964..55396c50797 100644
--- a/test/lisp/net/tramp-tests.el
+++ b/test/lisp/net/tramp-tests.el
@@ -6071,7 +6071,7 @@ This requires restrictions of file name syntax."
    'tramp-ftp-file-name-handler))
 
 (defun tramp--test-crypt-p ()
-  "Check, whether the remote directory is crypted"
+  "Check, whether the remote directory is crypted."
   (tramp-crypt-file-name-p tramp-test-temporary-file-directory))
 
 (defun tramp--test-docker-p ()
diff --git a/test/lisp/newcomment-tests.el b/test/lisp/newcomment-tests.el
index 5485673b72d..65690e593db 100644
--- a/test/lisp/newcomment-tests.el
+++ b/test/lisp/newcomment-tests.el
@@ -1,4 +1,4 @@
-;;; newcomment-tests.el  -*- lexical-binding:t -*-
+;;; newcomment-tests.el --- Tests for newcomment.el  -*- lexical-binding:t -*-
 
 ;; Copyright (C) 2021 Free Software Foundation, Inc.
 
@@ -36,4 +36,4 @@
               (uncomment-region (point-min) (point-max))
               (buffer-string))))))
 
-;;; newcomment-testsuite.el ends here
+;;; newcomment-tests.el ends here
diff --git a/test/lisp/org/org-tests.el b/test/lisp/org/org-tests.el
index c1985a46a40..e53b0384081 100644
--- a/test/lisp/org/org-tests.el
+++ b/test/lisp/org/org-tests.el
@@ -29,3 +29,5 @@ Ref <https://debbugs.gnu.org/30310>."
   (should (require 'org-version nil t))
   (should (equal (version-to-list (org-release))
                  (cdr (assq 'org package--builtin-versions)))))
+
+;;; org-tests.el ends here
diff --git a/test/lisp/play/cookie1-tests.el b/test/lisp/play/cookie1-tests.el
index 75dea4e5ef0..2dd73d18028 100644
--- a/test/lisp/play/cookie1-tests.el
+++ b/test/lisp/play/cookie1-tests.el
@@ -37,4 +37,4 @@
     (should (= (length (cookie-apropos "false" fortune-file)) 1))))
 
 (provide 'fortune-tests)
-;;; fortune-tests.el ends here
+;;; cookie1-tests.el ends here
diff --git a/test/lisp/progmodes/elisp-mode-tests.el b/test/lisp/progmodes/elisp-mode-tests.el
index 60946c2f446..ba349237cb7 100644
--- a/test/lisp/progmodes/elisp-mode-tests.el
+++ b/test/lisp/progmodes/elisp-mode-tests.el
@@ -429,7 +429,7 @@ to (xref-elisp-test-descr-to-target xref)."
   slot-1)
 
 (cl-defgeneric xref-elisp-generic-no-methods (arg1 arg2)
-  "doc string generic no-methods"
+  "Doc string generic no-methods."
   ;; No default implementation, no methods, but fboundp is true for
   ;; this symbol; it calls cl-no-applicable-method
   )
@@ -440,44 +440,44 @@ to (xref-elisp-test-descr-to-target xref)."
 ;; ‘this’. It passes in interactive tests, so I haven't been able to
 ;; track down the problem.
 (cl-defmethod xref-elisp-generic-no-default ((this xref-elisp-root-type) arg2)
-  "doc string generic no-default xref-elisp-root-type"
+  "Doc string generic no-default xref-elisp-root-type."
   "non-default for no-default")
 
 ;; defgeneric after defmethod in file to ensure the fallback search
 ;; method of just looking for the function name will fail.
 (cl-defgeneric xref-elisp-generic-no-default (arg1 arg2)
-  "doc string generic no-default generic"
+  "Doc string generic no-default generic."
   ;; No default implementation; this function calls the cl-generic
   ;; dispatching code.
   )
 
 (cl-defgeneric xref-elisp-generic-co-located-default (arg1 arg2)
-  "doc string generic co-located-default"
+  "Doc string generic co-located-default."
   "co-located default")
 
 (cl-defmethod xref-elisp-generic-co-located-default ((this xref-elisp-root-type) arg2)
-  "doc string generic co-located-default xref-elisp-root-type"
+  "Doc string generic co-located-default xref-elisp-root-type."
   "non-default for co-located-default")
 
 (cl-defgeneric xref-elisp-generic-separate-default (arg1 arg2)
-  "doc string generic separate-default"
+  "Doc string generic separate-default."
   ;; default implementation provided separately
   )
 
 (cl-defmethod xref-elisp-generic-separate-default (arg1 arg2)
-  "doc string generic separate-default default"
+  "Doc string generic separate-default default."
   "separate default")
 
 (cl-defmethod xref-elisp-generic-separate-default ((this xref-elisp-root-type) arg2)
-  "doc string generic separate-default xref-elisp-root-type"
+  "Doc string generic separate-default xref-elisp-root-type."
   "non-default for separate-default")
 
 (cl-defmethod xref-elisp-generic-implicit-generic (arg1 arg2)
-  "doc string generic implicit-generic default"
+  "Doc string generic implicit-generic default."
   "default for implicit generic")
 
 (cl-defmethod xref-elisp-generic-implicit-generic ((this xref-elisp-root-type) arg2)
-  "doc string generic implicit-generic xref-elisp-root-type"
+  "Doc string generic implicit-generic xref-elisp-root-type."
   "non-default for implicit generic")
 
 
@@ -623,35 +623,35 @@ to (xref-elisp-test-descr-to-target xref)."
 (declare-function xref-elisp-overloadable-no-default-default "elisp-mode-tests")
 
 (define-overloadable-function xref-elisp-overloadable-no-methods ()
-  "doc string overloadable no-methods")
+  "Doc string overloadable no-methods.")
 
 (define-overloadable-function xref-elisp-overloadable-no-default ()
-  "doc string overloadable no-default")
+  "Doc string overloadable no-default.")
 
 (define-mode-local-override xref-elisp-overloadable-no-default c-mode
   (_start _end &optional _nonterminal _depth _returnonerror)
-  "doc string overloadable no-default c-mode."
+  "Doc string overloadable no-default c-mode."
   "result overloadable no-default c-mode.")
 
 (define-overloadable-function xref-elisp-overloadable-co-located-default ()
-  "doc string overloadable co-located-default"
+  "Doc string overloadable co-located-default."
   "result overloadable co-located-default.")
 
 (define-mode-local-override xref-elisp-overloadable-co-located-default c-mode
   (_start _end &optional _nonterminal _depth _returnonerror)
-  "doc string overloadable co-located-default c-mode."
+  "Doc string overloadable co-located-default c-mode."
   "result overloadable co-located-default c-mode.")
 
 (define-overloadable-function xref-elisp-overloadable-separate-default ()
-  "doc string overloadable separate-default.")
+  "Doc string overloadable separate-default.")
 
 (defun xref-elisp-overloadable-separate-default-default ()
-  "doc string overloadable separate-default default"
+  "Doc string overloadable separate-default default."
   "result overloadable separate-default.")
 
 (define-mode-local-override xref-elisp-overloadable-separate-default c-mode
   (_start _end &optional _nonterminal _depth _returnonerror)
-  "doc string overloadable separate-default c-mode."
+  "Doc string overloadable separate-default c-mode."
   "result overloadable separate-default c-mode.")
 
 (xref-elisp-deftest find-defs-define-overload-no-methods
diff --git a/test/lisp/progmodes/etags-tests.el b/test/lisp/progmodes/etags-tests.el
index 35a2592e76f..9b14a3ae860 100644
--- a/test/lisp/progmodes/etags-tests.el
+++ b/test/lisp/progmodes/etags-tests.el
@@ -111,3 +111,5 @@
             (should (visit-tags-table-buffer))
             (should (equal tags-file-name (car tag-tables)))))
       (delete-file file))))
+
+;;; etags-tests.el ends here
diff --git a/test/lisp/progmodes/flymake-tests.el b/test/lisp/progmodes/flymake-tests.el
index 10111ca06cd..4c0d15d1e1b 100644
--- a/test/lisp/progmodes/flymake-tests.el
+++ b/test/lisp/progmodes/flymake-tests.el
@@ -193,7 +193,7 @@ SEVERITY-PREDICATE is used to setup
 
 (defun flymake-tests--diagnose-words
     (report-fn type words)
-  "Helper. Call REPORT-FN with diagnostics for WORDS in buffer."
+  "Helper.  Call REPORT-FN with diagnostics for WORDS in buffer."
   (funcall report-fn
            (cl-loop
             for word in words
diff --git a/test/lisp/progmodes/gdb-mi-tests.el b/test/lisp/progmodes/gdb-mi-tests.el
index ab482214afb..d66df961b63 100644
--- a/test/lisp/progmodes/gdb-mi-tests.el
+++ b/test/lisp/progmodes/gdb-mi-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Code:
+
 (require 'ert)
 (require 'gdb-mi)
 
@@ -44,3 +46,5 @@
   )
 
 (provide 'gdb-mi-tests)
+
+;;; gdb-mi-tests.el ends here
diff --git a/test/lisp/progmodes/opascal-tests.el b/test/lisp/progmodes/opascal-tests.el
index 682f2c6cb6b..ea91479362d 100644
--- a/test/lisp/progmodes/opascal-tests.el
+++ b/test/lisp/progmodes/opascal-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Code:
+
 (require 'ert)
 (require 'opascal)
 
diff --git a/test/lisp/progmodes/pascal-tests.el b/test/lisp/progmodes/pascal-tests.el
index e9c705806b3..f5202143e20 100644
--- a/test/lisp/progmodes/pascal-tests.el
+++ b/test/lisp/progmodes/pascal-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Code:
+
 (require 'ert)
 (require 'pascal)
 
@@ -61,3 +63,5 @@
     (should (equal (point) 15))))
 
 (provide 'pascal-tests)
+
+;;; pascal-tests.el ends here
diff --git a/test/lisp/progmodes/sql-tests.el b/test/lisp/progmodes/sql-tests.el
index 21dd0649529..99b79b61d65 100644
--- a/test/lisp/progmodes/sql-tests.el
+++ b/test/lisp/progmodes/sql-tests.el
@@ -50,7 +50,7 @@
         (lambda (_command) t))
        ((symbol-function 'process-lines)
         (lambda (_program &rest _args)
-          (error "some error"))))
+          (error "Some error"))))
     (should-not (sql-postgres-list-databases))))
 
 ;;; Check Connection Password Handling/Wallet
diff --git a/test/lisp/ps-print-tests.el b/test/lisp/ps-print-tests.el
index b25e88622d8..d468911dd3d 100644
--- a/test/lisp/ps-print-tests.el
+++ b/test/lisp/ps-print-tests.el
@@ -34,3 +34,5 @@
    (autoloadp
     (symbol-function
      'ps-mule-initialize))))
+
+;;; ps-print-tests.el ends here
diff --git a/test/lisp/saveplace-tests.el b/test/lisp/saveplace-tests.el
index 17199ed443a..63577fdd167 100644
--- a/test/lisp/saveplace-tests.el
+++ b/test/lisp/saveplace-tests.el
@@ -21,6 +21,8 @@
 
 ;;; Commentary:
 
+;;; Code:
+
 (require 'ert)
 (require 'ert-x)
 (require 'saveplace)
diff --git a/test/lisp/ses-tests.el b/test/lisp/ses-tests.el
index 04f255dcd4c..9a7fb502d7c 100644
--- a/test/lisp/ses-tests.el
+++ b/test/lisp/ses-tests.el
@@ -175,3 +175,5 @@ to `ses--bar' and inserting a row, makes A2 value empty, and `ses--bar' equal to
 
 
 (provide 'ses-tests)
+
+;;; ses-tests.el ends here
diff --git a/test/lisp/shell-tests.el b/test/lisp/shell-tests.el
index 223a18590b1..342b421911f 100644
--- a/test/lisp/shell-tests.el
+++ b/test/lisp/shell-tests.el
@@ -1,4 +1,4 @@
-;;; shell-tests.el  -*- lexical-binding:t -*-
+;;; shell-tests.el --- Tests for shell.el  -*- lexical-binding:t -*-
 
 ;; Copyright (C) 2010-2021 Free Software Foundation, Inc.
 
diff --git a/test/lisp/simple-tests.el b/test/lisp/simple-tests.el
index 3ece61290bc..742da0bde59 100644
--- a/test/lisp/simple-tests.el
+++ b/test/lisp/simple-tests.el
@@ -972,4 +972,4 @@ See Bug#21722."
     (should (= (length (delq nil (undo-make-selective-list 6 9))) 0))))
 
 (provide 'simple-test)
-;;; simple-test.el ends here
+;;; simple-tests.el ends here
diff --git a/test/lisp/so-long-tests/so-long-tests-helpers.el b/test/lisp/so-long-tests/so-long-tests-helpers.el
index dd2331e6e4a..f542806ac16 100644
--- a/test/lisp/so-long-tests/so-long-tests-helpers.el
+++ b/test/lisp/so-long-tests/so-long-tests-helpers.el
@@ -106,8 +106,8 @@
 (defun so-long-tests-remember ()
   "Remember the original states of modes and variables.
 
-Call this after setting up a buffer in the normal (not so-long)
-state for its major mode, so that after triggering a so-long
+Call this after setting up a buffer in the normal (not `so-long')
+state for its major mode, so that after triggering a `so-long'
 action we can call `so-long-revert' and compare the reverted
 state against this remembered state."
   (setq so-long-tests-memory nil)
diff --git a/test/lisp/tar-mode-tests.el b/test/lisp/tar-mode-tests.el
index 48a127157dd..6964d423185 100644
--- a/test/lisp/tar-mode-tests.el
+++ b/test/lisp/tar-mode-tests.el
@@ -47,4 +47,4 @@
 
 (provide 'tar-mode-tests)
 
-;; tar-mode-tests.el ends here
+;;; tar-mode-tests.el ends here
diff --git a/test/lisp/term/tty-colors-tests.el b/test/lisp/term/tty-colors-tests.el
index ba29a9c376e..d0e739b5ec9 100644
--- a/test/lisp/term/tty-colors-tests.el
+++ b/test/lisp/term/tty-colors-tests.el
@@ -35,4 +35,4 @@
 
 (provide 'term-tests)
 
-;;; term-tests.el ends here
+;;; tty-colors-tests.el ends here
diff --git a/test/lisp/textmodes/dns-mode-tests.el b/test/lisp/textmodes/dns-mode-tests.el
index 8bc48732c62..1be5291509f 100644
--- a/test/lisp/textmodes/dns-mode-tests.el
+++ b/test/lisp/textmodes/dns-mode-tests.el
@@ -77,3 +77,5 @@
       (insert " ")
       (dns-mode-ipv6-to-nibbles nil)
       (should (equal (buffer-string) "8.b.d.0.1.0.0.2.ip6.arpa.  ")))))
+
+;;; dns-mode-tests.el ends here
diff --git a/test/lisp/thingatpt-tests.el b/test/lisp/thingatpt-tests.el
index 1849480347e..2a32dc57b1c 100644
--- a/test/lisp/thingatpt-tests.el
+++ b/test/lisp/thingatpt-tests.el
@@ -70,7 +70,7 @@
     ;; UUID, only hex is allowed
     ("01234567-89ab-cdef-ABCD-EF0123456789" 1 uuid "01234567-89ab-cdef-ABCD-EF0123456789")
     ("01234567-89ab-cdef-ABCD-EF012345678G" 1 uuid nil))
-  "List of thing-at-point tests.
+  "List of `thing-at-point' tests.
 Each list element should have the form
 
   (STRING POS THING RESULT)
@@ -231,4 +231,4 @@ position to retrieve THING.")
     (goto-char 5)
     (should (eq (symbol-at-point) 'bar))))
 
-;;; thingatpt.el ends here
+;;; thingatpt-tests.el ends here
diff --git a/test/lisp/time-stamp-tests.el b/test/lisp/time-stamp-tests.el
index dc628af19fd..0449704b418 100644
--- a/test/lisp/time-stamp-tests.el
+++ b/test/lisp/time-stamp-tests.el
@@ -86,7 +86,7 @@
       (should (equal (time-stamp-string "%H %Z" ref-time1) "15 GMT")))))
 
 (iter-defun time-stamp-test-pattern-sequential ()
-  "Iterate through each possibility for a part of time-stamp-pattern."
+  "Iterate through each possibility for a part of `time-stamp-pattern'."
   (let ((pattern-value-parts
          '(("4/" "10/" "-4/" "0/" "")                     ;0: line limit
            ("stamp<" "")                                  ;1: start
@@ -115,7 +115,7 @@
                                     (extract-part 5))))))))))
 
 (iter-defun time-stamp-test-pattern-multiply ()
-  "Iterate through every combination of parts of time-stamp-pattern."
+  "Iterate through every combination of parts of `time-stamp-pattern'."
   (let ((line-limit-values '("" "4/"))
         (start-values '("" "stamp<"))
         (format-values '("%%" "%m"))
@@ -871,7 +871,7 @@ The functions in `pattern-mod' are composed left to right."
 
 (defmacro formatz-generate-tests
     (form-strings hour-mod mins-mod secs-mod big-mod secbig-mod)
-  "Defines ert-deftest tests for time formats FORM-STRINGS.
+  "Defines tests for time formats FORM-STRINGS.
 FORM-STRINGS is a list of formats, each \"%z\" or some variation thereof.
 
 Each of the remaining arguments is an unquoted list of the form
diff --git a/test/lisp/time-tests.el b/test/lisp/time-tests.el
index 88b7638d91d..89e6985b842 100644
--- a/test/lisp/time-tests.el
+++ b/test/lisp/time-tests.el
@@ -21,6 +21,8 @@
 
 ;;; Commentary:
 
+;;; Code:
+
 (require 'ert)
 (require 'ert-x)
 (require 'time)
diff --git a/test/lisp/timezone-tests.el b/test/lisp/timezone-tests.el
index 9f6961409e6..9bbe36cfe8a 100644
--- a/test/lisp/timezone-tests.el
+++ b/test/lisp/timezone-tests.el
@@ -21,6 +21,8 @@
 
 ;;; Commentary:
 
+;;; Code:
+
 (require 'ert)
 (require 'timezone)
 
diff --git a/test/lisp/url/url-parse-tests.el b/test/lisp/url/url-parse-tests.el
index 2418af40aca..a7f81eba8f5 100644
--- a/test/lisp/url/url-parse-tests.el
+++ b/test/lisp/url/url-parse-tests.el
@@ -23,7 +23,7 @@
 ;;; Commentary:
 
 ;; Test cases covering generic URI syntax as described in RFC3986,
-;; section 3. Syntax Components and 4. Usage. See also appendix
+;; section 3. Syntax Components and 4. Usage.  See also appendix
 ;; A. Collected ABNF for URI, as the example given here are all
 ;; productions of this grammar.
 
diff --git a/test/lisp/vc/add-log-tests.el b/test/lisp/vc/add-log-tests.el
index dc2b9961c6c..70e49fe57fe 100644
--- a/test/lisp/vc/add-log-tests.el
+++ b/test/lisp/vc/add-log-tests.el
@@ -29,8 +29,8 @@
 					      content marker expected-defun)
   "Generate an ert test for mode-own `add-log-current-defun-function'.
 Run `add-log-current-defun' at the point where MARKER specifies
-in a buffer which content is CONTENT under major mode MODE. Then
-it compares the result with EXPECTED-DEFUN."
+in a buffer which content is CONTENT under major mode MODE.
+Then it compares the result with EXPECTED-DEFUN."
   (let ((xname (intern (concat "add-log-current-defun-test-"
 			       (symbol-name name)
 			       ))))
diff --git a/test/lisp/vc/diff-mode-tests.el b/test/lisp/vc/diff-mode-tests.el
index fefe50d5173..ef19fe0e0e8 100644
--- a/test/lisp/vc/diff-mode-tests.el
+++ b/test/lisp/vc/diff-mode-tests.el
@@ -481,3 +481,4 @@ baz"))))
                    '("/tmp/ange-ftp1351895K.el" "/tmp/ange-ftp13518wvE.el")))))
 
 (provide 'diff-mode-tests)
+;;; diff-mode-tests.el ends here
diff --git a/test/lisp/vc/smerge-mode-tests.el b/test/lisp/vc/smerge-mode-tests.el
index 2c8f48618e5..d7827c7a8cb 100644
--- a/test/lisp/vc/smerge-mode-tests.el
+++ b/test/lisp/vc/smerge-mode-tests.el
@@ -34,3 +34,5 @@
     (should (equal (buffer-substring (point-min) (point-max)) ""))))
 
 (provide 'smerge-mode-tests)
+
+;;; smerge-mode-tests.el ends here
diff --git a/test/lisp/vc/vc-bzr-tests.el b/test/lisp/vc/vc-bzr-tests.el
index b02dce8f707..43385de5955 100644
--- a/test/lisp/vc/vc-bzr-tests.el
+++ b/test/lisp/vc/vc-bzr-tests.el
@@ -153,4 +153,4 @@
                          t)))
       (delete-directory homedir t))))
 
-;;; vc-bzr.el ends here
+;;; vc-bzr-tests.el ends here
diff --git a/test/lisp/whitespace-tests.el b/test/lisp/whitespace-tests.el
index 9f54a4fd340..1001476a286 100644
--- a/test/lisp/whitespace-tests.el
+++ b/test/lisp/whitespace-tests.el
@@ -51,7 +51,7 @@
 ;; We cannot call whitespace-mode because it will do nothing in batch
 ;; mode.  So we call its innards instead.
 (defun whitespace-tests-whitespace-mode-on ()
-  "Turn whitespace-mode on even in batch mode."
+  "Turn `whitespace-mode' on even in batch mode."
   (whitespace-turn-on)
   (whitespace-action-when-on)
   (setq whitespace-mode t))
diff --git a/test/lisp/xml-tests.el b/test/lisp/xml-tests.el
index b00b58acfc5..7c64ef39f8d 100644
--- a/test/lisp/xml-tests.el
+++ b/test/lisp/xml-tests.el
@@ -78,7 +78,7 @@
     ;; Bug#16344
     "<!----><x>< /x>"
     "<a>< b/></a>")
-  "List of XML strings that should signal an error in the parser")
+  "List of XML strings that should signal an error in the parser.")
 
 (defvar xml-parse-tests--qnames
   '( ;; Test data for name expansion
@@ -199,4 +199,4 @@ Parser is called with and without 'symbol-qnames argument.")
 ;; no-byte-compile: t
 ;; End:
 
-;;; xml-parse-tests.el ends here.
+;;; xml-tests.el ends here
diff --git a/test/manual/biditest.el b/test/manual/biditest.el
index a77fc158807..c84e7ed7310 100644
--- a/test/manual/biditest.el
+++ b/test/manual/biditest.el
@@ -121,3 +121,5 @@ BidiCharacterTest.txt file."
   (message "%s" (bidi-resolved-levels)))
 
 (define-key global-map [f8] #'bidi-levels)
+
+;;; biditest.el ends here
diff --git a/test/manual/cedet/ede-tests.el b/test/manual/cedet/ede-tests.el
index 2af50860c60..17618381ef2 100644
--- a/test/manual/cedet/ede-tests.el
+++ b/test/manual/cedet/ede-tests.el
@@ -80,4 +80,4 @@ The search is done with the current EDE root."
     (ede-locate-file-in-project loc file)
     (data-debug-insert-object-slots loc "]")))
 
-;;; ede-test.el ends here
+;;; ede-tests.el ends here
diff --git a/test/manual/cedet/semantic-tests.el b/test/manual/cedet/semantic-tests.el
index 044db29cda7..3e416cc6b20 100644
--- a/test/manual/cedet/semantic-tests.el
+++ b/test/manual/cedet/semantic-tests.el
@@ -271,3 +271,5 @@ tag that contains point, and return that."
 		 Lcount (semantic-tag-name target)
 		 (semantic-elapsed-time start nil)))
       Lcount)))
+
+;;; semantic-tests.el ends here
diff --git a/test/manual/cedet/tests/test.el b/test/manual/cedet/tests/test.el
index d1d0d1602f4..34c03619f88 100644
--- a/test/manual/cedet/tests/test.el
+++ b/test/manual/cedet/tests/test.el
@@ -19,31 +19,29 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
-;;; Require
-;;
+;;; Code:
+
 (require 'semantic)
 (require 'eieio "../eieio")
 
 ;; tags encapsulated in eval-when-compile and eval-and-compile
 ;; should be expanded out into the outer environment.
 (eval-when-compile
-  (require 'semantic-imenu)
-  )
+  (require 'semantic-imenu))
 
 (eval-and-compile
   (defconst const-1 nil)
   (defun function-1 (arg)
-    nil)
-  )
+    nil))
 
 ;;; Functions
 ;;
 (defun a-defun (arg1 arg2 &optional arg3)
-  "doc a"
+  "Doc a."
   nil)
 
 (defun a-defun-interactive (arg1 arg2 &optional arg3)
-  "doc a that is a command"
+  "Doc a that is a command."
   (interactive "R")
   nil)
 
@@ -52,15 +50,15 @@
   nil)
 
 (defsubst a-defsubst (arg1 arg2 &optional arg3)
-  "doc a-subst"
+  "Doc a-subst."
   nil)
 
 (defmacro a-defmacro (arg1 arg2 &optional arg3)
-  "doc a-macro"
+  "Doc a-macro."
   nil)
 
 (define-overload a-overload (arg)
-  "doc a-overload"
+  "Doc a-overload."
   nil)
 
 ;;; Methods
@@ -81,16 +79,16 @@
 ;;; Variables
 ;;
 (defvar a-defvar (cons 1 2)
-  "Variable a")
+  "Variable a.")
 
 ;; FIXME: This practice is not recommended in recent Emacs.  Remove?
 (defvar a-defvar-star (cons 1 2)
-  "*User visible var a")
+  "*User visible var a.")
 
-(defconst a-defconst 'a "var doc const")
+(defconst a-defconst 'a "Var doc const.")
 
 (defcustom a-defcustom nil
-  "doc custom"
+  "Doc custom."
   :group 'a-defgroup
   :type 'boolean)
 
@@ -111,7 +109,7 @@
 
 
 (defgroup a-defgroup nil
-  "Group for `emacs-lisp' regression-test")
+  "Group for `emacs-lisp' regression-test.")
 
 ;;; Classes
 ;;
@@ -154,3 +152,5 @@
   "some value")
 
 (provide 'test)
+
+;;; test.el ends here
diff --git a/test/manual/etags/el-src/emacs/lisp/progmodes/etags.el b/test/manual/etags/el-src/emacs/lisp/progmodes/etags.el
index 36f6624472d..86cc8825466 100644
--- a/test/manual/etags/el-src/emacs/lisp/progmodes/etags.el
+++ b/test/manual/etags/el-src/emacs/lisp/progmodes/etags.el
@@ -732,7 +732,7 @@ Returns t if it visits a tags table, or nil if there are no more in the list."
   "Return the file name of the file whose tags point is within.
 Assumes the tags table is the current buffer.
 If RELATIVE is non-nil, file name returned is relative to tags
-table file's directory. If RELATIVE is nil, file name returned
+table file's directory.  If RELATIVE is nil, file name returned
 is complete."
   (funcall file-of-tag-function relative))
 
diff --git a/test/manual/image-size-tests.el b/test/manual/image-size-tests.el
index 44846a7a67a..067a0bfc8e2 100644
--- a/test/manual/image-size-tests.el
+++ b/test/manual/image-size-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Commentary:
+
 ;; To test: Load the file and eval (image-size-tests).
 ;; A non-erroring result is a success.
 
diff --git a/test/manual/image-transforms-tests.el b/test/manual/image-transforms-tests.el
index debb74f2edb..acbaed5c0b6 100644
--- a/test/manual/image-transforms-tests.el
+++ b/test/manual/image-transforms-tests.el
@@ -174,3 +174,5 @@
     (test-scaling)
     (test-scaling-rotation)
     (goto-char (point-min))))
+
+;;; image-transforms-tests.el ends here
diff --git a/test/manual/redisplay-testsuite.el b/test/manual/redisplay-testsuite.el
index 8e90f2d7a5c..8a4828417c8 100644
--- a/test/manual/redisplay-testsuite.el
+++ b/test/manual/redisplay-testsuite.el
@@ -350,3 +350,5 @@ static unsigned char x_bits[] = {0xff, 0x81, 0xbd, 0xa5, 0xa5, 0xbd, 0x81, 0xff
     (test-redisplay-4)
     (test-redisplay-5)
     (goto-char (point-min))))
+
+;;; redisplay-testsuite.el ends here
diff --git a/test/misc/test-custom-libs.el b/test/misc/test-custom-libs.el
index cc2be99dea8..d826dfbcab4 100644
--- a/test/misc/test-custom-libs.el
+++ b/test/misc/test-custom-libs.el
@@ -19,7 +19,7 @@
 
 ;;; Commentary:
 
-;; This file runs for all libraries with autoloads separate emacs
+;; This file runs for all libraries with autoloads separate Emacs
 ;; processes of the form "emacs -batch -l LIB".
 
 ;;; Code:
@@ -45,4 +45,4 @@
   (cus-test-libs t)
   (should-not cus-test-libs-errors))
 
-;;; test-custom-deps.el ends here
+;;; test-custom-libs.el ends here
diff --git a/test/src/alloc-tests.el b/test/src/alloc-tests.el
index 1324c2d3b4d..5383c436035 100644
--- a/test/src/alloc-tests.el
+++ b/test/src/alloc-tests.el
@@ -58,3 +58,5 @@
     (dolist (c (list 10003 ?b 128 ?c ?d (max-char) ?e))
       (aset s 0 c)
       (should (equal s (make-string 1 c))))))
+
+;;; alloc-tests.el ends here
diff --git a/test/src/character-tests.el b/test/src/character-tests.el
index f630b32a5ee..ba24d49039c 100644
--- a/test/src/character-tests.el
+++ b/test/src/character-tests.el
@@ -43,3 +43,5 @@
   (should (= (string-width "áëòç" nil 4) 2))
   (should (= (string-width "הַרְבֵּה אַהֲבָה") 9))
   (should (= (string-width "הַרְבֵּה אַהֲבָה" nil 8) 4)))
+
+;;; character-tests.el ends here
diff --git a/test/src/charset-tests.el b/test/src/charset-tests.el
index 5c46627c163..23e201ad453 100644
--- a/test/src/charset-tests.el
+++ b/test/src/charset-tests.el
@@ -22,7 +22,9 @@
 (require 'ert)
 
 (ert-deftest charset-decode-char ()
-  "Test decode-char."
+  "Test `decode-char'."
   (should-error (decode-char 'ascii 0.5)))
 
 (provide 'charset-tests)
+
+;;; charset-tests.el ends here
diff --git a/test/src/coding-tests.el b/test/src/coding-tests.el
index 134f5676709..1c585ea5377 100644
--- a/test/src/coding-tests.el
+++ b/test/src/coding-tests.el
@@ -434,4 +434,4 @@
 ;; End:
 
 (provide 'coding-tests)
-;; coding-tests.el ends here
+;;; coding-tests.el ends here
diff --git a/test/src/comp-resources/comp-test-funcs.el b/test/src/comp-resources/comp-test-funcs.el
index f2a246320ac..eb2521e5d34 100644
--- a/test/src/comp-resources/comp-test-funcs.el
+++ b/test/src/comp-resources/comp-test-funcs.el
@@ -202,7 +202,7 @@
 (defun comp-tests-err-arith-f ()
   (/ 1 0))
 (defun comp-tests-err-foo-f ()
-  (error "foo"))
+  (error "Foo"))
 
 (defun comp-tests-condition-case-0-f ()
   ;; Bpushhandler Bpophandler
@@ -264,7 +264,7 @@
     (% a b)))
 
 (defun comp-tests-doc-f ()
-  "A nice docstring"
+  "A nice docstring."
   t)
 
 (defun comp-test-interactive-form0-f (dir)
@@ -479,7 +479,7 @@
       family)))
 
 (defun comp-test-46670-1-f (_)
-  "foo")
+  "Foo.")
 
 (defun comp-test-46670-2-f (s)
   (and (equal (comp-test-46670-1-f (length s)) s)
@@ -647,7 +647,7 @@
       (?> 2))))
 
 (defun comp-test-big-interactive (filename &optional force arg load)
-  ;; Check non trivial interactive form using `byte-recompile-file'.
+  "Check non trivial interactive form using `byte-recompile-file'."
   (interactive
    (let ((file buffer-file-name)
 	 (file-name nil)
@@ -683,17 +683,17 @@
 
 (defun comp-test-no-return-1 (x)
   (while x
-   (error "foo")))
+   (error "Foo")))
 
 (defun comp-test-no-return-2 (x)
   (cond
    ((eql x '2) t)
-   ((error "bar") nil)))
+   ((error "Bar") nil)))
 
 (defun comp-test-no-return-3 ())
 (defun comp-test-no-return-4 (x)
   (when x
-    (error "foo")
+    (error "Foo")
     (while (comp-test-no-return-3)
       (comp-test-no-return-3))))
 
diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el
index fb9441eb66e..f1778b38568 100644
--- a/test/src/comp-tests.el
+++ b/test/src/comp-tests.el
@@ -1167,7 +1167,7 @@ Return a list of results."
 
       ;; 49
       ((defun comp-tests-ret-type-spec-f ()
-         (error "foo"))
+         (error "Foo"))
        nil)
 
       ;; 50
@@ -1373,7 +1373,7 @@ Return a list of results."
 
 (defun comp-tests-pure-checker-1 (_)
   "Check that inside `comp-tests-pure-caller-f' `comp-tests-pure-callee-f' is
- folded."
+folded."
   (should
    (cl-notany
     #'identity
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index b1e5fa0767c..03dfae8cc3c 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -26,10 +26,10 @@
 (defconst data-tests--float-greater-than-fixnums (+ 1.0 most-positive-fixnum)
   "A floating-point value that is greater than all fixnums.
 It is also as small as conveniently possible, to make the tests sharper.
-Adding 1.0 to most-positive-fixnum should suffice on all
+Adding 1.0 to `most-positive-fixnum' should suffice on all
 practical Emacs platforms, since the result is a power of 2 and
 this is exactly representable and is greater than
-most-positive-fixnum, which is just less than a power of 2.")
+`most-positive-fixnum', which is just less than a power of 2.")
 
 (ert-deftest data-tests-= ()
   (should-error (=))
@@ -204,11 +204,11 @@ most-positive-fixnum, which is just less than a power of 2.")
                "")))
 
 (defun test-bool-vector-count-consecutive-tc (desc)
-  "Run a test case for bool-vector-count-consecutive.
+  "Run a test case for `bool-vector-count-consecutive'.
 DESC is a string describing the test.  It is a sequence of
 hexadecimal digits describing the bool vector.  We exhaustively
 test all counts at all possible positions in the vector by
-comparing the subr with a much slower lisp implementation."
+comparing the subr with a much slower Lisp implementation."
   (let ((bv (test-bool-vector-bv-from-hex-string desc)))
     (cl-loop
      for lf in '(nil t)
@@ -338,7 +338,7 @@ comparing the subr with a much slower lisp implementation."
     (should (eq binding-test-some-local 'local))))
 
 (ert-deftest binding-test-setq-default ()
-  "Test that a setq-default has no effect when there is a local binding."
+  "Test that a `setq-default' has no effect when there is a local binding."
   (with-current-buffer binding-test-buffer-B
     ;; This variable is not local in this buffer.
     (let ((binding-test-some-local 'something-else))
@@ -399,28 +399,28 @@ comparing the subr with a much slower lisp implementation."
 		   (eq binding-test-some-local 'outer))))))
 
 (ert-deftest binding-test-defvar-bool ()
-  "Test DEFVAR_BOOL"
+  "Test DEFVAR_BOOL."
   (let ((display-hourglass 5))
     (should (eq display-hourglass t))))
 
 (ert-deftest binding-test-defvar-int ()
-  "Test DEFVAR_INT"
+  "Test DEFVAR_INT."
   (should-error (setq gc-cons-threshold 5.0) :type 'wrong-type-argument))
 
 (ert-deftest binding-test-set-constant-t ()
-  "Test setting the constant t"
+  "Test setting the constant t."
   (with-no-warnings (should-error (setq t 'bob) :type 'setting-constant)))
 
 (ert-deftest binding-test-set-constant-nil ()
-  "Test setting the constant nil"
+  "Test setting the constant nil."
   (with-no-warnings (should-error (setq nil 'bob) :type 'setting-constant)))
 
 (ert-deftest binding-test-set-constant-keyword ()
-  "Test setting a keyword constant"
+  "Test setting a keyword constant."
   (with-no-warnings (should-error (setq :keyword 'bob) :type 'setting-constant)))
 
 (ert-deftest binding-test-set-constant-nil ()
-  "Test setting a keyword to itself"
+  "Test setting a keyword to itself."
   (with-no-warnings (should (setq :keyword :keyword))))
 
 (ert-deftest data-tests--set-default-per-buffer ()
diff --git a/test/src/decompress-tests.el b/test/src/decompress-tests.el
index 520445cca5a..1d25cf2f66b 100644
--- a/test/src/decompress-tests.el
+++ b/test/src/decompress-tests.el
@@ -42,4 +42,4 @@
 
 (provide 'decompress-tests)
 
-;;; decompress-tests.el ends here.
+;;; decompress-tests.el ends here
diff --git a/test/src/fileio-tests.el b/test/src/fileio-tests.el
index 438ebebb769..4143503aa18 100644
--- a/test/src/fileio-tests.el
+++ b/test/src/fileio-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Code:
+
 (require 'ert)
 
 (defun try-link (target link)
@@ -97,7 +99,7 @@ Also check that an encoding error can appear in a symlink."
   (should (equal (file-name-as-directory "D:/abc//") "d:/abc//")))
 
 (ert-deftest fileio-tests--relative-HOME ()
-  "Test that expand-file-name works even when HOME is relative."
+  "Test that `expand-file-name' works even when HOME is relative."
   (let ((process-environment (copy-sequence process-environment)))
     (setenv "HOME" "a/b/c")
     (should (equal (expand-file-name "~/foo")
@@ -128,7 +130,7 @@ Also check that an encoding error can appear in a symlink."
       (if f (delete-file f)))))
 
 (ert-deftest fileio-tests--relative-default-directory ()
-  "Test expand-file-name when default-directory is relative."
+  "Test `expand-file-name' when `default-directory' is relative."
   (let ((default-directory "some/relative/name"))
     (should (file-name-absolute-p (expand-file-name "foo"))))
   (let* ((default-directory "~foo")
@@ -137,7 +139,7 @@ Also check that an encoding error can appear in a symlink."
                  (not (eq (aref name 0) ?~))))))
 
 (ert-deftest fileio-test--expand-file-name-null-bytes ()
-  "Test that expand-file-name checks for null bytes in filenames."
+  "Test that `expand-file-name' checks for null bytes in filenames."
   (should-error (expand-file-name (concat "file" (char-to-string ?\0) ".txt"))
                 :type 'wrong-type-argument)
   (should-error (expand-file-name "file.txt" (concat "dir" (char-to-string ?\0)))
@@ -146,7 +148,7 @@ Also check that an encoding error can appear in a symlink."
     (should-error (expand-file-name "file.txt") :type 'wrong-type-argument)))
 
 (ert-deftest fileio-tests--file-name-absolute-p ()
-  "Test file-name-absolute-p."
+  "Test `file-name-absolute-p'."
   (dolist (suffix '("" "/" "//" "/foo" "/foo/" "/foo//" "/foo/bar"))
     (unless (string-equal suffix "")
       (should (file-name-absolute-p suffix)))
@@ -157,7 +159,7 @@ Also check that an encoding error can appear in a symlink."
       (should (not (file-name-absolute-p (concat "~nosuchuser" suffix)))))))
 
 (ert-deftest fileio-tests--circular-after-insert-file-functions ()
-  "Test after-insert-file-functions as a circular list."
+  "Test `after-insert-file-functions' as a circular list."
   (let ((f (make-temp-file "fileio"))
         (after-insert-file-functions (list 'identity)))
     (setcdr after-insert-file-functions after-insert-file-functions)
diff --git a/test/src/floatfns-tests.el b/test/src/floatfns-tests.el
index 4a3c03d833e..47fa1941626 100644
--- a/test/src/floatfns-tests.el
+++ b/test/src/floatfns-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Code:
+
 (require 'ert)
 
 (ert-deftest divide-extreme-sign ()
@@ -125,3 +127,5 @@
              (ash (1- (ash 1 53)) 2045))))
 
 (provide 'floatfns-tests)
+
+;;; floatfns-tests.el ends here
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index bd5a4358e65..57594572094 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -1114,3 +1114,5 @@
     (should (= (line-number-at-pos nil) 11))
     (should-error (line-number-at-pos -1))
     (should-error (line-number-at-pos 100))))
+
+;;; fns-tests.el ends here
diff --git a/test/src/indent-tests.el b/test/src/indent-tests.el
index 6a3f1a5c95f..6cfe64c07e4 100644
--- a/test/src/indent-tests.el
+++ b/test/src/indent-tests.el
@@ -57,3 +57,5 @@
       (move-to-column 12 t)
       (buffer-substring-no-properties 1 14))
     "\txxx    \tLine")))
+
+;;; indent-tests.el ends here
diff --git a/test/src/inotify-tests.el b/test/src/inotify-tests.el
index 5572c7d7a0f..8aab7eeb30a 100644
--- a/test/src/inotify-tests.el
+++ b/test/src/inotify-tests.el
@@ -70,4 +70,4 @@
 
 (provide 'inotify-tests)
 
-;;; inotify-tests.el ends here.
+;;; inotify-tests.el ends here
diff --git a/test/src/lcms-tests.el b/test/src/lcms-tests.el
index 40a48f1e9bb..d2d137e9bd5 100644
--- a/test/src/lcms-tests.el
+++ b/test/src/lcms-tests.el
@@ -95,7 +95,7 @@ B is considered the exact value."
     '(0.29902 0.31485 1.0))))
 
 (ert-deftest lcms-roundtrip ()
-  "Test accuracy of converting to and from different color spaces"
+  "Test accuracy of converting to and from different color spaces."
   (skip-unless (featurep 'lcms2))
   (should
    (let ((color '(.5 .3 .7)))
@@ -109,7 +109,7 @@ B is considered the exact value."
                            0.0001))))
 
 (ert-deftest lcms-ciecam02-gold ()
-  "Test CIE CAM02 JCh gold values"
+  "Test CIE CAM02 JCh gold values."
   (skip-unless (featurep 'lcms2))
   (should
    (lcms-triple-approx-p
diff --git a/test/src/marker-tests.el b/test/src/marker-tests.el
index 234a0b35ea7..cf8e82cd560 100644
--- a/test/src/marker-tests.el
+++ b/test/src/marker-tests.el
@@ -57,4 +57,4 @@
     (set-marker marker-2 marker-1)
     (should (goto-char marker-2))))
 
-;;; marker-tests.el ends here.
+;;; marker-tests.el ends here
diff --git a/test/src/minibuf-tests.el b/test/src/minibuf-tests.el
index feea1c112bf..51d9c67453e 100644
--- a/test/src/minibuf-tests.el
+++ b/test/src/minibuf-tests.el
@@ -414,8 +414,8 @@
   (let ((inhibit-interaction t))
     (should-error (read-from-minibuffer "foo: ") :type 'inhibited-interaction)
 
-    (should-error (y-or-n-p "foo: ") :type 'inhibited-interaction)
-    (should-error (yes-or-no-p "foo: ") :type 'inhibited-interaction)
+    (should-error (y-or-n-p "Foo?") :type 'inhibited-interaction)
+    (should-error (yes-or-no-p "Foo?") :type 'inhibited-interaction)
     (should-error (read-no-blanks-input "foo: ") :type 'inhibited-interaction)
 
     ;; See that we get the expected error.
diff --git a/test/src/process-tests.el b/test/src/process-tests.el
index 9bab523708e..e39f57d23be 100644
--- a/test/src/process-tests.el
+++ b/test/src/process-tests.el
@@ -745,7 +745,7 @@ Return nil if that can't be determined."
   process-tests--EMFILE-message)
 
 (ert-deftest process-tests/sentinel-called ()
-  "Check that sentinels are called after processes finish"
+  "Check that sentinels are called after processes finish."
   (let ((command (process-tests--emacs-command)))
     (skip-unless command)
     (dolist (conn-type '(pipe pty))
diff --git a/test/src/regex-emacs-tests.el b/test/src/regex-emacs-tests.el
index 0607eacf397..71e3189443e 100644
--- a/test/src/regex-emacs-tests.el
+++ b/test/src/regex-emacs-tests.el
@@ -279,11 +279,11 @@ on success"
 
 (defconst regex-tests-re-even-escapes
   "\\(?:^\\|[^\\]\\)\\(?:\\\\\\\\\\)*"
-  "Regex that matches an even number of \\ characters")
+  "Regex that matches an even number of \\ characters.")
 
 (defconst regex-tests-re-odd-escapes
   (concat regex-tests-re-even-escapes "\\\\")
-  "Regex that matches an odd number of \\ characters")
+  "Regex that matches an odd number of \\ characters.")
 
 
 (defun regex-tests-unextend (pattern)
@@ -396,9 +396,9 @@ pattern)"
    ;; emacs matches non-greedy regex ab.*? non-greedily
    639 677 712
    ]
-  "Line numbers in the boost test that should be skipped.  These
-are false-positive test failures that represent known/benign
-differences in behavior.")
+  "Line numbers in the boost test that should be skipped.
+These are false-positive test failures that represent
+known/benign differences in behavior.")
 
 ;; - Format
 ;;   - Comments are lines starting with ;
@@ -480,9 +480,9 @@ differences in behavior.")
    ;; ambiguous groupings are ambiguous
    610 611 1154 1157 1160 1168 1171 1176 1179 1182 1185 1188 1193 1196 1203
   ]
-  "Line numbers in the PCRE test that should be skipped.  These
-are false-positive test failures that represent known/benign
-differences in behavior.")
+  "Line numbers in the PCRE test that should be skipped.
+These are false-positive test failures that represent
+known/benign differences in behavior.")
 
 ;; - Format
 ;;
@@ -562,9 +562,9 @@ differences in behavior.")
    ;; fails to match
    168
   ]
-  "Line numbers in the PTESTS test that should be skipped.  These
-are false-positive test failures that represent known/benign
-differences in behavior.")
+  "Line numbers in the PTESTS test that should be skipped.
+These are false-positive test failures that represent
+known/benign differences in behavior.")
 
 ;; - Format
 ;;   - fields separated by ¦ (note: this is not a |)
@@ -621,9 +621,9 @@ differences in behavior.")
    ;; emacs is more stringent with regexes involving unbalanced )
    67
   ]
-  "Line numbers in the TESTS test that should be skipped.  These
-are false-positive test failures that represent known/benign
-differences in behavior.")
+  "Line numbers in the TESTS test that should be skipped.
+These are false-positive test failures that represent
+known/benign differences in behavior.")
 
 ;; - Format
 ;;   - fields separated by :. Watch for [\[:xxx:]]
diff --git a/test/src/textprop-tests.el b/test/src/textprop-tests.el
index b083588e645..c001579c474 100644
--- a/test/src/textprop-tests.el
+++ b/test/src/textprop-tests.el
@@ -69,4 +69,4 @@
 		 (null stack)))))
 
 (provide 'textprop-tests)
-;; textprop-tests.el ends here.
+;;; textprop-tests.el ends here
diff --git a/test/src/thread-tests.el b/test/src/thread-tests.el
index fc7bc7441b7..52eace7e9d2 100644
--- a/test/src/thread-tests.el
+++ b/test/src/thread-tests.el
@@ -70,12 +70,12 @@
    (thread-live-p (make-thread #'ignore))))
 
 (ert-deftest threads-all-threads ()
-  "Simple test for all-threads."
+  "Simple test for `all-threads'."
   (skip-unless (featurep 'threads))
   (should (listp (all-threads))))
 
 (ert-deftest threads-main-thread ()
-  "Simple test for all-threads."
+  "Simple test for `all-threads'."
   (skip-unless (featurep 'threads))
   (should (eq main-thread (car (all-threads)))))
 
@@ -155,7 +155,7 @@
   (should (eq (type-of (make-mutex)) 'mutex)))
 
 (ert-deftest threads-mutex-lock-unlock ()
-  "Test mutex-lock and unlock."
+  "Test `mutex-lock' and unlock."
   (skip-unless (featurep 'threads))
   (should
    (let ((mx (make-mutex)))
@@ -392,4 +392,4 @@
   (let ((th (make-thread 'ignore)))
     (should-not (equal th main-thread))))
 
-;;; threads.el ends here
+;;; thread-tests.el ends here
diff --git a/test/src/timefns-tests.el b/test/src/timefns-tests.el
index 0a450a7573f..bba9b3fcd8c 100644
--- a/test/src/timefns-tests.el
+++ b/test/src/timefns-tests.el
@@ -241,3 +241,5 @@ a fixed place on the right and are padded on the left."
         (let ((xdiv (/ x divisor)))
           (should (= xdiv (float-time (time-convert xdiv t))))))
       (setq x (* x 2)))))
+
+;;; timefns-tests.el ends here
diff --git a/test/src/xfaces-tests.el b/test/src/xfaces-tests.el
index 0a7ef55b2b6..cba706f4535 100644
--- a/test/src/xfaces-tests.el
+++ b/test/src/xfaces-tests.el
@@ -17,6 +17,8 @@
 ;; You should have received a copy of the GNU General Public License
 ;; along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.
 
+;;; Code:
+
 (require 'ert)
 
 (ert-deftest xfaces-color-distance ()
@@ -48,3 +50,5 @@
   (should (equal (color-values-from-color-spec "rgbi:0/0.5/10") nil)))
 
 (provide 'xfaces-tests)
+
+;;; xfaces-tests.el ends here
diff --git a/test/src/xml-tests.el b/test/src/xml-tests.el
index a35b4d2ccc8..7c4ca396f70 100644
--- a/test/src/xml-tests.el
+++ b/test/src/xml-tests.el
@@ -52,4 +52,4 @@
       (should (equal (cdr test)
                      (libxml-parse-xml-region (point-min) (point-max)))))))
 
-;;; libxml-tests.el ends here
+;;; xml-tests.el ends here
-- 
cgit v1.2.3


From 385741fae276c7cfe2975e8a64cf084e0f63cf3d Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefan@marxist.se>
Date: Sat, 6 Nov 2021 23:20:59 +0100
Subject: Prefer ert-with-temp-(directory|file)

* test/lisp/abbrev-tests.el (read-write-abbrev-file-test)
(read-write-abbrev-file-test-with-props)
(abbrev-edit-save-to-file-test):
* test/lisp/auth-source-tests.el (auth-source-test-netrc-create-secret)
(auth-source-delete):
* test/lisp/autoinsert-tests.el (autoinsert-tests-auto-insert-file):
* test/lisp/bookmark-tests.el (with-bookmark-test-save-load):
* test/lisp/buff-menu-tests.el (buff-menu-24962):
* test/lisp/calendar/icalendar-tests.el (icalendar-tests--do-test-export):
* test/lisp/calendar/todo-mode-tests.el (with-todo-test):
* test/lisp/dired-tests.el
(dired-test-bug27243-01, dired-test-bug27243-02)
(dired-test-bug27243-03, dired-test-bug27631)
(dired-test-bug27968, dired-test-with-temp-dirs):
* test/lisp/dired-x-tests.el (dired-test-bug25942):
* test/lisp/emacs-lisp/bytecomp-tests.el (bytecomp-tests--with-temp-file):
* test/lisp/emacs-lisp/check-declare-tests.el (check-declare-tests-scan)
(check-declare-tests-verify-mismatch):
* test/lisp/emacs-lisp/edebug-tests.el (edebug-tests-with-normal-env):
* test/lisp/emacs-lisp/package-tests.el (with-package-test)
(package-test-signed):
* test/lisp/emacs-lisp/testcover-tests.el (testcover-tests-markup-region)
(testcover-tests-run-test-case):
* test/lisp/emulation/viper-tests.el (viper-test-undo-kmacro):
* test/lisp/epg-tests.el (with-epg-tests):
* test/lisp/eshell/em-hist-tests.el (eshell-write-readonly-history):
* test/lisp/eshell/em-ls-tests.el (em-ls-test-bug27631):
* test/lisp/ffap-tests.el (ffap-tests-25243):
* test/lisp/files-tests.el (files-tests-bug-18141)
(files-tests-read-file-in-~, files-tests-make-directory)
(files-tests-copy-directory, files-tests-executable-find)
(files-tests-dont-rewrite-precious-files)
(files-tests--save-some-buffers):
* test/lisp/ls-lisp-tests.el (ls-lisp-test-bug27631):
* test/lisp/mail/uudecode-tests.el (uudecode-tests-decode-region-internal)
(uudecode-tests-decode-region-external):
* test/lisp/net/browse-url-tests.el (browse-url-tests-delete-temp-file):
* test/lisp/progmodes/elisp-mode-tests.el (xref--case-insensitive):
* test/lisp/progmodes/etags-tests.el (etags-buffer-local-tags-table-list):
* test/lisp/progmodes/flymake-tests.el (ruby-backend):
* test/lisp/progmodes/python-tests.el (python-tests-with-temp-file):
* test/lisp/progmodes/sql-tests.el (with-sql-test-connect-harness):
* test/lisp/saveplace-tests.el (saveplace-test-save-place-to-alist/file)
(saveplace-test-forget-unreadable-files)
(saveplace-test-place-alist-to-file):
* test/lisp/so-long-tests/spelling-tests.el:
* test/lisp/textmodes/reftex-tests.el (reftex-locate-bibliography-files)
(reftex-parse-from-file-test):
* test/lisp/thumbs-tests.el (thumbs-tests-thumbsdir/create-if-missing):
* test/lisp/vc/vc-bzr-tests.el (vc-bzr-test-bug9726)
(vc-bzr-test-bug9781, vc-bzr-test-faulty-bzr-autoloads):
* test/lisp/vc/diff-mode-tests.el (diff-mode-test-ignore-trailing-dashes):
* test/lisp/vc/ediff-ptch-tests.el (ediff-ptch-test-bug26084):
* test/lisp/wdired-tests.el (wdired-test-bug32173-01)
(wdired-test-bug32173-02, wdired-test-symlink-name)
(wdired-test-unfinished-edit-01, wdired-test-bug34915)
(wdired-test-bug39280):
* test/src/buffer-tests.el (test-kill-buffer-auto-save-default):
* test/src/filelock-tests.el (filelock-tests--fixture):
* test/src/inotify-tests.el (inotify-file-watch-simple):
* test/src/undo-tests.el (undo-test-file-modified): Prefer
'ert-with-temp-(directory|file)' to using 'make-temp-file' directly.
In some cases, this is just cleanup, but in several cases this fixes
bugs where an error would have lead to us not cleaning up.
---
 test/lisp/abbrev-tests.el                   |  60 +++--
 test/lisp/auth-source-tests.el              | 131 +++++------
 test/lisp/autoinsert-tests.el               |  19 +-
 test/lisp/bookmark-tests.el                 |  18 +-
 test/lisp/buff-menu-tests.el                |  21 +-
 test/lisp/calendar/icalendar-tests.el       |  50 ++--
 test/lisp/calendar/todo-mode-tests.el       |  37 ++-
 test/lisp/dired-aux-tests.el                |   1 +
 test/lisp/dired-tests.el                    | 352 ++++++++++++++--------------
 test/lisp/dired-x-tests.el                  |  30 ++-
 test/lisp/emacs-lisp/bytecomp-tests.el      |   3 +-
 test/lisp/emacs-lisp/check-declare-tests.el |  96 ++++----
 test/lisp/emacs-lisp/edebug-tests.el        |  42 ++--
 test/lisp/emacs-lisp/package-tests.el       | 136 ++++++-----
 test/lisp/emacs-lisp/testcover-tests.el     | 108 ++++-----
 test/lisp/emulation/viper-tests.el          |  80 +++----
 test/lisp/epg-tests.el                      |  77 +++---
 test/lisp/eshell/em-hist-tests.el           |  17 +-
 test/lisp/eshell/em-ls-tests.el             |  38 +--
 test/lisp/ffap-tests.el                     |  29 ++-
 test/lisp/files-tests.el                    | 248 ++++++++++----------
 test/lisp/ls-lisp-tests.el                  |  33 +--
 test/lisp/mail/uudecode-tests.el            |  26 +-
 test/lisp/net/browse-url-tests.el           |   6 +-
 test/lisp/progmodes/elisp-mode-tests.el     |   9 +-
 test/lisp/progmodes/etags-tests.el          |  31 ++-
 test/lisp/progmodes/flymake-tests.el        |  32 +--
 test/lisp/progmodes/python-tests.el         |  23 +-
 test/lisp/progmodes/sql-tests.el            |  90 ++++---
 test/lisp/saveplace-tests.el                |  67 +++---
 test/lisp/so-long-tests/spelling-tests.el   |  30 +--
 test/lisp/textmodes/reftex-tests.el         | 101 ++++----
 test/lisp/thumbs-tests.el                   |  10 +-
 test/lisp/vc/diff-mode-tests.el             |  56 +++--
 test/lisp/vc/ediff-ptch-tests.el            |  60 +++--
 test/lisp/vc/vc-bzr-tests.el                | 172 +++++++-------
 test/lisp/wdired-tests.el                   | 267 +++++++++++----------
 test/src/buffer-tests.el                    |  38 +--
 test/src/filelock-tests.el                  |  31 ++-
 test/src/inotify-tests.el                   |  31 ++-
 test/src/undo-tests.el                      |  20 +-
 41 files changed, 1321 insertions(+), 1405 deletions(-)

(limited to 'test/lisp/vc/diff-mode-tests.el')

diff --git a/test/lisp/abbrev-tests.el b/test/lisp/abbrev-tests.el
index 2dcfb1c309e..863806af7b3 100644
--- a/test/lisp/abbrev-tests.el
+++ b/test/lisp/abbrev-tests.el
@@ -28,6 +28,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'abbrev)
 (require 'seq)
 
@@ -236,44 +237,41 @@
 
 (ert-deftest read-write-abbrev-file-test ()
   "Test reading and writing abbrevs from file."
-  (let ((temp-test-file (make-temp-file "ert-abbrev-test"))
-        (ert-test-abbrevs (setup-test-abbrev-table)))
-    (write-abbrev-file temp-test-file)
-    (clear-abbrev-table ert-test-abbrevs)
-    (should (abbrev-table-empty-p ert-test-abbrevs))
-    (read-abbrev-file temp-test-file)
-    (should (equal "abbrev-ert-test" (abbrev-expansion "a-e-t" ert-test-abbrevs)))
-    (delete-file temp-test-file)))
+  (ert-with-temp-file temp-test-file
+    (let ((ert-test-abbrevs (setup-test-abbrev-table)))
+      (write-abbrev-file temp-test-file)
+      (clear-abbrev-table ert-test-abbrevs)
+      (should (abbrev-table-empty-p ert-test-abbrevs))
+      (read-abbrev-file temp-test-file)
+      (should (equal "abbrev-ert-test" (abbrev-expansion "a-e-t" ert-test-abbrevs))))))
 
 (ert-deftest read-write-abbrev-file-test-with-props ()
   "Test reading and writing abbrevs from file."
-  (let ((temp-test-file (make-temp-file "ert-abbrev-test"))
-        (ert-test-abbrevs (setup-test-abbrev-table-with-props)))
-    (write-abbrev-file temp-test-file)
-    (clear-abbrev-table ert-test-abbrevs)
-    (should (abbrev-table-empty-p ert-test-abbrevs))
-    (read-abbrev-file temp-test-file)
-    (should (equal "fooBar" (abbrev-expansion "fb" ert-test-abbrevs)))
-    (delete-file temp-test-file)))
+  (ert-with-temp-file temp-test-file
+    (let ((ert-test-abbrevs (setup-test-abbrev-table-with-props)))
+      (write-abbrev-file temp-test-file)
+      (clear-abbrev-table ert-test-abbrevs)
+      (should (abbrev-table-empty-p ert-test-abbrevs))
+      (read-abbrev-file temp-test-file)
+      (should (equal "fooBar" (abbrev-expansion "fb" ert-test-abbrevs))))))
 
 (ert-deftest abbrev-edit-save-to-file-test ()
   "Test saving abbrev definitions in buffer to file."
   (defvar ert-save-test-table nil)
-  (let ((temp-test-file (make-temp-file "ert-abbrev-test"))
-        (ert-test-abbrevs (setup-test-abbrev-table)))
-    (with-temp-buffer
-      (goto-char (point-min))
-      (insert "(ert-save-test-table)\n")
-      (insert "\n" "\"s-a-t\"\t" "0\t" "\"save-abbrevs-test\"\n")
-      (should (equal "abbrev-ert-test"
-                     (abbrev-expansion "a-e-t" ert-test-abbrevs)))
-      ;; clears abbrev tables
-      (abbrev-edit-save-to-file temp-test-file)
-      (should-not (abbrev-expansion "a-e-t" ert-test-abbrevs))
-      (read-abbrev-file temp-test-file)
-      (should (equal "save-abbrevs-test"
-                     (abbrev-expansion "s-a-t" ert-save-test-table)))
-      (delete-file temp-test-file))))
+  (ert-with-temp-file temp-test-file
+    (let ((ert-test-abbrevs (setup-test-abbrev-table)))
+      (with-temp-buffer
+        (goto-char (point-min))
+        (insert "(ert-save-test-table)\n")
+        (insert "\n" "\"s-a-t\"\t" "0\t" "\"save-abbrevs-test\"\n")
+        (should (equal "abbrev-ert-test"
+                       (abbrev-expansion "a-e-t" ert-test-abbrevs)))
+        ;; clears abbrev tables
+        (abbrev-edit-save-to-file temp-test-file)
+        (should-not (abbrev-expansion "a-e-t" ert-test-abbrevs))
+        (read-abbrev-file temp-test-file)
+        (should (equal "save-abbrevs-test"
+                       (abbrev-expansion "s-a-t" ert-save-test-table)))))))
 
 (ert-deftest inverse-add-abbrev-skips-trailing-nonword ()
   "Test that adding an inverse abbrev skips trailing nonword characters."
diff --git a/test/lisp/auth-source-tests.el b/test/lisp/auth-source-tests.el
index 5140970b0b6..0d2143f9d5a 100644
--- a/test/lisp/auth-source-tests.el
+++ b/test/lisp/auth-source-tests.el
@@ -27,6 +27,7 @@
 ;;; Code:
 
 (require 'ert)
+(eval-when-compile (require 'ert-x))
 (require 'cl-lib)
 (require 'auth-source)
 (require 'secrets)
@@ -360,77 +361,73 @@
        (format "%s@%s" (plist-get auth-info :user) (plist-get auth-info :host))))))
 
 (ert-deftest auth-source-test-netrc-create-secret ()
-  (let* ((netrc-file (make-temp-file "auth-source-test"))
-         (auth-sources (list netrc-file))
-         (auth-source-save-behavior t)
-         host auth-info auth-passwd)
-    (unwind-protect
-        (dolist (passwd '("foo" "" nil))
-          ;; Redefine `read-*' in order to avoid interactive input.
-          (cl-letf (((symbol-function 'read-passwd) (lambda (_) passwd))
-                    ((symbol-function 'read-string)
-                     (lambda (_prompt &optional _initial _history default
-                                      _inherit-input-method)
-                       default)))
-            (setq host
-                  (md5 (concat (prin1-to-string process-environment) passwd))
-                  auth-info
-                  (car (auth-source-search
-                        :max 1 :host host :require '(:user :secret) :create t))
-	          auth-passwd (plist-get auth-info :secret)
-	          auth-passwd (if (functionp auth-passwd)
-			          (funcall auth-passwd)
-			        auth-passwd))
-            (should (string-equal (plist-get auth-info :user) (user-login-name)))
-            (should (string-equal (plist-get auth-info :host) host))
-            (should (equal auth-passwd passwd))
-            (when (functionp (plist-get auth-info :save-function))
-              (funcall (plist-get auth-info :save-function)))
-
-            ;; Check, that the item has been created indeed.
-            (auth-source-forget+ :host t)
-            (setq auth-source-netrc-cache nil)
-            (setq auth-info (car (auth-source-search :host host))
-	          auth-passwd (plist-get auth-info :secret)
-	          auth-passwd (if (functionp auth-passwd)
-			          (funcall auth-passwd)
-			        auth-passwd))
-            (with-temp-buffer
-              (insert-file-contents netrc-file)
-              (if (zerop (length passwd))
-                  (progn
-                    (should-not (plist-get auth-info :user))
-                    (should-not (plist-get auth-info :host))
-                    (should-not auth-passwd)
-                    (should-not (search-forward host nil 'noerror)))
-                (should
-                 (string-equal (plist-get auth-info :user) (user-login-name)))
-                (should (string-equal (plist-get auth-info :host) host))
-                (should (string-equal auth-passwd passwd))
-                (should (search-forward host nil 'noerror))))))
-
-      ;; Cleanup.
-      (delete-file netrc-file))))
+  (ert-with-temp-file netrc-file
+    :suffix "auth-source-test"
+    (let* ((auth-sources (list netrc-file))
+           (auth-source-save-behavior t)
+           host auth-info auth-passwd)
+      (dolist (passwd '("foo" "" nil))
+        ;; Redefine `read-*' in order to avoid interactive input.
+        (cl-letf (((symbol-function 'read-passwd) (lambda (_) passwd))
+                  ((symbol-function 'read-string)
+                   (lambda (_prompt &optional _initial _history default
+                               _inherit-input-method)
+                     default)))
+          (setq host
+                (md5 (concat (prin1-to-string process-environment) passwd))
+                auth-info
+                (car (auth-source-search
+                      :max 1 :host host :require '(:user :secret) :create t))
+                auth-passwd (plist-get auth-info :secret)
+                auth-passwd (if (functionp auth-passwd)
+                                (funcall auth-passwd)
+                              auth-passwd))
+          (should (string-equal (plist-get auth-info :user) (user-login-name)))
+          (should (string-equal (plist-get auth-info :host) host))
+          (should (equal auth-passwd passwd))
+          (when (functionp (plist-get auth-info :save-function))
+            (funcall (plist-get auth-info :save-function)))
+
+          ;; Check, that the item has been created indeed.
+          (auth-source-forget+ :host t)
+          (setq auth-source-netrc-cache nil)
+          (setq auth-info (car (auth-source-search :host host))
+                auth-passwd (plist-get auth-info :secret)
+                auth-passwd (if (functionp auth-passwd)
+                                (funcall auth-passwd)
+                              auth-passwd))
+          (with-temp-buffer
+            (insert-file-contents netrc-file)
+            (if (zerop (length passwd))
+                (progn
+                  (should-not (plist-get auth-info :user))
+                  (should-not (plist-get auth-info :host))
+                  (should-not auth-passwd)
+                  (should-not (search-forward host nil 'noerror)))
+              (should
+               (string-equal (plist-get auth-info :user) (user-login-name)))
+              (should (string-equal (plist-get auth-info :host) host))
+              (should (string-equal auth-passwd passwd))
+              (should (search-forward host nil 'noerror)))))))))
 
 (ert-deftest auth-source-delete ()
-  (let* ((netrc-file (make-temp-file "auth-source-test" nil nil "\
+  (ert-with-temp-file netrc-file
+    :suffix "auth-source-test" :text "\
 machine a1 port a2 user a3 password a4
 machine b1 port b2 user b3 password b4
-machine c1 port c2 user c3 password c4\n"))
-         (auth-sources (list netrc-file))
-         (auth-source-do-cache nil)
-         (expected '((:host "a1" :port "a2" :user "a3" :secret "a4")))
-         (parameters '(:max 1 :host t)))
-    (unwind-protect
-        (let ((found (apply #'auth-source-delete parameters)))
-          (dolist (f found)
-            (let ((s (plist-get f :secret)))
-              (setf f (plist-put f :secret
-                                 (if (functionp s) (funcall s) s)))))
-          ;; Note: The netrc backend doesn't delete anything, so
-          ;; this is actually the same as `auth-source-search'.
-          (should (equal found expected)))
-      (delete-file netrc-file))))
+machine c1 port c2 user c3 password c4\n"
+    (let* ((auth-sources (list netrc-file))
+           (auth-source-do-cache nil)
+           (expected '((:host "a1" :port "a2" :user "a3" :secret "a4")))
+           (parameters '(:max 1 :host t))
+           (found (apply #'auth-source-delete parameters)))
+      (dolist (f found)
+        (let ((s (plist-get f :secret)))
+          (setf f (plist-put f :secret
+                             (if (functionp s) (funcall s) s)))))
+      ;; Note: The netrc backend doesn't delete anything, so
+      ;; this is actually the same as `auth-source-search'.
+      (should (equal found expected)))))
 
 (provide 'auth-source-tests)
 ;;; auth-source-tests.el ends here
diff --git a/test/lisp/autoinsert-tests.el b/test/lisp/autoinsert-tests.el
index 7ec4bf63791..b264323ca15 100644
--- a/test/lisp/autoinsert-tests.el
+++ b/test/lisp/autoinsert-tests.el
@@ -28,6 +28,7 @@
 
 (require 'autoinsert)
 (require 'ert)
+(require 'ert-x)
 
 (ert-deftest autoinsert-tests-auto-insert-skeleton ()
   (let ((auto-insert-alist '((text-mode nil "f" _ "oo")))
@@ -39,16 +40,14 @@
       (should (equal (point) (+ (point-min) 1))))))
 
 (ert-deftest autoinsert-tests-auto-insert-file ()
-  (let ((temp-file (make-temp-file "autoinsert-tests" nil nil "foo")))
-    (unwind-protect
-        (let ((auto-insert-alist `((text-mode . ,temp-file)))
-              (auto-insert-query nil))
-          (with-temp-buffer
-            (text-mode)
-            (auto-insert)
-            (should (equal (buffer-string) "foo"))))
-      (when (file-exists-p temp-file)
-        (delete-file temp-file)))))
+  (ert-with-temp-file temp-file
+    :text "foo"
+    (let ((auto-insert-alist `((text-mode . ,temp-file)))
+          (auto-insert-query nil))
+      (with-temp-buffer
+        (text-mode)
+        (auto-insert)
+        (should (equal (buffer-string) "foo"))))))
 
 (ert-deftest autoinsert-tests-auto-insert-function ()
   (let ((auto-insert-alist '((text-mode . (lambda () (insert "foo")))))
diff --git a/test/lisp/bookmark-tests.el b/test/lisp/bookmark-tests.el
index 9c33a27288a..dc2dec68ee3 100644
--- a/test/lisp/bookmark-tests.el
+++ b/test/lisp/bookmark-tests.el
@@ -371,16 +371,14 @@ Same as `with-bookmark-test' but also sets a temporary
 `bookmark-default-file', evaluates BODY, and then runs the test
 that saves and then loads the bookmark file."
   `(with-bookmark-test
-    (let ((file (make-temp-file "bookmark-tests-")))
-      (unwind-protect
-          (let ((bookmark-default-file file)
-                (old-alist bookmark-alist))
-            ,@body
-            (bookmark-save nil file t)
-            (setq bookmark-alist nil)
-            (bookmark-load file nil t)
-            (should (equal bookmark-alist old-alist)))
-        (delete-file file)))))
+    (ert-with-temp-file file
+      (let ((bookmark-default-file file)
+            (old-alist bookmark-alist))
+        ,@body
+        (bookmark-save nil file t)
+        (setq bookmark-alist nil)
+        (bookmark-load file nil t)
+        (should (equal bookmark-alist old-alist))))))
 
 (defvar bookmark-tests-non-ascii-data
   (concat "Здра́вствуйте!" "中文,普通话,汉语" "åäöøñ"
diff --git a/test/lisp/buff-menu-tests.el b/test/lisp/buff-menu-tests.el
index 18c988656d3..b223a643083 100644
--- a/test/lisp/buff-menu-tests.el
+++ b/test/lisp/buff-menu-tests.el
@@ -24,19 +24,20 @@
 ;;; Code:
 
 (require 'ert)
+(eval-when-compile (require 'ert-x))
 
 (ert-deftest buff-menu-24962 ()
   "Test for https://debbugs.gnu.org/24962 ."
-  (let* ((file (make-temp-file "foo"))
-         (buf (find-file file)))
-    (unwind-protect
-        (progn
-          (rename-buffer " foo")
-          (list-buffers)
-          (with-current-buffer "*Buffer List*"
-            (should (string= " foo" (buffer-name (Buffer-menu-buffer))))))
-      (and (buffer-live-p buf) (kill-buffer buf))
-      (and (file-exists-p file) (delete-file file)))))
+  (ert-with-temp-file file
+    :suffix "foo"
+    (let ((buf (find-file file)))
+      (unwind-protect
+          (progn
+            (rename-buffer " foo")
+            (list-buffers)
+            (with-current-buffer "*Buffer List*"
+              (should (string= " foo" (buffer-name (Buffer-menu-buffer))))))
+        (and (buffer-live-p buf) (kill-buffer buf))))))
 
 (provide 'buff-menu-tests)
 
diff --git a/test/lisp/calendar/icalendar-tests.el b/test/lisp/calendar/icalendar-tests.el
index a1853ff3d4e..264da3ce57d 100644
--- a/test/lisp/calendar/icalendar-tests.el
+++ b/test/lisp/calendar/icalendar-tests.el
@@ -698,17 +698,18 @@ and ISO style input data must use english month names."
   "Actually perform export test.
 Argument INPUT input diary string.
 Argument EXPECTED-OUTPUT expected iCalendar result string."
-  (let ((temp-file (make-temp-file "icalendar-tests-ics")))
+  (ert-with-temp-file temp-file
+    :suffix "icalendar-tests-ics"
     (unwind-protect
-	(progn
-	  (with-temp-buffer
-	    (insert input)
-	    (icalendar-export-region (point-min) (point-max) temp-file))
-	  (save-excursion
-	    (find-file temp-file)
-	    (goto-char (point-min))
-	    (cond (expected-output
-		   (should (re-search-forward "^\\s-*BEGIN:VCALENDAR
+        (progn
+          (with-temp-buffer
+            (insert input)
+            (icalendar-export-region (point-min) (point-max) temp-file))
+          (save-excursion
+            (find-file temp-file)
+            (goto-char (point-min))
+            (cond (expected-output
+                   (should (re-search-forward "^\\s-*BEGIN:VCALENDAR
 PRODID:-//Emacs//NONSGML icalendar.el//EN
 VERSION:2.0
 BEGIN:VEVENT
@@ -717,23 +718,22 @@ UID:emacs[0-9]+
 END:VEVENT
 END:VCALENDAR
 \\s-*$"
-					      nil t))
-		   (should (string-match
-			    (concat "^\\s-*"
-				    (regexp-quote (buffer-substring-no-properties
-						   (match-beginning 1) (match-end 1)))
-				    "\\s-*$")
-			    expected-output)))
-		  (t
-		   (should (re-search-forward "^\\s-*BEGIN:VCALENDAR
+                                              nil t))
+                   (should (string-match
+                            (concat "^\\s-*"
+                                    (regexp-quote (buffer-substring-no-properties
+                                                   (match-beginning 1) (match-end 1)))
+                                    "\\s-*$")
+                            expected-output)))
+                  (t
+                   (should (re-search-forward "^\\s-*BEGIN:VCALENDAR
 PRODID:-//Emacs//NONSGML icalendar.el//EN
 VERSION:2.0
 END:VCALENDAR
 \\s-*$"
-					      nil t))))))
+                                              nil t))))))
       ;; cleanup!!
-      (kill-buffer (find-buffer-visiting temp-file))
-      (delete-file temp-file))))
+      (kill-buffer (find-buffer-visiting temp-file)))))
 
 (ert-deftest icalendar-export-ordinary-no-time ()
   "Perform export test."
@@ -1031,7 +1031,8 @@ During import test the timezone is set to Central European Time."
 (defun icalendar-tests--do-test-import (expected-output)
   "Actually perform import test.
 Argument EXPECTED-OUTPUT file containing expected diary string."
-  (let ((temp-file (make-temp-file "icalendar-test-diary")))
+  (ert-with-temp-file temp-file
+    :suffix "icalendar-test-diary"
     ;; Test the Catch-the-mysterious-coding-header logic below.
     ;; Ruby-mode adds an after-save-hook which inserts the header!
     ;; (save-excursion
@@ -1061,8 +1062,7 @@ Argument EXPECTED-OUTPUT file containing expected diary string."
 
       (let ((result (buffer-substring-no-properties (point-min) (point-max))))
         (should (string= expected-output result)))
-      (kill-buffer (find-buffer-visiting temp-file))
-      (delete-file temp-file))))
+      (kill-buffer (find-buffer-visiting temp-file)))))
 
 (ert-deftest icalendar-import-non-recurring ()
   "Perform standard import tests."
diff --git a/test/lisp/calendar/todo-mode-tests.el b/test/lisp/calendar/todo-mode-tests.el
index 9b5d990b9bd..79978a2041f 100644
--- a/test/lisp/calendar/todo-mode-tests.el
+++ b/test/lisp/calendar/todo-mode-tests.el
@@ -37,25 +37,24 @@
 (defmacro with-todo-test (&rest body)
   "Set up an isolated `todo-mode' test environment."
   (declare (debug (body)))
-  `(let* ((todo-test-home (make-temp-file "todo-test-home-" t))
-          ;; Since we change HOME, clear this to avoid a conflict
-          ;; e.g. if Emacs runs within the user's home directory.
-          (abbreviated-home-dir nil)
-          (process-environment (cons (format "HOME=%s" todo-test-home)
-                                     process-environment))
-          (todo-directory (ert-resource-directory))
-          (todo-default-todo-file (todo-short-file-name
-				   (car (funcall todo-files-function)))))
-     (unwind-protect
-         (progn ,@body)
-       ;; Restore pre-test-run state of test files.
-       (dolist (f (directory-files todo-directory))
-         (let ((buf (get-file-buffer f)))
-           (when buf
-             (with-current-buffer buf
-               (restore-buffer-modified-p nil)
-               (kill-buffer)))))
-       (delete-directory todo-test-home t))))
+  `(ert-with-temp-directory todo-test-home
+     (let* (;; Since we change HOME, clear this to avoid a conflict
+            ;; e.g. if Emacs runs within the user's home directory.
+            (abbreviated-home-dir nil)
+            (process-environment (cons (format "HOME=%s" todo-test-home)
+                                       process-environment))
+            (todo-directory (ert-resource-directory))
+            (todo-default-todo-file (todo-short-file-name
+                                 (car (funcall todo-files-function)))))
+       (unwind-protect
+           (progn ,@body)
+         ;; Restore pre-test-run state of test files.
+         (dolist (f (directory-files todo-directory))
+           (let ((buf (get-file-buffer f)))
+             (when buf
+               (with-current-buffer buf
+                 (restore-buffer-modified-p nil)
+                 (kill-buffer)))))))))
 
 (defun todo-test--show (num &optional archive)
   "Display category NUM of test todo file.
diff --git a/test/lisp/dired-aux-tests.el b/test/lisp/dired-aux-tests.el
index d5940ed8ca7..88a2c9f92c5 100644
--- a/test/lisp/dired-aux-tests.el
+++ b/test/lisp/dired-aux-tests.el
@@ -19,6 +19,7 @@
 
 ;;; Code:
 (require 'ert)
+(require 'ert-x)
 (require 'dired-aux)
 (eval-when-compile (require 'cl-lib))
 
diff --git a/test/lisp/dired-tests.el b/test/lisp/dired-tests.el
index 83f7dc3cac7..ad1bca923d9 100644
--- a/test/lisp/dired-tests.el
+++ b/test/lisp/dired-tests.el
@@ -19,6 +19,7 @@
 
 ;;; Code:
 (require 'ert)
+(require 'ert-x)
 (require 'dired)
 
 (ert-deftest dired-autoload ()
@@ -141,116 +142,113 @@
 
 (ert-deftest dired-test-bug27243-01 ()
   "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#5 ."
-  (let* ((test-dir (file-name-as-directory (make-temp-file "test-dir-" t)))
-         (save-pos (lambda ()
-                     (with-current-buffer (car (dired-buffers-for-dir test-dir))
-                       (dired-save-positions))))
-         (dired-auto-revert-buffer t) buffers)
-    ;; On MS-Windows, get rid of 8+3 short names in test-dir, if the
-    ;; corresponding long file names exist, otherwise such names trip
-    ;; dired-buffers-for-dir.
-    (if (eq system-type 'windows-nt)
-        (setq test-dir (file-truename test-dir)))
-    (should-not (dired-buffers-for-dir test-dir))
-    (with-current-buffer (find-file-noselect test-dir)
-      (make-directory "test-subdir"))
-    (message "Saved pos: %S" (funcall save-pos))
-    ;; Point must be at end-of-buffer.
-    (with-current-buffer (car (dired-buffers-for-dir test-dir))
-      (should (eobp)))
-    (push (dired test-dir) buffers)
-    (message "Saved pos: %S" (funcall save-pos))
-    ;; Previous dired call shouldn't create a new buffer: must visit the one
-    ;; created by `find-file-noselect' above.
-    (should (eq 1 (length (dired-buffers-for-dir test-dir))))
-    (unwind-protect
-        (let ((buf (current-buffer))
-              (pt1 (point))
-              (test-file (concat (file-name-as-directory "test-subdir")
-                                 "test-file")))
-          (message "Saved pos: %S" (funcall save-pos))
-          (write-region "Test" nil test-file nil 'silent nil 'excl)
-          (message "Saved pos: %S" (funcall save-pos))
-          ;; Sanity check: point should now be on the subdirectory.
-          (should (equal (dired-file-name-at-point)
-                         (concat test-dir (file-name-as-directory "test-subdir"))))
-          (message "Saved pos: %S" (funcall save-pos))
-          (push (dired-find-file) buffers)
-          (let ((pt2 (point)))          ; Point is on test-file.
-            (pop-to-buffer-same-window buf)
-            ;; Sanity check: point should now be back on the subdirectory.
-            (should (eq (point) pt1))
+  (ert-with-temp-directory test-dir
+    (let* ((save-pos (lambda ()
+                       (with-current-buffer (car (dired-buffers-for-dir test-dir))
+                         (dired-save-positions))))
+           (dired-auto-revert-buffer t) buffers)
+      ;; On MS-Windows, get rid of 8+3 short names in test-dir, if the
+      ;; corresponding long file names exist, otherwise such names trip
+      ;; dired-buffers-for-dir.
+      (if (eq system-type 'windows-nt)
+          (setq test-dir (file-truename test-dir)))
+      (should-not (dired-buffers-for-dir test-dir))
+      (with-current-buffer (find-file-noselect test-dir)
+        (make-directory "test-subdir"))
+      (message "Saved pos: %S" (funcall save-pos))
+      ;; Point must be at end-of-buffer.
+      (with-current-buffer (car (dired-buffers-for-dir test-dir))
+        (should (eobp)))
+      (push (dired test-dir) buffers)
+      (message "Saved pos: %S" (funcall save-pos))
+      ;; Previous dired call shouldn't create a new buffer: must visit the one
+      ;; created by `find-file-noselect' above.
+      (should (eq 1 (length (dired-buffers-for-dir test-dir))))
+      (unwind-protect
+          (let ((buf (current-buffer))
+                (pt1 (point))
+                (test-file (concat (file-name-as-directory "test-subdir")
+                                   "test-file")))
+            (message "Saved pos: %S" (funcall save-pos))
+            (write-region "Test" nil test-file nil 'silent nil 'excl)
+            (message "Saved pos: %S" (funcall save-pos))
+            ;; Sanity check: point should now be on the subdirectory.
+            (should (equal (dired-file-name-at-point)
+                           (concat test-dir (file-name-as-directory "test-subdir"))))
+            (message "Saved pos: %S" (funcall save-pos))
             (push (dired-find-file) buffers)
-            (should (eq (point) pt2))))
-      (dolist (buf buffers)
-        (when (buffer-live-p buf) (kill-buffer buf)))
-      (delete-directory test-dir t))))
+            (let ((pt2 (point)))         ; Point is on test-file.
+              (pop-to-buffer-same-window buf)
+              ;; Sanity check: point should now be back on the subdirectory.
+              (should (eq (point) pt1))
+              (push (dired-find-file) buffers)
+              (should (eq (point) pt2))))
+        (dolist (buf buffers)
+          (when (buffer-live-p buf) (kill-buffer buf)))))))
 
 (ert-deftest dired-test-bug27243-02 ()
   "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#28 ."
-  (let ((test-dir (make-temp-file "test-dir-" t))
-        (dired-auto-revert-buffer t) buffers)
-    ;; On MS-Windows, get rid of 8+3 short names in test-dir, if the
-    ;; corresponding long file names exist, otherwise such names trip
-    ;; string comparisons below.
-    (if (eq system-type 'windows-nt)
-        (setq test-dir (file-truename test-dir)))
-    (with-current-buffer (find-file-noselect test-dir)
-      (make-directory "test-subdir"))
-    (push (dired test-dir) buffers)
-    (unwind-protect
-        (let ((buf (current-buffer))
-              (pt1 (point))
-              (test-file (concat (file-name-as-directory "test-subdir")
-                                 "test-file")))
-          (write-region "Test" nil test-file nil 'silent nil 'excl)
-          ;; Sanity check: point should now be on the subdirectory.
-          (should (equal (dired-file-name-at-point)
-                         (concat (file-name-as-directory test-dir)
-                                 (file-name-as-directory "test-subdir"))))
-          (push (dired-find-file) buffers)
-          ;; Point is on test-file.
-          (switch-to-buffer buf)
-          ;; Sanity check: point should now be back on the subdirectory.
-          (should (eq (point) pt1))
-          (push (dired test-dir) buffers)
-          (should (eq (point) pt1)))
-      (dolist (buf buffers)
-        (when (buffer-live-p buf) (kill-buffer buf)))
-      (delete-directory test-dir t))))
+  (ert-with-temp-directory test-dir
+    (let ((dired-auto-revert-buffer t) buffers)
+      ;; On MS-Windows, get rid of 8+3 short names in test-dir, if the
+      ;; corresponding long file names exist, otherwise such names trip
+      ;; string comparisons below.
+      (if (eq system-type 'windows-nt)
+          (setq test-dir (file-truename test-dir)))
+      (with-current-buffer (find-file-noselect test-dir)
+        (make-directory "test-subdir"))
+      (push (dired test-dir) buffers)
+      (unwind-protect
+          (let ((buf (current-buffer))
+                (pt1 (point))
+                (test-file (concat (file-name-as-directory "test-subdir")
+                                   "test-file")))
+            (write-region "Test" nil test-file nil 'silent nil 'excl)
+            ;; Sanity check: point should now be on the subdirectory.
+            (should (equal (dired-file-name-at-point)
+                           (concat (file-name-as-directory test-dir)
+                                   (file-name-as-directory "test-subdir"))))
+            (push (dired-find-file) buffers)
+            ;; Point is on test-file.
+            (switch-to-buffer buf)
+            ;; Sanity check: point should now be back on the subdirectory.
+            (should (eq (point) pt1))
+            (push (dired test-dir) buffers)
+            (should (eq (point) pt1)))
+        (dolist (buf buffers)
+          (when (buffer-live-p buf) (kill-buffer buf)))))))
 
 (ert-deftest dired-test-bug27243-03 ()
   "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#61 ."
-  (let ((test-dir (make-temp-file "test-dir-" t))
-        (dired-auto-revert-buffer t)
-        allbufs)
-    (unwind-protect
-        (progn
-          (with-current-buffer (find-file-noselect test-dir)
-            (push (current-buffer) allbufs)
-            (make-directory "test-subdir1")
-            (make-directory "test-subdir2")
-            (let ((test-file1 "test-file1")
-                  (test-file2 "test-file2"))
-              (with-current-buffer (find-file-noselect "test-subdir1")
-                (push (current-buffer) allbufs)
-                (write-region "Test1" nil test-file1 nil 'silent nil 'excl))
-              (with-current-buffer (find-file-noselect "test-subdir2")
-                (push (current-buffer) allbufs)
-                (write-region "Test2" nil test-file2 nil 'silent nil 'excl))))
-          ;; Call find-file with a wild card and test point in each file.
-          (let ((buffers (find-file (concat (file-name-as-directory test-dir)
-                                            "*")
-                                    t)))
-            (dolist (buf buffers)
-              (let ((pt (with-current-buffer buf (point))))
-                (switch-to-buffer (find-file-noselect test-dir))
-                (find-file (buffer-name buf))
-                (should (equal (point) pt))))
-            (append buffers allbufs)))
-      (dolist (buf allbufs)
-        (when (buffer-live-p buf) (kill-buffer buf)))
-      (delete-directory test-dir t))))
+  (ert-with-temp-directory test-dir
+    (let ((dired-auto-revert-buffer t)
+          allbufs)
+      (unwind-protect
+          (progn
+            (with-current-buffer (find-file-noselect test-dir)
+              (push (current-buffer) allbufs)
+              (make-directory "test-subdir1")
+              (make-directory "test-subdir2")
+              (let ((test-file1 "test-file1")
+                    (test-file2 "test-file2"))
+                (with-current-buffer (find-file-noselect "test-subdir1")
+                  (push (current-buffer) allbufs)
+                  (write-region "Test1" nil test-file1 nil 'silent nil 'excl))
+                (with-current-buffer (find-file-noselect "test-subdir2")
+                  (push (current-buffer) allbufs)
+                  (write-region "Test2" nil test-file2 nil 'silent nil 'excl))))
+            ;; Call find-file with a wild card and test point in each file.
+            (let ((buffers (find-file (concat (file-name-as-directory test-dir)
+                                              "*")
+                                      t)))
+              (dolist (buf buffers)
+                (let ((pt (with-current-buffer buf (point))))
+                  (switch-to-buffer (find-file-noselect test-dir))
+                  (find-file (buffer-name buf))
+                  (should (equal (point) pt))))
+              (append buffers allbufs)))
+        (dolist (buf allbufs)
+          (when (buffer-live-p buf) (kill-buffer buf)))))))
 
 (ert-deftest dired-test-bug7131 ()
   "Test for https://debbugs.gnu.org/7131 ."
@@ -274,22 +272,21 @@
   ;; ls-lisp-tests.el and em-ls-tests.el.
   (skip-unless (and (not (featurep 'ls-lisp))
                     (not (featurep 'eshell))))
-  (let* ((dir (make-temp-file "bug27631" 'dir))
-         (dir1 (expand-file-name "dir1" dir))
-         (dir2 (expand-file-name "dir2" dir))
-         (default-directory dir)
-         buf)
-    (unwind-protect
-        (progn
-          (make-directory dir1)
-          (make-directory dir2)
-          (with-temp-file (expand-file-name "a.txt" dir1))
-          (with-temp-file (expand-file-name "b.txt" dir2))
-          (setq buf (dired (expand-file-name "dir*/*.txt" dir)))
-          (dired-toggle-marks)
-          (should (cdr (dired-get-marked-files))))
-      (delete-directory dir 'recursive)
-      (when (buffer-live-p buf) (kill-buffer buf)))))
+  (ert-with-temp-directory dir
+    (let* ((dir1 (expand-file-name "dir1" dir))
+           (dir2 (expand-file-name "dir2" dir))
+           (default-directory dir)
+           buf)
+      (unwind-protect
+          (progn
+            (make-directory dir1)
+            (make-directory dir2)
+            (with-temp-file (expand-file-name "a.txt" dir1))
+            (with-temp-file (expand-file-name "b.txt" dir2))
+            (setq buf (dired (expand-file-name "dir*/*.txt" dir)))
+            (dired-toggle-marks)
+            (should (cdr (dired-get-marked-files))))
+        (when (buffer-live-p buf) (kill-buffer buf))))))
 
 (ert-deftest dired-test-bug27899 ()
   "Test for https://debbugs.gnu.org/27899 ."
@@ -310,72 +307,69 @@
 
 (ert-deftest dired-test-bug27968 ()
   "Test for https://debbugs.gnu.org/27968 ."
-  (let* ((top-dir (make-temp-file "top-dir" t))
-         (subdir (expand-file-name "subdir" top-dir))
-         (header-len-fn (lambda ()
-                          (save-excursion
-                            (goto-char 1)
-                            (forward-line 1)
-                            (- (point-at-eol) (point)))))
-         orig-len len diff pos line-nb)
-    (make-directory subdir 'parents)
-    (unwind-protect
-        (with-current-buffer (dired-noselect subdir)
-          (setq orig-len (funcall header-len-fn)
-                pos (point)
-                line-nb (line-number-at-pos))
-          ;; Bug arises when the header line changes its length; this may
-          ;; happen if the used space has changed: for instance, with the
-          ;; creation of additional files.
-          (make-directory "subdir" t)
-          (dired-revert)
-          ;; Change the header line.
-          (save-excursion
-            (goto-char 1)
-            (forward-line 1)
-            (let ((inhibit-read-only t)
-                  (new-header "  test-bug27968"))
-              (delete-region (point) (point-at-eol))
-              (when (= orig-len (length new-header))
-                ;; Wow lucky guy! I must buy lottery today.
-                (setq new-header (concat new-header " :-)")))
-              (insert new-header)))
-          (setq len (funcall header-len-fn)
-                diff (- len orig-len))
-          (should-not (zerop diff)) ; Header length has changed.
-          ;; If diff > 0, then the point moves back.
-          ;; If diff < 0, then the point moves forward.
-          ;; If diff = 0, then the point doesn't move.
-          ;; Sometimes this point movement causes
-          ;; line-nb != (line-number-at-pos pos), so that we get
-          ;; an unexpected file at point if we store buffer points.
-          ;; Note that the line number before/after revert
-          ;; doesn't change.
-          (should (= line-nb
-                     (line-number-at-pos)
-                     (line-number-at-pos (+ pos diff))))
-          ;; After revert, the point must be in 'subdir' line.
-          (should (equal "subdir" (dired-get-filename 'local t))))
-      (delete-directory top-dir t))))
+  (ert-with-temp-directory top-dir
+    (let* ((subdir (expand-file-name "subdir" top-dir))
+           (header-len-fn (lambda ()
+                            (save-excursion
+                              (goto-char 1)
+                              (forward-line 1)
+                              (- (point-at-eol) (point)))))
+           orig-len len diff pos line-nb)
+      (make-directory subdir 'parents)
+      (with-current-buffer (dired-noselect subdir)
+        (setq orig-len (funcall header-len-fn)
+              pos (point)
+              line-nb (line-number-at-pos))
+        ;; Bug arises when the header line changes its length; this may
+        ;; happen if the used space has changed: for instance, with the
+        ;; creation of additional files.
+        (make-directory "subdir" t)
+        (dired-revert)
+        ;; Change the header line.
+        (save-excursion
+          (goto-char 1)
+          (forward-line 1)
+          (let ((inhibit-read-only t)
+                (new-header "  test-bug27968"))
+            (delete-region (point) (point-at-eol))
+            (when (= orig-len (length new-header))
+              ;; Wow lucky guy! I must buy lottery today.
+              (setq new-header (concat new-header " :-)")))
+            (insert new-header)))
+        (setq len (funcall header-len-fn)
+              diff (- len orig-len))
+        (should-not (zerop diff))    ; Header length has changed.
+        ;; If diff > 0, then the point moves back.
+        ;; If diff < 0, then the point moves forward.
+        ;; If diff = 0, then the point doesn't move.
+        ;; Sometimes this point movement causes
+        ;; line-nb != (line-number-at-pos pos), so that we get
+        ;; an unexpected file at point if we store buffer points.
+        ;; Note that the line number before/after revert
+        ;; doesn't change.
+        (should (= line-nb
+                   (line-number-at-pos)
+                   (line-number-at-pos (+ pos diff))))
+        ;; After revert, the point must be in 'subdir' line.
+        (should (equal "subdir" (dired-get-filename 'local t)))))))
 
 
 (defmacro dired-test-with-temp-dirs (just-empty-dirs &rest body)
   "Helper macro for Bug#27940 test."
   (declare (indent 1) (debug body))
   (let ((dir (make-symbol "dir")))
-    `(let* ((,dir (make-temp-file "bug27940" t))
-            (dired-deletion-confirmer (lambda (_) "yes")) ; Suppress prompts.
-            (inhibit-message t)
-            (default-directory ,dir))
-       (dotimes (i 5) (make-directory (format "empty-dir-%d" i)))
-       (unless ,just-empty-dirs
-         (dotimes (i 5) (make-directory (format "non-empty-%d/foo" i) 'parents)))
-       (make-directory "zeta-empty-dir")
-       (unwind-protect
-           (progn
-             ,@body)
-         (delete-directory ,dir t)
-         (kill-buffer (current-buffer))))))
+    `(ert-with-temp-directory ,dir
+       (let* ((dired-deletion-confirmer (lambda (_) "yes")) ; Suppress prompts.
+              (inhibit-message t)
+              (default-directory ,dir))
+         (dotimes (i 5) (make-directory (format "empty-dir-%d" i)))
+         (unless ,just-empty-dirs
+           (dotimes (i 5) (make-directory (format "non-empty-%d/foo" i) 'parents)))
+         (make-directory "zeta-empty-dir")
+         (unwind-protect
+             (progn
+               ,@body)
+           (kill-buffer (current-buffer)))))))
 
 (ert-deftest dired-test-bug27940 ()
   "Test for https://debbugs.gnu.org/27940 ."
diff --git a/test/lisp/dired-x-tests.el b/test/lisp/dired-x-tests.el
index d00815e543c..fe4b9711d49 100644
--- a/test/lisp/dired-x-tests.el
+++ b/test/lisp/dired-x-tests.el
@@ -19,6 +19,7 @@
 
 ;;; Code:
 (require 'ert)
+(require 'ert-x)
 (require 'dired-x)
 
 
@@ -31,23 +32,20 @@
            (append (copy-sequence dirs)
                    (delete "c" (copy-sequence files)))
            #'string<))
-         (dir (make-temp-file "Bug25942" 'dir))
          (extension "c"))
-    (unwind-protect
-        (progn
-          (dolist (d dirs)
-            (make-directory (expand-file-name d dir)))
-          (dolist (f files)
-            (write-region nil nil (expand-file-name f dir)))
-          (dired dir)
-          (dired-mark-extension extension)
-          (should (equal '("bar.c" "foo.c")
-                         (sort (dired-get-marked-files 'local) #'string<)))
-          (dired-unmark-all-marks)
-          (dired-mark-suffix extension)
-          (should (equal all-but-c
-                         (sort (dired-get-marked-files 'local) #'string<))))
-      (delete-directory dir 'recursive))))
+    (ert-with-temp-directory dir
+      (dolist (d dirs)
+        (make-directory (expand-file-name d dir)))
+      (dolist (f files)
+        (write-region nil nil (expand-file-name f dir)))
+      (dired dir)
+      (dired-mark-extension extension)
+      (should (equal '("bar.c" "foo.c")
+                     (sort (dired-get-marked-files 'local) #'string<)))
+      (dired-unmark-all-marks)
+      (dired-mark-suffix extension)
+      (should (equal all-but-c
+                     (sort (dired-get-marked-files 'local) #'string<))))))
 
 (ert-deftest dired-guess-default ()
   (let ((dired-guess-shell-alist-user nil)
diff --git a/test/lisp/emacs-lisp/bytecomp-tests.el b/test/lisp/emacs-lisp/bytecomp-tests.el
index 41edc1f8289..cc6455bb2ee 100644
--- a/test/lisp/emacs-lisp/bytecomp-tests.el
+++ b/test/lisp/emacs-lisp/bytecomp-tests.el
@@ -1016,10 +1016,9 @@ byte-compiled.  Run with dynamic binding."
 (defmacro bytecomp-tests--with-temp-file (file-name-var &rest body)
   (declare (indent 1))
   (cl-check-type file-name-var symbol)
-  `(let ((,file-name-var (make-temp-file "emacs")))
+  `(ert-with-temp-file ,file-name-var
      (unwind-protect
          (progn ,@body)
-       (delete-file ,file-name-var)
        (let ((elc (concat ,file-name-var ".elc")))
          (if (file-exists-p elc) (delete-file elc))))))
 
diff --git a/test/lisp/emacs-lisp/check-declare-tests.el b/test/lisp/emacs-lisp/check-declare-tests.el
index 276530fb4d3..5c9d847e34a 100644
--- a/test/lisp/emacs-lisp/check-declare-tests.el
+++ b/test/lisp/emacs-lisp/check-declare-tests.el
@@ -28,6 +28,7 @@
 
 (require 'check-declare)
 (require 'ert)
+(require 'ert-x)
 (eval-when-compile (require 'subr-x))
 
 (ert-deftest check-declare-tests-locate ()
@@ -36,62 +37,53 @@
    (string-prefix-p "ext:" (check-declare-locate "ext:foo" ""))))
 
 (ert-deftest check-declare-tests-scan ()
-  (let ((file (make-temp-file "check-declare-tests-")))
-    (unwind-protect
-        (progn
-          (with-temp-file file
-            (insert
-             (string-join
-              '(";; foo comment"
-                "(declare-function ring-insert \"ring\" (ring item))"
-                "(let ((foo 'code)) foo)")
-              "\n")))
-          (let ((res (check-declare-scan file)))
-            (should (= (length res) 1))
-            (pcase-let ((`((,fnfile ,fn ,arglist ,fileonly)) res))
-              (should (string-match-p "ring" fnfile))
-              (should (equal "ring-insert" fn))
-              (should (equal '(ring item) arglist))
-              (should-not fileonly))))
-      (delete-file file))))
+  (ert-with-temp-file file
+    (with-temp-file file
+      (insert
+       (string-join
+        '(";; foo comment"
+          "(declare-function ring-insert \"ring\" (ring item))"
+          "(let ((foo 'code)) foo)")
+        "\n")))
+    (let ((res (check-declare-scan file)))
+      (should (= (length res) 1))
+      (pcase-let ((`((,fnfile ,fn ,arglist ,fileonly)) res))
+        (should (string-match-p "ring" fnfile))
+        (should (equal "ring-insert" fn))
+        (should (equal '(ring item) arglist))
+        (should-not fileonly)))))
 
 (ert-deftest check-declare-tests-verify ()
-  (let ((file (make-temp-file "check-declare-tests-")))
-    (unwind-protect
-        (progn
-          (with-temp-file file
-            (insert
-             (string-join
-              '(";; foo comment"
-                "(defun foo-fun ())"
-                "(defun ring-insert (ring item)"
-                "\"Insert onto ring RING the item ITEM.\""
-                "nil)")
-              "\n")))
-          (should-not
-           (check-declare-verify
-            file '(("foo.el" "ring-insert" (ring item))))))
-      (delete-file file))))
+  (ert-with-temp-file file
+    (with-temp-file file
+      (insert
+       (string-join
+        '(";; foo comment"
+          "(defun foo-fun ())"
+          "(defun ring-insert (ring item)"
+          "\"Insert onto ring RING the item ITEM.\""
+          "nil)")
+        "\n")))
+    (should-not
+     (check-declare-verify
+      file '(("foo.el" "ring-insert" (ring item)))))))
 
 (ert-deftest check-declare-tests-verify-mismatch ()
-  (let ((file (make-temp-file "check-declare-tests-")))
-    (unwind-protect
-        (progn
-          (with-temp-file file
-            (insert
-             (string-join
-              '(";; foo comment"
-                "(defun foo-fun ())"
-                "(defun ring-insert (ring)"
-                "\"Insert onto ring RING the item ITEM.\""
-                "nil)")
-              "\n")))
-          (should
-           (equal
-            (check-declare-verify
-             file '(("foo.el" "ring-insert" (ring item))))
-            '(("foo.el" "ring-insert" "arglist mismatch")))))
-      (delete-file file))))
+  (ert-with-temp-file file
+    (with-temp-file file
+      (insert
+       (string-join
+        '(";; foo comment"
+          "(defun foo-fun ())"
+          "(defun ring-insert (ring)"
+          "\"Insert onto ring RING the item ITEM.\""
+          "nil)")
+        "\n")))
+    (should
+     (equal
+      (check-declare-verify
+       file '(("foo.el" "ring-insert" (ring item))))
+      '(("foo.el" "ring-insert" "arglist mismatch"))))))
 
 (ert-deftest check-declare-tests-sort ()
   (should-not (check-declare-sort '()))
diff --git a/test/lisp/emacs-lisp/edebug-tests.el b/test/lisp/emacs-lisp/edebug-tests.el
index f8fa223da4c..9285b2c945c 100644
--- a/test/lisp/emacs-lisp/edebug-tests.el
+++ b/test/lisp/emacs-lisp/edebug-tests.el
@@ -107,27 +107,27 @@ back to the top level.")
   "Set up the environment for an Edebug test BODY, run it, and clean up."
   (declare (debug (body)))
   `(edebug-tests-with-default-config
-    (let ((edebug-tests-failure-in-post-command nil)
-          (edebug-tests-temp-file (make-temp-file "edebug-tests-" nil ".el"))
-          (find-file-suppress-same-file-warnings t))
-      (edebug-tests-setup-code-file edebug-tests-temp-file)
-      (ert-with-message-capture
-       edebug-tests-messages
-       (unwind-protect
-           (with-current-buffer (find-file edebug-tests-temp-file)
-             (read-only-mode)
-             (setq lexical-binding t)
-             (eval-buffer)
-             ,@body
-             (when edebug-tests-failure-in-post-command
-               (signal (car edebug-tests-failure-in-post-command)
-                       (cdr edebug-tests-failure-in-post-command))))
-         (unload-feature 'edebug-test-code)
-         (with-current-buffer (find-file-noselect edebug-tests-temp-file)
-           (set-buffer-modified-p nil))
-         (ignore-errors (kill-buffer (find-file-noselect
-                                      edebug-tests-temp-file)))
-         (ignore-errors (delete-file edebug-tests-temp-file)))))))
+    (ert-with-temp-file edebug-tests-temp-file
+      :suffix ".el"
+      (let ((edebug-tests-failure-in-post-command nil)
+            (find-file-suppress-same-file-warnings t))
+        (edebug-tests-setup-code-file edebug-tests-temp-file)
+        (ert-with-message-capture
+            edebug-tests-messages
+          (unwind-protect
+              (with-current-buffer (find-file edebug-tests-temp-file)
+                (read-only-mode)
+                (setq lexical-binding t)
+                (eval-buffer)
+                ,@body
+                (when edebug-tests-failure-in-post-command
+                  (signal (car edebug-tests-failure-in-post-command)
+                          (cdr edebug-tests-failure-in-post-command))))
+            (unload-feature 'edebug-test-code)
+            (with-current-buffer (find-file-noselect edebug-tests-temp-file)
+              (set-buffer-modified-p nil))
+            (ignore-errors (kill-buffer (find-file-noselect
+                                         edebug-tests-temp-file)))))))))
 
 ;; The following macro and its support functions implement an extension
 ;; to keyboard macros to allow interleaving of keyboard macro
diff --git a/test/lisp/emacs-lisp/package-tests.el b/test/lisp/emacs-lisp/package-tests.el
index c038c91e6a9..0f0ed029c3b 100644
--- a/test/lisp/emacs-lisp/package-tests.el
+++ b/test/lisp/emacs-lisp/package-tests.el
@@ -115,57 +115,55 @@
                                 &rest body)
   "Set up temporary locations and variables for testing."
   (declare (indent 1) (debug (([&rest form]) body)))
-  `(let* ((package-test-user-dir (make-temp-file "pkg-test-user-dir-" t))
-          (process-environment (cons (format "HOME=%s" package-test-user-dir)
-                                     process-environment))
-          (package-user-dir package-test-user-dir)
-          (package-gnupghome-dir (expand-file-name "gnupg" package-user-dir))
-          (package-archives `(("gnu" . ,(or ,location package-test-data-dir))))
-          (default-directory package-test-file-dir)
-          abbreviated-home-dir
-          package--initialized
-          package-alist
-          ,@(if update-news
-                '(package-update-news-on-upload t)
-              (list (cl-gensym)))
-          ,@(if upload-base
-                '((package-test-archive-upload-base (make-temp-file "pkg-archive-base-" t))
-                  (package-archive-upload-base package-test-archive-upload-base))
-              (list (cl-gensym)))) ;; Dummy value so `let' doesn't try to bind nil
-     (let ((buf (get-buffer "*Packages*")))
-       (when (buffer-live-p buf)
-         (kill-buffer buf)))
-     (unwind-protect
-         (progn
-           ,(if basedir `(cd ,basedir))
-           (unless (file-directory-p package-user-dir)
-             (mkdir package-user-dir))
-           (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t))
-                     ((symbol-function 'y-or-n-p)    (lambda (&rest _) t)))
-             ,@(when install
-                 `((package-initialize)
-                   (package-refresh-contents)
-                   (mapc 'package-install ,install)))
-             (with-temp-buffer
-               ,(if file
-                    `(insert-file-contents ,file))
-               ,@body)))
-
-       (when ,upload-base
-         (dolist (f '("archive-contents"
-                      "simple-single-1.3.el"
-                      "simple-single-1.4.el"
-                      "simple-single-readme.txt"))
-           (ignore-errors
-             (delete-file
-              (expand-file-name f package-test-archive-upload-base))))
-         (delete-directory package-test-archive-upload-base))
-       (when (file-directory-p package-test-user-dir)
-         (delete-directory package-test-user-dir t))
-
-       (when (and (boundp 'package-test-archive-upload-base)
-                  (file-directory-p package-test-archive-upload-base))
-         (delete-directory package-test-archive-upload-base t)))))
+  `(ert-with-temp-directory package-test-user-dir
+     (let* ((process-environment (cons (format "HOME=%s" package-test-user-dir)
+                                       process-environment))
+            (package-user-dir package-test-user-dir)
+            (package-gnupghome-dir (expand-file-name "gnupg" package-user-dir))
+            (package-archives `(("gnu" . ,(or ,location package-test-data-dir))))
+            (default-directory package-test-file-dir)
+            abbreviated-home-dir
+            package--initialized
+            package-alist
+            ,@(if update-news
+                  '(package-update-news-on-upload t)
+                (list (cl-gensym)))
+            ,@(if upload-base
+                  '((package-test-archive-upload-base (make-temp-file "pkg-archive-base-" t))
+                    (package-archive-upload-base package-test-archive-upload-base))
+                (list (cl-gensym)))) ;; Dummy value so `let' doesn't try to bind nil
+       (let ((buf (get-buffer "*Packages*")))
+         (when (buffer-live-p buf)
+           (kill-buffer buf)))
+       (unwind-protect
+           (progn
+             ,(if basedir `(cd ,basedir))
+             (unless (file-directory-p package-user-dir)
+               (mkdir package-user-dir))
+             (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t))
+                       ((symbol-function 'y-or-n-p)    (lambda (&rest _) t)))
+               ,@(when install
+                   `((package-initialize)
+                     (package-refresh-contents)
+                     (mapc 'package-install ,install)))
+               (with-temp-buffer
+                 ,(if file
+                      `(insert-file-contents ,file))
+                 ,@body)))
+
+         (when ,upload-base
+           (dolist (f '("archive-contents"
+                        "simple-single-1.3.el"
+                        "simple-single-1.4.el"
+                        "simple-single-readme.txt"))
+             (ignore-errors
+               (delete-file
+                (expand-file-name f package-test-archive-upload-base))))
+           (delete-directory package-test-archive-upload-base))
+
+         (when (and (boundp 'package-test-archive-upload-base)
+                    (file-directory-p package-test-archive-upload-base))
+           (delete-directory package-test-archive-upload-base t))))))
 
 (defmacro with-fake-help-buffer (&rest body)
   "Execute BODY in a temp buffer which is treated as the \"*Help*\" buffer."
@@ -715,25 +713,23 @@ but with a different end of line convention (bug#48137)."
 (defvar epg-config--program-alist) ; Silence byte-compiler.
 (ert-deftest package-test-signed ()
   "Test verifying package signature."
-  (skip-unless (let ((homedir (make-temp-file "package-test" t)))
-		 (unwind-protect
-		     (let ((process-environment
-			    (cons (concat "HOME=" homedir)
-				  process-environment)))
-                       (require 'epg-config)
-                       (defvar epg-config--program-alist)
-		       (epg-find-configuration
-                        'OpenPGP nil
-                        ;; By default we require gpg2 2.1+ due to some
-                        ;; practical problems with pinentry.  But this
-                        ;; test works fine with 2.0 as well.
-                        (let ((prog-alist (copy-tree epg-config--program-alist)))
-                          (setf (alist-get "gpg2"
-                                           (alist-get 'OpenPGP prog-alist)
-                                           nil nil #'equal)
-                                "2.0")
-                          prog-alist)))
-		   (delete-directory homedir t))))
+  (skip-unless (ert-with-temp-directory homedir
+                 (let ((process-environment
+                        (cons (concat "HOME=" homedir)
+                              process-environment)))
+                   (require 'epg-config)
+                   (defvar epg-config--program-alist)
+                   (epg-find-configuration
+                    'OpenPGP nil
+                    ;; By default we require gpg2 2.1+ due to some
+                    ;; practical problems with pinentry.  But this
+                    ;; test works fine with 2.0 as well.
+                    (let ((prog-alist (copy-tree epg-config--program-alist)))
+                      (setf (alist-get "gpg2"
+                                       (alist-get 'OpenPGP prog-alist)
+                                       nil nil #'equal)
+                            "2.0")
+                      prog-alist)))))
   (let* ((keyring (expand-file-name "key.pub" package-test-data-dir))
          (package-test-data-dir (ert-resource-file "signed")))
     (with-package-test ()
diff --git a/test/lisp/emacs-lisp/testcover-tests.el b/test/lisp/emacs-lisp/testcover-tests.el
index 7854e33e77d..a7e055a28b1 100644
--- a/test/lisp/emacs-lisp/testcover-tests.el
+++ b/test/lisp/emacs-lisp/testcover-tests.el
@@ -45,34 +45,34 @@ testcases.el.  This can be used to create test cases if Testcover
 is working correctly on a code sample.  OPTARGS are optional
 arguments for `testcover-start'."
     (interactive "r")
-    (let ((tempfile (make-temp-file "testcover-tests-" nil ".el"))
-          (find-file-suppress-same-file-warnings t)
-          (code (buffer-substring beg end))
-          (marked-up-code))
-      (unwind-protect
-          (progn
-            (with-temp-file tempfile
-              (insert code))
-            (save-current-buffer
-              (let ((buf (find-file-noselect tempfile)))
-                (set-buffer buf)
-                (apply 'testcover-start (cons tempfile optargs))
-                (testcover-mark-all buf)
-                (dolist (overlay (overlays-in (point-min) (point-max)))
-                  (let ((ov-face (overlay-get overlay 'face)))
-                    (goto-char (overlay-end overlay))
-                    (cond
-                     ((eq ov-face 'testcover-nohits) (insert "!!!"))
-                     ((eq ov-face 'testcover-1value) (insert "%%%"))
-                     (t nil))))
-                (setq marked-up-code (buffer-string)))
-              (set-buffer-modified-p nil)))
-        (ignore-errors (kill-buffer (find-file-noselect tempfile)))
-        (ignore-errors (delete-file tempfile)))
-
-      ;; Now replace the original code with the marked up code.
-      (delete-region beg end)
-      (insert marked-up-code))))
+    (ert-with-temp-file tempfile
+      :suffix ".el"
+      (let ((find-file-suppress-same-file-warnings t)
+            (code (buffer-substring beg end))
+            (marked-up-code))
+        (unwind-protect
+            (progn
+              (with-temp-file tempfile
+                (insert code))
+              (save-current-buffer
+                (let ((buf (find-file-noselect tempfile)))
+                  (set-buffer buf)
+                  (apply 'testcover-start (cons tempfile optargs))
+                  (testcover-mark-all buf)
+                  (dolist (overlay (overlays-in (point-min) (point-max)))
+                    (let ((ov-face (overlay-get overlay 'face)))
+                      (goto-char (overlay-end overlay))
+                      (cond
+                       ((eq ov-face 'testcover-nohits) (insert "!!!"))
+                       ((eq ov-face 'testcover-1value) (insert "%%%"))
+                       (t nil))))
+                  (setq marked-up-code (buffer-string)))
+                (set-buffer-modified-p nil)))
+          (ignore-errors (kill-buffer (find-file-noselect tempfile))))
+
+        ;; Now replace the original code with the marked up code.
+        (delete-region beg end)
+        (insert marked-up-code)))))
 
 (eval-and-compile
   (defun testcover-tests-unmarkup-region (beg end)
@@ -99,32 +99,32 @@ arguments for `testcover-start'."
 (eval-and-compile
   (defun testcover-tests-run-test-case (marked-up-code)
     "Test the operation of Testcover on the string MARKED-UP-CODE."
-    (let ((tempfile (make-temp-file "testcover-tests-" nil ".el"))
-          (find-file-suppress-same-file-warnings t))
-      (unwind-protect
-          (progn
-            (with-temp-file tempfile
-              (insert marked-up-code))
-            ;; Remove the marks and mark the code up again. The original
-            ;; and recreated versions should match.
-            (save-current-buffer
-              (set-buffer (find-file-noselect tempfile))
-              ;; Fail the test if the debugger tries to become active,
-              ;; which can happen if Testcover fails to attach itself
-              ;; correctly. Note that this will prevent debugging
-              ;; these tests using Edebug.
-              (cl-letf (((symbol-function #'edebug-default-enter)
-                         (lambda (&rest _args)
-                           (ert-fail "Debugger invoked during test run"))))
-                (dolist (byte-compile '(t nil))
-                  (testcover-tests-unmarkup-region (point-min) (point-max))
-                  (unwind-protect
-                      (testcover-tests-markup-region (point-min) (point-max) byte-compile)
-                    (set-buffer-modified-p nil))
-                  (should (string= marked-up-code
-                                   (buffer-string)))))))
-        (ignore-errors (kill-buffer (find-file-noselect tempfile)))
-        (ignore-errors (delete-file tempfile))))))
+    (ert-with-temp-file tempfile
+      :suffix ".el"
+      (let ((find-file-suppress-same-file-warnings t))
+        (unwind-protect
+            (progn
+              (with-temp-file tempfile
+                (insert marked-up-code))
+              ;; Remove the marks and mark the code up again. The original
+              ;; and recreated versions should match.
+              (save-current-buffer
+                (set-buffer (find-file-noselect tempfile))
+                ;; Fail the test if the debugger tries to become active,
+                ;; which can happen if Testcover fails to attach itself
+                ;; correctly. Note that this will prevent debugging
+                ;; these tests using Edebug.
+                (cl-letf (((symbol-function #'edebug-default-enter)
+                           (lambda (&rest _args)
+                             (ert-fail "Debugger invoked during test run"))))
+                  (dolist (byte-compile '(t nil))
+                    (testcover-tests-unmarkup-region (point-min) (point-max))
+                    (unwind-protect
+                        (testcover-tests-markup-region (point-min) (point-max) byte-compile)
+                      (set-buffer-modified-p nil))
+                    (should (string= marked-up-code
+                                     (buffer-string)))))))
+          (ignore-errors (kill-buffer (find-file-noselect tempfile))))))))
 
 ;; Convert test case file to ert-defmethod.
 
diff --git a/test/lisp/emulation/viper-tests.el b/test/lisp/emulation/viper-tests.el
index 0d999763b61..b8efc87ab70 100644
--- a/test/lisp/emulation/viper-tests.el
+++ b/test/lisp/emulation/viper-tests.el
@@ -21,7 +21,8 @@
 
 ;;; Code:
 
-
+(require 'ert)
+(require 'ert-x)
 (require 'viper)
 
 (defun viper-test-undo-kmacro (kmacro)
@@ -30,47 +31,42 @@
 This function makes as many attempts as possible to clean up
 after itself, although it will leave a buffer called
 *viper-test-buffer* if it fails (this is deliberate!)."
-  (let (
-        ;; Viper just turns itself off during batch use.
-        (noninteractive nil)
-        ;; Switch off start up message or it will chew the key presses.
-        (viper-inhibit-startup-message 't)
-        ;; Select an expert-level for the same reason.
-        (viper-expert-level 5)
-        ;; viper loads this even with -q so make sure it's empty!
-        (viper-custom-file-name (make-temp-file "viper-tests" nil ".elc"))
-        (before-buffer (current-buffer)))
-    (unwind-protect
-        (progn
-          ;; viper-mode is essentially global, so set it here.
-          (viper-mode)
-          ;; We must switch to buffer because we are using a keyboard macro
-          ;; which appears to not go to the current-buffer but what ever is
-          ;; currently taking keyboard events. We use a named buffer because
-          ;; then we can see what it in it if it all goes wrong.
-          (switch-to-buffer
-           (get-buffer-create
-            "*viper-test-buffer*"))
-          (erase-buffer)
-          ;; The new buffer fails to enter vi state so set it.
-          (viper-change-state-to-vi)
-          ;; Run the macro.
-          (execute-kbd-macro kmacro)
-          (let ((rtn
-                 (buffer-substring-no-properties
-                  (point-min)
-                  (point-max))))
-            ;; Kill the buffer iff the macro succeeds.
-            (kill-buffer)
-            rtn))
-      ;; Switch everything off and restore the buffer.
-      (toggle-viper-mode)
-      (delete-file viper-custom-file-name)
-      (switch-to-buffer before-buffer))))
-
-(ert-deftest viper-test-go ()
-  "Test that this file is running."
-  (should t))
+  (ert-with-temp-file viper-custom-file-name
+    ;; viper loads this even with -q so make sure it's empty!
+    :prefix "emacs-viper-tests" :suffix ".elc"
+    (let (;; Viper just turns itself off during batch use.
+          (noninteractive nil)
+          ;; Switch off start up message or it will chew the key presses.
+          (viper-inhibit-startup-message 't)
+          ;; Select an expert-level for the same reason.
+          (viper-expert-level 5)
+          (before-buffer (current-buffer)))
+      (unwind-protect
+          (progn
+            ;; viper-mode is essentially global, so set it here.
+            (viper-mode)
+            ;; We must switch to buffer because we are using a keyboard macro
+            ;; which appears to not go to the current-buffer but what ever is
+            ;; currently taking keyboard events. We use a named buffer because
+            ;; then we can see what it in it if it all goes wrong.
+            (switch-to-buffer
+             (get-buffer-create
+              "*viper-test-buffer*"))
+            (erase-buffer)
+            ;; The new buffer fails to enter vi state so set it.
+            (viper-change-state-to-vi)
+            ;; Run the macro.
+            (execute-kbd-macro kmacro)
+            (let ((rtn
+                   (buffer-substring-no-properties
+                    (point-min)
+                    (point-max))))
+              ;; Kill the buffer iff the macro succeeds.
+              (kill-buffer)
+              rtn))
+        ;; Switch everything off and restore the buffer.
+        (toggle-viper-mode)
+        (switch-to-buffer before-buffer)))))
 
 (ert-deftest viper-test-fix ()
   "Test that the viper kmacro fixture is working."
diff --git a/test/lisp/epg-tests.el b/test/lisp/epg-tests.el
index 741574f0adf..1384221c491 100644
--- a/test/lisp/epg-tests.el
+++ b/test/lisp/epg-tests.el
@@ -58,48 +58,45 @@
 (cl-defmacro with-epg-tests ((&optional &key require-passphrase
 					require-public-key
 					require-secret-key)
-			    &rest body)
+                             &rest body)
   "Set up temporary locations and variables for testing."
   (declare (indent 1) (debug (sexp body)))
-  `(let* ((epg-tests-home-directory (make-temp-file "epg-tests-homedir" t))
-	  (process-environment
-	   (append
-	    (list "GPG_AGENT_INFO"
-		  (format "GNUPGHOME=%s" epg-tests-home-directory))
-	    process-environment)))
-     (unwind-protect
-         ;; GNUPGHOME is needed to find a usable gpg, so we can't
-         ;; check whether to skip any earlier (Bug#23561).
-         (let ((epg-config (or (epg-tests-find-usable-gpg-configuration
-                                ,require-passphrase ,require-public-key)
-                               (ert-skip "No usable gpg config")))
-               (context (epg-make-context 'OpenPGP)))
-           (setf (epg-context-program context)
-                 (alist-get 'program epg-config))
-	   (setf (epg-context-home-directory context)
-		 epg-tests-home-directory)
-	   ,(if require-passphrase
-		'(with-temp-file (expand-file-name
-                                  "gpg-agent.conf" epg-tests-home-directory)
-                   (insert "pinentry-program "
-                           (ert-resource-file "dummy-pinentry")
-                           "\n")
-                   (epg-context-set-passphrase-callback
-                    context
-                    #'epg-tests-passphrase-callback)))
-	   ,(if require-public-key
-		'(epg-import-keys-from-file
-		  context
-                  (ert-resource-file "pubkey.asc")))
-	   ,(if require-secret-key
-		'(epg-import-keys-from-file
-		  context
-                  (ert-resource-file "seckey.asc")))
-	   (with-temp-buffer
-             (setq-local epg-tests-context context)
-	     ,@body))
-       (when (file-directory-p epg-tests-home-directory)
-	 (delete-directory epg-tests-home-directory t)))))
+  `(ert-with-temp-directory epg-tests-home-directory
+     (let* ((process-environment
+             (append
+              (list "GPG_AGENT_INFO"
+                    (format "GNUPGHOME=%s" epg-tests-home-directory))
+              process-environment)))
+       ;; GNUPGHOME is needed to find a usable gpg, so we can't
+       ;; check whether to skip any earlier (Bug#23561).
+       (let ((epg-config (or (epg-tests-find-usable-gpg-configuration
+                           ,require-passphrase ,require-public-key)
+                          (ert-skip "No usable gpg config")))
+             (context (epg-make-context 'OpenPGP)))
+         (setf (epg-context-program context)
+               (alist-get 'program epg-config))
+         (setf (epg-context-home-directory context)
+               epg-tests-home-directory)
+         ,(if require-passphrase
+              '(with-temp-file (expand-file-name
+                                "gpg-agent.conf" epg-tests-home-directory)
+                 (insert "pinentry-program "
+                         (ert-resource-file "dummy-pinentry")
+                         "\n")
+                 (epg-context-set-passphrase-callback
+                  context
+                  #'epg-tests-passphrase-callback)))
+         ,(if require-public-key
+              '(epg-import-keys-from-file
+                context
+                (ert-resource-file "pubkey.asc")))
+         ,(if require-secret-key
+              '(epg-import-keys-from-file
+                context
+                (ert-resource-file "seckey.asc")))
+         (with-temp-buffer
+           (setq-local epg-tests-context context)
+           ,@body)))))
 
 (ert-deftest epg-decrypt-1 ()
   :expected-result (if (getenv "EMACS_HYDRA_CI") :failed :passed) ; fixme
diff --git a/test/lisp/eshell/em-hist-tests.el b/test/lisp/eshell/em-hist-tests.el
index 31967a61c3c..5bc5690675d 100644
--- a/test/lisp/eshell/em-hist-tests.el
+++ b/test/lisp/eshell/em-hist-tests.el
@@ -20,19 +20,18 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'em-hist)
 
 (ert-deftest eshell-write-readonly-history ()
   "Test that having read-only strings in history is okay."
-  (let ((histfile (make-temp-file "eshell-history"))
-        (eshell-history-ring (make-ring 2)))
-    (ring-insert eshell-history-ring
-                 (propertize "echo foo" 'read-only t))
-    (ring-insert eshell-history-ring
-                 (propertize "echo bar" 'read-only t))
-    (unwind-protect
-        (eshell-write-history histfile)
-      (delete-file histfile))))
+  (ert-with-temp-file histfile
+    (let ((eshell-history-ring (make-ring 2)))
+      (ring-insert eshell-history-ring
+                   (propertize "echo foo" 'read-only t))
+      (ring-insert eshell-history-ring
+                   (propertize "echo bar" 'read-only t))
+      (eshell-write-history histfile))))
 
 (provide 'em-hist-test)
 
diff --git a/test/lisp/eshell/em-ls-tests.el b/test/lisp/eshell/em-ls-tests.el
index 5d1742b76fd..3ea11ab2de1 100644
--- a/test/lisp/eshell/em-ls-tests.el
+++ b/test/lisp/eshell/em-ls-tests.el
@@ -25,30 +25,30 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'em-ls)
 (require 'dired)
 
 (ert-deftest em-ls-test-bug27631 ()
   "Test for https://debbugs.gnu.org/27631 ."
-  (let* ((dir (make-temp-file "bug27631" 'dir))
-         (dir1 (expand-file-name "dir1" dir))
-         (dir2 (expand-file-name "dir2" dir))
-         (default-directory dir)
-         (orig eshell-ls-use-in-dired)
-         buf)
-    (unwind-protect
-        (progn
-          (customize-set-value 'eshell-ls-use-in-dired t)
-          (make-directory dir1)
-          (make-directory dir2)
-          (with-temp-file (expand-file-name "a.txt" dir1))
-          (with-temp-file (expand-file-name "b.txt" dir2))
-          (setq buf (dired (expand-file-name "dir*/*.txt" dir)))
-          (dired-toggle-marks)
-          (should (cdr (dired-get-marked-files))))
-      (customize-set-variable 'eshell-ls-use-in-dired orig)
-      (delete-directory dir 'recursive)
-      (when (buffer-live-p buf) (kill-buffer buf)))))
+  (ert-with-temp-directory dir
+    (let* ((dir1 (expand-file-name "dir1" dir))
+           (dir2 (expand-file-name "dir2" dir))
+           (default-directory dir)
+           (orig eshell-ls-use-in-dired)
+           buf)
+      (unwind-protect
+          (progn
+            (customize-set-value 'eshell-ls-use-in-dired t)
+            (make-directory dir1)
+            (make-directory dir2)
+            (with-temp-file (expand-file-name "a.txt" dir1))
+            (with-temp-file (expand-file-name "b.txt" dir2))
+            (setq buf (dired (expand-file-name "dir*/*.txt" dir)))
+            (dired-toggle-marks)
+            (should (cdr (dired-get-marked-files))))
+        (customize-set-variable 'eshell-ls-use-in-dired orig)
+        (when (buffer-live-p buf) (kill-buffer buf))))))
 
 (ert-deftest em-ls-test-bug27817 ()
   "Test for https://debbugs.gnu.org/27817 ."
diff --git a/test/lisp/ffap-tests.el b/test/lisp/ffap-tests.el
index f8113bffc1a..84b9cea6c12 100644
--- a/test/lisp/ffap-tests.el
+++ b/test/lisp/ffap-tests.el
@@ -25,30 +25,29 @@
 
 (require 'cl-lib)
 (require 'ert)
+(require 'ert-x)
 (require 'ffap)
 
 (ert-deftest ffap-tests-25243 ()
   "Test for https://debbugs.gnu.org/25243 ."
-  (let ((file (make-temp-file "test-Bug#25243")))
-    (unwind-protect
-        (with-temp-file file
-          (let ((str "diff --git b/lisp/ffap.el a/lisp/ffap.el
+  (ert-with-temp-file file
+    :suffix "-bug25243"
+    (let ((str "diff --git b/lisp/ffap.el a/lisp/ffap.el
 index 3d7cebadcf..ad4b70d737 100644
 --- b/lisp/ffap.el
 +++ a/lisp/ffap.el
 @@ -203,6 +203,9 @@ ffap-foo-at-bar-prefix
 "))
-            (transient-mark-mode 1)
-            (when (natnump ffap-max-region-length)
-              (insert
-               (concat
-                str
-                (make-string ffap-max-region-length #xa)
-                (format "%s ENDS HERE" file)))
-              (call-interactively 'mark-whole-buffer)
-              (should (equal "" (ffap-string-at-point)))
-              (should (equal '(1 1) ffap-string-at-point-region)))))
-      (and (file-exists-p file) (delete-file file)))))
+      (transient-mark-mode 1)
+      (when (natnump ffap-max-region-length)
+        (insert
+         (concat
+          str
+          (make-string ffap-max-region-length #xa)
+          (format "%s ENDS HERE" file)))
+        (call-interactively 'mark-whole-buffer)
+        (should (equal "" (ffap-string-at-point)))
+        (should (equal '(1 1) ffap-string-at-point-region))))))
 
 (ert-deftest ffap-gopher-at-point ()
   (with-temp-buffer
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index f2a6e062acc..c641851261d 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -176,15 +176,14 @@ form.")
   ;; If called interactively, environment variable
   ;; $EMACS_TEST_DIRECTORY does not exist.
   (skip-unless (file-exists-p files-test-bug-18141-file))
-  (let ((tempfile (make-temp-file "files-test-bug-18141" nil ".gz")))
-    (unwind-protect
-	(progn
-	  (copy-file files-test-bug-18141-file tempfile t)
-	  (with-current-buffer (find-file-noselect tempfile)
-	    (set-buffer-modified-p t)
-	    (save-buffer)
-	    (should (eq buffer-file-coding-system 'iso-2022-7bit-unix))))
-      (delete-file tempfile))))
+  (ert-with-temp-file tempfile
+    :prefix "emacs-test-files-bug-18141"
+    :suffix ".gz"
+    (copy-file files-test-bug-18141-file tempfile t)
+    (with-current-buffer (find-file-noselect tempfile)
+      (set-buffer-modified-p t)
+      (save-buffer)
+      (should (eq buffer-file-coding-system 'iso-2022-7bit-unix)))))
 
 (ert-deftest files-tests-make-temp-file-empty-prefix ()
   "Test make-temp-file with an empty prefix."
@@ -283,22 +282,20 @@ If we are in a directory named `~', the default value should not
 be $HOME."
   (cl-letf (((symbol-function 'completing-read)
              (lambda (_prompt _coll &optional _pred _req init _hist def _)
-               (or def init)))
-            (dir (make-temp-file "read-file-name-test" t)))
-    (unwind-protect
-        (let ((subdir (expand-file-name "./~/" dir)))
-          (make-directory subdir t)
-          (with-temp-buffer
-            (setq default-directory subdir)
-            (should-not (equal
-                         (expand-file-name (read-file-name "File: "))
-                         (expand-file-name "~/")))
-            ;; Don't overquote either!
-            (setq default-directory (concat "/:" subdir))
-            (should-not (equal
-                         (expand-file-name (read-file-name "File: "))
-                         (concat "/:/:" subdir)))))
-      (delete-directory dir 'recursive))))
+               (or def init))))
+    (ert-with-temp-directory dir
+      (let ((subdir (expand-file-name "./~/" dir)))
+        (make-directory subdir t)
+        (with-temp-buffer
+          (setq default-directory subdir)
+          (should-not (equal
+                       (expand-file-name (read-file-name "File: "))
+                       (expand-file-name "~/")))
+          ;; Don't overquote either!
+          (setq default-directory (concat "/:" subdir))
+          (should-not (equal
+                       (expand-file-name (read-file-name "File: "))
+                       (concat "/:/:" subdir))))))))
 
 (ert-deftest files-tests-file-name-non-special-quote-unquote ()
   (let (;; Just in case it is quoted, who knows.
@@ -1231,26 +1228,26 @@ works as expected if the default directory is quoted."
         (insert-directory-wildcard-in-dir-p (car path-res)))))))
 
 (ert-deftest files-tests-make-directory ()
-  (let* ((dir (make-temp-file "files-mkdir-test" t))
-	 (dirname (file-name-as-directory dir))
-	 (file (concat dirname "file"))
-	 (subdir1 (concat dirname "subdir1"))
-	 (subdir2 (concat dirname "subdir2"))
-	 (a/b (concat dirname "a/b")))
-    (write-region "" nil file)
-    (should-error (make-directory "/"))
-    (should-not (make-directory "/" t))
-    (should-error (make-directory dir))
-    (should-not (make-directory dir t))
-    (should-error (make-directory dirname))
-    (should-not (make-directory dirname t))
-    (should-error (make-directory file))
-    (should-error (make-directory file t))
-    (should-not (make-directory subdir1))
-    (should-not (make-directory subdir2 t))
-    (should-error (make-directory a/b))
-    (should-not (make-directory a/b t))
-    (delete-directory dir 'recursive)))
+  (ert-with-temp-directory dir
+    (let* ((dirname (file-name-as-directory dir))
+           (file (concat dirname "file"))
+           (subdir1 (concat dirname "subdir1"))
+           (subdir2 (concat dirname "subdir2"))
+           (a/b (concat dirname "a/b")))
+      (write-region "" nil file)
+      (should-error (make-directory "/"))
+      (should-not (make-directory "/" t))
+      (should-error (make-directory dir))
+      (should-not (make-directory dir t))
+      (should-error (make-directory dirname))
+      (should-not (make-directory dirname t))
+      (should-error (make-directory file))
+      (should-error (make-directory file t))
+      (should-not (make-directory subdir1))
+      (should-not (make-directory subdir2 t))
+      (should-error (make-directory a/b))
+      (should-not (make-directory a/b t))
+      (delete-directory dir 'recursive))))
 
 (ert-deftest files-tests-file-modes-symbolic-to-number ()
   (let ((alist (list (cons "a=rwx" #o777)
@@ -1318,21 +1315,21 @@ name (Bug#28412)."
         (should (eq (buffer-size) 1))))))
 
 (ert-deftest files-tests-copy-directory ()
-  (let* ((dir (make-temp-file "files-mkdir-test" t))
-	 (dirname (file-name-as-directory dir))
-	 (source (concat dirname "source"))
-	 (dest (concat dirname "dest/new/directory/"))
-	 (file (concat (file-name-as-directory source) "file"))
-	 (source2 (concat dirname "source2"))
-	 (dest2 (concat dirname "dest/new2")))
-    (make-directory source)
-    (write-region "" nil file)
-    (copy-directory source dest t t t)
-    (should (file-exists-p (concat dest "file")))
-    (make-directory (concat (file-name-as-directory source2) "a") t)
-    (copy-directory source2 dest2)
-    (should (file-directory-p (concat (file-name-as-directory dest2) "a")))
-    (delete-directory dir 'recursive)))
+  (ert-with-temp-directory dir
+    (let* ((dirname (file-name-as-directory dir))
+           (source (concat dirname "source"))
+           (dest (concat dirname "dest/new/directory/"))
+           (file (concat (file-name-as-directory source) "file"))
+           (source2 (concat dirname "source2"))
+           (dest2 (concat dirname "dest/new2")))
+      (make-directory source)
+      (write-region "" nil file)
+      (copy-directory source dest t t t)
+      (should (file-exists-p (concat dest "file")))
+      (make-directory (concat (file-name-as-directory source2) "a") t)
+      (copy-directory source2 dest2)
+      (should (file-directory-p (concat (file-name-as-directory dest2) "a")))
+      (delete-directory dir 'recursive))))
 
 (ert-deftest files-tests-abbreviated-home-dir ()
   "Test that changing HOME does not confuse `abbreviate-file-name'.
@@ -1351,43 +1348,41 @@ See <https://debbugs.gnu.org/19657#20>."
 (ert-deftest files-tests-executable-find ()
   "Test that `executable-find' works also with a relative or remote PATH.
 See <https://debbugs.gnu.org/35241>."
-  (let ((tmpfile (make-temp-file "files-test" nil (car exec-suffixes))))
-    (unwind-protect
-        (progn
-          (set-file-modes tmpfile #o777)
-          (let ((exec-path `(,temporary-file-directory)))
-            (should
-             (equal tmpfile
-                    (executable-find (file-name-nondirectory tmpfile)))))
-          ;; An empty element of `exec-path' means `default-directory'.
-          (let ((default-directory temporary-file-directory)
-                (exec-path nil))
-            (should
-             (equal tmpfile
-                    (executable-find (file-name-nondirectory tmpfile)))))
-          ;; The remote file name shall be quoted, and handled like a
-          ;; non-existing directory.
-          (let ((default-directory "/ssh::")
-                (exec-path (append exec-path `("." ,temporary-file-directory))))
-            (should
-             (equal tmpfile
-                    (executable-find (file-name-nondirectory tmpfile))))))
-      (delete-file tmpfile))))
+  (ert-with-temp-file tmpfile
+    :suffix (car exec-suffixes)
+    (let ((tmpfile (make-temp-file "files-test" nil )))
+      (set-file-modes tmpfile #o777)
+      (let ((exec-path `(,temporary-file-directory)))
+        (should
+         (equal tmpfile
+                (executable-find (file-name-nondirectory tmpfile)))))
+      ;; An empty element of `exec-path' means `default-directory'.
+      (let ((default-directory temporary-file-directory)
+            (exec-path nil))
+        (should
+         (equal tmpfile
+                (executable-find (file-name-nondirectory tmpfile)))))
+      ;; The remote file name shall be quoted, and handled like a
+      ;; non-existing directory.
+      (let ((default-directory "/ssh::")
+            (exec-path (append exec-path `("." ,temporary-file-directory))))
+        (should
+         (equal tmpfile
+                (executable-find (file-name-nondirectory tmpfile))))))))
 
 (ert-deftest files-tests-dont-rewrite-precious-files ()
   "Test that `file-precious-flag' forces files to be saved by
 renaming only, rather than modified in-place."
-  (let* ((temp-file-name (make-temp-file "files-tests"))
-         (advice (lambda (_start _end filename &rest _r)
-                   (should-not (string= filename temp-file-name)))))
-    (unwind-protect
-        (with-current-buffer (find-file-noselect temp-file-name)
-          (advice-add #'write-region :before advice)
-          (setq-local file-precious-flag t)
-          (insert "foobar")
-          (should (null (save-buffer))))
-      (ignore-errors (advice-remove #'write-region advice))
-      (ignore-errors (delete-file temp-file-name)))))
+  (ert-with-temp-file temp-file-name
+    (let* ((advice (lambda (_start _end filename &rest _r)
+                     (should-not (string= filename temp-file-name)))))
+      (unwind-protect
+          (with-current-buffer (find-file-noselect temp-file-name)
+            (advice-add #'write-region :before advice)
+            (setq-local file-precious-flag t)
+            (insert "foobar")
+            (should (null (save-buffer))))
+        (ignore-errors (advice-remove #'write-region advice))))))
 
 (ert-deftest files-test-file-size-human-readable ()
   (should (equal (file-size-human-readable 13) "13"))
@@ -1578,40 +1573,39 @@ on BUF-1 and BUF-2 after the `save-some-buffers' call.
 The test is repeated with `save-some-buffers-default-predicate'
 let-bound to PRED and passing nil as second arg of
 `save-some-buffers'."
-  (let* ((dir (make-temp-file "testdir" 'dir))
-         (file-1 (expand-file-name "subdir-1/file.foo" dir))
-         (file-2 (expand-file-name "subdir-2/file.bar" dir))
-         (inhibit-message t)
-         buf-1 buf-2)
-    (unwind-protect
-        (progn
-          (make-empty-file file-1 'parens)
-          (make-empty-file file-2 'parens)
-          (setq buf-1 (find-file file-1)
-                buf-2 (find-file file-2))
-          (dolist (buf (list buf-1 buf-2))
-            (with-current-buffer buf (insert "foobar\n")))
-          ;; Run the test.
-          (with-current-buffer buf-1
-            (let ((save-some-buffers-default-predicate def-pred-bind))
-              (save-some-buffers t pred))
-            (should (eq exp-1 (buffer-modified-p buf-1)))
-            (should (eq exp-2 (buffer-modified-p buf-2))))
-          ;; Set both buffers as modified to run another test.
-          (dolist (buf (list buf-1 buf-2))
-            (with-current-buffer buf (set-buffer-modified-p t)))
-          ;; The result of this test must be identical as the previous one.
-          (with-current-buffer buf-1
-            (let ((save-some-buffers-default-predicate (or pred def-pred-bind)))
-              (save-some-buffers t nil))
-            (should (eq exp-1 (buffer-modified-p buf-1)))
-            (should (eq exp-2 (buffer-modified-p buf-2)))))
-      ;; Clean up.
-      (dolist (buf (list buf-1 buf-2))
-        (with-current-buffer buf
-          (set-buffer-modified-p nil)
-          (kill-buffer buf)))
-      (delete-directory dir 'recursive))))
+  (ert-with-temp-directory dir
+    (let* ((file-1 (expand-file-name "subdir-1/file.foo" dir))
+           (file-2 (expand-file-name "subdir-2/file.bar" dir))
+           (inhibit-message t)
+           buf-1 buf-2)
+      (unwind-protect
+          (progn
+            (make-empty-file file-1 'parens)
+            (make-empty-file file-2 'parens)
+            (setq buf-1 (find-file file-1)
+                  buf-2 (find-file file-2))
+            (dolist (buf (list buf-1 buf-2))
+              (with-current-buffer buf (insert "foobar\n")))
+            ;; Run the test.
+            (with-current-buffer buf-1
+              (let ((save-some-buffers-default-predicate def-pred-bind))
+                (save-some-buffers t pred))
+              (should (eq exp-1 (buffer-modified-p buf-1)))
+              (should (eq exp-2 (buffer-modified-p buf-2))))
+            ;; Set both buffers as modified to run another test.
+            (dolist (buf (list buf-1 buf-2))
+              (with-current-buffer buf (set-buffer-modified-p t)))
+            ;; The result of this test must be identical as the previous one.
+            (with-current-buffer buf-1
+              (let ((save-some-buffers-default-predicate (or pred def-pred-bind)))
+                (save-some-buffers t nil))
+              (should (eq exp-1 (buffer-modified-p buf-1)))
+              (should (eq exp-2 (buffer-modified-p buf-2)))))
+        ;; Clean up.
+        (dolist (buf (list buf-1 buf-2))
+          (with-current-buffer buf
+            (set-buffer-modified-p nil)
+            (kill-buffer buf)))))))
 
 (ert-deftest files-tests-save-some-buffers ()
   "Test `save-some-buffers'.
diff --git a/test/lisp/ls-lisp-tests.el b/test/lisp/ls-lisp-tests.el
index e386398eea2..e3a75bed41d 100644
--- a/test/lisp/ls-lisp-tests.el
+++ b/test/lisp/ls-lisp-tests.el
@@ -25,6 +25,7 @@
 
 ;;; Code:
 (require 'ert)
+(require 'ert-x)
 (require 'ls-lisp)
 (require 'dired)
 
@@ -59,22 +60,22 @@
 
 (ert-deftest ls-lisp-test-bug27631 ()
   "Test for https://debbugs.gnu.org/27631 ."
-  (let* ((dir (make-temp-file "bug27631" 'dir))
-         (dir1 (expand-file-name "dir1" dir))
-         (dir2 (expand-file-name "dir2" dir))
-         (default-directory dir)
-         ls-lisp-use-insert-directory-program buf)
-    (unwind-protect
-        (progn
-          (make-directory dir1)
-          (make-directory dir2)
-          (with-temp-file (expand-file-name "a.txt" dir1))
-          (with-temp-file (expand-file-name "b.txt" dir2))
-          (setq buf (dired (expand-file-name "dir*/*.txt" dir)))
-          (dired-toggle-marks)
-          (should (cdr (dired-get-marked-files))))
-      (delete-directory dir 'recursive)
-      (when (buffer-live-p buf) (kill-buffer buf)))))
+  (ert-with-temp-directory dir
+    :suffix "bug27631"
+    (let* ((dir1 (expand-file-name "dir1" dir))
+           (dir2 (expand-file-name "dir2" dir))
+           (default-directory dir)
+           ls-lisp-use-insert-directory-program buf)
+      (unwind-protect
+          (progn
+            (make-directory dir1)
+            (make-directory dir2)
+            (with-temp-file (expand-file-name "a.txt" dir1))
+            (with-temp-file (expand-file-name "b.txt" dir2))
+            (setq buf (dired (expand-file-name "dir*/*.txt" dir)))
+            (dired-toggle-marks)
+            (should (cdr (dired-get-marked-files))))
+        (when (buffer-live-p buf) (kill-buffer buf))))))
 
 (ert-deftest ls-lisp-test-bug27693 ()
   "Test for https://debbugs.gnu.org/27693 ."
diff --git a/test/lisp/mail/uudecode-tests.el b/test/lisp/mail/uudecode-tests.el
index 981ce1c4ae0..1899ff50f69 100644
--- a/test/lisp/mail/uudecode-tests.el
+++ b/test/lisp/mail/uudecode-tests.el
@@ -50,14 +50,11 @@ Same as `uudecode-tests-encoded-str' but plain text.")
     (should (equal (buffer-string) uudecode-tests-decoded-str)))
   ;; Write to file
   (with-temp-buffer
-    (let ((tmpfile (make-temp-file "uudecode-tests-")))
-      (unwind-protect
-          (progn
-            (insert uudecode-tests-encoded-str)
-            (uudecode-decode-region-internal (point-min) (point-max) tmpfile)
-            (should (equal (uudecode-tests-read-file tmpfile)
-                           uudecode-tests-decoded-str)))
-        (delete-file tmpfile)))))
+    (ert-with-temp-file tmpfile
+      (insert uudecode-tests-encoded-str)
+      (uudecode-decode-region-internal (point-min) (point-max) tmpfile)
+      (should (equal (uudecode-tests-read-file tmpfile)
+                     uudecode-tests-decoded-str)))))
 
 (ert-deftest uudecode-tests-decode-region-external ()
   ;; Write to buffer
@@ -68,14 +65,11 @@ Same as `uudecode-tests-encoded-str' but plain text.")
       (should (equal (buffer-string) uudecode-tests-decoded-str)))
     ;; Write to file
     (with-temp-buffer
-      (let ((tmpfile (make-temp-file "uudecode-tests-")))
-        (unwind-protect
-            (progn
-              (insert uudecode-tests-encoded-str)
-              (uudecode-decode-region-external (point-min) (point-max) tmpfile)
-              (should (equal (uudecode-tests-read-file tmpfile)
-                             uudecode-tests-decoded-str)))
-          (delete-file tmpfile))))))
+      (ert-with-temp-file tmpfile
+        (insert uudecode-tests-encoded-str)
+        (uudecode-decode-region-external (point-min) (point-max) tmpfile)
+        (should (equal (uudecode-tests-read-file tmpfile)
+                       uudecode-tests-decoded-str))))))
 
 (provide 'uudecode-tests)
 ;;; uudecode-tests.el ends here
diff --git a/test/lisp/net/browse-url-tests.el b/test/lisp/net/browse-url-tests.el
index 4264e03d912..68c7c349013 100644
--- a/test/lisp/net/browse-url-tests.el
+++ b/test/lisp/net/browse-url-tests.el
@@ -28,6 +28,7 @@
 
 (require 'browse-url)
 (require 'ert)
+(require 'ert-x)
 
 (ert-deftest browse-url-tests-browser-kind ()
   (should (eq (browse-url--browser-kind #'browse-url-w3 "gnu.org")
@@ -87,11 +88,10 @@
                  "ftp://foo/")))
 
 (ert-deftest browse-url-tests-delete-temp-file ()
-  (let ((browse-url-temp-file-name
-         (make-temp-file "browse-url-tests-")))
+  (ert-with-temp-file browse-url-temp-file-name
     (browse-url-delete-temp-file)
     (should-not (file-exists-p browse-url-temp-file-name)))
-  (let ((file (make-temp-file "browse-url-tests-")))
+  (ert-with-temp-file file
     (browse-url-delete-temp-file file)
     (should-not (file-exists-p file))))
 
diff --git a/test/lisp/progmodes/elisp-mode-tests.el b/test/lisp/progmodes/elisp-mode-tests.el
index 9516687f5b0..7f1cd6795ef 100644
--- a/test/lisp/progmodes/elisp-mode-tests.el
+++ b/test/lisp/progmodes/elisp-mode-tests.el
@@ -302,12 +302,9 @@
 
 ;; tmp may be on a different filesystem to the tests, but, ehh.
 (defvar xref--case-insensitive
-  (let ((dir (make-temp-file "xref-test" t)))
-    (unwind-protect
-        (progn
-          (with-temp-file (expand-file-name "hElLo" dir) "hello")
-          (file-exists-p (expand-file-name "HELLO" dir)))
-      (delete-directory dir t)))
+  (ert-with-temp-directory dir
+    (with-temp-file (expand-file-name "hElLo" dir) "hello")
+    (file-exists-p (expand-file-name "HELLO" dir)))
   "Non-nil if file system seems to be case-insensitive.")
 
 (defun xref-elisp-test-run (xrefs expected-xrefs)
diff --git a/test/lisp/progmodes/etags-tests.el b/test/lisp/progmodes/etags-tests.el
index 9b14a3ae860..32b73f101e1 100644
--- a/test/lisp/progmodes/etags-tests.el
+++ b/test/lisp/progmodes/etags-tests.el
@@ -22,6 +22,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'etags)
 (eval-when-compile (require 'cl-lib))
 
@@ -95,21 +96,19 @@
 
 (ert-deftest etags-buffer-local-tags-table-list ()
   "Test that a buffer-local value of `tags-table-list' is used."
-  (let ((file (make-temp-file "etag-test-tmpfile")))
-    (unwind-protect
-        (progn
-          (set-buffer (find-file-noselect file))
-          (fundamental-mode)
-          (setq-local tags-table-list
-                      (list (expand-file-name "manual/etags/ETAGS.good_3"
-                                              etags-tests--test-dir)))
-          (cl-letf ((tag-tables tags-table-list)
-                    (tags-file-name nil)
-                    ((symbol-function 'read-file-name)
-                     (lambda (&rest _)
-                       (error "We should not prompt the user"))))
-            (should (visit-tags-table-buffer))
-            (should (equal tags-file-name (car tag-tables)))))
-      (delete-file file))))
+  (ert-with-temp-file file
+    :suffix "etag-test-tmpfile"
+    (set-buffer (find-file-noselect file))
+    (fundamental-mode)
+    (setq-local tags-table-list
+                (list (expand-file-name "manual/etags/ETAGS.good_3"
+                                        etags-tests--test-dir)))
+    (cl-letf ((tag-tables tags-table-list)
+              (tags-file-name nil)
+              ((symbol-function 'read-file-name)
+               (lambda (&rest _)
+                 (error "We should not prompt the user"))))
+      (should (visit-tags-table-buffer))
+      (should (equal tags-file-name (car tag-tables))))))
 
 ;;; etags-tests.el ends here
diff --git a/test/lisp/progmodes/flymake-tests.el b/test/lisp/progmodes/flymake-tests.el
index 4c0d15d1e1b..4840018236a 100644
--- a/test/lisp/progmodes/flymake-tests.el
+++ b/test/lisp/progmodes/flymake-tests.el
@@ -23,6 +23,7 @@
 
 ;;; Code:
 (require 'ert)
+(require 'ert-x)
 (require 'flymake)
 (eval-when-compile (require 'subr-x)) ; string-trim
 
@@ -123,22 +124,21 @@ SEVERITY-PREDICATE is used to setup
   "Test the ruby backend."
   (skip-unless (executable-find "ruby"))
   ;; Some versions of ruby fail if HOME doesn't exist (bug#29187).
-  (let* ((tempdir (make-temp-file "flymake-tests-ruby" t))
-         (process-environment (cons (format "HOME=%s" tempdir)
-                                    process-environment))
-         ;; And see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19657#20
-         ;; for this particular yuckiness
-         (abbreviated-home-dir nil))
-    (unwind-protect
-        (let ((ruby-mode-hook
-               (lambda ()
-                 (setq flymake-diagnostic-functions '(ruby-flymake-simple)))))
-          (flymake-tests--with-flymake ("test.rb")
-            (flymake-goto-next-error)
-            (should (eq 'flymake-warning (face-at-point)))
-            (flymake-goto-next-error)
-            (should (eq 'flymake-error (face-at-point)))))
-      (delete-directory tempdir t))))
+  (ert-with-temp-directory  tempdir
+    :suffix "flymake-tests-ruby"
+    (let* ((process-environment (cons (format "HOME=%s" tempdir)
+                                      process-environment))
+           ;; And see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19657#20
+           ;; for this particular yuckiness
+           (abbreviated-home-dir nil)
+           (ruby-mode-hook
+            (lambda ()
+              (setq flymake-diagnostic-functions '(ruby-flymake-simple)))))
+      (flymake-tests--with-flymake ("test.rb")
+        (flymake-goto-next-error)
+        (should (eq 'flymake-warning (face-at-point)))
+        (flymake-goto-next-error)
+        (should (eq 'flymake-error (face-at-point)))))))
 
 (ert-deftest different-diagnostic-types ()
   "Test GCC warning via function predicate."
diff --git a/test/lisp/progmodes/python-tests.el b/test/lisp/progmodes/python-tests.el
index 6ab9c62746e..15bda5c197a 100644
--- a/test/lisp/progmodes/python-tests.el
+++ b/test/lisp/progmodes/python-tests.el
@@ -22,6 +22,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'python)
 
 ;; Dependencies for testing:
@@ -48,17 +49,17 @@ BODY is code to be executed within the temp buffer.  Point is
 always located at the beginning of buffer."
   (declare (indent 1) (debug t))
   ;; temp-file never actually used for anything?
-  `(let* ((temp-file (make-temp-file "python-tests" nil ".py"))
-          (buffer (find-file-noselect temp-file))
-          (python-indent-guess-indent-offset nil))
-     (unwind-protect
-         (with-current-buffer buffer
-           (python-mode)
-           (insert ,contents)
-           (goto-char (point-min))
-           ,@body)
-       (and buffer (kill-buffer buffer))
-       (delete-file temp-file))))
+  `(ert-with-temp-file temp-file
+     :suffix "-python.py"
+     (let ((buffer (find-file-noselect temp-file))
+           (python-indent-guess-indent-offset nil))
+       (unwind-protect
+           (with-current-buffer buffer
+             (python-mode)
+             (insert ,contents)
+             (goto-char (point-min))
+             ,@body)
+         (and buffer (kill-buffer buffer))))))
 
 (defun python-tests-look-at (string &optional num restore-point)
   "Move point at beginning of STRING in the current buffer.
diff --git a/test/lisp/progmodes/sql-tests.el b/test/lisp/progmodes/sql-tests.el
index aed82b18825..1bbe3a95e90 100644
--- a/test/lisp/progmodes/sql-tests.el
+++ b/test/lisp/progmodes/sql-tests.el
@@ -28,6 +28,7 @@
 
 (require 'cl-lib)
 (require 'ert)
+(require 'ert-x)
 (require 'sql)
 
 (ert-deftest sql-tests-postgres-list-databases ()
@@ -63,52 +64,49 @@ Identify tests by ID.  Set :sql-login dialect attribute to
 LOGIN-PARAMS.  Provide the CONNECTION parameters and the EXPECTED
 string of values passed to the comint function for validation."
   (declare (indent 2))
-  `(cl-letf
-       ((sql-test-login-params ' ,login-params)
-        ((symbol-function 'sql-comint-test)
-         (lambda (product options &optional buf-name)
-           (with-current-buffer (get-buffer-create buf-name)
-             (insert (pp-to-string (list product options sql-user sql-password sql-server sql-database))))))
-        ((symbol-function 'sql-run-test)
-         (lambda (&optional buffer)
-           (interactive "P")
-           (sql-product-interactive 'sqltest buffer)))
-        (sql-user nil)
-        (sql-server nil)
-        (sql-database nil)
-        (sql-product-alist
-         '((ansi)
-           (sqltest
-            :name "SqlTest"
-            :sqli-login sql-test-login-params
-            :sqli-comint-func sql-comint-test)))
-        (sql-connection-alist
-         '((,(format "test-%s" id)
-            ,@connection)))
-        (sql-password-wallet
-         (list
-          (make-temp-file
-           "sql-test-netrc" nil nil
-           (mapconcat #'identity
-                      '("machine aMachine user aUserName password \"netrc-A aPassword\""
-                        "machine aServer user aUserName password \"netrc-B aPassword\""
-                        "machine aMachine server aServer user aUserName password \"netrc-C aPassword\""
-                        "machine aMachine database aDatabase user aUserName password \"netrc-D aPassword\""
-                        "machine aDatabase user aUserName password \"netrc-E aPassword\""
-                        "machine aMachine server aServer database aDatabase user aUserName password \"netrc-F aPassword\""
-                        "machine \"aServer/aDatabase\" user aUserName password \"netrc-G aPassword\""
-                        ) "\n")))))
-
-     (let* ((connection ,(format "test-%s" id))
-            (buffername (format "*SQL: ERT TEST <%s>*" connection)))
-       (when (get-buffer buffername)
-         (kill-buffer buffername))
-       (sql-connect connection buffername)
-       (should (get-buffer buffername))
-       (should (string-equal (with-current-buffer buffername (buffer-string)) ,expected))
-       (when (get-buffer buffername)
-         (kill-buffer buffername))
-       (delete-file (car sql-password-wallet)))))
+  `(ert-with-temp-file tempfile
+     :suffix "sql-test-netrc"
+     :text (concat
+            "machine aMachine user aUserName password \"netrc-A aPassword\""
+            "machine aServer user aUserName password \"netrc-B aPassword\""
+            "machine aMachine server aServer user aUserName password \"netrc-C aPassword\""
+            "machine aMachine database aDatabase user aUserName password \"netrc-D aPassword\""
+            "machine aDatabase user aUserName password \"netrc-E aPassword\""
+            "machine aMachine server aServer database aDatabase user aUserName password \"netrc-F aPassword\""
+            "machine \"aServer/aDatabase\" user aUserName password \"netrc-G aPassword\""
+            "\n")
+     (cl-letf
+         ((sql-test-login-params ' ,login-params)
+          ((symbol-function 'sql-comint-test)
+           (lambda (product options &optional buf-name)
+             (with-current-buffer (get-buffer-create buf-name)
+               (insert (pp-to-string (list product options sql-user sql-password sql-server sql-database))))))
+          ((symbol-function 'sql-run-test)
+           (lambda (&optional buffer)
+             (interactive "P")
+             (sql-product-interactive 'sqltest buffer)))
+          (sql-user nil)
+          (sql-server nil)
+          (sql-database nil)
+          (sql-product-alist
+           '((ansi)
+             (sqltest
+              :name "SqlTest"
+              :sqli-login sql-test-login-params
+              :sqli-comint-func sql-comint-test)))
+          (sql-connection-alist
+           '((,(format "test-%s" id)
+              ,@connection)))
+          (sql-password-wallet (list tempfile)))
+       (let* ((connection ,(format "test-%s" id))
+              (buffername (format "*SQL: ERT TEST <%s>*" connection)))
+         (when (get-buffer buffername)
+           (kill-buffer buffername))
+         (sql-connect connection buffername)
+         (should (get-buffer buffername))
+         (should (string-equal (with-current-buffer buffername (buffer-string)) ,expected))
+         (when (get-buffer buffername)
+           (kill-buffer buffername))))))
 
 (ert-deftest sql-test-connect ()
   "Test of basic `sql-connect'."
diff --git a/test/lisp/saveplace-tests.el b/test/lisp/saveplace-tests.el
index 63577fdd167..190ffb78288 100644
--- a/test/lisp/saveplace-tests.el
+++ b/test/lisp/saveplace-tests.el
@@ -41,49 +41,42 @@
 
 (ert-deftest saveplace-test-save-place-to-alist/file ()
   (save-place-mode)
-  (let* ((tmpfile (make-temp-file "emacs-test-saveplace-"))
-         (tmpfile (file-truename tmpfile))
-         (save-place-alist nil)
-         (save-place-loaded t)
-         (loc tmpfile)
-         (pos 4))
-    (unwind-protect
-        (save-window-excursion
-          (find-file loc)
-          (insert "abc") ; must insert something
-          (save-place-to-alist)
-          (should (equal save-place-alist (list (cons tmpfile pos)))))
-      (delete-file tmpfile))))
+  (ert-with-temp-file tmpfile
+    (let* ((tmpfile (file-truename tmpfile))
+           (save-place-alist nil)
+           (save-place-loaded t)
+           (loc tmpfile)
+           (pos 4))
+      (save-window-excursion
+        (find-file loc)
+        (insert "abc")                  ; must insert something
+        (save-place-to-alist)
+        (should (equal save-place-alist (list (cons tmpfile pos))))))))
 
 (ert-deftest saveplace-test-forget-unreadable-files ()
   (save-place-mode)
-  (let* ((save-place-loaded t)
-         (tmpfile (make-temp-file "emacs-test-saveplace-"))
-         (alist-orig (list (cons "/this/file/does/not/exist" 10)
-                           (cons tmpfile 1917)))
-         (save-place-alist alist-orig))
-    (unwind-protect
-        (progn
-          (save-place-forget-unreadable-files)
-          (should (equal save-place-alist (cdr alist-orig))))
-      (delete-file tmpfile))))
+  (ert-with-temp-file tmpfile
+    :suffix "-saveplace"
+    (let* ((save-place-loaded t)
+           (alist-orig (list (cons "/this/file/does/not/exist" 10)
+                             (cons tmpfile 1917)))
+           (save-place-alist alist-orig))
+      (save-place-forget-unreadable-files)
+      (should (equal save-place-alist (cdr alist-orig))))))
 
 (ert-deftest saveplace-test-place-alist-to-file ()
   (save-place-mode)
-  (let* ((tmpfile (make-temp-file "emacs-test-saveplace-"))
-         (tmpfile2 (make-temp-file "emacs-test-saveplace-"))
-         (save-place-file tmpfile)
-         (save-place-alist (list (cons tmpfile2 99))))
-    (unwind-protect
-        (progn (save-place-alist-to-file)
-               (setq save-place-alist nil)
-               (save-window-excursion
-                 (find-file save-place-file)
-                 (unwind-protect
-                     (should (string-match tmpfile2 (buffer-string)))
-                   (kill-buffer))))
-      (delete-file tmpfile)
-      (delete-file tmpfile2))))
+  (ert-with-temp-file tmpfile
+    (ert-with-temp-file tmpfile2
+      (let* ((save-place-file tmpfile)
+             (save-place-alist (list (cons tmpfile2 99))))
+        (save-place-alist-to-file)
+        (setq save-place-alist nil)
+        (save-window-excursion
+          (find-file save-place-file)
+          (unwind-protect
+              (should (string-match tmpfile2 (buffer-string)))
+            (kill-buffer)))))))
 
 (ert-deftest saveplace-test-load-alist-from-file ()
   (save-place-mode)
diff --git a/test/lisp/so-long-tests/spelling-tests.el b/test/lisp/so-long-tests/spelling-tests.el
index f778b646635..b598366ba7a 100644
--- a/test/lisp/so-long-tests/spelling-tests.el
+++ b/test/lisp/so-long-tests/spelling-tests.el
@@ -23,6 +23,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'ispell)
 (require 'cl-lib)
 
@@ -50,20 +51,19 @@
     ;; The Emacs test Makefile's use of HOME=/nonexistent triggers an error
     ;; when starting the inferior ispell process, so we set HOME to a valid
     ;; (but empty) temporary directory for this test.
-    (let* ((tmpdir (make-temp-file "so-long." :dir ".ispell"))
-           (process-environment (cons (format "HOME=%s" tmpdir)
-                                      process-environment))
-           (find-spelling-mistake
-            (unwind-protect
-                (cl-letf (((symbol-function 'ispell-command-loop)
-                           (lambda (_miss _guess word _start _end)
-                             (message "Unrecognised word: %s." word)
-                             (throw 'mistake t))))
-                  (catch 'mistake
-                    (find-library "so-long")
-                    (ispell-buffer)
-                    nil))
-              (delete-directory tmpdir))))
-      (should (not find-spelling-mistake)))))
+    (ert-with-temp-file tmpdir
+      :suffix "so-long.ispell"
+      (let* ((process-environment (cons (format "HOME=%s" tmpdir)
+                                        process-environment))
+             (find-spelling-mistake
+              (cl-letf (((symbol-function 'ispell-command-loop)
+                         (lambda (_miss _guess word _start _end)
+                           (message "Unrecognised word: %s." word)
+                           (throw 'mistake t))))
+                (catch 'mistake
+                  (find-library "so-long")
+                  (ispell-buffer)
+                  nil))))
+        (should (not find-spelling-mistake))))))
 
 ;;; spelling-tests.el ends here
diff --git a/test/lisp/textmodes/reftex-tests.el b/test/lisp/textmodes/reftex-tests.el
index b824e05f6d5..cc5b23e1c9c 100644
--- a/test/lisp/textmodes/reftex-tests.el
+++ b/test/lisp/textmodes/reftex-tests.el
@@ -24,6 +24,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 
 ;;; reftex
 (require 'reftex)
@@ -33,32 +34,31 @@
 
 (ert-deftest reftex-locate-bibliography-files ()
   "Test `reftex-locate-bibliography-files'."
-  (let ((temp-dir (make-temp-file "reftex-bib" 'dir))
-        (files '("ref1.bib" "ref2.bib"))
-        (test '(("\\addbibresource{ref1.bib}\n" . ("ref1.bib"))
-                ("\\\\addbibresource[label=x]{ref2.bib}\\n" . ("ref2.bib"))
-                ("\\begin{document}\n\\bibliographystyle{plain}\n
+  (ert-with-temp-directory temp-dir
+    (let ((files '("ref1.bib" "ref2.bib"))
+          (test '(("\\addbibresource{ref1.bib}\n" . ("ref1.bib"))
+                  ("\\\\addbibresource[label=x]{ref2.bib}\\n" . ("ref2.bib"))
+                  ("\\begin{document}\n\\bibliographystyle{plain}\n
 \\bibliography{ref1,ref2}\n\\end{document}" . ("ref1.bib" "ref2.bib"))))
-        (reftex-bibliography-commands
-         ;; Default value: See reftex-vars.el `reftex-bibliography-commands'
-         '("bibliography" "nobibliography" "setupbibtex\\[.*?database="
-           "addbibresource")))
-    (with-temp-buffer
-      (insert "test\n")
+          (reftex-bibliography-commands
+           ;; Default value: See reftex-vars.el `reftex-bibliography-commands'
+           '("bibliography" "nobibliography" "setupbibtex\\[.*?database="
+             "addbibresource")))
+      (with-temp-buffer
+        (insert "test\n")
+        (mapc
+         (lambda (file)
+           (write-region (point-min) (point-max) (expand-file-name file
+                                                                   temp-dir)))
+         files))
       (mapc
-       (lambda (file)
-        (write-region (point-min) (point-max) (expand-file-name file
-                                                                temp-dir)))
-       files))
-    (mapc
-     (lambda (data)
-       (with-temp-buffer
-         (insert (car data))
-         (let ((res (mapcar #'file-name-nondirectory
-                            (reftex-locate-bibliography-files temp-dir))))
-           (should (equal res (cdr data))))))
-     test)
-    (delete-directory temp-dir 'recursive)))
+       (lambda (data)
+         (with-temp-buffer
+           (insert (car data))
+           (let ((res (mapcar #'file-name-nondirectory
+                              (reftex-locate-bibliography-files temp-dir))))
+             (should (equal res (cdr data))))))
+       test))))
 
 (ert-deftest reftex-what-environment-test ()
   "Test `reftex-what-environment'."
@@ -102,12 +102,12 @@
   ;; reason.  (An alternative solution would be to use file-equal-p,
   ;; but I'm too lazy to do that, as one of the tests compares a
   ;; list.)
-  (let* ((temp-dir (file-truename (make-temp-file "reftex-parse" 'dir)))
-         (tex-file (expand-file-name "test.tex" temp-dir))
-         (bib-file (expand-file-name "ref.bib" temp-dir)))
-    (with-temp-buffer
-      (insert
-"\\begin{document}
+  (ert-with-temp-directory temp-dir
+    (let* ((tex-file (expand-file-name "test.tex" temp-dir))
+           (bib-file (expand-file-name "ref.bib" temp-dir)))
+      (with-temp-buffer
+        (insert
+         "\\begin{document}
 \\section{test}\\label{sec:test}
 \\subsection{subtest}
 
@@ -118,27 +118,26 @@
 \\bibliographystyle{plain}
 \\bibliography{ref}
 \\end{document}")
-      (write-region (point-min) (point-max) tex-file))
-    (with-temp-buffer
-      (insert "test\n")
-      (write-region (point-min) (point-max) bib-file))
-    (reftex-ensure-compiled-variables)
-    (let ((parsed (reftex-parse-from-file tex-file nil temp-dir)))
-      (should (equal (car parsed) `(eof ,tex-file)))
-      (pop parsed)
-      (while parsed
-        (let ((entry (pop parsed)))
-         (cond
-          ((eq (car entry) 'bib)
-           (should (string= (cadr entry) bib-file)))
-          ((eq (car entry) 'toc)) ;; ...
-          ((string= (car entry) "eq:foo"))
-          ((string= (car entry) "sec:test"))
-          ((eq (car entry) 'bof)
-           (should (string= (cadr entry) tex-file))
-           (should (null parsed)))
-          (t (should-not t)))))
-      (delete-directory temp-dir 'recursive))))
+        (write-region (point-min) (point-max) tex-file))
+      (with-temp-buffer
+        (insert "test\n")
+        (write-region (point-min) (point-max) bib-file))
+      (reftex-ensure-compiled-variables)
+      (let ((parsed (reftex-parse-from-file tex-file nil temp-dir)))
+        (should (equal (car parsed) `(eof ,tex-file)))
+        (pop parsed)
+        (while parsed
+          (let ((entry (pop parsed)))
+            (cond
+             ((eq (car entry) 'bib)
+              (should (string= (cadr entry) bib-file)))
+             ((eq (car entry) 'toc)) ;; ...
+             ((string= (car entry) "eq:foo"))
+             ((string= (car entry) "sec:test"))
+             ((eq (car entry) 'bof)
+              (should (string= (cadr entry) tex-file))
+              (should (null parsed)))
+             (t (should-not t)))))))))
 
 ;;; reftex-cite
 (require 'reftex-cite)
diff --git a/test/lisp/thumbs-tests.el b/test/lisp/thumbs-tests.el
index ee096138453..a9b41d7c00f 100644
--- a/test/lisp/thumbs-tests.el
+++ b/test/lisp/thumbs-tests.el
@@ -20,15 +20,13 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'thumbs)
 
 (ert-deftest thumbs-tests-thumbsdir/create-if-missing ()
-  (let ((thumbs-thumbsdir (make-temp-file "thumbs-test" t)))
-    (unwind-protect
-        (progn
-          (delete-directory thumbs-thumbsdir)
-          (should (file-directory-p (thumbs-thumbsdir))))
-      (delete-directory thumbs-thumbsdir))))
+  (ert-with-temp-directory thumbs-thumbsdir
+    (delete-directory thumbs-thumbsdir)
+    (should (file-directory-p (thumbs-thumbsdir)))))
 
 (provide 'thumbs-tests)
 ;;; thumbs-tests.el ends here
diff --git a/test/lisp/vc/diff-mode-tests.el b/test/lisp/vc/diff-mode-tests.el
index ef19fe0e0e8..909d5620de6 100644
--- a/test/lisp/vc/diff-mode-tests.el
+++ b/test/lisp/vc/diff-mode-tests.el
@@ -173,35 +173,33 @@ wristwatches
 wrongheadedly
 wrongheadedness
 youthfulness
-")
-        (temp-dir (make-temp-file "diff-mode-test" 'dir)))
-
-    (let ((buf  (find-file-noselect (format "%s/%s" temp-dir "fil" )))
-          (buf2 (find-file-noselect (format "%s/%s" temp-dir "fil2"))))
-      (unwind-protect
-          (progn
-            (with-current-buffer buf  (insert fil_before)  (save-buffer))
-            (with-current-buffer buf2 (insert fil2_before) (save-buffer))
-
-            (with-temp-buffer
-              (cd temp-dir)
-              (insert patch)
-              (goto-char (point-min))
-              (diff-apply-hunk)
-              (diff-apply-hunk)
-              (diff-apply-hunk))
-
-            (should (equal (with-current-buffer buf (buffer-string))
-                           fil_after))
-            (should (equal (with-current-buffer buf2 (buffer-string))
-                           fil2_after)))
-
-        (ignore-errors
-          (with-current-buffer buf (set-buffer-modified-p nil))
-          (kill-buffer buf)
-          (with-current-buffer buf2 (set-buffer-modified-p nil))
-          (kill-buffer buf2)
-          (delete-directory temp-dir 'recursive))))))
+"))
+    (ert-with-temp-directory temp-dir
+     (let ((buf  (find-file-noselect (format "%s/%s" temp-dir "fil" )))
+           (buf2 (find-file-noselect (format "%s/%s" temp-dir "fil2"))))
+       (unwind-protect
+           (progn
+             (with-current-buffer buf  (insert fil_before)  (save-buffer))
+             (with-current-buffer buf2 (insert fil2_before) (save-buffer))
+
+             (with-temp-buffer
+               (cd temp-dir)
+               (insert patch)
+               (goto-char (point-min))
+               (diff-apply-hunk)
+               (diff-apply-hunk)
+               (diff-apply-hunk))
+
+             (should (equal (with-current-buffer buf (buffer-string))
+                            fil_after))
+             (should (equal (with-current-buffer buf2 (buffer-string))
+                            fil2_after)))
+
+         (ignore-errors
+           (with-current-buffer buf (set-buffer-modified-p nil))
+           (kill-buffer buf)
+           (with-current-buffer buf2 (set-buffer-modified-p nil))
+           (kill-buffer buf2)))))))
 
 (ert-deftest diff-mode-test-hunk-text-no-newline ()
   "Check output of `diff-hunk-text' with no newline at end of file."
diff --git a/test/lisp/vc/ediff-ptch-tests.el b/test/lisp/vc/ediff-ptch-tests.el
index a464db2349d..0f09616a816 100644
--- a/test/lisp/vc/ediff-ptch-tests.el
+++ b/test/lisp/vc/ediff-ptch-tests.el
@@ -22,6 +22,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'ediff-ptch)
 
 (ert-deftest ediff-ptch-test-bug25010 ()
@@ -45,34 +46,33 @@ index 6a07f80..6e8e947 100644
   "Test for https://debbugs.gnu.org/26084 ."
   (skip-unless (executable-find "git"))
   (skip-unless (executable-find ediff-patch-program))
-  (let* ((tmpdir (make-temp-file "ediff-ptch-test" t))
-         (default-directory (file-name-as-directory tmpdir))
-         (patch (make-temp-file "ediff-ptch-test"))
-         (qux (expand-file-name "qux.txt" tmpdir))
-         (bar (expand-file-name "bar.txt" tmpdir))
-         (git-program (executable-find "git")))
-    ;; Create repository.
-    (with-temp-buffer
-      (insert "qux here\n")
-      (write-region nil nil qux nil 'silent)
-      (erase-buffer)
-      (insert "bar here\n")
-      (write-region nil nil bar nil 'silent))
-    (call-process git-program nil nil nil "init")
-    (call-process git-program nil nil nil "add" ".")
-    (call-process git-program nil nil nil "commit" "-m" "Test repository.")
-    ;; Update repo., save the diff and reset to initial state.
-    (with-temp-buffer
-      (insert "foo here\n")
-      (write-region nil nil qux nil 'silent)
-      (write-region nil nil bar nil 'silent))
-    (call-process git-program nil `(:file ,patch) nil "diff")
-    (call-process git-program nil nil nil "reset" "--hard" "HEAD")
-    ;; Visit the diff file i.e., patch; extract from it the parts
-    ;; affecting just each of the files: store in patch-bar the part
-    ;; affecting 'bar', and in patch-qux the part affecting 'qux'.
-    (find-file patch)
-    (unwind-protect
+  (ert-with-temp-directory tmpdir
+    (ert-with-temp-file patch
+      (let* ((default-directory (file-name-as-directory tmpdir))
+             (qux (expand-file-name "qux.txt" tmpdir))
+             (bar (expand-file-name "bar.txt" tmpdir))
+             (git-program (executable-find "git")))
+        ;; Create repository.
+        (with-temp-buffer
+          (insert "qux here\n")
+          (write-region nil nil qux nil 'silent)
+          (erase-buffer)
+          (insert "bar here\n")
+          (write-region nil nil bar nil 'silent))
+        (call-process git-program nil nil nil "init")
+        (call-process git-program nil nil nil "add" ".")
+        (call-process git-program nil nil nil "commit" "-m" "Test repository.")
+        ;; Update repo., save the diff and reset to initial state.
+        (with-temp-buffer
+          (insert "foo here\n")
+          (write-region nil nil qux nil 'silent)
+          (write-region nil nil bar nil 'silent))
+        (call-process git-program nil `(:file ,patch) nil "diff")
+        (call-process git-program nil nil nil "reset" "--hard" "HEAD")
+        ;; Visit the diff file i.e., patch; extract from it the parts
+        ;; affecting just each of the files: store in patch-bar the part
+        ;; affecting 'bar', and in patch-qux the part affecting 'qux'.
+        (find-file patch)
         (let* ((info
                 (progn (ediff-map-patch-buffer (current-buffer)) ediff-patch-map))
                (patch-bar
@@ -116,9 +116,7 @@ index 6a07f80..6e8e947 100644
                             (buffer-string))
                           (with-temp-buffer
                             (insert-file-contents backup)
-                            (buffer-string)))))))
-          (delete-directory tmpdir 'recursive)
-          (delete-file patch)))))
+                            (buffer-string))))))))))))
 
 
 (provide 'ediff-ptch-tests)
diff --git a/test/lisp/vc/vc-bzr-tests.el b/test/lisp/vc/vc-bzr-tests.el
index 43385de5955..afced819fbc 100644
--- a/test/lisp/vc/vc-bzr-tests.el
+++ b/test/lisp/vc/vc-bzr-tests.el
@@ -25,6 +25,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'vc-bzr)
 (require 'vc-dir)
 
@@ -51,106 +52,97 @@
   ;; temporary directory.
   ;; TODO does this means tests should be setting XDG_ variables (not
   ;; just HOME) to temporary values too?
-  (let* ((homedir (make-temp-file "vc-bzr-test" t))
-         (bzrdir (expand-file-name "bzr" homedir))
-         (ignored-dir (progn
-                        (make-directory bzrdir)
-                        (expand-file-name "ignored-dir" bzrdir)))
-         (default-directory (file-name-as-directory bzrdir))
-         (process-environment (cons (format "HOME=%s" homedir)
-                                    process-environment)))
-    (unwind-protect
-        (progn
-          (make-directory ignored-dir)
-          (with-temp-buffer
-            (insert (file-name-nondirectory ignored-dir))
-            (write-region nil nil (expand-file-name ".bzrignore" bzrdir)
-                          nil 'silent))
-          (skip-unless (eq 0            ; some internal bzr error
-                           (call-process vc-bzr-program nil nil nil "init")))
-          (call-process vc-bzr-program nil nil nil "add")
-          (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
-          (with-temp-buffer
-            (insert "unregistered file")
-            (write-region nil nil (expand-file-name "testfile2" ignored-dir)
-                          nil 'silent))
-          (vc-dir ignored-dir)
-          (while (vc-dir-busy)
-            (sit-for 0.1))
-          ;; FIXME better to explicitly test for error from process sentinel.
-          (with-current-buffer "*vc-dir*"
-            (goto-char (point-min))
-            (should (search-forward "unregistered" nil t))))
-      (delete-directory homedir t))))
+  (ert-with-temp-directory homedir
+    (let* ((bzrdir (expand-file-name "bzr" homedir))
+           (ignored-dir (progn
+                          (make-directory bzrdir)
+                          (expand-file-name "ignored-dir" bzrdir)))
+           (default-directory (file-name-as-directory bzrdir))
+           (process-environment (cons (format "HOME=%s" homedir)
+                                      process-environment)))
+      (make-directory ignored-dir)
+      (with-temp-buffer
+        (insert (file-name-nondirectory ignored-dir))
+        (write-region nil nil (expand-file-name ".bzrignore" bzrdir)
+                      nil 'silent))
+      (skip-unless (eq 0           ; some internal bzr error
+                       (call-process vc-bzr-program nil nil nil "init")))
+      (call-process vc-bzr-program nil nil nil "add")
+      (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
+      (with-temp-buffer
+        (insert "unregistered file")
+        (write-region nil nil (expand-file-name "testfile2" ignored-dir)
+                      nil 'silent))
+      (vc-dir ignored-dir)
+      (while (vc-dir-busy)
+        (sit-for 0.1))
+      ;; FIXME better to explicitly test for error from process sentinel.
+      (with-current-buffer "*vc-dir*"
+        (goto-char (point-min))
+        (should (search-forward "unregistered" nil t))))))
 
 ;; Not specific to bzr.
 (ert-deftest vc-bzr-test-bug9781 ()
   "Test for https://debbugs.gnu.org/9781 ."
   (skip-unless (executable-find vc-bzr-program))
-  (let* ((homedir (make-temp-file "vc-bzr-test" t))
-         (bzrdir (expand-file-name "bzr" homedir))
-         (subdir (progn
-                   (make-directory bzrdir)
-                   (expand-file-name "subdir" bzrdir)))
-         (file (expand-file-name "file" bzrdir))
-         (default-directory (file-name-as-directory bzrdir))
-         (process-environment (cons (format "HOME=%s" homedir)
-                                    process-environment)))
-    (unwind-protect
-        (progn
-          (skip-unless (eq 0            ; some internal bzr error
-                           (call-process vc-bzr-program nil nil nil "init")))
-          (make-directory subdir)
-          (with-temp-buffer
-            (insert "text")
-            (write-region nil nil file nil 'silent)
-            (write-region nil nil (expand-file-name "subfile" subdir)
-                          nil 'silent))
-          (call-process vc-bzr-program nil nil nil "add")
-          (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
-          (call-process vc-bzr-program nil nil nil "remove" subdir)
-          (with-temp-buffer
-            (insert "different text")
-            (write-region nil nil file nil 'silent))
-          (vc-dir bzrdir)
-          (while (vc-dir-busy)
-            (sit-for 0.1))
-          (vc-dir-mark-all-files t)
-          (cl-letf (((symbol-function 'y-or-n-p) (lambda (_) t)))
-            (vc-next-action nil))
-          (should (get-buffer "*vc-log*")))
-      (delete-directory homedir t))))
+  (ert-with-temp-directory homedir
+    (let* ((bzrdir (expand-file-name "bzr" homedir))
+           (subdir (progn
+                     (make-directory bzrdir)
+                     (expand-file-name "subdir" bzrdir)))
+           (file (expand-file-name "file" bzrdir))
+           (default-directory (file-name-as-directory bzrdir))
+           (process-environment (cons (format "HOME=%s" homedir)
+                                      process-environment)))
+      (skip-unless (eq 0           ; some internal bzr error
+                       (call-process vc-bzr-program nil nil nil "init")))
+      (make-directory subdir)
+      (with-temp-buffer
+        (insert "text")
+        (write-region nil nil file nil 'silent)
+        (write-region nil nil (expand-file-name "subfile" subdir)
+                      nil 'silent))
+      (call-process vc-bzr-program nil nil nil "add")
+      (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
+      (call-process vc-bzr-program nil nil nil "remove" subdir)
+      (with-temp-buffer
+        (insert "different text")
+        (write-region nil nil file nil 'silent))
+      (vc-dir bzrdir)
+      (while (vc-dir-busy)
+        (sit-for 0.1))
+      (vc-dir-mark-all-files t)
+      (cl-letf (((symbol-function 'y-or-n-p) (lambda (_) t)))
+        (vc-next-action nil))
+      (should (get-buffer "*vc-log*")))))
 
 ;; https://lists.gnu.org/r/help-gnu-emacs/2012-04/msg00145.html
 (ert-deftest vc-bzr-test-faulty-bzr-autoloads ()
   "Test we can generate autoloads in a bzr directory when bzr is faulty."
   (skip-unless (executable-find vc-bzr-program))
-  (let* ((homedir (make-temp-file "vc-bzr-test" t))
-         (bzrdir (expand-file-name "bzr" homedir))
-         (file (progn
-                 (make-directory bzrdir)
-                 (expand-file-name "foo.el" bzrdir)))
-         (default-directory (file-name-as-directory bzrdir))
-         (process-environment (cons (format "HOME=%s" homedir)
-                                    process-environment)))
-    (unwind-protect
-        (progn
-          (call-process vc-bzr-program nil nil nil "init")
-          (with-temp-buffer
-            (insert ";;;###autoload
+  (ert-with-temp-directory homedir
+    (let* ((bzrdir (expand-file-name "bzr" homedir))
+           (file (progn
+                   (make-directory bzrdir)
+                   (expand-file-name "foo.el" bzrdir)))
+           (default-directory (file-name-as-directory bzrdir))
+           (process-environment (cons (format "HOME=%s" homedir)
+                                      process-environment)))
+      (call-process vc-bzr-program nil nil nil "init")
+      (with-temp-buffer
+        (insert ";;;###autoload
 \(defun foo () \"foo\" (interactive) (message \"foo!\"))")
-            (write-region nil nil file nil 'silent))
-          (call-process vc-bzr-program nil nil nil "add")
-          (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
-          ;; Deleting dirstate ensures both that vc-bzr's status heuristic
-          ;; fails, so it has to call the external bzr status, and
-          ;; causes bzr status to fail.  This simulates a broken bzr
-          ;; installation.
-          (delete-file ".bzr/checkout/dirstate")
-          (should (progn (make-directory-autoloads
-                          default-directory
-                          (expand-file-name "loaddefs.el" bzrdir))
-                         t)))
-      (delete-directory homedir t))))
+        (write-region nil nil file nil 'silent))
+      (call-process vc-bzr-program nil nil nil "add")
+      (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1")
+      ;; Deleting dirstate ensures both that vc-bzr's status heuristic
+      ;; fails, so it has to call the external bzr status, and
+      ;; causes bzr status to fail.  This simulates a broken bzr
+      ;; installation.
+      (delete-file ".bzr/checkout/dirstate")
+      (should (progn (make-directory-autoloads
+                      default-directory
+                      (expand-file-name "loaddefs.el" bzrdir))
+                     t)))))
 
 ;;; vc-bzr-tests.el ends here
diff --git a/test/lisp/wdired-tests.el b/test/lisp/wdired-tests.el
index 96a01fc2c7b..e768a165529 100644
--- a/test/lisp/wdired-tests.el
+++ b/test/lisp/wdired-tests.el
@@ -20,6 +20,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'dired)
 (require 'wdired)
 
@@ -28,104 +29,100 @@
 (ert-deftest wdired-test-bug32173-01 ()
   "Test using non-nil wdired-use-interactive-rename.
 Partially modifying a file name should succeed."
-  (let* ((test-dir (make-temp-file "test-dir-" t))
-	 (test-file (concat (file-name-as-directory test-dir) "foo.c"))
-	 (replace "bar")
-	 (new-file (string-replace "foo" replace test-file))
-	 (wdired-use-interactive-rename t))
-    (write-region "" nil test-file nil 'silent)
-    (advice-add 'dired-query ; Don't ask confirmation to overwrite a file.
-                :override
-                (lambda (_sym _prompt &rest _args) (setq dired-query t))
-                '((name . "advice-dired-query")))
-    (let ((buf (find-file-noselect test-dir)))
-      (unwind-protect
-	  (with-current-buffer buf
-	    (should (equal (dired-file-name-at-point) test-file))
-	    (dired-toggle-read-only)
-	    (kill-region (point) (progn (search-forward ".")
-					(forward-char -1) (point)))
-	    (insert replace)
-	    (wdired-finish-edit)
-	    (should (equal (dired-file-name-at-point) new-file)))
-	(if buf (kill-buffer buf))
-	(delete-directory test-dir t)))))
+  (ert-with-temp-directory test-dir
+    (let* ((test-file (concat (file-name-as-directory test-dir) "foo.c"))
+           (replace "bar")
+           (new-file (string-replace "foo" replace test-file))
+           (wdired-use-interactive-rename t))
+      (write-region "" nil test-file nil 'silent)
+      (advice-add 'dired-query ; Don't ask confirmation to overwrite a file.
+                  :override
+                  (lambda (_sym _prompt &rest _args) (setq dired-query t))
+                  '((name . "advice-dired-query")))
+      (let ((buf (find-file-noselect test-dir)))
+        (unwind-protect
+            (with-current-buffer buf
+              (should (equal (dired-file-name-at-point) test-file))
+              (dired-toggle-read-only)
+              (kill-region (point) (progn (search-forward ".")
+                                          (forward-char -1) (point)))
+              (insert replace)
+              (wdired-finish-edit)
+              (should (equal (dired-file-name-at-point) new-file)))
+          (if buf (kill-buffer buf)))))))
 
 (ert-deftest wdired-test-bug32173-02 ()
   "Test using non-nil wdired-use-interactive-rename.
 Aborting an edit should leaving original file name unchanged."
-  (let* ((test-dir (make-temp-file "test-dir-" t))
-	 (test-file (concat (file-name-as-directory test-dir) "foo.c"))
-	 (wdired-use-interactive-rename t))
-    (write-region "" nil test-file nil 'silent)
-    ;; Make dired-do-create-files-regexp a noop to mimic typing C-g
-    ;; at its prompt before wdired-finish-edit returns.
-    (advice-add 'dired-do-create-files-regexp
-                :override
-                (lambda (&rest _) (ignore))
-                '((name . "advice-dired-do-create-files-regexp")))
-    (let ((buf (find-file-noselect test-dir)))
-      (unwind-protect
-	  (with-current-buffer buf
-	    (should (equal (dired-file-name-at-point) test-file))
-	    (dired-toggle-read-only)
-	    (kill-region (point) (progn (search-forward ".")
-					(forward-char -1) (point)))
-	    (insert "bar")
-	    (wdired-finish-edit)
-	    (should (equal (dired-get-filename) test-file)))
-	(if buf (kill-buffer buf))
-	(delete-directory test-dir t)))))
+  (ert-with-temp-directory test-dir
+    (let* ((test-file (concat (file-name-as-directory test-dir) "foo.c"))
+           (wdired-use-interactive-rename t))
+      (write-region "" nil test-file nil 'silent)
+      ;; Make dired-do-create-files-regexp a noop to mimic typing C-g
+      ;; at its prompt before wdired-finish-edit returns.
+      (advice-add 'dired-do-create-files-regexp
+                  :override
+                  (lambda (&rest _) (ignore))
+                  '((name . "advice-dired-do-create-files-regexp")))
+      (let ((buf (find-file-noselect test-dir)))
+        (unwind-protect
+            (with-current-buffer buf
+              (should (equal (dired-file-name-at-point) test-file))
+              (dired-toggle-read-only)
+              (kill-region (point) (progn (search-forward ".")
+                                          (forward-char -1) (point)))
+              (insert "bar")
+              (wdired-finish-edit)
+              (should (equal (dired-get-filename) test-file)))
+          (if buf (kill-buffer buf)))))))
 
 (ert-deftest wdired-test-symlink-name ()
   "Test the file name of a symbolic link.
 The Dired and WDired functions returning the name should include
 only the name before the link arrow."
-  (let* ((test-dir (make-temp-file "test-dir-" t))
-         (link-name "foo"))
-    (let ((buf (find-file-noselect test-dir)))
-      (unwind-protect
-	  (with-current-buffer buf
-            (skip-unless
-             ;; This check is for wdired, not symbolic links, so skip
-             ;; it when make-symbolic-link fails for any reason (like
-             ;; insufficient privileges).
-             (ignore-errors (make-symbolic-link "./bar/baz" link-name) t))
-            (revert-buffer)
-            (let* ((file-name (dired-get-filename))
-                   (dir-part (file-name-directory file-name))
-                   (lf-name (concat dir-part link-name)))
-	      (should (equal file-name lf-name))
-	      (dired-toggle-read-only)
-	      (should (equal (wdired-get-filename) lf-name))
-	      (dired-toggle-read-only)))
-	(if buf (kill-buffer buf))
-	(delete-directory test-dir t)))))
+  (ert-with-temp-directory test-dir
+    (let* ((link-name "foo"))
+      (let ((buf (find-file-noselect test-dir)))
+        (unwind-protect
+            (with-current-buffer buf
+              (skip-unless
+               ;; This check is for wdired, not symbolic links, so skip
+               ;; it when make-symbolic-link fails for any reason (like
+               ;; insufficient privileges).
+               (ignore-errors (make-symbolic-link "./bar/baz" link-name) t))
+              (revert-buffer)
+              (let* ((file-name (dired-get-filename))
+                     (dir-part (file-name-directory file-name))
+                     (lf-name (concat dir-part link-name)))
+                (should (equal file-name lf-name))
+                (dired-toggle-read-only)
+                (should (equal (wdired-get-filename) lf-name))
+                (dired-toggle-read-only)))
+          (if buf (kill-buffer buf)))))))
 
 (ert-deftest wdired-test-unfinished-edit-01 ()
   "Test editing a file name without saving the change.
 Finding the new name should be possible while still in
 wdired-mode."
-  (let* ((test-dir (make-temp-file "test-dir-" t))
-	 (test-file (concat (file-name-as-directory test-dir) "foo.c"))
-	 (replace "bar")
-	 (new-file (string-replace "foo" replace test-file)))
-    (write-region "" nil test-file nil 'silent)
-    (let ((buf (find-file-noselect test-dir)))
-      (unwind-protect
-	  (with-current-buffer buf
-	    (should (equal (dired-file-name-at-point) test-file))
-	    (dired-toggle-read-only)
-	    (kill-region (point) (progn (search-forward ".")
-					(forward-char -1) (point)))
-	    (insert replace)
-	    (should (equal (dired-get-filename) new-file)))
-	(when buf
-	  (with-current-buffer buf
-            ;; Prevent kill-buffer-query-functions from chiming in.
-	    (set-buffer-modified-p nil)
-	    (kill-buffer buf)))
-	(delete-directory test-dir t)))))
+  (ert-with-temp-directory test-dir
+    (let* ((test-file (concat (file-name-as-directory test-dir) "foo.c"))
+           (replace "bar")
+           (new-file (string-replace "foo" replace test-file)))
+      (write-region "" nil test-file nil 'silent)
+      (let ((buf (find-file-noselect test-dir)))
+        (unwind-protect
+            (with-current-buffer buf
+              (should (equal (dired-file-name-at-point) test-file))
+              (dired-toggle-read-only)
+              (kill-region (point) (progn (search-forward ".")
+                                          (forward-char -1) (point)))
+              (insert replace)
+              (should (equal (dired-get-filename) new-file)))
+          (when buf
+            (with-current-buffer buf
+              ;; Prevent kill-buffer-query-functions from chiming in.
+              (set-buffer-modified-p nil)
+              (kill-buffer buf))))))))
 
 (defvar server-socket-dir)
 (declare-function dired-smart-shell-command "dired-x"
@@ -139,61 +136,59 @@ dired-move-to-end-of-filename handles indicator characters, it
 suffices to compare the return values of dired-get-filename and
 wdired-get-filename before and after editing."
   ;; FIXME: Add a test for a door (indicator ">") only under Solaris?
-  (let* ((test-dir (make-temp-file "test-dir-" t))
-         (server-socket-dir test-dir)
-         (dired-listing-switches "-Fl")
-         (dired-ls-F-marks-symlinks (eq system-type 'darwin))
-         (buf (find-file-noselect test-dir)))
-    (unwind-protect
-        (progn
-	  (with-current-buffer buf
-            (dired-create-empty-file "foo")
-            (set-file-modes "foo" (file-modes-symbolic-to-number "+x"))
-            (make-symbolic-link "foo" "bar")
-            (make-directory "foodir")
-            (require 'dired-x)
-            (dired-smart-shell-command "mkfifo foopipe")
-            (server-force-delete)
-            ;; FIXME?  This seems a heavy-handed way of making a socket.
-            (server-start)              ; Add a socket file.
-            (kill-buffer buf))
-          (dired test-dir)
-          (dired-toggle-read-only)
-          (let (names)
-            ;; Test that the file names are the same in Dired and WDired.
-            (while (not (eobp))
-              (should (equal (dired-get-filename 'no-dir t)
-                             (wdired-get-filename t)))
-              (insert "w")
-              (push (wdired-get-filename t) names)
-              (dired-next-line 1))
-            (wdired-finish-edit)
-            ;; Test that editing the file names ignores the indicator
-            ;; character.
-            (let (dir)
-              (while (and (dired-previous-line 1)
-                          (setq dir (dired-get-filename 'no-dir t)))
-                (should (equal dir (pop names)))))))
-      (kill-buffer (get-buffer test-dir))
-      (server-force-delete)
-      (delete-directory test-dir t))))
+  (ert-with-temp-directory test-dir
+    (let* ((server-socket-dir test-dir)
+           (dired-listing-switches "-Fl")
+           (dired-ls-F-marks-symlinks (eq system-type 'darwin))
+           (buf (find-file-noselect test-dir)))
+      (unwind-protect
+          (progn
+            (with-current-buffer buf
+              (dired-create-empty-file "foo")
+              (set-file-modes "foo" (file-modes-symbolic-to-number "+x"))
+              (make-symbolic-link "foo" "bar")
+              (make-directory "foodir")
+              (require 'dired-x)
+              (dired-smart-shell-command "mkfifo foopipe")
+              (server-force-delete)
+              ;; FIXME?  This seems a heavy-handed way of making a socket.
+              (server-start)             ; Add a socket file.
+              (kill-buffer buf))
+            (dired test-dir)
+            (dired-toggle-read-only)
+            (let (names)
+              ;; Test that the file names are the same in Dired and WDired.
+              (while (not (eobp))
+                (should (equal (dired-get-filename 'no-dir t)
+                               (wdired-get-filename t)))
+                (insert "w")
+                (push (wdired-get-filename t) names)
+                (dired-next-line 1))
+              (wdired-finish-edit)
+              ;; Test that editing the file names ignores the indicator
+              ;; character.
+              (let (dir)
+                (while (and (dired-previous-line 1)
+                            (setq dir (dired-get-filename 'no-dir t)))
+                  (should (equal dir (pop names)))))))
+        (kill-buffer (get-buffer test-dir))
+        (server-force-delete)))))
 
 (ert-deftest wdired-test-bug39280 ()
   "Test for https://debbugs.gnu.org/39280."
-  (let* ((test-dir (make-temp-file "test-dir" 'dir))
-         (fname "foo")
-         (full-fname (expand-file-name fname test-dir)))
-    (make-empty-file full-fname)
-    (let ((buf (find-file-noselect test-dir)))
-      (unwind-protect
-	  (with-current-buffer buf
-	    (dired-toggle-read-only)
-            (dolist (old '(t nil))
-              (should (equal fname (wdired-get-filename 'nodir old)))
-              (should (equal full-fname (wdired-get-filename nil old))))
-	    (wdired-finish-edit))
-	(if buf (kill-buffer buf))
-	(delete-directory test-dir t)))))
+  (ert-with-temp-directory test-dir
+    (let* ((fname "foo")
+           (full-fname (expand-file-name fname test-dir)))
+      (make-empty-file full-fname)
+      (let ((buf (find-file-noselect test-dir)))
+        (unwind-protect
+            (with-current-buffer buf
+              (dired-toggle-read-only)
+              (dolist (old '(t nil))
+                (should (equal fname (wdired-get-filename 'nodir old)))
+                (should (equal full-fname (wdired-get-filename nil old))))
+              (wdired-finish-edit))
+          (if buf (kill-buffer buf)))))))
 
 (provide 'wdired-tests)
 ;;; wdired-tests.el ends here
diff --git a/test/src/buffer-tests.el b/test/src/buffer-tests.el
index 059926ff46b..ac213d1bade 100644
--- a/test/src/buffer-tests.el
+++ b/test/src/buffer-tests.el
@@ -19,6 +19,8 @@
 
 ;;; Code:
 
+(require 'ert)
+(require 'ert-x)
 (require 'cl-lib)
 
 (ert-deftest overlay-modification-hooks-message-other-buf ()
@@ -1421,25 +1423,23 @@ with parameters from the *Messages* buffer modification."
     (should (= (length (overlays-in (point-min) (point-max))) 0))))
 
 (ert-deftest test-kill-buffer-auto-save-default ()
-  (let ((file (make-temp-file "ert"))
-        auto-save)
-    (should (file-exists-p file))
-    ;; Always answer yes.
-    (cl-letf (((symbol-function #'yes-or-no-p) (lambda (_) t)))
-      (unwind-protect
-          (progn
-            (find-file file)
-            (auto-save-mode t)
-            (insert "foo\n")
-            (should buffer-auto-save-file-name)
-            (setq auto-save buffer-auto-save-file-name)
-            (do-auto-save)
-            (should (file-exists-p auto-save))
-            (kill-buffer (current-buffer))
-            (should (file-exists-p auto-save)))
-        (ignore-errors (delete-file file))
-        (when auto-save
-          (ignore-errors (delete-file auto-save)))))))
+  (ert-with-temp-file file
+    (let (auto-save)
+      ;; Always answer yes.
+      (cl-letf (((symbol-function #'yes-or-no-p) (lambda (_) t)))
+        (unwind-protect
+            (progn
+              (find-file file)
+              (auto-save-mode t)
+              (insert "foo\n")
+              (should buffer-auto-save-file-name)
+              (setq auto-save buffer-auto-save-file-name)
+              (do-auto-save)
+              (should (file-exists-p auto-save))
+              (kill-buffer (current-buffer))
+              (should (file-exists-p auto-save)))
+          (when auto-save
+            (ignore-errors (delete-file auto-save))))))))
 
 (ert-deftest test-kill-buffer-auto-save-delete ()
   (let ((file (make-temp-file "ert"))
diff --git a/test/src/filelock-tests.el b/test/src/filelock-tests.el
index a96d6d67289..ba001679639 100644
--- a/test/src/filelock-tests.el
+++ b/test/src/filelock-tests.el
@@ -28,6 +28,7 @@
 
 (require 'cl-macs)
 (require 'ert)
+(require 'ert-x)
 (require 'seq)
 
 (defun filelock-tests--fixture (test-function)
@@ -36,22 +37,20 @@ Create a test directory and a buffer whose `buffer-file-name' and
 `buffer-file-truename' are a file within it, then call
 TEST-FUNCTION.  Finally, delete the buffer and the test
 directory."
-  (let* ((temp-dir (make-temp-file "filelock-tests" t))
-         (name (concat (file-name-as-directory temp-dir)
-                       "userfile"))
-         (create-lockfiles t))
-    (unwind-protect
-        (with-temp-buffer
-          (setq buffer-file-name name
-                buffer-file-truename name)
-          (unwind-protect
-              (save-current-buffer
-                (funcall test-function))
-            ;; Set `buffer-file-truename' nil to prevent unlocking,
-            ;; which might prompt the user and/or signal errors.
-            (setq buffer-file-name nil
-                  buffer-file-truename nil)))
-      (delete-directory temp-dir t nil))))
+  (ert-with-temp-directory temp-dir
+    (let ((name (concat (file-name-as-directory temp-dir)
+                        "userfile"))
+          (create-lockfiles t))
+      (with-temp-buffer
+        (setq buffer-file-name name
+              buffer-file-truename name)
+        (unwind-protect
+            (save-current-buffer
+              (funcall test-function))
+          ;; Set `buffer-file-truename' nil to prevent unlocking,
+          ;; which might prompt the user and/or signal errors.
+          (setq buffer-file-name nil
+                buffer-file-truename nil))))))
 
 (defun filelock-tests--make-lock-name (file-name)
   "Return the lock file name for FILE-NAME.
diff --git a/test/src/inotify-tests.el b/test/src/inotify-tests.el
index 8aab7eeb30a..c341af5c393 100644
--- a/test/src/inotify-tests.el
+++ b/test/src/inotify-tests.el
@@ -24,6 +24,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 
 (declare-function inotify-add-watch "inotify.c" (file-name aspect callback))
 (declare-function inotify-rm-watch "inotify.c" (watch-descriptor))
@@ -50,23 +51,21 @@
 
 (ert-deftest inotify-file-watch-simple ()
   "Test if watching a normal file works."
-
   (skip-unless (featurep 'inotify))
-  (let ((temp-file (make-temp-file "inotify-simple"))
-	(events 0))
-    (let ((wd
-	   (inotify-add-watch temp-file t (lambda (_ev)
-					    (setq events (1+ events))))))
-      (unwind-protect
-	  (progn
-	    (with-temp-file temp-file
-	      (insert "Foo\n"))
-	    (read-event nil nil 5)
-	    (should (> events 0)))
-	(should (inotify-valid-p wd))
-	(inotify-rm-watch wd)
-	(should-not (inotify-valid-p wd))
-	(delete-file temp-file)))))
+  (ert-with-temp-file temp-file
+    (let ((events 0))
+      (let ((wd
+             (inotify-add-watch temp-file t (lambda (_ev)
+                                       (setq events (1+ events))))))
+        (unwind-protect
+            (progn
+              (with-temp-file temp-file
+                (insert "Foo\n"))
+              (read-event nil nil 5)
+              (should (> events 0)))
+          (should (inotify-valid-p wd))
+          (inotify-rm-watch wd)
+          (should-not (inotify-valid-p wd)))))))
 
 (provide 'inotify-tests)
 
diff --git a/test/src/undo-tests.el b/test/src/undo-tests.el
index a658bccf6dc..88fcfad14cc 100644
--- a/test/src/undo-tests.el
+++ b/test/src/undo-tests.el
@@ -46,6 +46,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 (require 'facemenu)
 
 (ert-deftest undo-test0 ()
@@ -218,17 +219,14 @@
 
 (ert-deftest undo-test-file-modified ()
   "Test undoing marks buffer visiting file unmodified."
-  (let ((tempfile (make-temp-file "undo-test")))
-    (unwind-protect
-        (progn
-          (with-current-buffer (find-file-noselect tempfile)
-            (insert "1")
-            (undo-boundary)
-            (set-buffer-modified-p nil)
-            (insert "2")
-            (undo)
-            (should-not (buffer-modified-p))))
-      (delete-file tempfile))))
+  (ert-with-temp-file tempfile
+    (with-current-buffer (find-file-noselect tempfile)
+      (insert "1")
+      (undo-boundary)
+      (set-buffer-modified-p nil)
+      (insert "2")
+      (undo)
+      (should-not (buffer-modified-p)))))
 
 (ert-deftest undo-test-region-not-most-recent ()
   "Test undo in region of an edit not the most recent."
-- 
cgit v1.2.3