From 44ad33843a5653bf9e49b37d7fdd2903a9142ee0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= <ludo@gnu.org>
Date: Mon, 18 Jan 2016 15:13:30 +0100
Subject: [PATCH] derivations: Add test for #:leaked-env-vars.

* tests/derivations.scm ("derivation #:leaked-env-vars"): New test.
---
 tests/derivations.scm | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/tests/derivations.scm b/tests/derivations.scm
index 1bbc93fe5c0..64cc8a94c92 100644
--- a/tests/derivations.scm
+++ b/tests/derivations.scm
@@ -1,5 +1,5 @@
 ;;; GNU Guix --- Functional package management for GNU
-;;; Copyright © 2012, 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2012, 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -472,6 +472,22 @@ (define (deps path . deps)
       (build-derivations %store (list drv))
       #f)))
 
+;; Here we should get the value of $NIX_STATE_DIR that the daemon sees, which
+;; is a unique value for each test process; this value is the same as the one
+;; we see in the process executing this file since it is set by 'test-env'.
+(test-equal "derivation #:leaked-env-vars"
+  (getenv "NIX_STATE_DIR")
+  (let* ((value (getenv "NIX_STATE_DIR"))
+         (drv   (derivation %store "leaked-env-vars" %bash
+                            '("-c" "echo -n $NIX_STATE_DIR > $out")
+                            #:hash (sha256 (string->utf8 value))
+                            #:hash-algo 'sha256
+                            #:inputs `((,%bash))
+                            #:leaked-env-vars '("NIX_STATE_DIR"))))
+    (and (build-derivations %store (list drv))
+         (call-with-input-file (derivation->output-path drv)
+           get-string-all))))
+
 
 (define %coreutils
   (false-if-exception
-- 
GitLab