tests: Honor environment variable 'TMP'.
authorJustus Winter <justus@g10code.com>
Tue, 5 Jul 2016 14:25:21 +0000 (16:25 +0200)
committerJustus Winter <justus@g10code.com>
Tue, 5 Jul 2016 14:25:21 +0000 (16:25 +0200)
This fixes problems with long socket names, e.g. when doing distcheck.

* tests/gpgscm/tests.scm (path-join): New function.
(with-temporary-working-directory): Honor 'TMP'.
(make-temporary-file): Likewise.
* tests/migrations/Makefile.am (TMP): Default to '/tmp'.
(TESTS_ENVIRONMENT): Set 'TMP'.
* tests/openpgp/Makefile.am (TMP): Default to '/tmp'.
(TESTS_ENVIRONMENT): Set 'TMP'.

Signed-off-by: Justus Winter <justus@g10code.com>
tests/gpgscm/tests.scm
tests/migrations/Makefile.am
tests/openpgp/Makefile.am

index ebe1be5..2728817 100644 (file)
          (sink (open to (logior O_WRONLY O_CREAT) #o600)))
     (splice source sink)))
 
+(define (path-join . components)
+  (let loop ((acc #f) (rest (filter (lambda (s)
+                                     (not (string=? "" s))) components)))
+    (if (null? rest)
+       acc
+       (loop (if (string? acc)
+                 (string-append acc "/" (car rest))
+                 (car rest))
+             (cdr rest)))))
+(assert (string=? (path-join "foo" "bar" "baz") "foo/bar/baz"))
+(assert (string=? (path-join "" "bar" "baz") "bar/baz"))
+
 (define (canonical-path path)
   (if (char=? #\/ (string-ref path 0))
       path
 (macro (with-temporary-working-directory form)
   (let ((result-sym (gensym)) (cwd-sym (gensym)) (tmp-sym (gensym)))
     `(let* ((,cwd-sym (getcwd))
-           (,tmp-sym (mkdtemp "gpgscm-XXXXXX"))
+           (,tmp-sym (mkdtemp (path-join (getenv "TMP") "gpgscm-XXXXXX")))
            (_ (chdir ,tmp-sym))
            (,result-sym (begin ,@(cdr form))))
        (chdir ,cwd-sym)
        ,result-sym)))
 
 (define (make-temporary-file . args)
-  (canonical-path (string-append (mkdtemp "gpgscm-XXXXXX")
-                                "/"
-                                (if (null? args) "a" (car args)))))
+  (canonical-path (path-join
+                  (mkdtemp (path-join (getenv "TMP") "gpgscm-XXXXXX"))
+                  (if (null? args) "a" (car args)))))
 
 (define (remove-temporary-file filename)
   (catch '()
index 0377b23..9c82d66 100644 (file)
@@ -26,8 +26,11 @@ include $(top_srcdir)/am/cmacros.am
 
 AM_CFLAGS =
 
+TMP ?= /tmp
+
 TESTS_ENVIRONMENT = GPG_AGENT_INFO= LC_ALL=C \
        PATH=../gpgscm:$(PATH) \
+       TMP=$(TMP) \
        GPGSCM_PATH=$(top_srcdir)/tests/gpgscm:$(top_srcdir)/tests/migrations
 
 TESTS = from-classic.scm \
index 4137018..012a3f2 100644 (file)
@@ -34,9 +34,12 @@ noinst_PROGRAMS = fake-pinentry
 
 fake_pinentry_SOURCES = fake-pinentry.c
 
+TMP ?= /tmp
+
 TESTS_ENVIRONMENT = GNUPGHOME=$(abs_builddir) GPG_AGENT_INFO= LC_ALL=C \
        EXEEXT=$(EXEEXT) \
        PATH=../gpgscm:$(PATH) \
+       TMP=$(TMP) \
        objdir=$(abs_top_builddir) \
        GPGSCM_PATH=$(top_srcdir)/tests/gpgscm:$(top_srcdir)/tests/openpgp