Skip to content

Commit

Permalink
Clean up temporary files with a macro rather than a function.
Browse files Browse the repository at this point in the history
Cleaning up temporary files should happen at test *execution* time, not at
definition time.
  • Loading branch information
haxney committed Sep 30, 2012
1 parent f6fc81c commit 9c76c10
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions package-test.el
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,15 @@
"Save the old value of `package-user-dir' to be restored later.")

(defvar package-test-user-dir (make-temp-name
(concat temporary-file-directory "pkg-test-user-dir-"))
(concat temporary-file-directory "pkg-test-user-dir-"))
"Directory to use for installing packages during testing.")

(setq package-user-dir package-test-user-dir)

(defun package-test-cleanup ()
"Clear `package-user-dir' to prepare for the next test.
WARNING: Make sure you aren't running this in your main Emacs
session!"
(when (file-directory-p package-test-user-dir)
(delete-directory package-test-user-dir t)))

(defvar simple-single-desc [cl-struct-package-desc simple-single (1 3)
"A single-file package with no dependencies"
nil single nil (".")
";;; Commentary:
"A single-file package with no dependencies"
nil single nil (".")
";;; Commentary:
;; This package provides a minor mode to frobnicate and/or bifurcate
;; any flanges you desire. To activate it, type \"C-M-r M-3 butterfly\"
Expand All @@ -76,6 +68,13 @@ session!"
"]
"Expected `package-desc' parsed from simple-single.el.")

(defmacro with-package-test (&rest body)
"Set up temporary locations and variables for testing."
`(let ((package-user-dir package-test-user-dir))
,@body
(when (file-directory-p package-test-user-dir)
(delete-directory package-test-user-dir t))))

(ert-deftest package-test-buffer-info ()
"Parse an elisp buffer to get a `package-desc' object."
(with-temp-buffer
Expand Down

0 comments on commit 9c76c10

Please sign in to comment.