tests: Fix macro.
authorJustus Winter <justus@g10code.com>
Thu, 5 Jan 2017 16:00:36 +0000 (17:00 +0100)
committerJustus Winter <justus@g10code.com>
Thu, 5 Jan 2017 16:00:36 +0000 (17:00 +0100)
* tests/openpgp/defs.scm (with-ephemeral-home-directory): Make
hygienic, use define-macro, do not change to the ephemeral home
directory.
* tests/gpgsm/setup.scm: Change to the ephemeral home directory.
* tests/openpgp/setup.scm: Likewise.

Signed-off-by: Justus Winter <justus@g10code.com>
tests/gpgsm/setup.scm
tests/openpgp/defs.scm
tests/openpgp/setup.scm

index fdf277d..91821a0 100644 (file)
@@ -24,6 +24,7 @@
        (error "Usage: setup.scm --create-tarball <file> ..."))
 
 (with-ephemeral-home-directory
+ (chdir (getenv "GNUPGHOME"))
  (create-gpgsmhome)
  (stop-agent)
  (call-check `(,(tool 'gpgtar) --create --output ,(car tarball) ".")))
index 863d128..837e096 100644 (file)
 
 ;; Evaluate a sequence of expressions with an ephemeral home
 ;; directory.
-(macro (with-ephemeral-home-directory form)
-  `(let ((original-home-directory (getenv "GNUPGHOME")))
-     (with-temporary-working-directory
-      (define ephemeral-home-directory (getcwd))
-      (dynamic-wind
-         (lambda () (setenv "GNUPGHOME" ephemeral-home-directory #t))
-         (lambda () ,@(cdr form))
-         (lambda () (setenv "GNUPGHOME" original-home-directory #t))))))
+(define-macro (with-ephemeral-home-directory . expressions)
+  (let ((original-home-directory (gensym))
+       (ephemeral-home-directory (gensym)))
+    `(let ((,original-home-directory (getenv "GNUPGHOME"))
+          (,ephemeral-home-directory (mkdtemp)))
+       (finally (unlink-recursively ,ephemeral-home-directory)
+        (dynamic-wind
+            (lambda () (setenv "GNUPGHOME" ,ephemeral-home-directory #t))
+            (lambda () ,@expressions)
+            (lambda () (setenv "GNUPGHOME" ,original-home-directory #t)))))))
 
 ;; Call GPG to obtain the hash sums.  Either specify an input file in
 ;; ARGS, or an string in INPUT.  Returns a list of (<algo>
index abe1157..d13799d 100755 (executable)
@@ -23,6 +23,7 @@
        (fail "Usage: setup.scm --create-tarball <file>"))
 
 (with-ephemeral-home-directory
+ (chdir (getenv "GNUPGHOME"))
  (create-gpghome)
  (create-legacy-gpghome)
  (stop-agent)