]> git.eshelyaron.com Git - emacs.git/commitdiff
Make uniquify-tests work with out-of-tree builds and clean up
authorMattias Engdegård <mattiase@acm.org>
Fri, 28 Jul 2023 09:12:09 +0000 (11:12 +0200)
committerMattias Engdegård <mattiase@acm.org>
Fri, 28 Jul 2023 09:31:58 +0000 (11:31 +0200)
* test/lisp/uniquify-tests.el (uniquify-project-transform):
Set an explicit default-directory.
* test/lisp/uniquify-tests.el (uniquify-dirs): Remove temporary
directory after test.

test/lisp/uniquify-tests.el

index e533c4b644c0f5189c8c9f492b19714dc487b720..224991cb048196b347a7184dbd1b07990d488ff1 100644 (file)
@@ -22,6 +22,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'ert-x)
 
 (ert-deftest uniquify-basic ()
   (let (bufs old-names)
 
 (ert-deftest uniquify-dirs ()
   "Check strip-common-suffix and trailing-separator-p work together; bug#47132"
-  (let* ((root (make-temp-file "emacs-uniquify-tests" 'dir))
-         (a-path (file-name-concat root "a/x/y/dir"))
-         (b-path (file-name-concat root "b/x/y/dir")))
-    (make-directory a-path 'parents)
-    (make-directory b-path 'parents)
-    (let ((uniquify-buffer-name-style 'forward)
-          (uniquify-strip-common-suffix t)
-          (uniquify-trailing-separator-p nil))
-      (let ((bufs (list (find-file-noselect a-path)
-                       (find-file-noselect b-path))))
-        (should (equal (mapcar #'buffer-name bufs)
-                       '("a/dir" "b/dir")))
-        (mapc #'kill-buffer bufs)))
-    (let ((uniquify-buffer-name-style 'forward)
-          (uniquify-strip-common-suffix nil)
-          (uniquify-trailing-separator-p t))
-      (let ((bufs (list (find-file-noselect a-path)
-                       (find-file-noselect b-path))))
-        (should (equal (mapcar #'buffer-name bufs)
-                       '("a/x/y/dir/" "b/x/y/dir/")))
-        (mapc #'kill-buffer bufs)))
-    (let ((uniquify-buffer-name-style 'forward)
-          (uniquify-strip-common-suffix t)
-          (uniquify-trailing-separator-p t))
-      (let ((bufs (list (find-file-noselect a-path)
-                       (find-file-noselect b-path))))
-        (should (equal (mapcar #'buffer-name bufs)
-                       '("a/dir/" "b/dir/")))
-        (mapc #'kill-buffer bufs)))))
+  (ert-with-temp-directory root
+    (let ((a-path (file-name-concat root "a/x/y/dir"))
+          (b-path (file-name-concat root "b/x/y/dir")))
+      (make-directory a-path 'parents)
+      (make-directory b-path 'parents)
+      (let ((uniquify-buffer-name-style 'forward)
+            (uniquify-strip-common-suffix t)
+            (uniquify-trailing-separator-p nil))
+        (let ((bufs (list (find-file-noselect a-path)
+                          (find-file-noselect b-path))))
+          (should (equal (mapcar #'buffer-name bufs)
+                         '("a/dir" "b/dir")))
+          (mapc #'kill-buffer bufs)))
+      (let ((uniquify-buffer-name-style 'forward)
+            (uniquify-strip-common-suffix nil)
+            (uniquify-trailing-separator-p t))
+        (let ((bufs (list (find-file-noselect a-path)
+                          (find-file-noselect b-path))))
+          (should (equal (mapcar #'buffer-name bufs)
+                         '("a/x/y/dir/" "b/x/y/dir/")))
+          (mapc #'kill-buffer bufs)))
+      (let ((uniquify-buffer-name-style 'forward)
+            (uniquify-strip-common-suffix t)
+            (uniquify-trailing-separator-p t))
+        (let ((bufs (list (find-file-noselect a-path)
+                          (find-file-noselect b-path))))
+          (should (equal (mapcar #'buffer-name bufs)
+                         '("a/dir/" "b/dir/")))
+          (mapc #'kill-buffer bufs))))))
 
 (ert-deftest uniquify-home ()
   "uniquify works, albeit confusingly, in the presence of directories named \"~\""
@@ -147,16 +148,18 @@ uniquify-trailing-separator-p is ignored"
         (project-vc-name "foo1/bar")
         bufs)
     (save-excursion
-      (should (file-exists-p "../README"))
-      (push (find-file-noselect "../README") bufs)
-      (push (find-file-noselect "other/README") bufs)
-      (should (equal (mapcar #'buffer-name bufs)
-                     '("README<other>" "README<bar>")))
-      (push (find-file-noselect "foo2/bar/README") bufs)
-      (should (equal (mapcar #'buffer-name bufs)
-                     '("README<foo2/bar>" "README<other>" "README<foo1/bar>")))
-      (while bufs
-        (kill-buffer (pop bufs))))))
+      (let ((default-directory (expand-file-name "test/" source-directory)))
+        (should (file-exists-p "../README"))
+        (push (find-file-noselect "../README") bufs)
+        (push (find-file-noselect "other/README") bufs)
+        (should (equal (mapcar #'buffer-name bufs)
+                       '("README<other>" "README<bar>")))
+        (push (find-file-noselect "foo2/bar/README") bufs)
+        (should (equal (mapcar #'buffer-name bufs)
+                       '("README<foo2/bar>" "README<other>"
+                         "README<foo1/bar>")))
+        (while bufs
+          (kill-buffer (pop bufs)))))))
 
 (provide 'uniquify-tests)
 ;;; uniquify-tests.el ends here