aboutsummaryrefslogtreecommitdiff
path: root/guix/tests.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2019-03-16 15:11:29 +0100
committerLudovic Courtès <ludo@gnu.org>2019-03-16 18:15:09 +0100
commit22f95e028f038cee342f455dfc55bd32b804907c (patch)
treedade133425c4c41f26ffad0ecad315923db94dee /guix/tests.scm
parent0848615300ec0693b2849e80103a13063fa4b190 (diff)
downloadguix-22f95e028f038cee342f455dfc55bd32b804907c.tar
guix-22f95e028f038cee342f455dfc55bd32b804907c.tar.gz
tests: Add 'with-environment-variable'.
* tests/scripts.scm (with-environment-variable): Move to... * guix/tests.scm (with-environment-variable): ... here. * tests/build-utils.scm ("wrap-program, one input, multiple calls"): Use it instead of 'setenv'.
Diffstat (limited to 'guix/tests.scm')
-rw-r--r--guix/tests.scm15
1 files changed, 15 insertions, 0 deletions
diff --git a/guix/tests.scm b/guix/tests.scm
index 749a4edd7a..35ebf8464d 100644
--- a/guix/tests.scm
+++ b/guix/tests.scm
@@ -39,6 +39,8 @@
canonical-file?
network-reachable?
shebang-too-long?
+ with-environment-variable
+
mock
%test-substitute-urls
test-assertm
@@ -195,6 +197,19 @@ store is opened."
(run-with-store store exp
#:guile-for-build (%guile-for-build)))))
+(define-syntax-rule (with-environment-variable variable value body ...)
+ "Run BODY with VARIABLE set to VALUE."
+ (let ((orig (getenv variable)))
+ (dynamic-wind
+ (lambda ()
+ (setenv variable value))
+ (lambda ()
+ body ...)
+ (lambda ()
+ (if orig
+ (setenv variable orig)
+ (unsetenv variable))))))
+
;;;
;;; Narinfo files, as used by the substituter.