guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/03: tests: Add 'with-environment-variable'.


From: guix-commits
Subject: 01/03: tests: Add 'with-environment-variable'.
Date: Sat, 16 Mar 2019 13:15:26 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit 22f95e028f038cee342f455dfc55bd32b804907c
Author: Ludovic Courtès <address@hidden>
Date:   Sat Mar 16 15:11:29 2019 +0100

    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'.
---
 guix/tests.scm        | 15 +++++++++++++++
 tests/build-utils.scm | 30 ++++++++++++++++--------------
 tests/scripts.scm     | 15 +--------------
 3 files changed, 32 insertions(+), 28 deletions(-)

diff --git a/guix/tests.scm b/guix/tests.scm
index 749a4ed..35ebf84 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.
diff --git a/tests/build-utils.scm b/tests/build-utils.scm
index 7d49446..03216f9 100644
--- a/tests/build-utils.scm
+++ b/tests/build-utils.scm
@@ -107,19 +107,21 @@
        ;; it can't know about the bootstrap bash in the store, since it's not
        ;; named "bash".  Help it out a bit by providing a symlink it this
        ;; package's output.
-       (setenv "PATH" (dirname bash))
-       (wrap-program foo `("GUIX_FOO" prefix ("hello")))
-       (wrap-program foo `("GUIX_BAR" prefix ("world")))
-
-       ;; The bootstrap Bash is linked against an old libc and would abort with
-       ;; an assertion failure when trying to load incompatible locale data.
-       (unsetenv "LOCPATH")
-
-       (let* ((pipe (open-input-pipe foo))
-              (str  (get-string-all pipe)))
-         (with-directory-excursion directory
-           (for-each delete-file '("foo" ".foo-real")))
-         (and (zero? (close-pipe pipe))
-              str))))))
+       (with-environment-variable "PATH" (dirname bash)
+         (wrap-program foo `("GUIX_FOO" prefix ("hello")))
+         (wrap-program foo `("GUIX_BAR" prefix ("world")))
+
+         ;; The bootstrap Bash is linked against an old libc and would abort
+         ;; with an assertion failure when trying to load incompatible locale
+         ;; data.
+         (unsetenv "LOCPATH")
+
+         (let* ((pipe (open-input-pipe foo))
+                (str  (get-string-all pipe)))
+           (with-directory-excursion directory
+             (for-each delete-file '("foo" ".foo-real")))
+           (and (zero? (close-pipe pipe))
+                str)))))))
+
 
 (test-end)
diff --git a/tests/scripts.scm b/tests/scripts.scm
index 3901710..efee271 100644
--- a/tests/scripts.scm
+++ b/tests/scripts.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2015 Ludovic Courtès <address@hidden>
+;;; Copyright © 2015, 2019 Ludovic Courtès <address@hidden>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -25,19 +25,6 @@
 
 ;; Test the (guix scripts) module.
 
-(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))))))
-
 
 (test-begin "scripts")
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]