diff options
| author | Stefan Kangas | 2021-11-06 23:20:59 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2021-11-07 01:54:31 +0100 |
| commit | 385741fae276c7cfe2975e8a64cf084e0f63cf3d (patch) | |
| tree | 3ce34e66d95489b07c0b4681b0ebcaceb7cfa584 /test | |
| parent | 5dd27fef5885bf0f6ec3b12bad7972276834ccfa (diff) | |
| download | emacs-385741fae276c7cfe2975e8a64cf084e0f63cf3d.tar.gz emacs-385741fae276c7cfe2975e8a64cf084e0f63cf3d.zip | |
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.
Diffstat (limited to 'test')
41 files changed, 1321 insertions, 1405 deletions
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 @@ | |||
| 28 | ;;; Code: | 28 | ;;; Code: |
| 29 | 29 | ||
| 30 | (require 'ert) | 30 | (require 'ert) |
| 31 | (require 'ert-x) | ||
| 31 | (require 'abbrev) | 32 | (require 'abbrev) |
| 32 | (require 'seq) | 33 | (require 'seq) |
| 33 | 34 | ||
| @@ -236,44 +237,41 @@ | |||
| 236 | 237 | ||
| 237 | (ert-deftest read-write-abbrev-file-test () | 238 | (ert-deftest read-write-abbrev-file-test () |
| 238 | "Test reading and writing abbrevs from file." | 239 | "Test reading and writing abbrevs from file." |
| 239 | (let ((temp-test-file (make-temp-file "ert-abbrev-test")) | 240 | (ert-with-temp-file temp-test-file |
| 240 | (ert-test-abbrevs (setup-test-abbrev-table))) | 241 | (let ((ert-test-abbrevs (setup-test-abbrev-table))) |
| 241 | (write-abbrev-file temp-test-file) | 242 | (write-abbrev-file temp-test-file) |
| 242 | (clear-abbrev-table ert-test-abbrevs) | 243 | (clear-abbrev-table ert-test-abbrevs) |
| 243 | (should (abbrev-table-empty-p ert-test-abbrevs)) | 244 | (should (abbrev-table-empty-p ert-test-abbrevs)) |
| 244 | (read-abbrev-file temp-test-file) | 245 | (read-abbrev-file temp-test-file) |
| 245 | (should (equal "abbrev-ert-test" (abbrev-expansion "a-e-t" ert-test-abbrevs))) | 246 | (should (equal "abbrev-ert-test" (abbrev-expansion "a-e-t" ert-test-abbrevs)))))) |
| 246 | (delete-file temp-test-file))) | ||
| 247 | 247 | ||
| 248 | (ert-deftest read-write-abbrev-file-test-with-props () | 248 | (ert-deftest read-write-abbrev-file-test-with-props () |
| 249 | "Test reading and writing abbrevs from file." | 249 | "Test reading and writing abbrevs from file." |
| 250 | (let ((temp-test-file (make-temp-file "ert-abbrev-test")) | 250 | (ert-with-temp-file temp-test-file |
| 251 | (ert-test-abbrevs (setup-test-abbrev-table-with-props))) | 251 | (let ((ert-test-abbrevs (setup-test-abbrev-table-with-props))) |
| 252 | (write-abbrev-file temp-test-file) | 252 | (write-abbrev-file temp-test-file) |
| 253 | (clear-abbrev-table ert-test-abbrevs) | 253 | (clear-abbrev-table ert-test-abbrevs) |
| 254 | (should (abbrev-table-empty-p ert-test-abbrevs)) | 254 | (should (abbrev-table-empty-p ert-test-abbrevs)) |
| 255 | (read-abbrev-file temp-test-file) | 255 | (read-abbrev-file temp-test-file) |
| 256 | (should (equal "fooBar" (abbrev-expansion "fb" ert-test-abbrevs))) | 256 | (should (equal "fooBar" (abbrev-expansion "fb" ert-test-abbrevs)))))) |
| 257 | (delete-file temp-test-file))) | ||
| 258 | 257 | ||
| 259 | (ert-deftest abbrev-edit-save-to-file-test () | 258 | (ert-deftest abbrev-edit-save-to-file-test () |
| 260 | "Test saving abbrev definitions in buffer to file." | 259 | "Test saving abbrev definitions in buffer to file." |
| 261 | (defvar ert-save-test-table nil) | 260 | (defvar ert-save-test-table nil) |
| 262 | (let ((temp-test-file (make-temp-file "ert-abbrev-test")) | 261 | (ert-with-temp-file temp-test-file |
| 263 | (ert-test-abbrevs (setup-test-abbrev-table))) | 262 | (let ((ert-test-abbrevs (setup-test-abbrev-table))) |
| 264 | (with-temp-buffer | 263 | (with-temp-buffer |
| 265 | (goto-char (point-min)) | 264 | (goto-char (point-min)) |
| 266 | (insert "(ert-save-test-table)\n") | 265 | (insert "(ert-save-test-table)\n") |
| 267 | (insert "\n" "\"s-a-t\"\t" "0\t" "\"save-abbrevs-test\"\n") | 266 | (insert "\n" "\"s-a-t\"\t" "0\t" "\"save-abbrevs-test\"\n") |
| 268 | (should (equal "abbrev-ert-test" | 267 | (should (equal "abbrev-ert-test" |
| 269 | (abbrev-expansion "a-e-t" ert-test-abbrevs))) | 268 | (abbrev-expansion "a-e-t" ert-test-abbrevs))) |
| 270 | ;; clears abbrev tables | 269 | ;; clears abbrev tables |
| 271 | (abbrev-edit-save-to-file temp-test-file) | 270 | (abbrev-edit-save-to-file temp-test-file) |
| 272 | (should-not (abbrev-expansion "a-e-t" ert-test-abbrevs)) | 271 | (should-not (abbrev-expansion "a-e-t" ert-test-abbrevs)) |
| 273 | (read-abbrev-file temp-test-file) | 272 | (read-abbrev-file temp-test-file) |
| 274 | (should (equal "save-abbrevs-test" | 273 | (should (equal "save-abbrevs-test" |
| 275 | (abbrev-expansion "s-a-t" ert-save-test-table))) | 274 | (abbrev-expansion "s-a-t" ert-save-test-table))))))) |
| 276 | (delete-file temp-test-file)))) | ||
| 277 | 275 | ||
| 278 | (ert-deftest inverse-add-abbrev-skips-trailing-nonword () | 276 | (ert-deftest inverse-add-abbrev-skips-trailing-nonword () |
| 279 | "Test that adding an inverse abbrev skips trailing nonword characters." | 277 | "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 @@ | |||
| 27 | ;;; Code: | 27 | ;;; Code: |
| 28 | 28 | ||
| 29 | (require 'ert) | 29 | (require 'ert) |
| 30 | (eval-when-compile (require 'ert-x)) | ||
| 30 | (require 'cl-lib) | 31 | (require 'cl-lib) |
| 31 | (require 'auth-source) | 32 | (require 'auth-source) |
| 32 | (require 'secrets) | 33 | (require 'secrets) |
| @@ -360,77 +361,73 @@ | |||
| 360 | (format "%s@%s" (plist-get auth-info :user) (plist-get auth-info :host)))))) | 361 | (format "%s@%s" (plist-get auth-info :user) (plist-get auth-info :host)))))) |
| 361 | 362 | ||
| 362 | (ert-deftest auth-source-test-netrc-create-secret () | 363 | (ert-deftest auth-source-test-netrc-create-secret () |
| 363 | (let* ((netrc-file (make-temp-file "auth-source-test")) | 364 | (ert-with-temp-file netrc-file |
| 364 | (auth-sources (list netrc-file)) | 365 | :suffix "auth-source-test" |
| 365 | (auth-source-save-behavior t) | 366 | (let* ((auth-sources (list netrc-file)) |
| 366 | host auth-info auth-passwd) | 367 | (auth-source-save-behavior t) |
| 367 | (unwind-protect | 368 | host auth-info auth-passwd) |
| 368 | (dolist (passwd '("foo" "" nil)) | 369 | (dolist (passwd '("foo" "" nil)) |
| 369 | ;; Redefine `read-*' in order to avoid interactive input. | 370 | ;; Redefine `read-*' in order to avoid interactive input. |
| 370 | (cl-letf (((symbol-function 'read-passwd) (lambda (_) passwd)) | 371 | (cl-letf (((symbol-function 'read-passwd) (lambda (_) passwd)) |
| 371 | ((symbol-function 'read-string) | 372 | ((symbol-function 'read-string) |
| 372 | (lambda (_prompt &optional _initial _history default | 373 | (lambda (_prompt &optional _initial _history default |
| 373 | _inherit-input-method) | 374 | _inherit-input-method) |
| 374 | default))) | 375 | default))) |
| 375 | (setq host | 376 | (setq host |
| 376 | (md5 (concat (prin1-to-string process-environment) passwd)) | 377 | (md5 (concat (prin1-to-string process-environment) passwd)) |
| 377 | auth-info | 378 | auth-info |
| 378 | (car (auth-source-search | 379 | (car (auth-source-search |
| 379 | :max 1 :host host :require '(:user :secret) :create t)) | 380 | :max 1 :host host :require '(:user :secret) :create t)) |
| 380 | auth-passwd (plist-get auth-info :secret) | 381 | auth-passwd (plist-get auth-info :secret) |
| 381 | auth-passwd (if (functionp auth-passwd) | 382 | auth-passwd (if (functionp auth-passwd) |
| 382 | (funcall auth-passwd) | 383 | (funcall auth-passwd) |
| 383 | auth-passwd)) | 384 | auth-passwd)) |
| 384 | (should (string-equal (plist-get auth-info :user) (user-login-name))) | 385 | (should (string-equal (plist-get auth-info :user) (user-login-name))) |
| 385 | (should (string-equal (plist-get auth-info :host) host)) | 386 | (should (string-equal (plist-get auth-info :host) host)) |
| 386 | (should (equal auth-passwd passwd)) | 387 | (should (equal auth-passwd passwd)) |
| 387 | (when (functionp (plist-get auth-info :save-function)) | 388 | (when (functionp (plist-get auth-info :save-function)) |
| 388 | (funcall (plist-get auth-info :save-function))) | 389 | (funcall (plist-get auth-info :save-function))) |
| 389 | 390 | ||
| 390 | ;; Check, that the item has been created indeed. | 391 | ;; Check, that the item has been created indeed. |
| 391 | (auth-source-forget+ :host t) | 392 | (auth-source-forget+ :host t) |
| 392 | (setq auth-source-netrc-cache nil) | 393 | (setq auth-source-netrc-cache nil) |
| 393 | (setq auth-info (car (auth-source-search :host host)) | 394 | (setq auth-info (car (auth-source-search :host host)) |
| 394 | auth-passwd (plist-get auth-info :secret) | 395 | auth-passwd (plist-get auth-info :secret) |
| 395 | auth-passwd (if (functionp auth-passwd) | 396 | auth-passwd (if (functionp auth-passwd) |
| 396 | (funcall auth-passwd) | 397 | (funcall auth-passwd) |
| 397 | auth-passwd)) | 398 | auth-passwd)) |
| 398 | (with-temp-buffer | 399 | (with-temp-buffer |
| 399 | (insert-file-contents netrc-file) | 400 | (insert-file-contents netrc-file) |
| 400 | (if (zerop (length passwd)) | 401 | (if (zerop (length passwd)) |
| 401 | (progn | 402 | (progn |
| 402 | (should-not (plist-get auth-info :user)) | 403 | (should-not (plist-get auth-info :user)) |
| 403 | (should-not (plist-get auth-info :host)) | 404 | (should-not (plist-get auth-info :host)) |
| 404 | (should-not auth-passwd) | 405 | (should-not auth-passwd) |
| 405 | (should-not (search-forward host nil 'noerror))) | 406 | (should-not (search-forward host nil 'noerror))) |
| 406 | (should | 407 | (should |
| 407 | (string-equal (plist-get auth-info :user) (user-login-name))) | 408 | (string-equal (plist-get auth-info :user) (user-login-name))) |
| 408 | (should (string-equal (plist-get auth-info :host) host)) | 409 | (should (string-equal (plist-get auth-info :host) host)) |
| 409 | (should (string-equal auth-passwd passwd)) | 410 | (should (string-equal auth-passwd passwd)) |
| 410 | (should (search-forward host nil 'noerror)))))) | 411 | (should (search-forward host nil 'noerror))))))))) |
| 411 | |||
| 412 | ;; Cleanup. | ||
| 413 | (delete-file netrc-file)))) | ||
| 414 | 412 | ||
| 415 | (ert-deftest auth-source-delete () | 413 | (ert-deftest auth-source-delete () |
| 416 | (let* ((netrc-file (make-temp-file "auth-source-test" nil nil "\ | 414 | (ert-with-temp-file netrc-file |
| 415 | :suffix "auth-source-test" :text "\ | ||
| 417 | machine a1 port a2 user a3 password a4 | 416 | machine a1 port a2 user a3 password a4 |
| 418 | machine b1 port b2 user b3 password b4 | 417 | machine b1 port b2 user b3 password b4 |
| 419 | machine c1 port c2 user c3 password c4\n")) | 418 | machine c1 port c2 user c3 password c4\n" |
| 420 | (auth-sources (list netrc-file)) | 419 | (let* ((auth-sources (list netrc-file)) |
| 421 | (auth-source-do-cache nil) | 420 | (auth-source-do-cache nil) |
| 422 | (expected '((:host "a1" :port "a2" :user "a3" :secret "a4"))) | 421 | (expected '((:host "a1" :port "a2" :user "a3" :secret "a4"))) |
| 423 | (parameters '(:max 1 :host t))) | 422 | (parameters '(:max 1 :host t)) |
| 424 | (unwind-protect | 423 | (found (apply #'auth-source-delete parameters))) |
| 425 | (let ((found (apply #'auth-source-delete parameters))) | 424 | (dolist (f found) |
| 426 | (dolist (f found) | 425 | (let ((s (plist-get f :secret))) |
| 427 | (let ((s (plist-get f :secret))) | 426 | (setf f (plist-put f :secret |
| 428 | (setf f (plist-put f :secret | 427 | (if (functionp s) (funcall s) s))))) |
| 429 | (if (functionp s) (funcall s) s))))) | 428 | ;; Note: The netrc backend doesn't delete anything, so |
| 430 | ;; Note: The netrc backend doesn't delete anything, so | 429 | ;; this is actually the same as `auth-source-search'. |
| 431 | ;; this is actually the same as `auth-source-search'. | 430 | (should (equal found expected))))) |
| 432 | (should (equal found expected))) | ||
| 433 | (delete-file netrc-file)))) | ||
| 434 | 431 | ||
| 435 | (provide 'auth-source-tests) | 432 | (provide 'auth-source-tests) |
| 436 | ;;; auth-source-tests.el ends here | 433 | ;;; 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 @@ | |||
| 28 | 28 | ||
| 29 | (require 'autoinsert) | 29 | (require 'autoinsert) |
| 30 | (require 'ert) | 30 | (require 'ert) |
| 31 | (require 'ert-x) | ||
| 31 | 32 | ||
| 32 | (ert-deftest autoinsert-tests-auto-insert-skeleton () | 33 | (ert-deftest autoinsert-tests-auto-insert-skeleton () |
| 33 | (let ((auto-insert-alist '((text-mode nil "f" _ "oo"))) | 34 | (let ((auto-insert-alist '((text-mode nil "f" _ "oo"))) |
| @@ -39,16 +40,14 @@ | |||
| 39 | (should (equal (point) (+ (point-min) 1)))))) | 40 | (should (equal (point) (+ (point-min) 1)))))) |
| 40 | 41 | ||
| 41 | (ert-deftest autoinsert-tests-auto-insert-file () | 42 | (ert-deftest autoinsert-tests-auto-insert-file () |
| 42 | (let ((temp-file (make-temp-file "autoinsert-tests" nil nil "foo"))) | 43 | (ert-with-temp-file temp-file |
| 43 | (unwind-protect | 44 | :text "foo" |
| 44 | (let ((auto-insert-alist `((text-mode . ,temp-file))) | 45 | (let ((auto-insert-alist `((text-mode . ,temp-file))) |
| 45 | (auto-insert-query nil)) | 46 | (auto-insert-query nil)) |
| 46 | (with-temp-buffer | 47 | (with-temp-buffer |
| 47 | (text-mode) | 48 | (text-mode) |
| 48 | (auto-insert) | 49 | (auto-insert) |
| 49 | (should (equal (buffer-string) "foo")))) | 50 | (should (equal (buffer-string) "foo")))))) |
| 50 | (when (file-exists-p temp-file) | ||
| 51 | (delete-file temp-file))))) | ||
| 52 | 51 | ||
| 53 | (ert-deftest autoinsert-tests-auto-insert-function () | 52 | (ert-deftest autoinsert-tests-auto-insert-function () |
| 54 | (let ((auto-insert-alist '((text-mode . (lambda () (insert "foo"))))) | 53 | (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 | |||
| 371 | `bookmark-default-file', evaluates BODY, and then runs the test | 371 | `bookmark-default-file', evaluates BODY, and then runs the test |
| 372 | that saves and then loads the bookmark file." | 372 | that saves and then loads the bookmark file." |
| 373 | `(with-bookmark-test | 373 | `(with-bookmark-test |
| 374 | (let ((file (make-temp-file "bookmark-tests-"))) | 374 | (ert-with-temp-file file |
| 375 | (unwind-protect | 375 | (let ((bookmark-default-file file) |
| 376 | (let ((bookmark-default-file file) | 376 | (old-alist bookmark-alist)) |
| 377 | (old-alist bookmark-alist)) | 377 | ,@body |
| 378 | ,@body | 378 | (bookmark-save nil file t) |
| 379 | (bookmark-save nil file t) | 379 | (setq bookmark-alist nil) |
| 380 | (setq bookmark-alist nil) | 380 | (bookmark-load file nil t) |
| 381 | (bookmark-load file nil t) | 381 | (should (equal bookmark-alist old-alist)))))) |
| 382 | (should (equal bookmark-alist old-alist))) | ||
| 383 | (delete-file file))))) | ||
| 384 | 382 | ||
| 385 | (defvar bookmark-tests-non-ascii-data | 383 | (defvar bookmark-tests-non-ascii-data |
| 386 | (concat "Здра́вствуйте!" "中文,普通话,汉语" "åäöøñ" | 384 | (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 @@ | |||
| 24 | ;;; Code: | 24 | ;;; Code: |
| 25 | 25 | ||
| 26 | (require 'ert) | 26 | (require 'ert) |
| 27 | (eval-when-compile (require 'ert-x)) | ||
| 27 | 28 | ||
| 28 | (ert-deftest buff-menu-24962 () | 29 | (ert-deftest buff-menu-24962 () |
| 29 | "Test for https://debbugs.gnu.org/24962 ." | 30 | "Test for https://debbugs.gnu.org/24962 ." |
| 30 | (let* ((file (make-temp-file "foo")) | 31 | (ert-with-temp-file file |
| 31 | (buf (find-file file))) | 32 | :suffix "foo" |
| 32 | (unwind-protect | 33 | (let ((buf (find-file file))) |
| 33 | (progn | 34 | (unwind-protect |
| 34 | (rename-buffer " foo") | 35 | (progn |
| 35 | (list-buffers) | 36 | (rename-buffer " foo") |
| 36 | (with-current-buffer "*Buffer List*" | 37 | (list-buffers) |
| 37 | (should (string= " foo" (buffer-name (Buffer-menu-buffer)))))) | 38 | (with-current-buffer "*Buffer List*" |
| 38 | (and (buffer-live-p buf) (kill-buffer buf)) | 39 | (should (string= " foo" (buffer-name (Buffer-menu-buffer)))))) |
| 39 | (and (file-exists-p file) (delete-file file))))) | 40 | (and (buffer-live-p buf) (kill-buffer buf)))))) |
| 40 | 41 | ||
| 41 | (provide 'buff-menu-tests) | 42 | (provide 'buff-menu-tests) |
| 42 | 43 | ||
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." | |||
| 698 | "Actually perform export test. | 698 | "Actually perform export test. |
| 699 | Argument INPUT input diary string. | 699 | Argument INPUT input diary string. |
| 700 | Argument EXPECTED-OUTPUT expected iCalendar result string." | 700 | Argument EXPECTED-OUTPUT expected iCalendar result string." |
| 701 | (let ((temp-file (make-temp-file "icalendar-tests-ics"))) | 701 | (ert-with-temp-file temp-file |
| 702 | :suffix "icalendar-tests-ics" | ||
| 702 | (unwind-protect | 703 | (unwind-protect |
| 703 | (progn | 704 | (progn |
| 704 | (with-temp-buffer | 705 | (with-temp-buffer |
| 705 | (insert input) | 706 | (insert input) |
| 706 | (icalendar-export-region (point-min) (point-max) temp-file)) | 707 | (icalendar-export-region (point-min) (point-max) temp-file)) |
| 707 | (save-excursion | 708 | (save-excursion |
| 708 | (find-file temp-file) | 709 | (find-file temp-file) |
| 709 | (goto-char (point-min)) | 710 | (goto-char (point-min)) |
| 710 | (cond (expected-output | 711 | (cond (expected-output |
| 711 | (should (re-search-forward "^\\s-*BEGIN:VCALENDAR | 712 | (should (re-search-forward "^\\s-*BEGIN:VCALENDAR |
| 712 | PRODID:-//Emacs//NONSGML icalendar.el//EN | 713 | PRODID:-//Emacs//NONSGML icalendar.el//EN |
| 713 | VERSION:2.0 | 714 | VERSION:2.0 |
| 714 | BEGIN:VEVENT | 715 | BEGIN:VEVENT |
| @@ -717,23 +718,22 @@ UID:emacs[0-9]+ | |||
| 717 | END:VEVENT | 718 | END:VEVENT |
| 718 | END:VCALENDAR | 719 | END:VCALENDAR |
| 719 | \\s-*$" | 720 | \\s-*$" |
| 720 | nil t)) | 721 | nil t)) |
| 721 | (should (string-match | 722 | (should (string-match |
| 722 | (concat "^\\s-*" | 723 | (concat "^\\s-*" |
| 723 | (regexp-quote (buffer-substring-no-properties | 724 | (regexp-quote (buffer-substring-no-properties |
| 724 | (match-beginning 1) (match-end 1))) | 725 | (match-beginning 1) (match-end 1))) |
| 725 | "\\s-*$") | 726 | "\\s-*$") |
| 726 | expected-output))) | 727 | expected-output))) |
| 727 | (t | 728 | (t |
| 728 | (should (re-search-forward "^\\s-*BEGIN:VCALENDAR | 729 | (should (re-search-forward "^\\s-*BEGIN:VCALENDAR |
| 729 | PRODID:-//Emacs//NONSGML icalendar.el//EN | 730 | PRODID:-//Emacs//NONSGML icalendar.el//EN |
| 730 | VERSION:2.0 | 731 | VERSION:2.0 |
| 731 | END:VCALENDAR | 732 | END:VCALENDAR |
| 732 | \\s-*$" | 733 | \\s-*$" |
| 733 | nil t)))))) | 734 | nil t)))))) |
| 734 | ;; cleanup!! | 735 | ;; cleanup!! |
| 735 | (kill-buffer (find-buffer-visiting temp-file)) | 736 | (kill-buffer (find-buffer-visiting temp-file))))) |
| 736 | (delete-file temp-file)))) | ||
| 737 | 737 | ||
| 738 | (ert-deftest icalendar-export-ordinary-no-time () | 738 | (ert-deftest icalendar-export-ordinary-no-time () |
| 739 | "Perform export test." | 739 | "Perform export test." |
| @@ -1031,7 +1031,8 @@ During import test the timezone is set to Central European Time." | |||
| 1031 | (defun icalendar-tests--do-test-import (expected-output) | 1031 | (defun icalendar-tests--do-test-import (expected-output) |
| 1032 | "Actually perform import test. | 1032 | "Actually perform import test. |
| 1033 | Argument EXPECTED-OUTPUT file containing expected diary string." | 1033 | Argument EXPECTED-OUTPUT file containing expected diary string." |
| 1034 | (let ((temp-file (make-temp-file "icalendar-test-diary"))) | 1034 | (ert-with-temp-file temp-file |
| 1035 | :suffix "icalendar-test-diary" | ||
| 1035 | ;; Test the Catch-the-mysterious-coding-header logic below. | 1036 | ;; Test the Catch-the-mysterious-coding-header logic below. |
| 1036 | ;; Ruby-mode adds an after-save-hook which inserts the header! | 1037 | ;; Ruby-mode adds an after-save-hook which inserts the header! |
| 1037 | ;; (save-excursion | 1038 | ;; (save-excursion |
| @@ -1061,8 +1062,7 @@ Argument EXPECTED-OUTPUT file containing expected diary string." | |||
| 1061 | 1062 | ||
| 1062 | (let ((result (buffer-substring-no-properties (point-min) (point-max)))) | 1063 | (let ((result (buffer-substring-no-properties (point-min) (point-max)))) |
| 1063 | (should (string= expected-output result))) | 1064 | (should (string= expected-output result))) |
| 1064 | (kill-buffer (find-buffer-visiting temp-file)) | 1065 | (kill-buffer (find-buffer-visiting temp-file))))) |
| 1065 | (delete-file temp-file)))) | ||
| 1066 | 1066 | ||
| 1067 | (ert-deftest icalendar-import-non-recurring () | 1067 | (ert-deftest icalendar-import-non-recurring () |
| 1068 | "Perform standard import tests." | 1068 | "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 @@ | |||
| 37 | (defmacro with-todo-test (&rest body) | 37 | (defmacro with-todo-test (&rest body) |
| 38 | "Set up an isolated `todo-mode' test environment." | 38 | "Set up an isolated `todo-mode' test environment." |
| 39 | (declare (debug (body))) | 39 | (declare (debug (body))) |
| 40 | `(let* ((todo-test-home (make-temp-file "todo-test-home-" t)) | 40 | `(ert-with-temp-directory todo-test-home |
| 41 | ;; Since we change HOME, clear this to avoid a conflict | 41 | (let* (;; Since we change HOME, clear this to avoid a conflict |
| 42 | ;; e.g. if Emacs runs within the user's home directory. | 42 | ;; e.g. if Emacs runs within the user's home directory. |
| 43 | (abbreviated-home-dir nil) | 43 | (abbreviated-home-dir nil) |
| 44 | (process-environment (cons (format "HOME=%s" todo-test-home) | 44 | (process-environment (cons (format "HOME=%s" todo-test-home) |
| 45 | process-environment)) | 45 | process-environment)) |
| 46 | (todo-directory (ert-resource-directory)) | 46 | (todo-directory (ert-resource-directory)) |
| 47 | (todo-default-todo-file (todo-short-file-name | 47 | (todo-default-todo-file (todo-short-file-name |
| 48 | (car (funcall todo-files-function))))) | 48 | (car (funcall todo-files-function))))) |
| 49 | (unwind-protect | 49 | (unwind-protect |
| 50 | (progn ,@body) | 50 | (progn ,@body) |
| 51 | ;; Restore pre-test-run state of test files. | 51 | ;; Restore pre-test-run state of test files. |
| 52 | (dolist (f (directory-files todo-directory)) | 52 | (dolist (f (directory-files todo-directory)) |
| 53 | (let ((buf (get-file-buffer f))) | 53 | (let ((buf (get-file-buffer f))) |
| 54 | (when buf | 54 | (when buf |
| 55 | (with-current-buffer buf | 55 | (with-current-buffer buf |
| 56 | (restore-buffer-modified-p nil) | 56 | (restore-buffer-modified-p nil) |
| 57 | (kill-buffer))))) | 57 | (kill-buffer))))))))) |
| 58 | (delete-directory todo-test-home t)))) | ||
| 59 | 58 | ||
| 60 | (defun todo-test--show (num &optional archive) | 59 | (defun todo-test--show (num &optional archive) |
| 61 | "Display category NUM of test todo file. | 60 | "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 @@ | |||
| 19 | 19 | ||
| 20 | ;;; Code: | 20 | ;;; Code: |
| 21 | (require 'ert) | 21 | (require 'ert) |
| 22 | (require 'ert-x) | ||
| 22 | (require 'dired-aux) | 23 | (require 'dired-aux) |
| 23 | (eval-when-compile (require 'cl-lib)) | 24 | (eval-when-compile (require 'cl-lib)) |
| 24 | 25 | ||
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 @@ | |||
| 19 | 19 | ||
| 20 | ;;; Code: | 20 | ;;; Code: |
| 21 | (require 'ert) | 21 | (require 'ert) |
| 22 | (require 'ert-x) | ||
| 22 | (require 'dired) | 23 | (require 'dired) |
| 23 | 24 | ||
| 24 | (ert-deftest dired-autoload () | 25 | (ert-deftest dired-autoload () |
| @@ -141,116 +142,113 @@ | |||
| 141 | 142 | ||
| 142 | (ert-deftest dired-test-bug27243-01 () | 143 | (ert-deftest dired-test-bug27243-01 () |
| 143 | "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#5 ." | 144 | "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#5 ." |
| 144 | (let* ((test-dir (file-name-as-directory (make-temp-file "test-dir-" t))) | 145 | (ert-with-temp-directory test-dir |
| 145 | (save-pos (lambda () | 146 | (let* ((save-pos (lambda () |
| 146 | (with-current-buffer (car (dired-buffers-for-dir test-dir)) | 147 | (with-current-buffer (car (dired-buffers-for-dir test-dir)) |
| 147 | (dired-save-positions)))) | 148 | (dired-save-positions)))) |
| 148 | (dired-auto-revert-buffer t) buffers) | 149 | (dired-auto-revert-buffer t) buffers) |
| 149 | ;; On MS-Windows, get rid of 8+3 short names in test-dir, if the | 150 | ;; On MS-Windows, get rid of 8+3 short names in test-dir, if the |
| 150 | ;; corresponding long file names exist, otherwise such names trip | 151 | ;; corresponding long file names exist, otherwise such names trip |
| 151 | ;; dired-buffers-for-dir. | 152 | ;; dired-buffers-for-dir. |
| 152 | (if (eq system-type 'windows-nt) | 153 | (if (eq system-type 'windows-nt) |
| 153 | (setq test-dir (file-truename test-dir))) | 154 | (setq test-dir (file-truename test-dir))) |
| 154 | (should-not (dired-buffers-for-dir test-dir)) | 155 | (should-not (dired-buffers-for-dir test-dir)) |
| 155 | (with-current-buffer (find-file-noselect test-dir) | 156 | (with-current-buffer (find-file-noselect test-dir) |
| 156 | (make-directory "test-subdir")) | 157 | (make-directory "test-subdir")) |
| 157 | (message "Saved pos: %S" (funcall save-pos)) | 158 | (message "Saved pos: %S" (funcall save-pos)) |
| 158 | ;; Point must be at end-of-buffer. | 159 | ;; Point must be at end-of-buffer. |
| 159 | (with-current-buffer (car (dired-buffers-for-dir test-dir)) | 160 | (with-current-buffer (car (dired-buffers-for-dir test-dir)) |
| 160 | (should (eobp))) | 161 | (should (eobp))) |
| 161 | (push (dired test-dir) buffers) | 162 | (push (dired test-dir) buffers) |
| 162 | (message "Saved pos: %S" (funcall save-pos)) | 163 | (message "Saved pos: %S" (funcall save-pos)) |
| 163 | ;; Previous dired call shouldn't create a new buffer: must visit the one | 164 | ;; Previous dired call shouldn't create a new buffer: must visit the one |
| 164 | ;; created by `find-file-noselect' above. | 165 | ;; created by `find-file-noselect' above. |
| 165 | (should (eq 1 (length (dired-buffers-for-dir test-dir)))) | 166 | (should (eq 1 (length (dired-buffers-for-dir test-dir)))) |
| 166 | (unwind-protect | 167 | (unwind-protect |
| 167 | (let ((buf (current-buffer)) | 168 | (let ((buf (current-buffer)) |
| 168 | (pt1 (point)) | 169 | (pt1 (point)) |
| 169 | (test-file (concat (file-name-as-directory "test-subdir") | 170 | (test-file (concat (file-name-as-directory "test-subdir") |
| 170 | "test-file"))) | 171 | "test-file"))) |
| 171 | (message "Saved pos: %S" (funcall save-pos)) | 172 | (message "Saved pos: %S" (funcall save-pos)) |
| 172 | (write-region "Test" nil test-file nil 'silent nil 'excl) | 173 | (write-region "Test" nil test-file nil 'silent nil 'excl) |
| 173 | (message "Saved pos: %S" (funcall save-pos)) | 174 | (message "Saved pos: %S" (funcall save-pos)) |
| 174 | ;; Sanity check: point should now be on the subdirectory. | 175 | ;; Sanity check: point should now be on the subdirectory. |
| 175 | (should (equal (dired-file-name-at-point) | 176 | (should (equal (dired-file-name-at-point) |
| 176 | (concat test-dir (file-name-as-directory "test-subdir")))) | 177 | (concat test-dir (file-name-as-directory "test-subdir")))) |
| 177 | (message "Saved pos: %S" (funcall save-pos)) | 178 | (message "Saved pos: %S" (funcall save-pos)) |
| 178 | (push (dired-find-file) buffers) | ||
| 179 | (let ((pt2 (point))) ; Point is on test-file. | ||
| 180 | (pop-to-buffer-same-window buf) | ||
| 181 | ;; Sanity check: point should now be back on the subdirectory. | ||
| 182 | (should (eq (point) pt1)) | ||
| 183 | (push (dired-find-file) buffers) | 179 | (push (dired-find-file) buffers) |
| 184 | (should (eq (point) pt2)))) | 180 | (let ((pt2 (point))) ; Point is on test-file. |
| 185 | (dolist (buf buffers) | 181 | (pop-to-buffer-same-window buf) |
| 186 | (when (buffer-live-p buf) (kill-buffer buf))) | 182 | ;; Sanity check: point should now be back on the subdirectory. |
| 187 | (delete-directory test-dir t)))) | 183 | (should (eq (point) pt1)) |
| 184 | (push (dired-find-file) buffers) | ||
| 185 | (should (eq (point) pt2)))) | ||
| 186 | (dolist (buf buffers) | ||
| 187 | (when (buffer-live-p buf) (kill-buffer buf))))))) | ||
| 188 | 188 | ||
| 189 | (ert-deftest dired-test-bug27243-02 () | 189 | (ert-deftest dired-test-bug27243-02 () |
| 190 | "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#28 ." | 190 | "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#28 ." |
| 191 | (let ((test-dir (make-temp-file "test-dir-" t)) | 191 | (ert-with-temp-directory test-dir |
| 192 | (dired-auto-revert-buffer t) buffers) | 192 | (let ((dired-auto-revert-buffer t) buffers) |
| 193 | ;; On MS-Windows, get rid of 8+3 short names in test-dir, if the | 193 | ;; On MS-Windows, get rid of 8+3 short names in test-dir, if the |
| 194 | ;; corresponding long file names exist, otherwise such names trip | 194 | ;; corresponding long file names exist, otherwise such names trip |
| 195 | ;; string comparisons below. | 195 | ;; string comparisons below. |
| 196 | (if (eq system-type 'windows-nt) | 196 | (if (eq system-type 'windows-nt) |
| 197 | (setq test-dir (file-truename test-dir))) | 197 | (setq test-dir (file-truename test-dir))) |
| 198 | (with-current-buffer (find-file-noselect test-dir) | 198 | (with-current-buffer (find-file-noselect test-dir) |
| 199 | (make-directory "test-subdir")) | 199 | (make-directory "test-subdir")) |
| 200 | (push (dired test-dir) buffers) | 200 | (push (dired test-dir) buffers) |
| 201 | (unwind-protect | 201 | (unwind-protect |
| 202 | (let ((buf (current-buffer)) | 202 | (let ((buf (current-buffer)) |
| 203 | (pt1 (point)) | 203 | (pt1 (point)) |
| 204 | (test-file (concat (file-name-as-directory "test-subdir") | 204 | (test-file (concat (file-name-as-directory "test-subdir") |
| 205 | "test-file"))) | 205 | "test-file"))) |
| 206 | (write-region "Test" nil test-file nil 'silent nil 'excl) | 206 | (write-region "Test" nil test-file nil 'silent nil 'excl) |
| 207 | ;; Sanity check: point should now be on the subdirectory. | 207 | ;; Sanity check: point should now be on the subdirectory. |
| 208 | (should (equal (dired-file-name-at-point) | 208 | (should (equal (dired-file-name-at-point) |
| 209 | (concat (file-name-as-directory test-dir) | 209 | (concat (file-name-as-directory test-dir) |
| 210 | (file-name-as-directory "test-subdir")))) | 210 | (file-name-as-directory "test-subdir")))) |
| 211 | (push (dired-find-file) buffers) | 211 | (push (dired-find-file) buffers) |
| 212 | ;; Point is on test-file. | 212 | ;; Point is on test-file. |
| 213 | (switch-to-buffer buf) | 213 | (switch-to-buffer buf) |
| 214 | ;; Sanity check: point should now be back on the subdirectory. | 214 | ;; Sanity check: point should now be back on the subdirectory. |
| 215 | (should (eq (point) pt1)) | 215 | (should (eq (point) pt1)) |
| 216 | (push (dired test-dir) buffers) | 216 | (push (dired test-dir) buffers) |
| 217 | (should (eq (point) pt1))) | 217 | (should (eq (point) pt1))) |
| 218 | (dolist (buf buffers) | 218 | (dolist (buf buffers) |
| 219 | (when (buffer-live-p buf) (kill-buffer buf))) | 219 | (when (buffer-live-p buf) (kill-buffer buf))))))) |
| 220 | (delete-directory test-dir t)))) | ||
| 221 | 220 | ||
| 222 | (ert-deftest dired-test-bug27243-03 () | 221 | (ert-deftest dired-test-bug27243-03 () |
| 223 | "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#61 ." | 222 | "Test for https://debbugs.gnu.org/cgi/bugreport.cgi?bug=27243#61 ." |
| 224 | (let ((test-dir (make-temp-file "test-dir-" t)) | 223 | (ert-with-temp-directory test-dir |
| 225 | (dired-auto-revert-buffer t) | 224 | (let ((dired-auto-revert-buffer t) |
| 226 | allbufs) | 225 | allbufs) |
| 227 | (unwind-protect | 226 | (unwind-protect |
| 228 | (progn | 227 | (progn |
| 229 | (with-current-buffer (find-file-noselect test-dir) | 228 | (with-current-buffer (find-file-noselect test-dir) |
| 230 | (push (current-buffer) allbufs) | 229 | (push (current-buffer) allbufs) |
| 231 | (make-directory "test-subdir1") | 230 | (make-directory "test-subdir1") |
| 232 | (make-directory "test-subdir2") | 231 | (make-directory "test-subdir2") |
| 233 | (let ((test-file1 "test-file1") | 232 | (let ((test-file1 "test-file1") |
| 234 | (test-file2 "test-file2")) | 233 | (test-file2 "test-file2")) |
| 235 | (with-current-buffer (find-file-noselect "test-subdir1") | 234 | (with-current-buffer (find-file-noselect "test-subdir1") |
| 236 | (push (current-buffer) allbufs) | 235 | (push (current-buffer) allbufs) |
| 237 | (write-region "Test1" nil test-file1 nil 'silent nil 'excl)) | 236 | (write-region "Test1" nil test-file1 nil 'silent nil 'excl)) |
| 238 | (with-current-buffer (find-file-noselect "test-subdir2") | 237 | (with-current-buffer (find-file-noselect "test-subdir2") |
| 239 | (push (current-buffer) allbufs) | 238 | (push (current-buffer) allbufs) |
| 240 | (write-region "Test2" nil test-file2 nil 'silent nil 'excl)))) | 239 | (write-region "Test2" nil test-file2 nil 'silent nil 'excl)))) |
| 241 | ;; Call find-file with a wild card and test point in each file. | 240 | ;; Call find-file with a wild card and test point in each file. |
| 242 | (let ((buffers (find-file (concat (file-name-as-directory test-dir) | 241 | (let ((buffers (find-file (concat (file-name-as-directory test-dir) |
| 243 | "*") | 242 | "*") |
| 244 | t))) | 243 | t))) |
| 245 | (dolist (buf buffers) | 244 | (dolist (buf buffers) |
| 246 | (let ((pt (with-current-buffer buf (point)))) | 245 | (let ((pt (with-current-buffer buf (point)))) |
| 247 | (switch-to-buffer (find-file-noselect test-dir)) | 246 | (switch-to-buffer (find-file-noselect test-dir)) |
| 248 | (find-file (buffer-name buf)) | 247 | (find-file (buffer-name buf)) |
| 249 | (should (equal (point) pt)))) | 248 | (should (equal (point) pt)))) |
| 250 | (append buffers allbufs))) | 249 | (append buffers allbufs))) |
| 251 | (dolist (buf allbufs) | 250 | (dolist (buf allbufs) |
| 252 | (when (buffer-live-p buf) (kill-buffer buf))) | 251 | (when (buffer-live-p buf) (kill-buffer buf))))))) |
| 253 | (delete-directory test-dir t)))) | ||
| 254 | 252 | ||
| 255 | (ert-deftest dired-test-bug7131 () | 253 | (ert-deftest dired-test-bug7131 () |
| 256 | "Test for https://debbugs.gnu.org/7131 ." | 254 | "Test for https://debbugs.gnu.org/7131 ." |
| @@ -274,22 +272,21 @@ | |||
| 274 | ;; ls-lisp-tests.el and em-ls-tests.el. | 272 | ;; ls-lisp-tests.el and em-ls-tests.el. |
| 275 | (skip-unless (and (not (featurep 'ls-lisp)) | 273 | (skip-unless (and (not (featurep 'ls-lisp)) |
| 276 | (not (featurep 'eshell)))) | 274 | (not (featurep 'eshell)))) |
| 277 | (let* ((dir (make-temp-file "bug27631" 'dir)) | 275 | (ert-with-temp-directory dir |
| 278 | (dir1 (expand-file-name "dir1" dir)) | 276 | (let* ((dir1 (expand-file-name "dir1" dir)) |
| 279 | (dir2 (expand-file-name "dir2" dir)) | 277 | (dir2 (expand-file-name "dir2" dir)) |
| 280 | (default-directory dir) | 278 | (default-directory dir) |
| 281 | buf) | 279 | buf) |
| 282 | (unwind-protect | 280 | (unwind-protect |
| 283 | (progn | 281 | (progn |
| 284 | (make-directory dir1) | 282 | (make-directory dir1) |
| 285 | (make-directory dir2) | 283 | (make-directory dir2) |
| 286 | (with-temp-file (expand-file-name "a.txt" dir1)) | 284 | (with-temp-file (expand-file-name "a.txt" dir1)) |
| 287 | (with-temp-file (expand-file-name "b.txt" dir2)) | 285 | (with-temp-file (expand-file-name "b.txt" dir2)) |
| 288 | (setq buf (dired (expand-file-name "dir*/*.txt" dir))) | 286 | (setq buf (dired (expand-file-name "dir*/*.txt" dir))) |
| 289 | (dired-toggle-marks) | 287 | (dired-toggle-marks) |
| 290 | (should (cdr (dired-get-marked-files)))) | 288 | (should (cdr (dired-get-marked-files)))) |
| 291 | (delete-directory dir 'recursive) | 289 | (when (buffer-live-p buf) (kill-buffer buf)))))) |
| 292 | (when (buffer-live-p buf) (kill-buffer buf))))) | ||
| 293 | 290 | ||
| 294 | (ert-deftest dired-test-bug27899 () | 291 | (ert-deftest dired-test-bug27899 () |
| 295 | "Test for https://debbugs.gnu.org/27899 ." | 292 | "Test for https://debbugs.gnu.org/27899 ." |
| @@ -310,72 +307,69 @@ | |||
| 310 | 307 | ||
| 311 | (ert-deftest dired-test-bug27968 () | 308 | (ert-deftest dired-test-bug27968 () |
| 312 | "Test for https://debbugs.gnu.org/27968 ." | 309 | "Test for https://debbugs.gnu.org/27968 ." |
| 313 | (let* ((top-dir (make-temp-file "top-dir" t)) | 310 | (ert-with-temp-directory top-dir |
| 314 | (subdir (expand-file-name "subdir" top-dir)) | 311 | (let* ((subdir (expand-file-name "subdir" top-dir)) |
| 315 | (header-len-fn (lambda () | 312 | (header-len-fn (lambda () |
| 316 | (save-excursion | 313 | (save-excursion |
| 317 | (goto-char 1) | 314 | (goto-char 1) |
| 318 | (forward-line 1) | 315 | (forward-line 1) |
| 319 | (- (point-at-eol) (point))))) | 316 | (- (point-at-eol) (point))))) |
| 320 | orig-len len diff pos line-nb) | 317 | orig-len len diff pos line-nb) |
| 321 | (make-directory subdir 'parents) | 318 | (make-directory subdir 'parents) |
| 322 | (unwind-protect | 319 | (with-current-buffer (dired-noselect subdir) |
| 323 | (with-current-buffer (dired-noselect subdir) | 320 | (setq orig-len (funcall header-len-fn) |
| 324 | (setq orig-len (funcall header-len-fn) | 321 | pos (point) |
| 325 | pos (point) | 322 | line-nb (line-number-at-pos)) |
| 326 | line-nb (line-number-at-pos)) | 323 | ;; Bug arises when the header line changes its length; this may |
| 327 | ;; Bug arises when the header line changes its length; this may | 324 | ;; happen if the used space has changed: for instance, with the |
| 328 | ;; happen if the used space has changed: for instance, with the | 325 | ;; creation of additional files. |
| 329 | ;; creation of additional files. | 326 | (make-directory "subdir" t) |
| 330 | (make-directory "subdir" t) | 327 | (dired-revert) |
| 331 | (dired-revert) | 328 | ;; Change the header line. |
| 332 | ;; Change the header line. | 329 | (save-excursion |
| 333 | (save-excursion | 330 | (goto-char 1) |
| 334 | (goto-char 1) | 331 | (forward-line 1) |
| 335 | (forward-line 1) | 332 | (let ((inhibit-read-only t) |
| 336 | (let ((inhibit-read-only t) | 333 | (new-header " test-bug27968")) |
| 337 | (new-header " test-bug27968")) | 334 | (delete-region (point) (point-at-eol)) |
| 338 | (delete-region (point) (point-at-eol)) | 335 | (when (= orig-len (length new-header)) |
| 339 | (when (= orig-len (length new-header)) | 336 | ;; Wow lucky guy! I must buy lottery today. |
| 340 | ;; Wow lucky guy! I must buy lottery today. | 337 | (setq new-header (concat new-header " :-)"))) |
| 341 | (setq new-header (concat new-header " :-)"))) | 338 | (insert new-header))) |
| 342 | (insert new-header))) | 339 | (setq len (funcall header-len-fn) |
| 343 | (setq len (funcall header-len-fn) | 340 | diff (- len orig-len)) |
| 344 | diff (- len orig-len)) | 341 | (should-not (zerop diff)) ; Header length has changed. |
| 345 | (should-not (zerop diff)) ; Header length has changed. | 342 | ;; If diff > 0, then the point moves back. |
| 346 | ;; If diff > 0, then the point moves back. | 343 | ;; If diff < 0, then the point moves forward. |
| 347 | ;; If diff < 0, then the point moves forward. | 344 | ;; If diff = 0, then the point doesn't move. |
| 348 | ;; If diff = 0, then the point doesn't move. | 345 | ;; Sometimes this point movement causes |
| 349 | ;; Sometimes this point movement causes | 346 | ;; line-nb != (line-number-at-pos pos), so that we get |
| 350 | ;; line-nb != (line-number-at-pos pos), so that we get | 347 | ;; an unexpected file at point if we store buffer points. |
| 351 | ;; an unexpected file at point if we store buffer points. | 348 | ;; Note that the line number before/after revert |
| 352 | ;; Note that the line number before/after revert | 349 | ;; doesn't change. |
| 353 | ;; doesn't change. | 350 | (should (= line-nb |
| 354 | (should (= line-nb | 351 | (line-number-at-pos) |
| 355 | (line-number-at-pos) | 352 | (line-number-at-pos (+ pos diff)))) |
| 356 | (line-number-at-pos (+ pos diff)))) | 353 | ;; After revert, the point must be in 'subdir' line. |
| 357 | ;; After revert, the point must be in 'subdir' line. | 354 | (should (equal "subdir" (dired-get-filename 'local t))))))) |
| 358 | (should (equal "subdir" (dired-get-filename 'local t)))) | ||
| 359 | (delete-directory top-dir t)))) | ||
| 360 | 355 | ||
| 361 | 356 | ||
| 362 | (defmacro dired-test-with-temp-dirs (just-empty-dirs &rest body) | 357 | (defmacro dired-test-with-temp-dirs (just-empty-dirs &rest body) |
| 363 | "Helper macro for Bug#27940 test." | 358 | "Helper macro for Bug#27940 test." |
| 364 | (declare (indent 1) (debug body)) | 359 | (declare (indent 1) (debug body)) |
| 365 | (let ((dir (make-symbol "dir"))) | 360 | (let ((dir (make-symbol "dir"))) |
| 366 | `(let* ((,dir (make-temp-file "bug27940" t)) | 361 | `(ert-with-temp-directory ,dir |
| 367 | (dired-deletion-confirmer (lambda (_) "yes")) ; Suppress prompts. | 362 | (let* ((dired-deletion-confirmer (lambda (_) "yes")) ; Suppress prompts. |
| 368 | (inhibit-message t) | 363 | (inhibit-message t) |
| 369 | (default-directory ,dir)) | 364 | (default-directory ,dir)) |
| 370 | (dotimes (i 5) (make-directory (format "empty-dir-%d" i))) | 365 | (dotimes (i 5) (make-directory (format "empty-dir-%d" i))) |
| 371 | (unless ,just-empty-dirs | 366 | (unless ,just-empty-dirs |
| 372 | (dotimes (i 5) (make-directory (format "non-empty-%d/foo" i) 'parents))) | 367 | (dotimes (i 5) (make-directory (format "non-empty-%d/foo" i) 'parents))) |
| 373 | (make-directory "zeta-empty-dir") | 368 | (make-directory "zeta-empty-dir") |
| 374 | (unwind-protect | 369 | (unwind-protect |
| 375 | (progn | 370 | (progn |
| 376 | ,@body) | 371 | ,@body) |
| 377 | (delete-directory ,dir t) | 372 | (kill-buffer (current-buffer))))))) |
| 378 | (kill-buffer (current-buffer)))))) | ||
| 379 | 373 | ||
| 380 | (ert-deftest dired-test-bug27940 () | 374 | (ert-deftest dired-test-bug27940 () |
| 381 | "Test for https://debbugs.gnu.org/27940 ." | 375 | "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 @@ | |||
| 19 | 19 | ||
| 20 | ;;; Code: | 20 | ;;; Code: |
| 21 | (require 'ert) | 21 | (require 'ert) |
| 22 | (require 'ert-x) | ||
| 22 | (require 'dired-x) | 23 | (require 'dired-x) |
| 23 | 24 | ||
| 24 | 25 | ||
| @@ -31,23 +32,20 @@ | |||
| 31 | (append (copy-sequence dirs) | 32 | (append (copy-sequence dirs) |
| 32 | (delete "c" (copy-sequence files))) | 33 | (delete "c" (copy-sequence files))) |
| 33 | #'string<)) | 34 | #'string<)) |
| 34 | (dir (make-temp-file "Bug25942" 'dir)) | ||
| 35 | (extension "c")) | 35 | (extension "c")) |
| 36 | (unwind-protect | 36 | (ert-with-temp-directory dir |
| 37 | (progn | 37 | (dolist (d dirs) |
| 38 | (dolist (d dirs) | 38 | (make-directory (expand-file-name d dir))) |
| 39 | (make-directory (expand-file-name d dir))) | 39 | (dolist (f files) |
| 40 | (dolist (f files) | 40 | (write-region nil nil (expand-file-name f dir))) |
| 41 | (write-region nil nil (expand-file-name f dir))) | 41 | (dired dir) |
| 42 | (dired dir) | 42 | (dired-mark-extension extension) |
| 43 | (dired-mark-extension extension) | 43 | (should (equal '("bar.c" "foo.c") |
| 44 | (should (equal '("bar.c" "foo.c") | 44 | (sort (dired-get-marked-files 'local) #'string<))) |
| 45 | (sort (dired-get-marked-files 'local) #'string<))) | 45 | (dired-unmark-all-marks) |
| 46 | (dired-unmark-all-marks) | 46 | (dired-mark-suffix extension) |
| 47 | (dired-mark-suffix extension) | 47 | (should (equal all-but-c |
| 48 | (should (equal all-but-c | 48 | (sort (dired-get-marked-files 'local) #'string<)))))) |
| 49 | (sort (dired-get-marked-files 'local) #'string<)))) | ||
| 50 | (delete-directory dir 'recursive)))) | ||
| 51 | 49 | ||
| 52 | (ert-deftest dired-guess-default () | 50 | (ert-deftest dired-guess-default () |
| 53 | (let ((dired-guess-shell-alist-user nil) | 51 | (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." | |||
| 1016 | (defmacro bytecomp-tests--with-temp-file (file-name-var &rest body) | 1016 | (defmacro bytecomp-tests--with-temp-file (file-name-var &rest body) |
| 1017 | (declare (indent 1)) | 1017 | (declare (indent 1)) |
| 1018 | (cl-check-type file-name-var symbol) | 1018 | (cl-check-type file-name-var symbol) |
| 1019 | `(let ((,file-name-var (make-temp-file "emacs"))) | 1019 | `(ert-with-temp-file ,file-name-var |
| 1020 | (unwind-protect | 1020 | (unwind-protect |
| 1021 | (progn ,@body) | 1021 | (progn ,@body) |
| 1022 | (delete-file ,file-name-var) | ||
| 1023 | (let ((elc (concat ,file-name-var ".elc"))) | 1022 | (let ((elc (concat ,file-name-var ".elc"))) |
| 1024 | (if (file-exists-p elc) (delete-file elc)))))) | 1023 | (if (file-exists-p elc) (delete-file elc)))))) |
| 1025 | 1024 | ||
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 @@ | |||
| 28 | 28 | ||
| 29 | (require 'check-declare) | 29 | (require 'check-declare) |
| 30 | (require 'ert) | 30 | (require 'ert) |
| 31 | (require 'ert-x) | ||
| 31 | (eval-when-compile (require 'subr-x)) | 32 | (eval-when-compile (require 'subr-x)) |
| 32 | 33 | ||
| 33 | (ert-deftest check-declare-tests-locate () | 34 | (ert-deftest check-declare-tests-locate () |
| @@ -36,62 +37,53 @@ | |||
| 36 | (string-prefix-p "ext:" (check-declare-locate "ext:foo" "")))) | 37 | (string-prefix-p "ext:" (check-declare-locate "ext:foo" "")))) |
| 37 | 38 | ||
| 38 | (ert-deftest check-declare-tests-scan () | 39 | (ert-deftest check-declare-tests-scan () |
| 39 | (let ((file (make-temp-file "check-declare-tests-"))) | 40 | (ert-with-temp-file file |
| 40 | (unwind-protect | 41 | (with-temp-file file |
| 41 | (progn | 42 | (insert |
| 42 | (with-temp-file file | 43 | (string-join |
| 43 | (insert | 44 | '(";; foo comment" |
| 44 | (string-join | 45 | "(declare-function ring-insert \"ring\" (ring item))" |
| 45 | '(";; foo comment" | 46 | "(let ((foo 'code)) foo)") |
| 46 | "(declare-function ring-insert \"ring\" (ring item))" | 47 | "\n"))) |
| 47 | "(let ((foo 'code)) foo)") | 48 | (let ((res (check-declare-scan file))) |
| 48 | "\n"))) | 49 | (should (= (length res) 1)) |
| 49 | (let ((res (check-declare-scan file))) | 50 | (pcase-let ((`((,fnfile ,fn ,arglist ,fileonly)) res)) |
| 50 | (should (= (length res) 1)) | 51 | (should (string-match-p "ring" fnfile)) |
| 51 | (pcase-let ((`((,fnfile ,fn ,arglist ,fileonly)) res)) | 52 | (should (equal "ring-insert" fn)) |
| 52 | (should (string-match-p "ring" fnfile)) | 53 | (should (equal '(ring item) arglist)) |
| 53 | (should (equal "ring-insert" fn)) | 54 | (should-not fileonly))))) |
| 54 | (should (equal '(ring item) arglist)) | ||
| 55 | (should-not fileonly)))) | ||
| 56 | (delete-file file)))) | ||
| 57 | 55 | ||
| 58 | (ert-deftest check-declare-tests-verify () | 56 | (ert-deftest check-declare-tests-verify () |
| 59 | (let ((file (make-temp-file "check-declare-tests-"))) | 57 | (ert-with-temp-file file |
| 60 | (unwind-protect | 58 | (with-temp-file file |
| 61 | (progn | 59 | (insert |
| 62 | (with-temp-file file | 60 | (string-join |
| 63 | (insert | 61 | '(";; foo comment" |
| 64 | (string-join | 62 | "(defun foo-fun ())" |
| 65 | '(";; foo comment" | 63 | "(defun ring-insert (ring item)" |
| 66 | "(defun foo-fun ())" | 64 | "\"Insert onto ring RING the item ITEM.\"" |
| 67 | "(defun ring-insert (ring item)" | 65 | "nil)") |
| 68 | "\"Insert onto ring RING the item ITEM.\"" | 66 | "\n"))) |
| 69 | "nil)") | 67 | (should-not |
| 70 | "\n"))) | 68 | (check-declare-verify |
| 71 | (should-not | 69 | file '(("foo.el" "ring-insert" (ring item))))))) |
| 72 | (check-declare-verify | ||
| 73 | file '(("foo.el" "ring-insert" (ring item)))))) | ||
| 74 | (delete-file file)))) | ||
| 75 | 70 | ||
| 76 | (ert-deftest check-declare-tests-verify-mismatch () | 71 | (ert-deftest check-declare-tests-verify-mismatch () |
| 77 | (let ((file (make-temp-file "check-declare-tests-"))) | 72 | (ert-with-temp-file file |
| 78 | (unwind-protect | 73 | (with-temp-file file |
| 79 | (progn | 74 | (insert |
| 80 | (with-temp-file file | 75 | (string-join |
| 81 | (insert | 76 | '(";; foo comment" |
| 82 | (string-join | 77 | "(defun foo-fun ())" |
| 83 | '(";; foo comment" | 78 | "(defun ring-insert (ring)" |
| 84 | "(defun foo-fun ())" | 79 | "\"Insert onto ring RING the item ITEM.\"" |
| 85 | "(defun ring-insert (ring)" | 80 | "nil)") |
| 86 | "\"Insert onto ring RING the item ITEM.\"" | 81 | "\n"))) |
| 87 | "nil)") | 82 | (should |
| 88 | "\n"))) | 83 | (equal |
| 89 | (should | 84 | (check-declare-verify |
| 90 | (equal | 85 | file '(("foo.el" "ring-insert" (ring item)))) |
| 91 | (check-declare-verify | 86 | '(("foo.el" "ring-insert" "arglist mismatch")))))) |
| 92 | file '(("foo.el" "ring-insert" (ring item)))) | ||
| 93 | '(("foo.el" "ring-insert" "arglist mismatch"))))) | ||
| 94 | (delete-file file)))) | ||
| 95 | 87 | ||
| 96 | (ert-deftest check-declare-tests-sort () | 88 | (ert-deftest check-declare-tests-sort () |
| 97 | (should-not (check-declare-sort '())) | 89 | (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.") | |||
| 107 | "Set up the environment for an Edebug test BODY, run it, and clean up." | 107 | "Set up the environment for an Edebug test BODY, run it, and clean up." |
| 108 | (declare (debug (body))) | 108 | (declare (debug (body))) |
| 109 | `(edebug-tests-with-default-config | 109 | `(edebug-tests-with-default-config |
| 110 | (let ((edebug-tests-failure-in-post-command nil) | 110 | (ert-with-temp-file edebug-tests-temp-file |
| 111 | (edebug-tests-temp-file (make-temp-file "edebug-tests-" nil ".el")) | 111 | :suffix ".el" |
| 112 | (find-file-suppress-same-file-warnings t)) | 112 | (let ((edebug-tests-failure-in-post-command nil) |
| 113 | (edebug-tests-setup-code-file edebug-tests-temp-file) | 113 | (find-file-suppress-same-file-warnings t)) |
| 114 | (ert-with-message-capture | 114 | (edebug-tests-setup-code-file edebug-tests-temp-file) |
| 115 | edebug-tests-messages | 115 | (ert-with-message-capture |
| 116 | (unwind-protect | 116 | edebug-tests-messages |
| 117 | (with-current-buffer (find-file edebug-tests-temp-file) | 117 | (unwind-protect |
| 118 | (read-only-mode) | 118 | (with-current-buffer (find-file edebug-tests-temp-file) |
| 119 | (setq lexical-binding t) | 119 | (read-only-mode) |
| 120 | (eval-buffer) | 120 | (setq lexical-binding t) |
| 121 | ,@body | 121 | (eval-buffer) |
| 122 | (when edebug-tests-failure-in-post-command | 122 | ,@body |
| 123 | (signal (car edebug-tests-failure-in-post-command) | 123 | (when edebug-tests-failure-in-post-command |
| 124 | (cdr edebug-tests-failure-in-post-command)))) | 124 | (signal (car edebug-tests-failure-in-post-command) |
| 125 | (unload-feature 'edebug-test-code) | 125 | (cdr edebug-tests-failure-in-post-command)))) |
| 126 | (with-current-buffer (find-file-noselect edebug-tests-temp-file) | 126 | (unload-feature 'edebug-test-code) |
| 127 | (set-buffer-modified-p nil)) | 127 | (with-current-buffer (find-file-noselect edebug-tests-temp-file) |
| 128 | (ignore-errors (kill-buffer (find-file-noselect | 128 | (set-buffer-modified-p nil)) |
| 129 | edebug-tests-temp-file))) | 129 | (ignore-errors (kill-buffer (find-file-noselect |
| 130 | (ignore-errors (delete-file edebug-tests-temp-file))))))) | 130 | edebug-tests-temp-file))))))))) |
| 131 | 131 | ||
| 132 | ;; The following macro and its support functions implement an extension | 132 | ;; The following macro and its support functions implement an extension |
| 133 | ;; to keyboard macros to allow interleaving of keyboard macro | 133 | ;; 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 @@ | |||
| 115 | &rest body) | 115 | &rest body) |
| 116 | "Set up temporary locations and variables for testing." | 116 | "Set up temporary locations and variables for testing." |
| 117 | (declare (indent 1) (debug (([&rest form]) body))) | 117 | (declare (indent 1) (debug (([&rest form]) body))) |
| 118 | `(let* ((package-test-user-dir (make-temp-file "pkg-test-user-dir-" t)) | 118 | `(ert-with-temp-directory package-test-user-dir |
| 119 | (process-environment (cons (format "HOME=%s" package-test-user-dir) | 119 | (let* ((process-environment (cons (format "HOME=%s" package-test-user-dir) |
| 120 | process-environment)) | 120 | process-environment)) |
| 121 | (package-user-dir package-test-user-dir) | 121 | (package-user-dir package-test-user-dir) |
| 122 | (package-gnupghome-dir (expand-file-name "gnupg" package-user-dir)) | 122 | (package-gnupghome-dir (expand-file-name "gnupg" package-user-dir)) |
| 123 | (package-archives `(("gnu" . ,(or ,location package-test-data-dir)))) | 123 | (package-archives `(("gnu" . ,(or ,location package-test-data-dir)))) |
| 124 | (default-directory package-test-file-dir) | 124 | (default-directory package-test-file-dir) |
| 125 | abbreviated-home-dir | 125 | abbreviated-home-dir |
| 126 | package--initialized | 126 | package--initialized |
| 127 | package-alist | 127 | package-alist |
| 128 | ,@(if update-news | 128 | ,@(if update-news |
| 129 | '(package-update-news-on-upload t) | 129 | '(package-update-news-on-upload t) |
| 130 | (list (cl-gensym))) | 130 | (list (cl-gensym))) |
| 131 | ,@(if upload-base | 131 | ,@(if upload-base |
| 132 | '((package-test-archive-upload-base (make-temp-file "pkg-archive-base-" t)) | 132 | '((package-test-archive-upload-base (make-temp-file "pkg-archive-base-" t)) |
| 133 | (package-archive-upload-base package-test-archive-upload-base)) | 133 | (package-archive-upload-base package-test-archive-upload-base)) |
| 134 | (list (cl-gensym)))) ;; Dummy value so `let' doesn't try to bind nil | 134 | (list (cl-gensym)))) ;; Dummy value so `let' doesn't try to bind nil |
| 135 | (let ((buf (get-buffer "*Packages*"))) | 135 | (let ((buf (get-buffer "*Packages*"))) |
| 136 | (when (buffer-live-p buf) | 136 | (when (buffer-live-p buf) |
| 137 | (kill-buffer buf))) | 137 | (kill-buffer buf))) |
| 138 | (unwind-protect | 138 | (unwind-protect |
| 139 | (progn | 139 | (progn |
| 140 | ,(if basedir `(cd ,basedir)) | 140 | ,(if basedir `(cd ,basedir)) |
| 141 | (unless (file-directory-p package-user-dir) | 141 | (unless (file-directory-p package-user-dir) |
| 142 | (mkdir package-user-dir)) | 142 | (mkdir package-user-dir)) |
| 143 | (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t)) | 143 | (cl-letf (((symbol-function 'yes-or-no-p) (lambda (&rest _) t)) |
| 144 | ((symbol-function 'y-or-n-p) (lambda (&rest _) t))) | 144 | ((symbol-function 'y-or-n-p) (lambda (&rest _) t))) |
| 145 | ,@(when install | 145 | ,@(when install |
| 146 | `((package-initialize) | 146 | `((package-initialize) |
| 147 | (package-refresh-contents) | 147 | (package-refresh-contents) |
| 148 | (mapc 'package-install ,install))) | 148 | (mapc 'package-install ,install))) |
| 149 | (with-temp-buffer | 149 | (with-temp-buffer |
| 150 | ,(if file | 150 | ,(if file |
| 151 | `(insert-file-contents ,file)) | 151 | `(insert-file-contents ,file)) |
| 152 | ,@body))) | 152 | ,@body))) |
| 153 | 153 | ||
| 154 | (when ,upload-base | 154 | (when ,upload-base |
| 155 | (dolist (f '("archive-contents" | 155 | (dolist (f '("archive-contents" |
| 156 | "simple-single-1.3.el" | 156 | "simple-single-1.3.el" |
| 157 | "simple-single-1.4.el" | 157 | "simple-single-1.4.el" |
| 158 | "simple-single-readme.txt")) | 158 | "simple-single-readme.txt")) |
| 159 | (ignore-errors | 159 | (ignore-errors |
| 160 | (delete-file | 160 | (delete-file |
| 161 | (expand-file-name f package-test-archive-upload-base)))) | 161 | (expand-file-name f package-test-archive-upload-base)))) |
| 162 | (delete-directory package-test-archive-upload-base)) | 162 | (delete-directory package-test-archive-upload-base)) |
| 163 | (when (file-directory-p package-test-user-dir) | 163 | |
| 164 | (delete-directory package-test-user-dir t)) | 164 | (when (and (boundp 'package-test-archive-upload-base) |
| 165 | 165 | (file-directory-p package-test-archive-upload-base)) | |
| 166 | (when (and (boundp 'package-test-archive-upload-base) | 166 | (delete-directory package-test-archive-upload-base t)))))) |
| 167 | (file-directory-p package-test-archive-upload-base)) | ||
| 168 | (delete-directory package-test-archive-upload-base t))))) | ||
| 169 | 167 | ||
| 170 | (defmacro with-fake-help-buffer (&rest body) | 168 | (defmacro with-fake-help-buffer (&rest body) |
| 171 | "Execute BODY in a temp buffer which is treated as the \"*Help*\" buffer." | 169 | "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)." | |||
| 715 | (defvar epg-config--program-alist) ; Silence byte-compiler. | 713 | (defvar epg-config--program-alist) ; Silence byte-compiler. |
| 716 | (ert-deftest package-test-signed () | 714 | (ert-deftest package-test-signed () |
| 717 | "Test verifying package signature." | 715 | "Test verifying package signature." |
| 718 | (skip-unless (let ((homedir (make-temp-file "package-test" t))) | 716 | (skip-unless (ert-with-temp-directory homedir |
| 719 | (unwind-protect | 717 | (let ((process-environment |
| 720 | (let ((process-environment | 718 | (cons (concat "HOME=" homedir) |
| 721 | (cons (concat "HOME=" homedir) | 719 | process-environment))) |
| 722 | process-environment))) | 720 | (require 'epg-config) |
| 723 | (require 'epg-config) | 721 | (defvar epg-config--program-alist) |
| 724 | (defvar epg-config--program-alist) | 722 | (epg-find-configuration |
| 725 | (epg-find-configuration | 723 | 'OpenPGP nil |
| 726 | 'OpenPGP nil | 724 | ;; By default we require gpg2 2.1+ due to some |
| 727 | ;; By default we require gpg2 2.1+ due to some | 725 | ;; practical problems with pinentry. But this |
| 728 | ;; practical problems with pinentry. But this | 726 | ;; test works fine with 2.0 as well. |
| 729 | ;; test works fine with 2.0 as well. | 727 | (let ((prog-alist (copy-tree epg-config--program-alist))) |
| 730 | (let ((prog-alist (copy-tree epg-config--program-alist))) | 728 | (setf (alist-get "gpg2" |
| 731 | (setf (alist-get "gpg2" | 729 | (alist-get 'OpenPGP prog-alist) |
| 732 | (alist-get 'OpenPGP prog-alist) | 730 | nil nil #'equal) |
| 733 | nil nil #'equal) | 731 | "2.0") |
| 734 | "2.0") | 732 | prog-alist))))) |
| 735 | prog-alist))) | ||
| 736 | (delete-directory homedir t)))) | ||
| 737 | (let* ((keyring (expand-file-name "key.pub" package-test-data-dir)) | 733 | (let* ((keyring (expand-file-name "key.pub" package-test-data-dir)) |
| 738 | (package-test-data-dir (ert-resource-file "signed"))) | 734 | (package-test-data-dir (ert-resource-file "signed"))) |
| 739 | (with-package-test () | 735 | (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 | |||
| 45 | is working correctly on a code sample. OPTARGS are optional | 45 | is working correctly on a code sample. OPTARGS are optional |
| 46 | arguments for `testcover-start'." | 46 | arguments for `testcover-start'." |
| 47 | (interactive "r") | 47 | (interactive "r") |
| 48 | (let ((tempfile (make-temp-file "testcover-tests-" nil ".el")) | 48 | (ert-with-temp-file tempfile |
| 49 | (find-file-suppress-same-file-warnings t) | 49 | :suffix ".el" |
| 50 | (code (buffer-substring beg end)) | 50 | (let ((find-file-suppress-same-file-warnings t) |
| 51 | (marked-up-code)) | 51 | (code (buffer-substring beg end)) |
| 52 | (unwind-protect | 52 | (marked-up-code)) |
| 53 | (progn | 53 | (unwind-protect |
| 54 | (with-temp-file tempfile | 54 | (progn |
| 55 | (insert code)) | 55 | (with-temp-file tempfile |
| 56 | (save-current-buffer | 56 | (insert code)) |
| 57 | (let ((buf (find-file-noselect tempfile))) | 57 | (save-current-buffer |
| 58 | (set-buffer buf) | 58 | (let ((buf (find-file-noselect tempfile))) |
| 59 | (apply 'testcover-start (cons tempfile optargs)) | 59 | (set-buffer buf) |
| 60 | (testcover-mark-all buf) | 60 | (apply 'testcover-start (cons tempfile optargs)) |
| 61 | (dolist (overlay (overlays-in (point-min) (point-max))) | 61 | (testcover-mark-all buf) |
| 62 | (let ((ov-face (overlay-get overlay 'face))) | 62 | (dolist (overlay (overlays-in (point-min) (point-max))) |
| 63 | (goto-char (overlay-end overlay)) | 63 | (let ((ov-face (overlay-get overlay 'face))) |
| 64 | (cond | 64 | (goto-char (overlay-end overlay)) |
| 65 | ((eq ov-face 'testcover-nohits) (insert "!!!")) | 65 | (cond |
| 66 | ((eq ov-face 'testcover-1value) (insert "%%%")) | 66 | ((eq ov-face 'testcover-nohits) (insert "!!!")) |
| 67 | (t nil)))) | 67 | ((eq ov-face 'testcover-1value) (insert "%%%")) |
| 68 | (setq marked-up-code (buffer-string))) | 68 | (t nil)))) |
| 69 | (set-buffer-modified-p nil))) | 69 | (setq marked-up-code (buffer-string))) |
| 70 | (ignore-errors (kill-buffer (find-file-noselect tempfile))) | 70 | (set-buffer-modified-p nil))) |
| 71 | (ignore-errors (delete-file tempfile))) | 71 | (ignore-errors (kill-buffer (find-file-noselect tempfile)))) |
| 72 | 72 | ||
| 73 | ;; Now replace the original code with the marked up code. | 73 | ;; Now replace the original code with the marked up code. |
| 74 | (delete-region beg end) | 74 | (delete-region beg end) |
| 75 | (insert marked-up-code)))) | 75 | (insert marked-up-code))))) |
| 76 | 76 | ||
| 77 | (eval-and-compile | 77 | (eval-and-compile |
| 78 | (defun testcover-tests-unmarkup-region (beg end) | 78 | (defun testcover-tests-unmarkup-region (beg end) |
| @@ -99,32 +99,32 @@ arguments for `testcover-start'." | |||
| 99 | (eval-and-compile | 99 | (eval-and-compile |
| 100 | (defun testcover-tests-run-test-case (marked-up-code) | 100 | (defun testcover-tests-run-test-case (marked-up-code) |
| 101 | "Test the operation of Testcover on the string MARKED-UP-CODE." | 101 | "Test the operation of Testcover on the string MARKED-UP-CODE." |
| 102 | (let ((tempfile (make-temp-file "testcover-tests-" nil ".el")) | 102 | (ert-with-temp-file tempfile |
| 103 | (find-file-suppress-same-file-warnings t)) | 103 | :suffix ".el" |
| 104 | (unwind-protect | 104 | (let ((find-file-suppress-same-file-warnings t)) |
| 105 | (progn | 105 | (unwind-protect |
| 106 | (with-temp-file tempfile | 106 | (progn |
| 107 | (insert marked-up-code)) | 107 | (with-temp-file tempfile |
| 108 | ;; Remove the marks and mark the code up again. The original | 108 | (insert marked-up-code)) |
| 109 | ;; and recreated versions should match. | 109 | ;; Remove the marks and mark the code up again. The original |
| 110 | (save-current-buffer | 110 | ;; and recreated versions should match. |
| 111 | (set-buffer (find-file-noselect tempfile)) | 111 | (save-current-buffer |
| 112 | ;; Fail the test if the debugger tries to become active, | 112 | (set-buffer (find-file-noselect tempfile)) |
| 113 | ;; which can happen if Testcover fails to attach itself | 113 | ;; Fail the test if the debugger tries to become active, |
| 114 | ;; correctly. Note that this will prevent debugging | 114 | ;; which can happen if Testcover fails to attach itself |
| 115 | ;; these tests using Edebug. | 115 | ;; correctly. Note that this will prevent debugging |
| 116 | (cl-letf (((symbol-function #'edebug-default-enter) | 116 | ;; these tests using Edebug. |
| 117 | (lambda (&rest _args) | 117 | (cl-letf (((symbol-function #'edebug-default-enter) |
| 118 | (ert-fail "Debugger invoked during test run")))) | 118 | (lambda (&rest _args) |
| 119 | (dolist (byte-compile '(t nil)) | 119 | (ert-fail "Debugger invoked during test run")))) |
| 120 | (testcover-tests-unmarkup-region (point-min) (point-max)) | 120 | (dolist (byte-compile '(t nil)) |
| 121 | (unwind-protect | 121 | (testcover-tests-unmarkup-region (point-min) (point-max)) |
| 122 | (testcover-tests-markup-region (point-min) (point-max) byte-compile) | 122 | (unwind-protect |
| 123 | (set-buffer-modified-p nil)) | 123 | (testcover-tests-markup-region (point-min) (point-max) byte-compile) |
| 124 | (should (string= marked-up-code | 124 | (set-buffer-modified-p nil)) |
| 125 | (buffer-string))))))) | 125 | (should (string= marked-up-code |
| 126 | (ignore-errors (kill-buffer (find-file-noselect tempfile))) | 126 | (buffer-string))))))) |
| 127 | (ignore-errors (delete-file tempfile)))))) | 127 | (ignore-errors (kill-buffer (find-file-noselect tempfile)))))))) |
| 128 | 128 | ||
| 129 | ;; Convert test case file to ert-defmethod. | 129 | ;; Convert test case file to ert-defmethod. |
| 130 | 130 | ||
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 @@ | |||
| 21 | 21 | ||
| 22 | ;;; Code: | 22 | ;;; Code: |
| 23 | 23 | ||
| 24 | 24 | (require 'ert) | |
| 25 | (require 'ert-x) | ||
| 25 | (require 'viper) | 26 | (require 'viper) |
| 26 | 27 | ||
| 27 | (defun viper-test-undo-kmacro (kmacro) | 28 | (defun viper-test-undo-kmacro (kmacro) |
| @@ -30,47 +31,42 @@ | |||
| 30 | This function makes as many attempts as possible to clean up | 31 | This function makes as many attempts as possible to clean up |
| 31 | after itself, although it will leave a buffer called | 32 | after itself, although it will leave a buffer called |
| 32 | *viper-test-buffer* if it fails (this is deliberate!)." | 33 | *viper-test-buffer* if it fails (this is deliberate!)." |
| 33 | (let ( | 34 | (ert-with-temp-file viper-custom-file-name |
| 34 | ;; Viper just turns itself off during batch use. | 35 | ;; viper loads this even with -q so make sure it's empty! |
| 35 | (noninteractive nil) | 36 | :prefix "emacs-viper-tests" :suffix ".elc" |
| 36 | ;; Switch off start up message or it will chew the key presses. | 37 | (let (;; Viper just turns itself off during batch use. |
| 37 | (viper-inhibit-startup-message 't) | 38 | (noninteractive nil) |
| 38 | ;; Select an expert-level for the same reason. | 39 | ;; Switch off start up message or it will chew the key presses. |
| 39 | (viper-expert-level 5) | 40 | (viper-inhibit-startup-message 't) |
| 40 | ;; viper loads this even with -q so make sure it's empty! | 41 | ;; Select an expert-level for the same reason. |
| 41 | (viper-custom-file-name (make-temp-file "viper-tests" nil ".elc")) | 42 | (viper-expert-level 5) |
| 42 | (before-buffer (current-buffer))) | 43 | (before-buffer (current-buffer))) |
| 43 | (unwind-protect | 44 | (unwind-protect |
| 44 | (progn | 45 | (progn |
| 45 | ;; viper-mode is essentially global, so set it here. | 46 | ;; viper-mode is essentially global, so set it here. |
| 46 | (viper-mode) | 47 | (viper-mode) |
| 47 | ;; We must switch to buffer because we are using a keyboard macro | 48 | ;; We must switch to buffer because we are using a keyboard macro |
| 48 | ;; which appears to not go to the current-buffer but what ever is | 49 | ;; which appears to not go to the current-buffer but what ever is |
| 49 | ;; currently taking keyboard events. We use a named buffer because | 50 | ;; currently taking keyboard events. We use a named buffer because |
| 50 | ;; then we can see what it in it if it all goes wrong. | 51 | ;; then we can see what it in it if it all goes wrong. |
| 51 | (switch-to-buffer | 52 | (switch-to-buffer |
| 52 | (get-buffer-create | 53 | (get-buffer-create |
| 53 | "*viper-test-buffer*")) | 54 | "*viper-test-buffer*")) |
| 54 | (erase-buffer) | 55 | (erase-buffer) |
| 55 | ;; The new buffer fails to enter vi state so set it. | 56 | ;; The new buffer fails to enter vi state so set it. |
| 56 | (viper-change-state-to-vi) | 57 | (viper-change-state-to-vi) |
| 57 | ;; Run the macro. | 58 | ;; Run the macro. |
| 58 | (execute-kbd-macro kmacro) | 59 | (execute-kbd-macro kmacro) |
| 59 | (let ((rtn | 60 | (let ((rtn |
| 60 | (buffer-substring-no-properties | 61 | (buffer-substring-no-properties |
| 61 | (point-min) | 62 | (point-min) |
| 62 | (point-max)))) | 63 | (point-max)))) |
| 63 | ;; Kill the buffer iff the macro succeeds. | 64 | ;; Kill the buffer iff the macro succeeds. |
| 64 | (kill-buffer) | 65 | (kill-buffer) |
| 65 | rtn)) | 66 | rtn)) |
| 66 | ;; Switch everything off and restore the buffer. | 67 | ;; Switch everything off and restore the buffer. |
| 67 | (toggle-viper-mode) | 68 | (toggle-viper-mode) |
| 68 | (delete-file viper-custom-file-name) | 69 | (switch-to-buffer before-buffer))))) |
| 69 | (switch-to-buffer before-buffer)))) | ||
| 70 | |||
| 71 | (ert-deftest viper-test-go () | ||
| 72 | "Test that this file is running." | ||
| 73 | (should t)) | ||
| 74 | 70 | ||
| 75 | (ert-deftest viper-test-fix () | 71 | (ert-deftest viper-test-fix () |
| 76 | "Test that the viper kmacro fixture is working." | 72 | "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 @@ | |||
| 58 | (cl-defmacro with-epg-tests ((&optional &key require-passphrase | 58 | (cl-defmacro with-epg-tests ((&optional &key require-passphrase |
| 59 | require-public-key | 59 | require-public-key |
| 60 | require-secret-key) | 60 | require-secret-key) |
| 61 | &rest body) | 61 | &rest body) |
| 62 | "Set up temporary locations and variables for testing." | 62 | "Set up temporary locations and variables for testing." |
| 63 | (declare (indent 1) (debug (sexp body))) | 63 | (declare (indent 1) (debug (sexp body))) |
| 64 | `(let* ((epg-tests-home-directory (make-temp-file "epg-tests-homedir" t)) | 64 | `(ert-with-temp-directory epg-tests-home-directory |
| 65 | (process-environment | 65 | (let* ((process-environment |
| 66 | (append | 66 | (append |
| 67 | (list "GPG_AGENT_INFO" | 67 | (list "GPG_AGENT_INFO" |
| 68 | (format "GNUPGHOME=%s" epg-tests-home-directory)) | 68 | (format "GNUPGHOME=%s" epg-tests-home-directory)) |
| 69 | process-environment))) | 69 | process-environment))) |
| 70 | (unwind-protect | 70 | ;; GNUPGHOME is needed to find a usable gpg, so we can't |
| 71 | ;; GNUPGHOME is needed to find a usable gpg, so we can't | 71 | ;; check whether to skip any earlier (Bug#23561). |
| 72 | ;; check whether to skip any earlier (Bug#23561). | 72 | (let ((epg-config (or (epg-tests-find-usable-gpg-configuration |
| 73 | (let ((epg-config (or (epg-tests-find-usable-gpg-configuration | 73 | ,require-passphrase ,require-public-key) |
| 74 | ,require-passphrase ,require-public-key) | 74 | (ert-skip "No usable gpg config"))) |
| 75 | (ert-skip "No usable gpg config"))) | 75 | (context (epg-make-context 'OpenPGP))) |
| 76 | (context (epg-make-context 'OpenPGP))) | 76 | (setf (epg-context-program context) |
| 77 | (setf (epg-context-program context) | 77 | (alist-get 'program epg-config)) |
| 78 | (alist-get 'program epg-config)) | 78 | (setf (epg-context-home-directory context) |
| 79 | (setf (epg-context-home-directory context) | 79 | epg-tests-home-directory) |
| 80 | epg-tests-home-directory) | 80 | ,(if require-passphrase |
| 81 | ,(if require-passphrase | 81 | '(with-temp-file (expand-file-name |
| 82 | '(with-temp-file (expand-file-name | 82 | "gpg-agent.conf" epg-tests-home-directory) |
| 83 | "gpg-agent.conf" epg-tests-home-directory) | 83 | (insert "pinentry-program " |
| 84 | (insert "pinentry-program " | 84 | (ert-resource-file "dummy-pinentry") |
| 85 | (ert-resource-file "dummy-pinentry") | 85 | "\n") |
| 86 | "\n") | 86 | (epg-context-set-passphrase-callback |
| 87 | (epg-context-set-passphrase-callback | 87 | context |
| 88 | context | 88 | #'epg-tests-passphrase-callback))) |
| 89 | #'epg-tests-passphrase-callback))) | 89 | ,(if require-public-key |
| 90 | ,(if require-public-key | 90 | '(epg-import-keys-from-file |
| 91 | '(epg-import-keys-from-file | 91 | context |
| 92 | context | 92 | (ert-resource-file "pubkey.asc"))) |
| 93 | (ert-resource-file "pubkey.asc"))) | 93 | ,(if require-secret-key |
| 94 | ,(if require-secret-key | 94 | '(epg-import-keys-from-file |
| 95 | '(epg-import-keys-from-file | 95 | context |
| 96 | context | 96 | (ert-resource-file "seckey.asc"))) |
| 97 | (ert-resource-file "seckey.asc"))) | 97 | (with-temp-buffer |
| 98 | (with-temp-buffer | 98 | (setq-local epg-tests-context context) |
| 99 | (setq-local epg-tests-context context) | 99 | ,@body))))) |
| 100 | ,@body)) | ||
| 101 | (when (file-directory-p epg-tests-home-directory) | ||
| 102 | (delete-directory epg-tests-home-directory t))))) | ||
| 103 | 100 | ||
| 104 | (ert-deftest epg-decrypt-1 () | 101 | (ert-deftest epg-decrypt-1 () |
| 105 | :expected-result (if (getenv "EMACS_HYDRA_CI") :failed :passed) ; fixme | 102 | :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 @@ | |||
| 20 | ;;; Code: | 20 | ;;; Code: |
| 21 | 21 | ||
| 22 | (require 'ert) | 22 | (require 'ert) |
| 23 | (require 'ert-x) | ||
| 23 | (require 'em-hist) | 24 | (require 'em-hist) |
| 24 | 25 | ||
| 25 | (ert-deftest eshell-write-readonly-history () | 26 | (ert-deftest eshell-write-readonly-history () |
| 26 | "Test that having read-only strings in history is okay." | 27 | "Test that having read-only strings in history is okay." |
| 27 | (let ((histfile (make-temp-file "eshell-history")) | 28 | (ert-with-temp-file histfile |
| 28 | (eshell-history-ring (make-ring 2))) | 29 | (let ((eshell-history-ring (make-ring 2))) |
| 29 | (ring-insert eshell-history-ring | 30 | (ring-insert eshell-history-ring |
| 30 | (propertize "echo foo" 'read-only t)) | 31 | (propertize "echo foo" 'read-only t)) |
| 31 | (ring-insert eshell-history-ring | 32 | (ring-insert eshell-history-ring |
| 32 | (propertize "echo bar" 'read-only t)) | 33 | (propertize "echo bar" 'read-only t)) |
| 33 | (unwind-protect | 34 | (eshell-write-history histfile)))) |
| 34 | (eshell-write-history histfile) | ||
| 35 | (delete-file histfile)))) | ||
| 36 | 35 | ||
| 37 | (provide 'em-hist-test) | 36 | (provide 'em-hist-test) |
| 38 | 37 | ||
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 @@ | |||
| 25 | ;;; Code: | 25 | ;;; Code: |
| 26 | 26 | ||
| 27 | (require 'ert) | 27 | (require 'ert) |
| 28 | (require 'ert-x) | ||
| 28 | (require 'em-ls) | 29 | (require 'em-ls) |
| 29 | (require 'dired) | 30 | (require 'dired) |
| 30 | 31 | ||
| 31 | (ert-deftest em-ls-test-bug27631 () | 32 | (ert-deftest em-ls-test-bug27631 () |
| 32 | "Test for https://debbugs.gnu.org/27631 ." | 33 | "Test for https://debbugs.gnu.org/27631 ." |
| 33 | (let* ((dir (make-temp-file "bug27631" 'dir)) | 34 | (ert-with-temp-directory dir |
| 34 | (dir1 (expand-file-name "dir1" dir)) | 35 | (let* ((dir1 (expand-file-name "dir1" dir)) |
| 35 | (dir2 (expand-file-name "dir2" dir)) | 36 | (dir2 (expand-file-name "dir2" dir)) |
| 36 | (default-directory dir) | 37 | (default-directory dir) |
| 37 | (orig eshell-ls-use-in-dired) | 38 | (orig eshell-ls-use-in-dired) |
| 38 | buf) | 39 | buf) |
| 39 | (unwind-protect | 40 | (unwind-protect |
| 40 | (progn | 41 | (progn |
| 41 | (customize-set-value 'eshell-ls-use-in-dired t) | 42 | (customize-set-value 'eshell-ls-use-in-dired t) |
| 42 | (make-directory dir1) | 43 | (make-directory dir1) |
| 43 | (make-directory dir2) | 44 | (make-directory dir2) |
| 44 | (with-temp-file (expand-file-name "a.txt" dir1)) | 45 | (with-temp-file (expand-file-name "a.txt" dir1)) |
| 45 | (with-temp-file (expand-file-name "b.txt" dir2)) | 46 | (with-temp-file (expand-file-name "b.txt" dir2)) |
| 46 | (setq buf (dired (expand-file-name "dir*/*.txt" dir))) | 47 | (setq buf (dired (expand-file-name "dir*/*.txt" dir))) |
| 47 | (dired-toggle-marks) | 48 | (dired-toggle-marks) |
| 48 | (should (cdr (dired-get-marked-files)))) | 49 | (should (cdr (dired-get-marked-files)))) |
| 49 | (customize-set-variable 'eshell-ls-use-in-dired orig) | 50 | (customize-set-variable 'eshell-ls-use-in-dired orig) |
| 50 | (delete-directory dir 'recursive) | 51 | (when (buffer-live-p buf) (kill-buffer buf)))))) |
| 51 | (when (buffer-live-p buf) (kill-buffer buf))))) | ||
| 52 | 52 | ||
| 53 | (ert-deftest em-ls-test-bug27817 () | 53 | (ert-deftest em-ls-test-bug27817 () |
| 54 | "Test for https://debbugs.gnu.org/27817 ." | 54 | "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 @@ | |||
| 25 | 25 | ||
| 26 | (require 'cl-lib) | 26 | (require 'cl-lib) |
| 27 | (require 'ert) | 27 | (require 'ert) |
| 28 | (require 'ert-x) | ||
| 28 | (require 'ffap) | 29 | (require 'ffap) |
| 29 | 30 | ||
| 30 | (ert-deftest ffap-tests-25243 () | 31 | (ert-deftest ffap-tests-25243 () |
| 31 | "Test for https://debbugs.gnu.org/25243 ." | 32 | "Test for https://debbugs.gnu.org/25243 ." |
| 32 | (let ((file (make-temp-file "test-Bug#25243"))) | 33 | (ert-with-temp-file file |
| 33 | (unwind-protect | 34 | :suffix "-bug25243" |
| 34 | (with-temp-file file | 35 | (let ((str "diff --git b/lisp/ffap.el a/lisp/ffap.el |
| 35 | (let ((str "diff --git b/lisp/ffap.el a/lisp/ffap.el | ||
| 36 | index 3d7cebadcf..ad4b70d737 100644 | 36 | index 3d7cebadcf..ad4b70d737 100644 |
| 37 | --- b/lisp/ffap.el | 37 | --- b/lisp/ffap.el |
| 38 | +++ a/lisp/ffap.el | 38 | +++ a/lisp/ffap.el |
| 39 | @@ -203,6 +203,9 @@ ffap-foo-at-bar-prefix | 39 | @@ -203,6 +203,9 @@ ffap-foo-at-bar-prefix |
| 40 | ")) | 40 | ")) |
| 41 | (transient-mark-mode 1) | 41 | (transient-mark-mode 1) |
| 42 | (when (natnump ffap-max-region-length) | 42 | (when (natnump ffap-max-region-length) |
| 43 | (insert | 43 | (insert |
| 44 | (concat | 44 | (concat |
| 45 | str | 45 | str |
| 46 | (make-string ffap-max-region-length #xa) | 46 | (make-string ffap-max-region-length #xa) |
| 47 | (format "%s ENDS HERE" file))) | 47 | (format "%s ENDS HERE" file))) |
| 48 | (call-interactively 'mark-whole-buffer) | 48 | (call-interactively 'mark-whole-buffer) |
| 49 | (should (equal "" (ffap-string-at-point))) | 49 | (should (equal "" (ffap-string-at-point))) |
| 50 | (should (equal '(1 1) ffap-string-at-point-region))))) | 50 | (should (equal '(1 1) ffap-string-at-point-region)))))) |
| 51 | (and (file-exists-p file) (delete-file file))))) | ||
| 52 | 51 | ||
| 53 | (ert-deftest ffap-gopher-at-point () | 52 | (ert-deftest ffap-gopher-at-point () |
| 54 | (with-temp-buffer | 53 | (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.") | |||
| 176 | ;; If called interactively, environment variable | 176 | ;; If called interactively, environment variable |
| 177 | ;; $EMACS_TEST_DIRECTORY does not exist. | 177 | ;; $EMACS_TEST_DIRECTORY does not exist. |
| 178 | (skip-unless (file-exists-p files-test-bug-18141-file)) | 178 | (skip-unless (file-exists-p files-test-bug-18141-file)) |
| 179 | (let ((tempfile (make-temp-file "files-test-bug-18141" nil ".gz"))) | 179 | (ert-with-temp-file tempfile |
| 180 | (unwind-protect | 180 | :prefix "emacs-test-files-bug-18141" |
| 181 | (progn | 181 | :suffix ".gz" |
| 182 | (copy-file files-test-bug-18141-file tempfile t) | 182 | (copy-file files-test-bug-18141-file tempfile t) |
| 183 | (with-current-buffer (find-file-noselect tempfile) | 183 | (with-current-buffer (find-file-noselect tempfile) |
| 184 | (set-buffer-modified-p t) | 184 | (set-buffer-modified-p t) |
| 185 | (save-buffer) | 185 | (save-buffer) |
| 186 | (should (eq buffer-file-coding-system 'iso-2022-7bit-unix)))) | 186 | (should (eq buffer-file-coding-system 'iso-2022-7bit-unix))))) |
| 187 | (delete-file tempfile)))) | ||
| 188 | 187 | ||
| 189 | (ert-deftest files-tests-make-temp-file-empty-prefix () | 188 | (ert-deftest files-tests-make-temp-file-empty-prefix () |
| 190 | "Test make-temp-file with an empty prefix." | 189 | "Test make-temp-file with an empty prefix." |
| @@ -283,22 +282,20 @@ If we are in a directory named `~', the default value should not | |||
| 283 | be $HOME." | 282 | be $HOME." |
| 284 | (cl-letf (((symbol-function 'completing-read) | 283 | (cl-letf (((symbol-function 'completing-read) |
| 285 | (lambda (_prompt _coll &optional _pred _req init _hist def _) | 284 | (lambda (_prompt _coll &optional _pred _req init _hist def _) |
| 286 | (or def init))) | 285 | (or def init)))) |
| 287 | (dir (make-temp-file "read-file-name-test" t))) | 286 | (ert-with-temp-directory dir |
| 288 | (unwind-protect | 287 | (let ((subdir (expand-file-name "./~/" dir))) |
| 289 | (let ((subdir (expand-file-name "./~/" dir))) | 288 | (make-directory subdir t) |
| 290 | (make-directory subdir t) | 289 | (with-temp-buffer |
| 291 | (with-temp-buffer | 290 | (setq default-directory subdir) |
| 292 | (setq default-directory subdir) | 291 | (should-not (equal |
| 293 | (should-not (equal | 292 | (expand-file-name (read-file-name "File: ")) |
| 294 | (expand-file-name (read-file-name "File: ")) | 293 | (expand-file-name "~/"))) |
| 295 | (expand-file-name "~/"))) | 294 | ;; Don't overquote either! |
| 296 | ;; Don't overquote either! | 295 | (setq default-directory (concat "/:" subdir)) |
| 297 | (setq default-directory (concat "/:" subdir)) | 296 | (should-not (equal |
| 298 | (should-not (equal | 297 | (expand-file-name (read-file-name "File: ")) |
| 299 | (expand-file-name (read-file-name "File: ")) | 298 | (concat "/:/:" subdir)))))))) |
| 300 | (concat "/:/:" subdir))))) | ||
| 301 | (delete-directory dir 'recursive)))) | ||
| 302 | 299 | ||
| 303 | (ert-deftest files-tests-file-name-non-special-quote-unquote () | 300 | (ert-deftest files-tests-file-name-non-special-quote-unquote () |
| 304 | (let (;; Just in case it is quoted, who knows. | 301 | (let (;; Just in case it is quoted, who knows. |
| @@ -1231,26 +1228,26 @@ works as expected if the default directory is quoted." | |||
| 1231 | (insert-directory-wildcard-in-dir-p (car path-res))))))) | 1228 | (insert-directory-wildcard-in-dir-p (car path-res))))))) |
| 1232 | 1229 | ||
| 1233 | (ert-deftest files-tests-make-directory () | 1230 | (ert-deftest files-tests-make-directory () |
| 1234 | (let* ((dir (make-temp-file "files-mkdir-test" t)) | 1231 | (ert-with-temp-directory dir |
| 1235 | (dirname (file-name-as-directory dir)) | 1232 | (let* ((dirname (file-name-as-directory dir)) |
| 1236 | (file (concat dirname "file")) | 1233 | (file (concat dirname "file")) |
| 1237 | (subdir1 (concat dirname "subdir1")) | 1234 | (subdir1 (concat dirname "subdir1")) |
| 1238 | (subdir2 (concat dirname "subdir2")) | 1235 | (subdir2 (concat dirname "subdir2")) |
| 1239 | (a/b (concat dirname "a/b"))) | 1236 | (a/b (concat dirname "a/b"))) |
| 1240 | (write-region "" nil file) | 1237 | (write-region "" nil file) |
| 1241 | (should-error (make-directory "/")) | 1238 | (should-error (make-directory "/")) |
| 1242 | (should-not (make-directory "/" t)) | 1239 | (should-not (make-directory "/" t)) |
| 1243 | (should-error (make-directory dir)) | 1240 | (should-error (make-directory dir)) |
| 1244 | (should-not (make-directory dir t)) | 1241 | (should-not (make-directory dir t)) |
| 1245 | (should-error (make-directory dirname)) | 1242 | (should-error (make-directory dirname)) |
| 1246 | (should-not (make-directory dirname t)) | 1243 | (should-not (make-directory dirname t)) |
| 1247 | (should-error (make-directory file)) | 1244 | (should-error (make-directory file)) |
| 1248 | (should-error (make-directory file t)) | 1245 | (should-error (make-directory file t)) |
| 1249 | (should-not (make-directory subdir1)) | 1246 | (should-not (make-directory subdir1)) |
| 1250 | (should-not (make-directory subdir2 t)) | 1247 | (should-not (make-directory subdir2 t)) |
| 1251 | (should-error (make-directory a/b)) | 1248 | (should-error (make-directory a/b)) |
| 1252 | (should-not (make-directory a/b t)) | 1249 | (should-not (make-directory a/b t)) |
| 1253 | (delete-directory dir 'recursive))) | 1250 | (delete-directory dir 'recursive)))) |
| 1254 | 1251 | ||
| 1255 | (ert-deftest files-tests-file-modes-symbolic-to-number () | 1252 | (ert-deftest files-tests-file-modes-symbolic-to-number () |
| 1256 | (let ((alist (list (cons "a=rwx" #o777) | 1253 | (let ((alist (list (cons "a=rwx" #o777) |
| @@ -1318,21 +1315,21 @@ name (Bug#28412)." | |||
| 1318 | (should (eq (buffer-size) 1)))))) | 1315 | (should (eq (buffer-size) 1)))))) |
| 1319 | 1316 | ||
| 1320 | (ert-deftest files-tests-copy-directory () | 1317 | (ert-deftest files-tests-copy-directory () |
| 1321 | (let* ((dir (make-temp-file "files-mkdir-test" t)) | 1318 | (ert-with-temp-directory dir |
| 1322 | (dirname (file-name-as-directory dir)) | 1319 | (let* ((dirname (file-name-as-directory dir)) |
| 1323 | (source (concat dirname "source")) | 1320 | (source (concat dirname "source")) |
| 1324 | (dest (concat dirname "dest/new/directory/")) | 1321 | (dest (concat dirname "dest/new/directory/")) |
| 1325 | (file (concat (file-name-as-directory source) "file")) | 1322 | (file (concat (file-name-as-directory source) "file")) |
| 1326 | (source2 (concat dirname "source2")) | 1323 | (source2 (concat dirname "source2")) |
| 1327 | (dest2 (concat dirname "dest/new2"))) | 1324 | (dest2 (concat dirname "dest/new2"))) |
| 1328 | (make-directory source) | 1325 | (make-directory source) |
| 1329 | (write-region "" nil file) | 1326 | (write-region "" nil file) |
| 1330 | (copy-directory source dest t t t) | 1327 | (copy-directory source dest t t t) |
| 1331 | (should (file-exists-p (concat dest "file"))) | 1328 | (should (file-exists-p (concat dest "file"))) |
| 1332 | (make-directory (concat (file-name-as-directory source2) "a") t) | 1329 | (make-directory (concat (file-name-as-directory source2) "a") t) |
| 1333 | (copy-directory source2 dest2) | 1330 | (copy-directory source2 dest2) |
| 1334 | (should (file-directory-p (concat (file-name-as-directory dest2) "a"))) | 1331 | (should (file-directory-p (concat (file-name-as-directory dest2) "a"))) |
| 1335 | (delete-directory dir 'recursive))) | 1332 | (delete-directory dir 'recursive)))) |
| 1336 | 1333 | ||
| 1337 | (ert-deftest files-tests-abbreviated-home-dir () | 1334 | (ert-deftest files-tests-abbreviated-home-dir () |
| 1338 | "Test that changing HOME does not confuse `abbreviate-file-name'. | 1335 | "Test that changing HOME does not confuse `abbreviate-file-name'. |
| @@ -1351,43 +1348,41 @@ See <https://debbugs.gnu.org/19657#20>." | |||
| 1351 | (ert-deftest files-tests-executable-find () | 1348 | (ert-deftest files-tests-executable-find () |
| 1352 | "Test that `executable-find' works also with a relative or remote PATH. | 1349 | "Test that `executable-find' works also with a relative or remote PATH. |
| 1353 | See <https://debbugs.gnu.org/35241>." | 1350 | See <https://debbugs.gnu.org/35241>." |
| 1354 | (let ((tmpfile (make-temp-file "files-test" nil (car exec-suffixes)))) | 1351 | (ert-with-temp-file tmpfile |
| 1355 | (unwind-protect | 1352 | :suffix (car exec-suffixes) |
| 1356 | (progn | 1353 | (let ((tmpfile (make-temp-file "files-test" nil ))) |
| 1357 | (set-file-modes tmpfile #o777) | 1354 | (set-file-modes tmpfile #o777) |
| 1358 | (let ((exec-path `(,temporary-file-directory))) | 1355 | (let ((exec-path `(,temporary-file-directory))) |
| 1359 | (should | 1356 | (should |
| 1360 | (equal tmpfile | 1357 | (equal tmpfile |
| 1361 | (executable-find (file-name-nondirectory tmpfile))))) | 1358 | (executable-find (file-name-nondirectory tmpfile))))) |
| 1362 | ;; An empty element of `exec-path' means `default-directory'. | 1359 | ;; An empty element of `exec-path' means `default-directory'. |
| 1363 | (let ((default-directory temporary-file-directory) | 1360 | (let ((default-directory temporary-file-directory) |
| 1364 | (exec-path nil)) | 1361 | (exec-path nil)) |
| 1365 | (should | 1362 | (should |
| 1366 | (equal tmpfile | 1363 | (equal tmpfile |
| 1367 | (executable-find (file-name-nondirectory tmpfile))))) | 1364 | (executable-find (file-name-nondirectory tmpfile))))) |
| 1368 | ;; The remote file name shall be quoted, and handled like a | 1365 | ;; The remote file name shall be quoted, and handled like a |
| 1369 | ;; non-existing directory. | 1366 | ;; non-existing directory. |
| 1370 | (let ((default-directory "/ssh::") | 1367 | (let ((default-directory "/ssh::") |
| 1371 | (exec-path (append exec-path `("." ,temporary-file-directory)))) | 1368 | (exec-path (append exec-path `("." ,temporary-file-directory)))) |
| 1372 | (should | 1369 | (should |
| 1373 | (equal tmpfile | 1370 | (equal tmpfile |
| 1374 | (executable-find (file-name-nondirectory tmpfile)))))) | 1371 | (executable-find (file-name-nondirectory tmpfile)))))))) |
| 1375 | (delete-file tmpfile)))) | ||
| 1376 | 1372 | ||
| 1377 | (ert-deftest files-tests-dont-rewrite-precious-files () | 1373 | (ert-deftest files-tests-dont-rewrite-precious-files () |
| 1378 | "Test that `file-precious-flag' forces files to be saved by | 1374 | "Test that `file-precious-flag' forces files to be saved by |
| 1379 | renaming only, rather than modified in-place." | 1375 | renaming only, rather than modified in-place." |
| 1380 | (let* ((temp-file-name (make-temp-file "files-tests")) | 1376 | (ert-with-temp-file temp-file-name |
| 1381 | (advice (lambda (_start _end filename &rest _r) | 1377 | (let* ((advice (lambda (_start _end filename &rest _r) |
| 1382 | (should-not (string= filename temp-file-name))))) | 1378 | (should-not (string= filename temp-file-name))))) |
| 1383 | (unwind-protect | 1379 | (unwind-protect |
| 1384 | (with-current-buffer (find-file-noselect temp-file-name) | 1380 | (with-current-buffer (find-file-noselect temp-file-name) |
| 1385 | (advice-add #'write-region :before advice) | 1381 | (advice-add #'write-region :before advice) |
| 1386 | (setq-local file-precious-flag t) | 1382 | (setq-local file-precious-flag t) |
| 1387 | (insert "foobar") | 1383 | (insert "foobar") |
| 1388 | (should (null (save-buffer)))) | 1384 | (should (null (save-buffer)))) |
| 1389 | (ignore-errors (advice-remove #'write-region advice)) | 1385 | (ignore-errors (advice-remove #'write-region advice)))))) |
| 1390 | (ignore-errors (delete-file temp-file-name))))) | ||
| 1391 | 1386 | ||
| 1392 | (ert-deftest files-test-file-size-human-readable () | 1387 | (ert-deftest files-test-file-size-human-readable () |
| 1393 | (should (equal (file-size-human-readable 13) "13")) | 1388 | (should (equal (file-size-human-readable 13) "13")) |
| @@ -1578,40 +1573,39 @@ on BUF-1 and BUF-2 after the `save-some-buffers' call. | |||
| 1578 | The test is repeated with `save-some-buffers-default-predicate' | 1573 | The test is repeated with `save-some-buffers-default-predicate' |
| 1579 | let-bound to PRED and passing nil as second arg of | 1574 | let-bound to PRED and passing nil as second arg of |
| 1580 | `save-some-buffers'." | 1575 | `save-some-buffers'." |
| 1581 | (let* ((dir (make-temp-file "testdir" 'dir)) | 1576 | (ert-with-temp-directory dir |
| 1582 | (file-1 (expand-file-name "subdir-1/file.foo" dir)) | 1577 | (let* ((file-1 (expand-file-name "subdir-1/file.foo" dir)) |
| 1583 | (file-2 (expand-file-name "subdir-2/file.bar" dir)) | 1578 | (file-2 (expand-file-name "subdir-2/file.bar" dir)) |
| 1584 | (inhibit-message t) | 1579 | (inhibit-message t) |
| 1585 | buf-1 buf-2) | 1580 | buf-1 buf-2) |
| 1586 | (unwind-protect | 1581 | (unwind-protect |
| 1587 | (progn | 1582 | (progn |
| 1588 | (make-empty-file file-1 'parens) | 1583 | (make-empty-file file-1 'parens) |
| 1589 | (make-empty-file file-2 'parens) | 1584 | (make-empty-file file-2 'parens) |
| 1590 | (setq buf-1 (find-file file-1) | 1585 | (setq buf-1 (find-file file-1) |
| 1591 | buf-2 (find-file file-2)) | 1586 | buf-2 (find-file file-2)) |
| 1592 | (dolist (buf (list buf-1 buf-2)) | 1587 | (dolist (buf (list buf-1 buf-2)) |
| 1593 | (with-current-buffer buf (insert "foobar\n"))) | 1588 | (with-current-buffer buf (insert "foobar\n"))) |
| 1594 | ;; Run the test. | 1589 | ;; Run the test. |
| 1595 | (with-current-buffer buf-1 | 1590 | (with-current-buffer buf-1 |
| 1596 | (let ((save-some-buffers-default-predicate def-pred-bind)) | 1591 | (let ((save-some-buffers-default-predicate def-pred-bind)) |
| 1597 | (save-some-buffers t pred)) | 1592 | (save-some-buffers t pred)) |
| 1598 | (should (eq exp-1 (buffer-modified-p buf-1))) | 1593 | (should (eq exp-1 (buffer-modified-p buf-1))) |
| 1599 | (should (eq exp-2 (buffer-modified-p buf-2)))) | 1594 | (should (eq exp-2 (buffer-modified-p buf-2)))) |
| 1600 | ;; Set both buffers as modified to run another test. | 1595 | ;; Set both buffers as modified to run another test. |
| 1601 | (dolist (buf (list buf-1 buf-2)) | 1596 | (dolist (buf (list buf-1 buf-2)) |
| 1602 | (with-current-buffer buf (set-buffer-modified-p t))) | 1597 | (with-current-buffer buf (set-buffer-modified-p t))) |
| 1603 | ;; The result of this test must be identical as the previous one. | 1598 | ;; The result of this test must be identical as the previous one. |
| 1604 | (with-current-buffer buf-1 | 1599 | (with-current-buffer buf-1 |
| 1605 | (let ((save-some-buffers-default-predicate (or pred def-pred-bind))) | 1600 | (let ((save-some-buffers-default-predicate (or pred def-pred-bind))) |
| 1606 | (save-some-buffers t nil)) | 1601 | (save-some-buffers t nil)) |
| 1607 | (should (eq exp-1 (buffer-modified-p buf-1))) | 1602 | (should (eq exp-1 (buffer-modified-p buf-1))) |
| 1608 | (should (eq exp-2 (buffer-modified-p buf-2))))) | 1603 | (should (eq exp-2 (buffer-modified-p buf-2))))) |
| 1609 | ;; Clean up. | 1604 | ;; Clean up. |
| 1610 | (dolist (buf (list buf-1 buf-2)) | 1605 | (dolist (buf (list buf-1 buf-2)) |
| 1611 | (with-current-buffer buf | 1606 | (with-current-buffer buf |
| 1612 | (set-buffer-modified-p nil) | 1607 | (set-buffer-modified-p nil) |
| 1613 | (kill-buffer buf))) | 1608 | (kill-buffer buf))))))) |
| 1614 | (delete-directory dir 'recursive)))) | ||
| 1615 | 1609 | ||
| 1616 | (ert-deftest files-tests-save-some-buffers () | 1610 | (ert-deftest files-tests-save-some-buffers () |
| 1617 | "Test `save-some-buffers'. | 1611 | "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 @@ | |||
| 25 | 25 | ||
| 26 | ;;; Code: | 26 | ;;; Code: |
| 27 | (require 'ert) | 27 | (require 'ert) |
| 28 | (require 'ert-x) | ||
| 28 | (require 'ls-lisp) | 29 | (require 'ls-lisp) |
| 29 | (require 'dired) | 30 | (require 'dired) |
| 30 | 31 | ||
| @@ -59,22 +60,22 @@ | |||
| 59 | 60 | ||
| 60 | (ert-deftest ls-lisp-test-bug27631 () | 61 | (ert-deftest ls-lisp-test-bug27631 () |
| 61 | "Test for https://debbugs.gnu.org/27631 ." | 62 | "Test for https://debbugs.gnu.org/27631 ." |
| 62 | (let* ((dir (make-temp-file "bug27631" 'dir)) | 63 | (ert-with-temp-directory dir |
| 63 | (dir1 (expand-file-name "dir1" dir)) | 64 | :suffix "bug27631" |
| 64 | (dir2 (expand-file-name "dir2" dir)) | 65 | (let* ((dir1 (expand-file-name "dir1" dir)) |
| 65 | (default-directory dir) | 66 | (dir2 (expand-file-name "dir2" dir)) |
| 66 | ls-lisp-use-insert-directory-program buf) | 67 | (default-directory dir) |
| 67 | (unwind-protect | 68 | ls-lisp-use-insert-directory-program buf) |
| 68 | (progn | 69 | (unwind-protect |
| 69 | (make-directory dir1) | 70 | (progn |
| 70 | (make-directory dir2) | 71 | (make-directory dir1) |
| 71 | (with-temp-file (expand-file-name "a.txt" dir1)) | 72 | (make-directory dir2) |
| 72 | (with-temp-file (expand-file-name "b.txt" dir2)) | 73 | (with-temp-file (expand-file-name "a.txt" dir1)) |
| 73 | (setq buf (dired (expand-file-name "dir*/*.txt" dir))) | 74 | (with-temp-file (expand-file-name "b.txt" dir2)) |
| 74 | (dired-toggle-marks) | 75 | (setq buf (dired (expand-file-name "dir*/*.txt" dir))) |
| 75 | (should (cdr (dired-get-marked-files)))) | 76 | (dired-toggle-marks) |
| 76 | (delete-directory dir 'recursive) | 77 | (should (cdr (dired-get-marked-files)))) |
| 77 | (when (buffer-live-p buf) (kill-buffer buf))))) | 78 | (when (buffer-live-p buf) (kill-buffer buf)))))) |
| 78 | 79 | ||
| 79 | (ert-deftest ls-lisp-test-bug27693 () | 80 | (ert-deftest ls-lisp-test-bug27693 () |
| 80 | "Test for https://debbugs.gnu.org/27693 ." | 81 | "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.") | |||
| 50 | (should (equal (buffer-string) uudecode-tests-decoded-str))) | 50 | (should (equal (buffer-string) uudecode-tests-decoded-str))) |
| 51 | ;; Write to file | 51 | ;; Write to file |
| 52 | (with-temp-buffer | 52 | (with-temp-buffer |
| 53 | (let ((tmpfile (make-temp-file "uudecode-tests-"))) | 53 | (ert-with-temp-file tmpfile |
| 54 | (unwind-protect | 54 | (insert uudecode-tests-encoded-str) |
| 55 | (progn | 55 | (uudecode-decode-region-internal (point-min) (point-max) tmpfile) |
| 56 | (insert uudecode-tests-encoded-str) | 56 | (should (equal (uudecode-tests-read-file tmpfile) |
| 57 | (uudecode-decode-region-internal (point-min) (point-max) tmpfile) | 57 | uudecode-tests-decoded-str))))) |
| 58 | (should (equal (uudecode-tests-read-file tmpfile) | ||
| 59 | uudecode-tests-decoded-str))) | ||
| 60 | (delete-file tmpfile))))) | ||
| 61 | 58 | ||
| 62 | (ert-deftest uudecode-tests-decode-region-external () | 59 | (ert-deftest uudecode-tests-decode-region-external () |
| 63 | ;; Write to buffer | 60 | ;; Write to buffer |
| @@ -68,14 +65,11 @@ Same as `uudecode-tests-encoded-str' but plain text.") | |||
| 68 | (should (equal (buffer-string) uudecode-tests-decoded-str))) | 65 | (should (equal (buffer-string) uudecode-tests-decoded-str))) |
| 69 | ;; Write to file | 66 | ;; Write to file |
| 70 | (with-temp-buffer | 67 | (with-temp-buffer |
| 71 | (let ((tmpfile (make-temp-file "uudecode-tests-"))) | 68 | (ert-with-temp-file tmpfile |
| 72 | (unwind-protect | 69 | (insert uudecode-tests-encoded-str) |
| 73 | (progn | 70 | (uudecode-decode-region-external (point-min) (point-max) tmpfile) |
| 74 | (insert uudecode-tests-encoded-str) | 71 | (should (equal (uudecode-tests-read-file tmpfile) |
| 75 | (uudecode-decode-region-external (point-min) (point-max) tmpfile) | 72 | uudecode-tests-decoded-str)))))) |
| 76 | (should (equal (uudecode-tests-read-file tmpfile) | ||
| 77 | uudecode-tests-decoded-str))) | ||
| 78 | (delete-file tmpfile)))))) | ||
| 79 | 73 | ||
| 80 | (provide 'uudecode-tests) | 74 | (provide 'uudecode-tests) |
| 81 | ;;; uudecode-tests.el ends here | 75 | ;;; 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 @@ | |||
| 28 | 28 | ||
| 29 | (require 'browse-url) | 29 | (require 'browse-url) |
| 30 | (require 'ert) | 30 | (require 'ert) |
| 31 | (require 'ert-x) | ||
| 31 | 32 | ||
| 32 | (ert-deftest browse-url-tests-browser-kind () | 33 | (ert-deftest browse-url-tests-browser-kind () |
| 33 | (should (eq (browse-url--browser-kind #'browse-url-w3 "gnu.org") | 34 | (should (eq (browse-url--browser-kind #'browse-url-w3 "gnu.org") |
| @@ -87,11 +88,10 @@ | |||
| 87 | "ftp://foo/"))) | 88 | "ftp://foo/"))) |
| 88 | 89 | ||
| 89 | (ert-deftest browse-url-tests-delete-temp-file () | 90 | (ert-deftest browse-url-tests-delete-temp-file () |
| 90 | (let ((browse-url-temp-file-name | 91 | (ert-with-temp-file browse-url-temp-file-name |
| 91 | (make-temp-file "browse-url-tests-"))) | ||
| 92 | (browse-url-delete-temp-file) | 92 | (browse-url-delete-temp-file) |
| 93 | (should-not (file-exists-p browse-url-temp-file-name))) | 93 | (should-not (file-exists-p browse-url-temp-file-name))) |
| 94 | (let ((file (make-temp-file "browse-url-tests-"))) | 94 | (ert-with-temp-file file |
| 95 | (browse-url-delete-temp-file file) | 95 | (browse-url-delete-temp-file file) |
| 96 | (should-not (file-exists-p file)))) | 96 | (should-not (file-exists-p file)))) |
| 97 | 97 | ||
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 @@ | |||
| 302 | 302 | ||
| 303 | ;; tmp may be on a different filesystem to the tests, but, ehh. | 303 | ;; tmp may be on a different filesystem to the tests, but, ehh. |
| 304 | (defvar xref--case-insensitive | 304 | (defvar xref--case-insensitive |
| 305 | (let ((dir (make-temp-file "xref-test" t))) | 305 | (ert-with-temp-directory dir |
| 306 | (unwind-protect | 306 | (with-temp-file (expand-file-name "hElLo" dir) "hello") |
| 307 | (progn | 307 | (file-exists-p (expand-file-name "HELLO" dir))) |
| 308 | (with-temp-file (expand-file-name "hElLo" dir) "hello") | ||
| 309 | (file-exists-p (expand-file-name "HELLO" dir))) | ||
| 310 | (delete-directory dir t))) | ||
| 311 | "Non-nil if file system seems to be case-insensitive.") | 308 | "Non-nil if file system seems to be case-insensitive.") |
| 312 | 309 | ||
| 313 | (defun xref-elisp-test-run (xrefs expected-xrefs) | 310 | (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 @@ | |||
| 22 | ;;; Code: | 22 | ;;; Code: |
| 23 | 23 | ||
| 24 | (require 'ert) | 24 | (require 'ert) |
| 25 | (require 'ert-x) | ||
| 25 | (require 'etags) | 26 | (require 'etags) |
| 26 | (eval-when-compile (require 'cl-lib)) | 27 | (eval-when-compile (require 'cl-lib)) |
| 27 | 28 | ||
| @@ -95,21 +96,19 @@ | |||
| 95 | 96 | ||
| 96 | (ert-deftest etags-buffer-local-tags-table-list () | 97 | (ert-deftest etags-buffer-local-tags-table-list () |
| 97 | "Test that a buffer-local value of `tags-table-list' is used." | 98 | "Test that a buffer-local value of `tags-table-list' is used." |
| 98 | (let ((file (make-temp-file "etag-test-tmpfile"))) | 99 | (ert-with-temp-file file |
| 99 | (unwind-protect | 100 | :suffix "etag-test-tmpfile" |
| 100 | (progn | 101 | (set-buffer (find-file-noselect file)) |
| 101 | (set-buffer (find-file-noselect file)) | 102 | (fundamental-mode) |
| 102 | (fundamental-mode) | 103 | (setq-local tags-table-list |
| 103 | (setq-local tags-table-list | 104 | (list (expand-file-name "manual/etags/ETAGS.good_3" |
| 104 | (list (expand-file-name "manual/etags/ETAGS.good_3" | 105 | etags-tests--test-dir))) |
| 105 | etags-tests--test-dir))) | 106 | (cl-letf ((tag-tables tags-table-list) |
| 106 | (cl-letf ((tag-tables tags-table-list) | 107 | (tags-file-name nil) |
| 107 | (tags-file-name nil) | 108 | ((symbol-function 'read-file-name) |
| 108 | ((symbol-function 'read-file-name) | 109 | (lambda (&rest _) |
| 109 | (lambda (&rest _) | 110 | (error "We should not prompt the user")))) |
| 110 | (error "We should not prompt the user")))) | 111 | (should (visit-tags-table-buffer)) |
| 111 | (should (visit-tags-table-buffer)) | 112 | (should (equal tags-file-name (car tag-tables)))))) |
| 112 | (should (equal tags-file-name (car tag-tables))))) | ||
| 113 | (delete-file file)))) | ||
| 114 | 113 | ||
| 115 | ;;; etags-tests.el ends here | 114 | ;;; 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 @@ | |||
| 23 | 23 | ||
| 24 | ;;; Code: | 24 | ;;; Code: |
| 25 | (require 'ert) | 25 | (require 'ert) |
| 26 | (require 'ert-x) | ||
| 26 | (require 'flymake) | 27 | (require 'flymake) |
| 27 | (eval-when-compile (require 'subr-x)) ; string-trim | 28 | (eval-when-compile (require 'subr-x)) ; string-trim |
| 28 | 29 | ||
| @@ -123,22 +124,21 @@ SEVERITY-PREDICATE is used to setup | |||
| 123 | "Test the ruby backend." | 124 | "Test the ruby backend." |
| 124 | (skip-unless (executable-find "ruby")) | 125 | (skip-unless (executable-find "ruby")) |
| 125 | ;; Some versions of ruby fail if HOME doesn't exist (bug#29187). | 126 | ;; Some versions of ruby fail if HOME doesn't exist (bug#29187). |
| 126 | (let* ((tempdir (make-temp-file "flymake-tests-ruby" t)) | 127 | (ert-with-temp-directory tempdir |
| 127 | (process-environment (cons (format "HOME=%s" tempdir) | 128 | :suffix "flymake-tests-ruby" |
| 128 | process-environment)) | 129 | (let* ((process-environment (cons (format "HOME=%s" tempdir) |
| 129 | ;; And see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19657#20 | 130 | process-environment)) |
| 130 | ;; for this particular yuckiness | 131 | ;; And see https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19657#20 |
| 131 | (abbreviated-home-dir nil)) | 132 | ;; for this particular yuckiness |
| 132 | (unwind-protect | 133 | (abbreviated-home-dir nil) |
| 133 | (let ((ruby-mode-hook | 134 | (ruby-mode-hook |
| 134 | (lambda () | 135 | (lambda () |
| 135 | (setq flymake-diagnostic-functions '(ruby-flymake-simple))))) | 136 | (setq flymake-diagnostic-functions '(ruby-flymake-simple))))) |
| 136 | (flymake-tests--with-flymake ("test.rb") | 137 | (flymake-tests--with-flymake ("test.rb") |
| 137 | (flymake-goto-next-error) | 138 | (flymake-goto-next-error) |
| 138 | (should (eq 'flymake-warning (face-at-point))) | 139 | (should (eq 'flymake-warning (face-at-point))) |
| 139 | (flymake-goto-next-error) | 140 | (flymake-goto-next-error) |
| 140 | (should (eq 'flymake-error (face-at-point))))) | 141 | (should (eq 'flymake-error (face-at-point))))))) |
| 141 | (delete-directory tempdir t)))) | ||
| 142 | 142 | ||
| 143 | (ert-deftest different-diagnostic-types () | 143 | (ert-deftest different-diagnostic-types () |
| 144 | "Test GCC warning via function predicate." | 144 | "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 @@ | |||
| 22 | ;;; Code: | 22 | ;;; Code: |
| 23 | 23 | ||
| 24 | (require 'ert) | 24 | (require 'ert) |
| 25 | (require 'ert-x) | ||
| 25 | (require 'python) | 26 | (require 'python) |
| 26 | 27 | ||
| 27 | ;; Dependencies for testing: | 28 | ;; Dependencies for testing: |
| @@ -48,17 +49,17 @@ BODY is code to be executed within the temp buffer. Point is | |||
| 48 | always located at the beginning of buffer." | 49 | always located at the beginning of buffer." |
| 49 | (declare (indent 1) (debug t)) | 50 | (declare (indent 1) (debug t)) |
| 50 | ;; temp-file never actually used for anything? | 51 | ;; temp-file never actually used for anything? |
| 51 | `(let* ((temp-file (make-temp-file "python-tests" nil ".py")) | 52 | `(ert-with-temp-file temp-file |
| 52 | (buffer (find-file-noselect temp-file)) | 53 | :suffix "-python.py" |
| 53 | (python-indent-guess-indent-offset nil)) | 54 | (let ((buffer (find-file-noselect temp-file)) |
| 54 | (unwind-protect | 55 | (python-indent-guess-indent-offset nil)) |
| 55 | (with-current-buffer buffer | 56 | (unwind-protect |
| 56 | (python-mode) | 57 | (with-current-buffer buffer |
| 57 | (insert ,contents) | 58 | (python-mode) |
| 58 | (goto-char (point-min)) | 59 | (insert ,contents) |
| 59 | ,@body) | 60 | (goto-char (point-min)) |
| 60 | (and buffer (kill-buffer buffer)) | 61 | ,@body) |
| 61 | (delete-file temp-file)))) | 62 | (and buffer (kill-buffer buffer)))))) |
| 62 | 63 | ||
| 63 | (defun python-tests-look-at (string &optional num restore-point) | 64 | (defun python-tests-look-at (string &optional num restore-point) |
| 64 | "Move point at beginning of STRING in the current buffer. | 65 | "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 @@ | |||
| 28 | 28 | ||
| 29 | (require 'cl-lib) | 29 | (require 'cl-lib) |
| 30 | (require 'ert) | 30 | (require 'ert) |
| 31 | (require 'ert-x) | ||
| 31 | (require 'sql) | 32 | (require 'sql) |
| 32 | 33 | ||
| 33 | (ert-deftest sql-tests-postgres-list-databases () | 34 | (ert-deftest sql-tests-postgres-list-databases () |
| @@ -63,52 +64,49 @@ Identify tests by ID. Set :sql-login dialect attribute to | |||
| 63 | LOGIN-PARAMS. Provide the CONNECTION parameters and the EXPECTED | 64 | LOGIN-PARAMS. Provide the CONNECTION parameters and the EXPECTED |
| 64 | string of values passed to the comint function for validation." | 65 | string of values passed to the comint function for validation." |
| 65 | (declare (indent 2)) | 66 | (declare (indent 2)) |
| 66 | `(cl-letf | 67 | `(ert-with-temp-file tempfile |
| 67 | ((sql-test-login-params ' ,login-params) | 68 | :suffix "sql-test-netrc" |
| 68 | ((symbol-function 'sql-comint-test) | 69 | :text (concat |
| 69 | (lambda (product options &optional buf-name) | 70 | "machine aMachine user aUserName password \"netrc-A aPassword\"" |
| 70 | (with-current-buffer (get-buffer-create buf-name) | 71 | "machine aServer user aUserName password \"netrc-B aPassword\"" |
| 71 | (insert (pp-to-string (list product options sql-user sql-password sql-server sql-database)))))) | 72 | "machine aMachine server aServer user aUserName password \"netrc-C aPassword\"" |
| 72 | ((symbol-function 'sql-run-test) | 73 | "machine aMachine database aDatabase user aUserName password \"netrc-D aPassword\"" |
| 73 | (lambda (&optional buffer) | 74 | "machine aDatabase user aUserName password \"netrc-E aPassword\"" |
| 74 | (interactive "P") | 75 | "machine aMachine server aServer database aDatabase user aUserName password \"netrc-F aPassword\"" |
| 75 | (sql-product-interactive 'sqltest buffer))) | 76 | "machine \"aServer/aDatabase\" user aUserName password \"netrc-G aPassword\"" |
| 76 | (sql-user nil) | 77 | "\n") |
| 77 | (sql-server nil) | 78 | (cl-letf |
| 78 | (sql-database nil) | 79 | ((sql-test-login-params ' ,login-params) |
| 79 | (sql-product-alist | 80 | ((symbol-function 'sql-comint-test) |
| 80 | '((ansi) | 81 | (lambda (product options &optional buf-name) |
| 81 | (sqltest | 82 | (with-current-buffer (get-buffer-create buf-name) |
| 82 | :name "SqlTest" | 83 | (insert (pp-to-string (list product options sql-user sql-password sql-server sql-database)))))) |
| 83 | :sqli-login sql-test-login-params | 84 | ((symbol-function 'sql-run-test) |
| 84 | :sqli-comint-func sql-comint-test))) | 85 | (lambda (&optional buffer) |
| 85 | (sql-connection-alist | 86 | (interactive "P") |
| 86 | '((,(format "test-%s" id) | 87 | (sql-product-interactive 'sqltest buffer))) |
| 87 | ,@connection))) | 88 | (sql-user nil) |
| 88 | (sql-password-wallet | 89 | (sql-server nil) |
| 89 | (list | 90 | (sql-database nil) |
| 90 | (make-temp-file | 91 | (sql-product-alist |
| 91 | "sql-test-netrc" nil nil | 92 | '((ansi) |
| 92 | (mapconcat #'identity | 93 | (sqltest |
| 93 | '("machine aMachine user aUserName password \"netrc-A aPassword\"" | 94 | :name "SqlTest" |
| 94 | "machine aServer user aUserName password \"netrc-B aPassword\"" | 95 | :sqli-login sql-test-login-params |
| 95 | "machine aMachine server aServer user aUserName password \"netrc-C aPassword\"" | 96 | :sqli-comint-func sql-comint-test))) |
| 96 | "machine aMachine database aDatabase user aUserName password \"netrc-D aPassword\"" | 97 | (sql-connection-alist |
| 97 | "machine aDatabase user aUserName password \"netrc-E aPassword\"" | 98 | '((,(format "test-%s" id) |
| 98 | "machine aMachine server aServer database aDatabase user aUserName password \"netrc-F aPassword\"" | 99 | ,@connection))) |
| 99 | "machine \"aServer/aDatabase\" user aUserName password \"netrc-G aPassword\"" | 100 | (sql-password-wallet (list tempfile))) |
| 100 | ) "\n"))))) | 101 | (let* ((connection ,(format "test-%s" id)) |
| 101 | 102 | (buffername (format "*SQL: ERT TEST <%s>*" connection))) | |
| 102 | (let* ((connection ,(format "test-%s" id)) | 103 | (when (get-buffer buffername) |
| 103 | (buffername (format "*SQL: ERT TEST <%s>*" connection))) | 104 | (kill-buffer buffername)) |
| 104 | (when (get-buffer buffername) | 105 | (sql-connect connection buffername) |
| 105 | (kill-buffer buffername)) | 106 | (should (get-buffer buffername)) |
| 106 | (sql-connect connection buffername) | 107 | (should (string-equal (with-current-buffer buffername (buffer-string)) ,expected)) |
| 107 | (should (get-buffer buffername)) | 108 | (when (get-buffer buffername) |
| 108 | (should (string-equal (with-current-buffer buffername (buffer-string)) ,expected)) | 109 | (kill-buffer buffername)))))) |
| 109 | (when (get-buffer buffername) | ||
| 110 | (kill-buffer buffername)) | ||
| 111 | (delete-file (car sql-password-wallet))))) | ||
| 112 | 110 | ||
| 113 | (ert-deftest sql-test-connect () | 111 | (ert-deftest sql-test-connect () |
| 114 | "Test of basic `sql-connect'." | 112 | "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 @@ | |||
| 41 | 41 | ||
| 42 | (ert-deftest saveplace-test-save-place-to-alist/file () | 42 | (ert-deftest saveplace-test-save-place-to-alist/file () |
| 43 | (save-place-mode) | 43 | (save-place-mode) |
| 44 | (let* ((tmpfile (make-temp-file "emacs-test-saveplace-")) | 44 | (ert-with-temp-file tmpfile |
| 45 | (tmpfile (file-truename tmpfile)) | 45 | (let* ((tmpfile (file-truename tmpfile)) |
| 46 | (save-place-alist nil) | 46 | (save-place-alist nil) |
| 47 | (save-place-loaded t) | 47 | (save-place-loaded t) |
| 48 | (loc tmpfile) | 48 | (loc tmpfile) |
| 49 | (pos 4)) | 49 | (pos 4)) |
| 50 | (unwind-protect | 50 | (save-window-excursion |
| 51 | (save-window-excursion | 51 | (find-file loc) |
| 52 | (find-file loc) | 52 | (insert "abc") ; must insert something |
| 53 | (insert "abc") ; must insert something | 53 | (save-place-to-alist) |
| 54 | (save-place-to-alist) | 54 | (should (equal save-place-alist (list (cons tmpfile pos)))))))) |
| 55 | (should (equal save-place-alist (list (cons tmpfile pos))))) | ||
| 56 | (delete-file tmpfile)))) | ||
| 57 | 55 | ||
| 58 | (ert-deftest saveplace-test-forget-unreadable-files () | 56 | (ert-deftest saveplace-test-forget-unreadable-files () |
| 59 | (save-place-mode) | 57 | (save-place-mode) |
| 60 | (let* ((save-place-loaded t) | 58 | (ert-with-temp-file tmpfile |
| 61 | (tmpfile (make-temp-file "emacs-test-saveplace-")) | 59 | :suffix "-saveplace" |
| 62 | (alist-orig (list (cons "/this/file/does/not/exist" 10) | 60 | (let* ((save-place-loaded t) |
| 63 | (cons tmpfile 1917))) | 61 | (alist-orig (list (cons "/this/file/does/not/exist" 10) |
| 64 | (save-place-alist alist-orig)) | 62 | (cons tmpfile 1917))) |
| 65 | (unwind-protect | 63 | (save-place-alist alist-orig)) |
| 66 | (progn | 64 | (save-place-forget-unreadable-files) |
| 67 | (save-place-forget-unreadable-files) | 65 | (should (equal save-place-alist (cdr alist-orig)))))) |
| 68 | (should (equal save-place-alist (cdr alist-orig)))) | ||
| 69 | (delete-file tmpfile)))) | ||
| 70 | 66 | ||
| 71 | (ert-deftest saveplace-test-place-alist-to-file () | 67 | (ert-deftest saveplace-test-place-alist-to-file () |
| 72 | (save-place-mode) | 68 | (save-place-mode) |
| 73 | (let* ((tmpfile (make-temp-file "emacs-test-saveplace-")) | 69 | (ert-with-temp-file tmpfile |
| 74 | (tmpfile2 (make-temp-file "emacs-test-saveplace-")) | 70 | (ert-with-temp-file tmpfile2 |
| 75 | (save-place-file tmpfile) | 71 | (let* ((save-place-file tmpfile) |
| 76 | (save-place-alist (list (cons tmpfile2 99)))) | 72 | (save-place-alist (list (cons tmpfile2 99)))) |
| 77 | (unwind-protect | 73 | (save-place-alist-to-file) |
| 78 | (progn (save-place-alist-to-file) | 74 | (setq save-place-alist nil) |
| 79 | (setq save-place-alist nil) | 75 | (save-window-excursion |
| 80 | (save-window-excursion | 76 | (find-file save-place-file) |
| 81 | (find-file save-place-file) | 77 | (unwind-protect |
| 82 | (unwind-protect | 78 | (should (string-match tmpfile2 (buffer-string))) |
| 83 | (should (string-match tmpfile2 (buffer-string))) | 79 | (kill-buffer))))))) |
| 84 | (kill-buffer)))) | ||
| 85 | (delete-file tmpfile) | ||
| 86 | (delete-file tmpfile2)))) | ||
| 87 | 80 | ||
| 88 | (ert-deftest saveplace-test-load-alist-from-file () | 81 | (ert-deftest saveplace-test-load-alist-from-file () |
| 89 | (save-place-mode) | 82 | (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 @@ | |||
| 23 | ;;; Code: | 23 | ;;; Code: |
| 24 | 24 | ||
| 25 | (require 'ert) | 25 | (require 'ert) |
| 26 | (require 'ert-x) | ||
| 26 | (require 'ispell) | 27 | (require 'ispell) |
| 27 | (require 'cl-lib) | 28 | (require 'cl-lib) |
| 28 | 29 | ||
| @@ -50,20 +51,19 @@ | |||
| 50 | ;; The Emacs test Makefile's use of HOME=/nonexistent triggers an error | 51 | ;; The Emacs test Makefile's use of HOME=/nonexistent triggers an error |
| 51 | ;; when starting the inferior ispell process, so we set HOME to a valid | 52 | ;; when starting the inferior ispell process, so we set HOME to a valid |
| 52 | ;; (but empty) temporary directory for this test. | 53 | ;; (but empty) temporary directory for this test. |
| 53 | (let* ((tmpdir (make-temp-file "so-long." :dir ".ispell")) | 54 | (ert-with-temp-file tmpdir |
| 54 | (process-environment (cons (format "HOME=%s" tmpdir) | 55 | :suffix "so-long.ispell" |
| 55 | process-environment)) | 56 | (let* ((process-environment (cons (format "HOME=%s" tmpdir) |
| 56 | (find-spelling-mistake | 57 | process-environment)) |
| 57 | (unwind-protect | 58 | (find-spelling-mistake |
| 58 | (cl-letf (((symbol-function 'ispell-command-loop) | 59 | (cl-letf (((symbol-function 'ispell-command-loop) |
| 59 | (lambda (_miss _guess word _start _end) | 60 | (lambda (_miss _guess word _start _end) |
| 60 | (message "Unrecognised word: %s." word) | 61 | (message "Unrecognised word: %s." word) |
| 61 | (throw 'mistake t)))) | 62 | (throw 'mistake t)))) |
| 62 | (catch 'mistake | 63 | (catch 'mistake |
| 63 | (find-library "so-long") | 64 | (find-library "so-long") |
| 64 | (ispell-buffer) | 65 | (ispell-buffer) |
| 65 | nil)) | 66 | nil)))) |
| 66 | (delete-directory tmpdir)))) | 67 | (should (not find-spelling-mistake)))))) |
| 67 | (should (not find-spelling-mistake))))) | ||
| 68 | 68 | ||
| 69 | ;;; spelling-tests.el ends here | 69 | ;;; 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 @@ | |||
| 24 | ;;; Code: | 24 | ;;; Code: |
| 25 | 25 | ||
| 26 | (require 'ert) | 26 | (require 'ert) |
| 27 | (require 'ert-x) | ||
| 27 | 28 | ||
| 28 | ;;; reftex | 29 | ;;; reftex |
| 29 | (require 'reftex) | 30 | (require 'reftex) |
| @@ -33,32 +34,31 @@ | |||
| 33 | 34 | ||
| 34 | (ert-deftest reftex-locate-bibliography-files () | 35 | (ert-deftest reftex-locate-bibliography-files () |
| 35 | "Test `reftex-locate-bibliography-files'." | 36 | "Test `reftex-locate-bibliography-files'." |
| 36 | (let ((temp-dir (make-temp-file "reftex-bib" 'dir)) | 37 | (ert-with-temp-directory temp-dir |
| 37 | (files '("ref1.bib" "ref2.bib")) | 38 | (let ((files '("ref1.bib" "ref2.bib")) |
| 38 | (test '(("\\addbibresource{ref1.bib}\n" . ("ref1.bib")) | 39 | (test '(("\\addbibresource{ref1.bib}\n" . ("ref1.bib")) |
| 39 | ("\\\\addbibresource[label=x]{ref2.bib}\\n" . ("ref2.bib")) | 40 | ("\\\\addbibresource[label=x]{ref2.bib}\\n" . ("ref2.bib")) |
| 40 | ("\\begin{document}\n\\bibliographystyle{plain}\n | 41 | ("\\begin{document}\n\\bibliographystyle{plain}\n |
| 41 | \\bibliography{ref1,ref2}\n\\end{document}" . ("ref1.bib" "ref2.bib")))) | 42 | \\bibliography{ref1,ref2}\n\\end{document}" . ("ref1.bib" "ref2.bib")))) |
| 42 | (reftex-bibliography-commands | 43 | (reftex-bibliography-commands |
| 43 | ;; Default value: See reftex-vars.el `reftex-bibliography-commands' | 44 | ;; Default value: See reftex-vars.el `reftex-bibliography-commands' |
| 44 | '("bibliography" "nobibliography" "setupbibtex\\[.*?database=" | 45 | '("bibliography" "nobibliography" "setupbibtex\\[.*?database=" |
| 45 | "addbibresource"))) | 46 | "addbibresource"))) |
| 46 | (with-temp-buffer | 47 | (with-temp-buffer |
| 47 | (insert "test\n") | 48 | (insert "test\n") |
| 49 | (mapc | ||
| 50 | (lambda (file) | ||
| 51 | (write-region (point-min) (point-max) (expand-file-name file | ||
| 52 | temp-dir))) | ||
| 53 | files)) | ||
| 48 | (mapc | 54 | (mapc |
| 49 | (lambda (file) | 55 | (lambda (data) |
| 50 | (write-region (point-min) (point-max) (expand-file-name file | 56 | (with-temp-buffer |
| 51 | temp-dir))) | 57 | (insert (car data)) |
| 52 | files)) | 58 | (let ((res (mapcar #'file-name-nondirectory |
| 53 | (mapc | 59 | (reftex-locate-bibliography-files temp-dir)))) |
| 54 | (lambda (data) | 60 | (should (equal res (cdr data)))))) |
| 55 | (with-temp-buffer | 61 | test)))) |
| 56 | (insert (car data)) | ||
| 57 | (let ((res (mapcar #'file-name-nondirectory | ||
| 58 | (reftex-locate-bibliography-files temp-dir)))) | ||
| 59 | (should (equal res (cdr data)))))) | ||
| 60 | test) | ||
| 61 | (delete-directory temp-dir 'recursive))) | ||
| 62 | 62 | ||
| 63 | (ert-deftest reftex-what-environment-test () | 63 | (ert-deftest reftex-what-environment-test () |
| 64 | "Test `reftex-what-environment'." | 64 | "Test `reftex-what-environment'." |
| @@ -102,12 +102,12 @@ | |||
| 102 | ;; reason. (An alternative solution would be to use file-equal-p, | 102 | ;; reason. (An alternative solution would be to use file-equal-p, |
| 103 | ;; but I'm too lazy to do that, as one of the tests compares a | 103 | ;; but I'm too lazy to do that, as one of the tests compares a |
| 104 | ;; list.) | 104 | ;; list.) |
| 105 | (let* ((temp-dir (file-truename (make-temp-file "reftex-parse" 'dir))) | 105 | (ert-with-temp-directory temp-dir |
| 106 | (tex-file (expand-file-name "test.tex" temp-dir)) | 106 | (let* ((tex-file (expand-file-name "test.tex" temp-dir)) |
| 107 | (bib-file (expand-file-name "ref.bib" temp-dir))) | 107 | (bib-file (expand-file-name "ref.bib" temp-dir))) |
| 108 | (with-temp-buffer | 108 | (with-temp-buffer |
| 109 | (insert | 109 | (insert |
| 110 | "\\begin{document} | 110 | "\\begin{document} |
| 111 | \\section{test}\\label{sec:test} | 111 | \\section{test}\\label{sec:test} |
| 112 | \\subsection{subtest} | 112 | \\subsection{subtest} |
| 113 | 113 | ||
| @@ -118,27 +118,26 @@ | |||
| 118 | \\bibliographystyle{plain} | 118 | \\bibliographystyle{plain} |
| 119 | \\bibliography{ref} | 119 | \\bibliography{ref} |
| 120 | \\end{document}") | 120 | \\end{document}") |
| 121 | (write-region (point-min) (point-max) tex-file)) | 121 | (write-region (point-min) (point-max) tex-file)) |
| 122 | (with-temp-buffer | 122 | (with-temp-buffer |
| 123 | (insert "test\n") | 123 | (insert "test\n") |
| 124 | (write-region (point-min) (point-max) bib-file)) | 124 | (write-region (point-min) (point-max) bib-file)) |
| 125 | (reftex-ensure-compiled-variables) | 125 | (reftex-ensure-compiled-variables) |
| 126 | (let ((parsed (reftex-parse-from-file tex-file nil temp-dir))) | 126 | (let ((parsed (reftex-parse-from-file tex-file nil temp-dir))) |
| 127 | (should (equal (car parsed) `(eof ,tex-file))) | 127 | (should (equal (car parsed) `(eof ,tex-file))) |
| 128 | (pop parsed) | 128 | (pop parsed) |
| 129 | (while parsed | 129 | (while parsed |
| 130 | (let ((entry (pop parsed))) | 130 | (let ((entry (pop parsed))) |
| 131 | (cond | 131 | (cond |
| 132 | ((eq (car entry) 'bib) | 132 | ((eq (car entry) 'bib) |
| 133 | (should (string= (cadr entry) bib-file))) | 133 | (should (string= (cadr entry) bib-file))) |
| 134 | ((eq (car entry) 'toc)) ;; ... | 134 | ((eq (car entry) 'toc)) ;; ... |
| 135 | ((string= (car entry) "eq:foo")) | 135 | ((string= (car entry) "eq:foo")) |
| 136 | ((string= (car entry) "sec:test")) | 136 | ((string= (car entry) "sec:test")) |
| 137 | ((eq (car entry) 'bof) | 137 | ((eq (car entry) 'bof) |
| 138 | (should (string= (cadr entry) tex-file)) | 138 | (should (string= (cadr entry) tex-file)) |
| 139 | (should (null parsed))) | 139 | (should (null parsed))) |
| 140 | (t (should-not t))))) | 140 | (t (should-not t))))))))) |
| 141 | (delete-directory temp-dir 'recursive)))) | ||
| 142 | 141 | ||
| 143 | ;;; reftex-cite | 142 | ;;; reftex-cite |
| 144 | (require 'reftex-cite) | 143 | (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 @@ | |||
| 20 | ;;; Code: | 20 | ;;; Code: |
| 21 | 21 | ||
| 22 | (require 'ert) | 22 | (require 'ert) |
| 23 | (require 'ert-x) | ||
| 23 | (require 'thumbs) | 24 | (require 'thumbs) |
| 24 | 25 | ||
| 25 | (ert-deftest thumbs-tests-thumbsdir/create-if-missing () | 26 | (ert-deftest thumbs-tests-thumbsdir/create-if-missing () |
| 26 | (let ((thumbs-thumbsdir (make-temp-file "thumbs-test" t))) | 27 | (ert-with-temp-directory thumbs-thumbsdir |
| 27 | (unwind-protect | 28 | (delete-directory thumbs-thumbsdir) |
| 28 | (progn | 29 | (should (file-directory-p (thumbs-thumbsdir))))) |
| 29 | (delete-directory thumbs-thumbsdir) | ||
| 30 | (should (file-directory-p (thumbs-thumbsdir)))) | ||
| 31 | (delete-directory thumbs-thumbsdir)))) | ||
| 32 | 30 | ||
| 33 | (provide 'thumbs-tests) | 31 | (provide 'thumbs-tests) |
| 34 | ;;; thumbs-tests.el ends here | 32 | ;;; 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 | |||
| 173 | wrongheadedly | 173 | wrongheadedly |
| 174 | wrongheadedness | 174 | wrongheadedness |
| 175 | youthfulness | 175 | youthfulness |
| 176 | ") | 176 | ")) |
| 177 | (temp-dir (make-temp-file "diff-mode-test" 'dir))) | 177 | (ert-with-temp-directory temp-dir |
| 178 | 178 | (let ((buf (find-file-noselect (format "%s/%s" temp-dir "fil" ))) | |
| 179 | (let ((buf (find-file-noselect (format "%s/%s" temp-dir "fil" ))) | 179 | (buf2 (find-file-noselect (format "%s/%s" temp-dir "fil2")))) |
| 180 | (buf2 (find-file-noselect (format "%s/%s" temp-dir "fil2")))) | 180 | (unwind-protect |
| 181 | (unwind-protect | 181 | (progn |
| 182 | (progn | 182 | (with-current-buffer buf (insert fil_before) (save-buffer)) |
| 183 | (with-current-buffer buf (insert fil_before) (save-buffer)) | 183 | (with-current-buffer buf2 (insert fil2_before) (save-buffer)) |
| 184 | (with-current-buffer buf2 (insert fil2_before) (save-buffer)) | 184 | |
| 185 | 185 | (with-temp-buffer | |
| 186 | (with-temp-buffer | 186 | (cd temp-dir) |
| 187 | (cd temp-dir) | 187 | (insert patch) |
| 188 | (insert patch) | 188 | (goto-char (point-min)) |
| 189 | (goto-char (point-min)) | 189 | (diff-apply-hunk) |
| 190 | (diff-apply-hunk) | 190 | (diff-apply-hunk) |
| 191 | (diff-apply-hunk) | 191 | (diff-apply-hunk)) |
| 192 | (diff-apply-hunk)) | 192 | |
| 193 | 193 | (should (equal (with-current-buffer buf (buffer-string)) | |
| 194 | (should (equal (with-current-buffer buf (buffer-string)) | 194 | fil_after)) |
| 195 | fil_after)) | 195 | (should (equal (with-current-buffer buf2 (buffer-string)) |
| 196 | (should (equal (with-current-buffer buf2 (buffer-string)) | 196 | fil2_after))) |
| 197 | fil2_after))) | 197 | |
| 198 | 198 | (ignore-errors | |
| 199 | (ignore-errors | 199 | (with-current-buffer buf (set-buffer-modified-p nil)) |
| 200 | (with-current-buffer buf (set-buffer-modified-p nil)) | 200 | (kill-buffer buf) |
| 201 | (kill-buffer buf) | 201 | (with-current-buffer buf2 (set-buffer-modified-p nil)) |
| 202 | (with-current-buffer buf2 (set-buffer-modified-p nil)) | 202 | (kill-buffer buf2))))))) |
| 203 | (kill-buffer buf2) | ||
| 204 | (delete-directory temp-dir 'recursive)))))) | ||
| 205 | 203 | ||
| 206 | (ert-deftest diff-mode-test-hunk-text-no-newline () | 204 | (ert-deftest diff-mode-test-hunk-text-no-newline () |
| 207 | "Check output of `diff-hunk-text' with no newline at end of file." | 205 | "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 @@ | |||
| 22 | ;;; Code: | 22 | ;;; Code: |
| 23 | 23 | ||
| 24 | (require 'ert) | 24 | (require 'ert) |
| 25 | (require 'ert-x) | ||
| 25 | (require 'ediff-ptch) | 26 | (require 'ediff-ptch) |
| 26 | 27 | ||
| 27 | (ert-deftest ediff-ptch-test-bug25010 () | 28 | (ert-deftest ediff-ptch-test-bug25010 () |
| @@ -45,34 +46,33 @@ index 6a07f80..6e8e947 100644 | |||
| 45 | "Test for https://debbugs.gnu.org/26084 ." | 46 | "Test for https://debbugs.gnu.org/26084 ." |
| 46 | (skip-unless (executable-find "git")) | 47 | (skip-unless (executable-find "git")) |
| 47 | (skip-unless (executable-find ediff-patch-program)) | 48 | (skip-unless (executable-find ediff-patch-program)) |
| 48 | (let* ((tmpdir (make-temp-file "ediff-ptch-test" t)) | 49 | (ert-with-temp-directory tmpdir |
| 49 | (default-directory (file-name-as-directory tmpdir)) | 50 | (ert-with-temp-file patch |
| 50 | (patch (make-temp-file "ediff-ptch-test")) | 51 | (let* ((default-directory (file-name-as-directory tmpdir)) |
| 51 | (qux (expand-file-name "qux.txt" tmpdir)) | 52 | (qux (expand-file-name "qux.txt" tmpdir)) |
| 52 | (bar (expand-file-name "bar.txt" tmpdir)) | 53 | (bar (expand-file-name "bar.txt" tmpdir)) |
| 53 | (git-program (executable-find "git"))) | 54 | (git-program (executable-find "git"))) |
| 54 | ;; Create repository. | 55 | ;; Create repository. |
| 55 | (with-temp-buffer | 56 | (with-temp-buffer |
| 56 | (insert "qux here\n") | 57 | (insert "qux here\n") |
| 57 | (write-region nil nil qux nil 'silent) | 58 | (write-region nil nil qux nil 'silent) |
| 58 | (erase-buffer) | 59 | (erase-buffer) |
| 59 | (insert "bar here\n") | 60 | (insert "bar here\n") |
| 60 | (write-region nil nil bar nil 'silent)) | 61 | (write-region nil nil bar nil 'silent)) |
| 61 | (call-process git-program nil nil nil "init") | 62 | (call-process git-program nil nil nil "init") |
| 62 | (call-process git-program nil nil nil "add" ".") | 63 | (call-process git-program nil nil nil "add" ".") |
| 63 | (call-process git-program nil nil nil "commit" "-m" "Test repository.") | 64 | (call-process git-program nil nil nil "commit" "-m" "Test repository.") |
| 64 | ;; Update repo., save the diff and reset to initial state. | 65 | ;; Update repo., save the diff and reset to initial state. |
| 65 | (with-temp-buffer | 66 | (with-temp-buffer |
| 66 | (insert "foo here\n") | 67 | (insert "foo here\n") |
| 67 | (write-region nil nil qux nil 'silent) | 68 | (write-region nil nil qux nil 'silent) |
| 68 | (write-region nil nil bar nil 'silent)) | 69 | (write-region nil nil bar nil 'silent)) |
| 69 | (call-process git-program nil `(:file ,patch) nil "diff") | 70 | (call-process git-program nil `(:file ,patch) nil "diff") |
| 70 | (call-process git-program nil nil nil "reset" "--hard" "HEAD") | 71 | (call-process git-program nil nil nil "reset" "--hard" "HEAD") |
| 71 | ;; Visit the diff file i.e., patch; extract from it the parts | 72 | ;; Visit the diff file i.e., patch; extract from it the parts |
| 72 | ;; affecting just each of the files: store in patch-bar the part | 73 | ;; affecting just each of the files: store in patch-bar the part |
| 73 | ;; affecting 'bar', and in patch-qux the part affecting 'qux'. | 74 | ;; affecting 'bar', and in patch-qux the part affecting 'qux'. |
| 74 | (find-file patch) | 75 | (find-file patch) |
| 75 | (unwind-protect | ||
| 76 | (let* ((info | 76 | (let* ((info |
| 77 | (progn (ediff-map-patch-buffer (current-buffer)) ediff-patch-map)) | 77 | (progn (ediff-map-patch-buffer (current-buffer)) ediff-patch-map)) |
| 78 | (patch-bar | 78 | (patch-bar |
| @@ -116,9 +116,7 @@ index 6a07f80..6e8e947 100644 | |||
| 116 | (buffer-string)) | 116 | (buffer-string)) |
| 117 | (with-temp-buffer | 117 | (with-temp-buffer |
| 118 | (insert-file-contents backup) | 118 | (insert-file-contents backup) |
| 119 | (buffer-string))))))) | 119 | (buffer-string)))))))))))) |
| 120 | (delete-directory tmpdir 'recursive) | ||
| 121 | (delete-file patch))))) | ||
| 122 | 120 | ||
| 123 | 121 | ||
| 124 | (provide 'ediff-ptch-tests) | 122 | (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 @@ | |||
| 25 | ;;; Code: | 25 | ;;; Code: |
| 26 | 26 | ||
| 27 | (require 'ert) | 27 | (require 'ert) |
| 28 | (require 'ert-x) | ||
| 28 | (require 'vc-bzr) | 29 | (require 'vc-bzr) |
| 29 | (require 'vc-dir) | 30 | (require 'vc-dir) |
| 30 | 31 | ||
| @@ -51,106 +52,97 @@ | |||
| 51 | ;; temporary directory. | 52 | ;; temporary directory. |
| 52 | ;; TODO does this means tests should be setting XDG_ variables (not | 53 | ;; TODO does this means tests should be setting XDG_ variables (not |
| 53 | ;; just HOME) to temporary values too? | 54 | ;; just HOME) to temporary values too? |
| 54 | (let* ((homedir (make-temp-file "vc-bzr-test" t)) | 55 | (ert-with-temp-directory homedir |
| 55 | (bzrdir (expand-file-name "bzr" homedir)) | 56 | (let* ((bzrdir (expand-file-name "bzr" homedir)) |
| 56 | (ignored-dir (progn | 57 | (ignored-dir (progn |
| 57 | (make-directory bzrdir) | 58 | (make-directory bzrdir) |
| 58 | (expand-file-name "ignored-dir" bzrdir))) | 59 | (expand-file-name "ignored-dir" bzrdir))) |
| 59 | (default-directory (file-name-as-directory bzrdir)) | 60 | (default-directory (file-name-as-directory bzrdir)) |
| 60 | (process-environment (cons (format "HOME=%s" homedir) | 61 | (process-environment (cons (format "HOME=%s" homedir) |
| 61 | process-environment))) | 62 | process-environment))) |
| 62 | (unwind-protect | 63 | (make-directory ignored-dir) |
| 63 | (progn | 64 | (with-temp-buffer |
| 64 | (make-directory ignored-dir) | 65 | (insert (file-name-nondirectory ignored-dir)) |
| 65 | (with-temp-buffer | 66 | (write-region nil nil (expand-file-name ".bzrignore" bzrdir) |
| 66 | (insert (file-name-nondirectory ignored-dir)) | 67 | nil 'silent)) |
| 67 | (write-region nil nil (expand-file-name ".bzrignore" bzrdir) | 68 | (skip-unless (eq 0 ; some internal bzr error |
| 68 | nil 'silent)) | 69 | (call-process vc-bzr-program nil nil nil "init"))) |
| 69 | (skip-unless (eq 0 ; some internal bzr error | 70 | (call-process vc-bzr-program nil nil nil "add") |
| 70 | (call-process vc-bzr-program nil nil nil "init"))) | 71 | (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1") |
| 71 | (call-process vc-bzr-program nil nil nil "add") | 72 | (with-temp-buffer |
| 72 | (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1") | 73 | (insert "unregistered file") |
| 73 | (with-temp-buffer | 74 | (write-region nil nil (expand-file-name "testfile2" ignored-dir) |
| 74 | (insert "unregistered file") | 75 | nil 'silent)) |
| 75 | (write-region nil nil (expand-file-name "testfile2" ignored-dir) | 76 | (vc-dir ignored-dir) |
| 76 | nil 'silent)) | 77 | (while (vc-dir-busy) |
| 77 | (vc-dir ignored-dir) | 78 | (sit-for 0.1)) |
| 78 | (while (vc-dir-busy) | 79 | ;; FIXME better to explicitly test for error from process sentinel. |
| 79 | (sit-for 0.1)) | 80 | (with-current-buffer "*vc-dir*" |
| 80 | ;; FIXME better to explicitly test for error from process sentinel. | 81 | (goto-char (point-min)) |
| 81 | (with-current-buffer "*vc-dir*" | 82 | (should (search-forward "unregistered" nil t)))))) |
| 82 | (goto-char (point-min)) | ||
| 83 | (should (search-forward "unregistered" nil t)))) | ||
| 84 | (delete-directory homedir t)))) | ||
| 85 | 83 | ||
| 86 | ;; Not specific to bzr. | 84 | ;; Not specific to bzr. |
| 87 | (ert-deftest vc-bzr-test-bug9781 () | 85 | (ert-deftest vc-bzr-test-bug9781 () |
| 88 | "Test for https://debbugs.gnu.org/9781 ." | 86 | "Test for https://debbugs.gnu.org/9781 ." |
| 89 | (skip-unless (executable-find vc-bzr-program)) | 87 | (skip-unless (executable-find vc-bzr-program)) |
| 90 | (let* ((homedir (make-temp-file "vc-bzr-test" t)) | 88 | (ert-with-temp-directory homedir |
| 91 | (bzrdir (expand-file-name "bzr" homedir)) | 89 | (let* ((bzrdir (expand-file-name "bzr" homedir)) |
| 92 | (subdir (progn | 90 | (subdir (progn |
| 93 | (make-directory bzrdir) | 91 | (make-directory bzrdir) |
| 94 | (expand-file-name "subdir" bzrdir))) | 92 | (expand-file-name "subdir" bzrdir))) |
| 95 | (file (expand-file-name "file" bzrdir)) | 93 | (file (expand-file-name "file" bzrdir)) |
| 96 | (default-directory (file-name-as-directory bzrdir)) | 94 | (default-directory (file-name-as-directory bzrdir)) |
| 97 | (process-environment (cons (format "HOME=%s" homedir) | 95 | (process-environment (cons (format "HOME=%s" homedir) |
| 98 | process-environment))) | 96 | process-environment))) |
| 99 | (unwind-protect | 97 | (skip-unless (eq 0 ; some internal bzr error |
| 100 | (progn | 98 | (call-process vc-bzr-program nil nil nil "init"))) |
| 101 | (skip-unless (eq 0 ; some internal bzr error | 99 | (make-directory subdir) |
| 102 | (call-process vc-bzr-program nil nil nil "init"))) | 100 | (with-temp-buffer |
| 103 | (make-directory subdir) | 101 | (insert "text") |
| 104 | (with-temp-buffer | 102 | (write-region nil nil file nil 'silent) |
| 105 | (insert "text") | 103 | (write-region nil nil (expand-file-name "subfile" subdir) |
| 106 | (write-region nil nil file nil 'silent) | 104 | nil 'silent)) |
| 107 | (write-region nil nil (expand-file-name "subfile" subdir) | 105 | (call-process vc-bzr-program nil nil nil "add") |
| 108 | nil 'silent)) | 106 | (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1") |
| 109 | (call-process vc-bzr-program nil nil nil "add") | 107 | (call-process vc-bzr-program nil nil nil "remove" subdir) |
| 110 | (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1") | 108 | (with-temp-buffer |
| 111 | (call-process vc-bzr-program nil nil nil "remove" subdir) | 109 | (insert "different text") |
| 112 | (with-temp-buffer | 110 | (write-region nil nil file nil 'silent)) |
| 113 | (insert "different text") | 111 | (vc-dir bzrdir) |
| 114 | (write-region nil nil file nil 'silent)) | 112 | (while (vc-dir-busy) |
| 115 | (vc-dir bzrdir) | 113 | (sit-for 0.1)) |
| 116 | (while (vc-dir-busy) | 114 | (vc-dir-mark-all-files t) |
| 117 | (sit-for 0.1)) | 115 | (cl-letf (((symbol-function 'y-or-n-p) (lambda (_) t))) |
| 118 | (vc-dir-mark-all-files t) | 116 | (vc-next-action nil)) |
| 119 | (cl-letf (((symbol-function 'y-or-n-p) (lambda (_) t))) | 117 | (should (get-buffer "*vc-log*"))))) |
| 120 | (vc-next-action nil)) | ||
| 121 | (should (get-buffer "*vc-log*"))) | ||
| 122 | (delete-directory homedir t)))) | ||
| 123 | 118 | ||
| 124 | ;; https://lists.gnu.org/r/help-gnu-emacs/2012-04/msg00145.html | 119 | ;; https://lists.gnu.org/r/help-gnu-emacs/2012-04/msg00145.html |
| 125 | (ert-deftest vc-bzr-test-faulty-bzr-autoloads () | 120 | (ert-deftest vc-bzr-test-faulty-bzr-autoloads () |
| 126 | "Test we can generate autoloads in a bzr directory when bzr is faulty." | 121 | "Test we can generate autoloads in a bzr directory when bzr is faulty." |
| 127 | (skip-unless (executable-find vc-bzr-program)) | 122 | (skip-unless (executable-find vc-bzr-program)) |
| 128 | (let* ((homedir (make-temp-file "vc-bzr-test" t)) | 123 | (ert-with-temp-directory homedir |
| 129 | (bzrdir (expand-file-name "bzr" homedir)) | 124 | (let* ((bzrdir (expand-file-name "bzr" homedir)) |
| 130 | (file (progn | 125 | (file (progn |
| 131 | (make-directory bzrdir) | 126 | (make-directory bzrdir) |
| 132 | (expand-file-name "foo.el" bzrdir))) | 127 | (expand-file-name "foo.el" bzrdir))) |
| 133 | (default-directory (file-name-as-directory bzrdir)) | 128 | (default-directory (file-name-as-directory bzrdir)) |
| 134 | (process-environment (cons (format "HOME=%s" homedir) | 129 | (process-environment (cons (format "HOME=%s" homedir) |
| 135 | process-environment))) | 130 | process-environment))) |
| 136 | (unwind-protect | 131 | (call-process vc-bzr-program nil nil nil "init") |
| 137 | (progn | 132 | (with-temp-buffer |
| 138 | (call-process vc-bzr-program nil nil nil "init") | 133 | (insert ";;;###autoload |
| 139 | (with-temp-buffer | ||
| 140 | (insert ";;;###autoload | ||
| 141 | \(defun foo () \"foo\" (interactive) (message \"foo!\"))") | 134 | \(defun foo () \"foo\" (interactive) (message \"foo!\"))") |
| 142 | (write-region nil nil file nil 'silent)) | 135 | (write-region nil nil file nil 'silent)) |
| 143 | (call-process vc-bzr-program nil nil nil "add") | 136 | (call-process vc-bzr-program nil nil nil "add") |
| 144 | (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1") | 137 | (call-process vc-bzr-program nil nil nil "commit" "-m" "Commit 1") |
| 145 | ;; Deleting dirstate ensures both that vc-bzr's status heuristic | 138 | ;; Deleting dirstate ensures both that vc-bzr's status heuristic |
| 146 | ;; fails, so it has to call the external bzr status, and | 139 | ;; fails, so it has to call the external bzr status, and |
| 147 | ;; causes bzr status to fail. This simulates a broken bzr | 140 | ;; causes bzr status to fail. This simulates a broken bzr |
| 148 | ;; installation. | 141 | ;; installation. |
| 149 | (delete-file ".bzr/checkout/dirstate") | 142 | (delete-file ".bzr/checkout/dirstate") |
| 150 | (should (progn (make-directory-autoloads | 143 | (should (progn (make-directory-autoloads |
| 151 | default-directory | 144 | default-directory |
| 152 | (expand-file-name "loaddefs.el" bzrdir)) | 145 | (expand-file-name "loaddefs.el" bzrdir)) |
| 153 | t))) | 146 | t))))) |
| 154 | (delete-directory homedir t)))) | ||
| 155 | 147 | ||
| 156 | ;;; vc-bzr-tests.el ends here | 148 | ;;; 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 @@ | |||
| 20 | ;;; Code: | 20 | ;;; Code: |
| 21 | 21 | ||
| 22 | (require 'ert) | 22 | (require 'ert) |
| 23 | (require 'ert-x) | ||
| 23 | (require 'dired) | 24 | (require 'dired) |
| 24 | (require 'wdired) | 25 | (require 'wdired) |
| 25 | 26 | ||
| @@ -28,104 +29,100 @@ | |||
| 28 | (ert-deftest wdired-test-bug32173-01 () | 29 | (ert-deftest wdired-test-bug32173-01 () |
| 29 | "Test using non-nil wdired-use-interactive-rename. | 30 | "Test using non-nil wdired-use-interactive-rename. |
| 30 | Partially modifying a file name should succeed." | 31 | Partially modifying a file name should succeed." |
| 31 | (let* ((test-dir (make-temp-file "test-dir-" t)) | 32 | (ert-with-temp-directory test-dir |
| 32 | (test-file (concat (file-name-as-directory test-dir) "foo.c")) | 33 | (let* ((test-file (concat (file-name-as-directory test-dir) "foo.c")) |
| 33 | (replace "bar") | 34 | (replace "bar") |
| 34 | (new-file (string-replace "foo" replace test-file)) | 35 | (new-file (string-replace "foo" replace test-file)) |
| 35 | (wdired-use-interactive-rename t)) | 36 | (wdired-use-interactive-rename t)) |
| 36 | (write-region "" nil test-file nil 'silent) | 37 | (write-region "" nil test-file nil 'silent) |
| 37 | (advice-add 'dired-query ; Don't ask confirmation to overwrite a file. | 38 | (advice-add 'dired-query ; Don't ask confirmation to overwrite a file. |
| 38 | :override | 39 | :override |
| 39 | (lambda (_sym _prompt &rest _args) (setq dired-query t)) | 40 | (lambda (_sym _prompt &rest _args) (setq dired-query t)) |
| 40 | '((name . "advice-dired-query"))) | 41 | '((name . "advice-dired-query"))) |
| 41 | (let ((buf (find-file-noselect test-dir))) | 42 | (let ((buf (find-file-noselect test-dir))) |
| 42 | (unwind-protect | 43 | (unwind-protect |
| 43 | (with-current-buffer buf | 44 | (with-current-buffer buf |
| 44 | (should (equal (dired-file-name-at-point) test-file)) | 45 | (should (equal (dired-file-name-at-point) test-file)) |
| 45 | (dired-toggle-read-only) | 46 | (dired-toggle-read-only) |
| 46 | (kill-region (point) (progn (search-forward ".") | 47 | (kill-region (point) (progn (search-forward ".") |
| 47 | (forward-char -1) (point))) | 48 | (forward-char -1) (point))) |
| 48 | (insert replace) | 49 | (insert replace) |
| 49 | (wdired-finish-edit) | 50 | (wdired-finish-edit) |
| 50 | (should (equal (dired-file-name-at-point) new-file))) | 51 | (should (equal (dired-file-name-at-point) new-file))) |
| 51 | (if buf (kill-buffer buf)) | 52 | (if buf (kill-buffer buf))))))) |
| 52 | (delete-directory test-dir t))))) | ||
| 53 | 53 | ||
| 54 | (ert-deftest wdired-test-bug32173-02 () | 54 | (ert-deftest wdired-test-bug32173-02 () |
| 55 | "Test using non-nil wdired-use-interactive-rename. | 55 | "Test using non-nil wdired-use-interactive-rename. |
| 56 | Aborting an edit should leaving original file name unchanged." | 56 | Aborting an edit should leaving original file name unchanged." |
| 57 | (let* ((test-dir (make-temp-file "test-dir-" t)) | 57 | (ert-with-temp-directory test-dir |
| 58 | (test-file (concat (file-name-as-directory test-dir) "foo.c")) | 58 | (let* ((test-file (concat (file-name-as-directory test-dir) "foo.c")) |
| 59 | (wdired-use-interactive-rename t)) | 59 | (wdired-use-interactive-rename t)) |
| 60 | (write-region "" nil test-file nil 'silent) | 60 | (write-region "" nil test-file nil 'silent) |
| 61 | ;; Make dired-do-create-files-regexp a noop to mimic typing C-g | 61 | ;; Make dired-do-create-files-regexp a noop to mimic typing C-g |
| 62 | ;; at its prompt before wdired-finish-edit returns. | 62 | ;; at its prompt before wdired-finish-edit returns. |
| 63 | (advice-add 'dired-do-create-files-regexp | 63 | (advice-add 'dired-do-create-files-regexp |
| 64 | :override | 64 | :override |
| 65 | (lambda (&rest _) (ignore)) | 65 | (lambda (&rest _) (ignore)) |
| 66 | '((name . "advice-dired-do-create-files-regexp"))) | 66 | '((name . "advice-dired-do-create-files-regexp"))) |
| 67 | (let ((buf (find-file-noselect test-dir))) | 67 | (let ((buf (find-file-noselect test-dir))) |
| 68 | (unwind-protect | 68 | (unwind-protect |
| 69 | (with-current-buffer buf | 69 | (with-current-buffer buf |
| 70 | (should (equal (dired-file-name-at-point) test-file)) | 70 | (should (equal (dired-file-name-at-point) test-file)) |
| 71 | (dired-toggle-read-only) | 71 | (dired-toggle-read-only) |
| 72 | (kill-region (point) (progn (search-forward ".") | 72 | (kill-region (point) (progn (search-forward ".") |
| 73 | (forward-char -1) (point))) | 73 | (forward-char -1) (point))) |
| 74 | (insert "bar") | 74 | (insert "bar") |
| 75 | (wdired-finish-edit) | 75 | (wdired-finish-edit) |
| 76 | (should (equal (dired-get-filename) test-file))) | 76 | (should (equal (dired-get-filename) test-file))) |
| 77 | (if buf (kill-buffer buf)) | 77 | (if buf (kill-buffer buf))))))) |
| 78 | (delete-directory test-dir t))))) | ||
| 79 | 78 | ||
| 80 | (ert-deftest wdired-test-symlink-name () | 79 | (ert-deftest wdired-test-symlink-name () |
| 81 | "Test the file name of a symbolic link. | 80 | "Test the file name of a symbolic link. |
| 82 | The Dired and WDired functions returning the name should include | 81 | The Dired and WDired functions returning the name should include |
| 83 | only the name before the link arrow." | 82 | only the name before the link arrow." |
| 84 | (let* ((test-dir (make-temp-file "test-dir-" t)) | 83 | (ert-with-temp-directory test-dir |
| 85 | (link-name "foo")) | 84 | (let* ((link-name "foo")) |
| 86 | (let ((buf (find-file-noselect test-dir))) | 85 | (let ((buf (find-file-noselect test-dir))) |
| 87 | (unwind-protect | 86 | (unwind-protect |
| 88 | (with-current-buffer buf | 87 | (with-current-buffer buf |
| 89 | (skip-unless | 88 | (skip-unless |
| 90 | ;; This check is for wdired, not symbolic links, so skip | 89 | ;; This check is for wdired, not symbolic links, so skip |
| 91 | ;; it when make-symbolic-link fails for any reason (like | 90 | ;; it when make-symbolic-link fails for any reason (like |
| 92 | ;; insufficient privileges). | 91 | ;; insufficient privileges). |
| 93 | (ignore-errors (make-symbolic-link "./bar/baz" link-name) t)) | 92 | (ignore-errors (make-symbolic-link "./bar/baz" link-name) t)) |
| 94 | (revert-buffer) | 93 | (revert-buffer) |
| 95 | (let* ((file-name (dired-get-filename)) | 94 | (let* ((file-name (dired-get-filename)) |
| 96 | (dir-part (file-name-directory file-name)) | 95 | (dir-part (file-name-directory file-name)) |
| 97 | (lf-name (concat dir-part link-name))) | 96 | (lf-name (concat dir-part link-name))) |
| 98 | (should (equal file-name lf-name)) | 97 | (should (equal file-name lf-name)) |
| 99 | (dired-toggle-read-only) | 98 | (dired-toggle-read-only) |
| 100 | (should (equal (wdired-get-filename) lf-name)) | 99 | (should (equal (wdired-get-filename) lf-name)) |
| 101 | (dired-toggle-read-only))) | 100 | (dired-toggle-read-only))) |
| 102 | (if buf (kill-buffer buf)) | 101 | (if buf (kill-buffer buf))))))) |
| 103 | (delete-directory test-dir t))))) | ||
| 104 | 102 | ||
| 105 | (ert-deftest wdired-test-unfinished-edit-01 () | 103 | (ert-deftest wdired-test-unfinished-edit-01 () |
| 106 | "Test editing a file name without saving the change. | 104 | "Test editing a file name without saving the change. |
| 107 | Finding the new name should be possible while still in | 105 | Finding the new name should be possible while still in |
| 108 | wdired-mode." | 106 | wdired-mode." |
| 109 | (let* ((test-dir (make-temp-file "test-dir-" t)) | 107 | (ert-with-temp-directory test-dir |
| 110 | (test-file (concat (file-name-as-directory test-dir) "foo.c")) | 108 | (let* ((test-file (concat (file-name-as-directory test-dir) "foo.c")) |
| 111 | (replace "bar") | 109 | (replace "bar") |
| 112 | (new-file (string-replace "foo" replace test-file))) | 110 | (new-file (string-replace "foo" replace test-file))) |
| 113 | (write-region "" nil test-file nil 'silent) | 111 | (write-region "" nil test-file nil 'silent) |
| 114 | (let ((buf (find-file-noselect test-dir))) | 112 | (let ((buf (find-file-noselect test-dir))) |
| 115 | (unwind-protect | 113 | (unwind-protect |
| 116 | (with-current-buffer buf | 114 | (with-current-buffer buf |
| 117 | (should (equal (dired-file-name-at-point) test-file)) | 115 | (should (equal (dired-file-name-at-point) test-file)) |
| 118 | (dired-toggle-read-only) | 116 | (dired-toggle-read-only) |
| 119 | (kill-region (point) (progn (search-forward ".") | 117 | (kill-region (point) (progn (search-forward ".") |
| 120 | (forward-char -1) (point))) | 118 | (forward-char -1) (point))) |
| 121 | (insert replace) | 119 | (insert replace) |
| 122 | (should (equal (dired-get-filename) new-file))) | 120 | (should (equal (dired-get-filename) new-file))) |
| 123 | (when buf | 121 | (when buf |
| 124 | (with-current-buffer buf | 122 | (with-current-buffer buf |
| 125 | ;; Prevent kill-buffer-query-functions from chiming in. | 123 | ;; Prevent kill-buffer-query-functions from chiming in. |
| 126 | (set-buffer-modified-p nil) | 124 | (set-buffer-modified-p nil) |
| 127 | (kill-buffer buf))) | 125 | (kill-buffer buf)))))))) |
| 128 | (delete-directory test-dir t))))) | ||
| 129 | 126 | ||
| 130 | (defvar server-socket-dir) | 127 | (defvar server-socket-dir) |
| 131 | (declare-function dired-smart-shell-command "dired-x" | 128 | (declare-function dired-smart-shell-command "dired-x" |
| @@ -139,61 +136,59 @@ dired-move-to-end-of-filename handles indicator characters, it | |||
| 139 | suffices to compare the return values of dired-get-filename and | 136 | suffices to compare the return values of dired-get-filename and |
| 140 | wdired-get-filename before and after editing." | 137 | wdired-get-filename before and after editing." |
| 141 | ;; FIXME: Add a test for a door (indicator ">") only under Solaris? | 138 | ;; FIXME: Add a test for a door (indicator ">") only under Solaris? |
| 142 | (let* ((test-dir (make-temp-file "test-dir-" t)) | 139 | (ert-with-temp-directory test-dir |
| 143 | (server-socket-dir test-dir) | 140 | (let* ((server-socket-dir test-dir) |
| 144 | (dired-listing-switches "-Fl") | 141 | (dired-listing-switches "-Fl") |
| 145 | (dired-ls-F-marks-symlinks (eq system-type 'darwin)) | 142 | (dired-ls-F-marks-symlinks (eq system-type 'darwin)) |
| 146 | (buf (find-file-noselect test-dir))) | 143 | (buf (find-file-noselect test-dir))) |
| 147 | (unwind-protect | 144 | (unwind-protect |
| 148 | (progn | 145 | (progn |
| 149 | (with-current-buffer buf | 146 | (with-current-buffer buf |
| 150 | (dired-create-empty-file "foo") | 147 | (dired-create-empty-file "foo") |
| 151 | (set-file-modes "foo" (file-modes-symbolic-to-number "+x")) | 148 | (set-file-modes "foo" (file-modes-symbolic-to-number "+x")) |
| 152 | (make-symbolic-link "foo" "bar") | 149 | (make-symbolic-link "foo" "bar") |
| 153 | (make-directory "foodir") | 150 | (make-directory "foodir") |
| 154 | (require 'dired-x) | 151 | (require 'dired-x) |
| 155 | (dired-smart-shell-command "mkfifo foopipe") | 152 | (dired-smart-shell-command "mkfifo foopipe") |
| 156 | (server-force-delete) | 153 | (server-force-delete) |
| 157 | ;; FIXME? This seems a heavy-handed way of making a socket. | 154 | ;; FIXME? This seems a heavy-handed way of making a socket. |
| 158 | (server-start) ; Add a socket file. | 155 | (server-start) ; Add a socket file. |
| 159 | (kill-buffer buf)) | 156 | (kill-buffer buf)) |
| 160 | (dired test-dir) | 157 | (dired test-dir) |
| 161 | (dired-toggle-read-only) | 158 | (dired-toggle-read-only) |
| 162 | (let (names) | 159 | (let (names) |
| 163 | ;; Test that the file names are the same in Dired and WDired. | 160 | ;; Test that the file names are the same in Dired and WDired. |
| 164 | (while (not (eobp)) | 161 | (while (not (eobp)) |
| 165 | (should (equal (dired-get-filename 'no-dir t) | 162 | (should (equal (dired-get-filename 'no-dir t) |
| 166 | (wdired-get-filename t))) | 163 | (wdired-get-filename t))) |
| 167 | (insert "w") | 164 | (insert "w") |
| 168 | (push (wdired-get-filename t) names) | 165 | (push (wdired-get-filename t) names) |
| 169 | (dired-next-line 1)) | 166 | (dired-next-line 1)) |
| 170 | (wdired-finish-edit) | 167 | (wdired-finish-edit) |
| 171 | ;; Test that editing the file names ignores the indicator | 168 | ;; Test that editing the file names ignores the indicator |
| 172 | ;; character. | 169 | ;; character. |
| 173 | (let (dir) | 170 | (let (dir) |
| 174 | (while (and (dired-previous-line 1) | 171 | (while (and (dired-previous-line 1) |
| 175 | (setq dir (dired-get-filename 'no-dir t))) | 172 | (setq dir (dired-get-filename 'no-dir t))) |
| 176 | (should (equal dir (pop names))))))) | 173 | (should (equal dir (pop names))))))) |
| 177 | (kill-buffer (get-buffer test-dir)) | 174 | (kill-buffer (get-buffer test-dir)) |
| 178 | (server-force-delete) | 175 | (server-force-delete))))) |
| 179 | (delete-directory test-dir t)))) | ||
| 180 | 176 | ||
| 181 | (ert-deftest wdired-test-bug39280 () | 177 | (ert-deftest wdired-test-bug39280 () |
| 182 | "Test for https://debbugs.gnu.org/39280." | 178 | "Test for https://debbugs.gnu.org/39280." |
| 183 | (let* ((test-dir (make-temp-file "test-dir" 'dir)) | 179 | (ert-with-temp-directory test-dir |
| 184 | (fname "foo") | 180 | (let* ((fname "foo") |
| 185 | (full-fname (expand-file-name fname test-dir))) | 181 | (full-fname (expand-file-name fname test-dir))) |
| 186 | (make-empty-file full-fname) | 182 | (make-empty-file full-fname) |
| 187 | (let ((buf (find-file-noselect test-dir))) | 183 | (let ((buf (find-file-noselect test-dir))) |
| 188 | (unwind-protect | 184 | (unwind-protect |
| 189 | (with-current-buffer buf | 185 | (with-current-buffer buf |
| 190 | (dired-toggle-read-only) | 186 | (dired-toggle-read-only) |
| 191 | (dolist (old '(t nil)) | 187 | (dolist (old '(t nil)) |
| 192 | (should (equal fname (wdired-get-filename 'nodir old))) | 188 | (should (equal fname (wdired-get-filename 'nodir old))) |
| 193 | (should (equal full-fname (wdired-get-filename nil old)))) | 189 | (should (equal full-fname (wdired-get-filename nil old)))) |
| 194 | (wdired-finish-edit)) | 190 | (wdired-finish-edit)) |
| 195 | (if buf (kill-buffer buf)) | 191 | (if buf (kill-buffer buf))))))) |
| 196 | (delete-directory test-dir t))))) | ||
| 197 | 192 | ||
| 198 | (provide 'wdired-tests) | 193 | (provide 'wdired-tests) |
| 199 | ;;; wdired-tests.el ends here | 194 | ;;; 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 @@ | |||
| 19 | 19 | ||
| 20 | ;;; Code: | 20 | ;;; Code: |
| 21 | 21 | ||
| 22 | (require 'ert) | ||
| 23 | (require 'ert-x) | ||
| 22 | (require 'cl-lib) | 24 | (require 'cl-lib) |
| 23 | 25 | ||
| 24 | (ert-deftest overlay-modification-hooks-message-other-buf () | 26 | (ert-deftest overlay-modification-hooks-message-other-buf () |
| @@ -1421,25 +1423,23 @@ with parameters from the *Messages* buffer modification." | |||
| 1421 | (should (= (length (overlays-in (point-min) (point-max))) 0)))) | 1423 | (should (= (length (overlays-in (point-min) (point-max))) 0)))) |
| 1422 | 1424 | ||
| 1423 | (ert-deftest test-kill-buffer-auto-save-default () | 1425 | (ert-deftest test-kill-buffer-auto-save-default () |
| 1424 | (let ((file (make-temp-file "ert")) | 1426 | (ert-with-temp-file file |
| 1425 | auto-save) | 1427 | (let (auto-save) |
| 1426 | (should (file-exists-p file)) | 1428 | ;; Always answer yes. |
| 1427 | ;; Always answer yes. | 1429 | (cl-letf (((symbol-function #'yes-or-no-p) (lambda (_) t))) |
| 1428 | (cl-letf (((symbol-function #'yes-or-no-p) (lambda (_) t))) | 1430 | (unwind-protect |
| 1429 | (unwind-protect | 1431 | (progn |
| 1430 | (progn | 1432 | (find-file file) |
| 1431 | (find-file file) | 1433 | (auto-save-mode t) |
| 1432 | (auto-save-mode t) | 1434 | (insert "foo\n") |
| 1433 | (insert "foo\n") | 1435 | (should buffer-auto-save-file-name) |
| 1434 | (should buffer-auto-save-file-name) | 1436 | (setq auto-save buffer-auto-save-file-name) |
| 1435 | (setq auto-save buffer-auto-save-file-name) | 1437 | (do-auto-save) |
| 1436 | (do-auto-save) | 1438 | (should (file-exists-p auto-save)) |
| 1437 | (should (file-exists-p auto-save)) | 1439 | (kill-buffer (current-buffer)) |
| 1438 | (kill-buffer (current-buffer)) | 1440 | (should (file-exists-p auto-save))) |
| 1439 | (should (file-exists-p auto-save))) | 1441 | (when auto-save |
| 1440 | (ignore-errors (delete-file file)) | 1442 | (ignore-errors (delete-file auto-save)))))))) |
| 1441 | (when auto-save | ||
| 1442 | (ignore-errors (delete-file auto-save))))))) | ||
| 1443 | 1443 | ||
| 1444 | (ert-deftest test-kill-buffer-auto-save-delete () | 1444 | (ert-deftest test-kill-buffer-auto-save-delete () |
| 1445 | (let ((file (make-temp-file "ert")) | 1445 | (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 @@ | |||
| 28 | 28 | ||
| 29 | (require 'cl-macs) | 29 | (require 'cl-macs) |
| 30 | (require 'ert) | 30 | (require 'ert) |
| 31 | (require 'ert-x) | ||
| 31 | (require 'seq) | 32 | (require 'seq) |
| 32 | 33 | ||
| 33 | (defun filelock-tests--fixture (test-function) | 34 | (defun filelock-tests--fixture (test-function) |
| @@ -36,22 +37,20 @@ Create a test directory and a buffer whose `buffer-file-name' and | |||
| 36 | `buffer-file-truename' are a file within it, then call | 37 | `buffer-file-truename' are a file within it, then call |
| 37 | TEST-FUNCTION. Finally, delete the buffer and the test | 38 | TEST-FUNCTION. Finally, delete the buffer and the test |
| 38 | directory." | 39 | directory." |
| 39 | (let* ((temp-dir (make-temp-file "filelock-tests" t)) | 40 | (ert-with-temp-directory temp-dir |
| 40 | (name (concat (file-name-as-directory temp-dir) | 41 | (let ((name (concat (file-name-as-directory temp-dir) |
| 41 | "userfile")) | 42 | "userfile")) |
| 42 | (create-lockfiles t)) | 43 | (create-lockfiles t)) |
| 43 | (unwind-protect | 44 | (with-temp-buffer |
| 44 | (with-temp-buffer | 45 | (setq buffer-file-name name |
| 45 | (setq buffer-file-name name | 46 | buffer-file-truename name) |
| 46 | buffer-file-truename name) | 47 | (unwind-protect |
| 47 | (unwind-protect | 48 | (save-current-buffer |
| 48 | (save-current-buffer | 49 | (funcall test-function)) |
| 49 | (funcall test-function)) | 50 | ;; Set `buffer-file-truename' nil to prevent unlocking, |
| 50 | ;; Set `buffer-file-truename' nil to prevent unlocking, | 51 | ;; which might prompt the user and/or signal errors. |
| 51 | ;; which might prompt the user and/or signal errors. | 52 | (setq buffer-file-name nil |
| 52 | (setq buffer-file-name nil | 53 | buffer-file-truename nil)))))) |
| 53 | buffer-file-truename nil))) | ||
| 54 | (delete-directory temp-dir t nil)))) | ||
| 55 | 54 | ||
| 56 | (defun filelock-tests--make-lock-name (file-name) | 55 | (defun filelock-tests--make-lock-name (file-name) |
| 57 | "Return the lock file name for FILE-NAME. | 56 | "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 @@ | |||
| 24 | ;;; Code: | 24 | ;;; Code: |
| 25 | 25 | ||
| 26 | (require 'ert) | 26 | (require 'ert) |
| 27 | (require 'ert-x) | ||
| 27 | 28 | ||
| 28 | (declare-function inotify-add-watch "inotify.c" (file-name aspect callback)) | 29 | (declare-function inotify-add-watch "inotify.c" (file-name aspect callback)) |
| 29 | (declare-function inotify-rm-watch "inotify.c" (watch-descriptor)) | 30 | (declare-function inotify-rm-watch "inotify.c" (watch-descriptor)) |
| @@ -50,23 +51,21 @@ | |||
| 50 | 51 | ||
| 51 | (ert-deftest inotify-file-watch-simple () | 52 | (ert-deftest inotify-file-watch-simple () |
| 52 | "Test if watching a normal file works." | 53 | "Test if watching a normal file works." |
| 53 | |||
| 54 | (skip-unless (featurep 'inotify)) | 54 | (skip-unless (featurep 'inotify)) |
| 55 | (let ((temp-file (make-temp-file "inotify-simple")) | 55 | (ert-with-temp-file temp-file |
| 56 | (events 0)) | 56 | (let ((events 0)) |
| 57 | (let ((wd | 57 | (let ((wd |
| 58 | (inotify-add-watch temp-file t (lambda (_ev) | 58 | (inotify-add-watch temp-file t (lambda (_ev) |
| 59 | (setq events (1+ events)))))) | 59 | (setq events (1+ events)))))) |
| 60 | (unwind-protect | 60 | (unwind-protect |
| 61 | (progn | 61 | (progn |
| 62 | (with-temp-file temp-file | 62 | (with-temp-file temp-file |
| 63 | (insert "Foo\n")) | 63 | (insert "Foo\n")) |
| 64 | (read-event nil nil 5) | 64 | (read-event nil nil 5) |
| 65 | (should (> events 0))) | 65 | (should (> events 0))) |
| 66 | (should (inotify-valid-p wd)) | 66 | (should (inotify-valid-p wd)) |
| 67 | (inotify-rm-watch wd) | 67 | (inotify-rm-watch wd) |
| 68 | (should-not (inotify-valid-p wd)) | 68 | (should-not (inotify-valid-p wd))))))) |
| 69 | (delete-file temp-file))))) | ||
| 70 | 69 | ||
| 71 | (provide 'inotify-tests) | 70 | (provide 'inotify-tests) |
| 72 | 71 | ||
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 @@ | |||
| 46 | ;;; Code: | 46 | ;;; Code: |
| 47 | 47 | ||
| 48 | (require 'ert) | 48 | (require 'ert) |
| 49 | (require 'ert-x) | ||
| 49 | (require 'facemenu) | 50 | (require 'facemenu) |
| 50 | 51 | ||
| 51 | (ert-deftest undo-test0 () | 52 | (ert-deftest undo-test0 () |
| @@ -218,17 +219,14 @@ | |||
| 218 | 219 | ||
| 219 | (ert-deftest undo-test-file-modified () | 220 | (ert-deftest undo-test-file-modified () |
| 220 | "Test undoing marks buffer visiting file unmodified." | 221 | "Test undoing marks buffer visiting file unmodified." |
| 221 | (let ((tempfile (make-temp-file "undo-test"))) | 222 | (ert-with-temp-file tempfile |
| 222 | (unwind-protect | 223 | (with-current-buffer (find-file-noselect tempfile) |
| 223 | (progn | 224 | (insert "1") |
| 224 | (with-current-buffer (find-file-noselect tempfile) | 225 | (undo-boundary) |
| 225 | (insert "1") | 226 | (set-buffer-modified-p nil) |
| 226 | (undo-boundary) | 227 | (insert "2") |
| 227 | (set-buffer-modified-p nil) | 228 | (undo) |
| 228 | (insert "2") | 229 | (should-not (buffer-modified-p))))) |
| 229 | (undo) | ||
| 230 | (should-not (buffer-modified-p)))) | ||
| 231 | (delete-file tempfile)))) | ||
| 232 | 230 | ||
| 233 | (ert-deftest undo-test-region-not-most-recent () | 231 | (ert-deftest undo-test-region-not-most-recent () |
| 234 | "Test undo in region of an edit not the most recent." | 232 | "Test undo in region of an edit not the most recent." |