about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/binary-cache.sh2
-rwxr-xr-xtests/build-hook.hook.sh23
-rw-r--r--tests/build-hook.sh10
-rw-r--r--tests/build-remote.sh17
-rw-r--r--tests/common.sh.in1
-rw-r--r--tests/config.nix2
-rw-r--r--tests/lang/lib.nix2
-rw-r--r--tests/lang/parse-okay-url.nix3
-rw-r--r--tests/linux-sandbox.sh2
-rw-r--r--tests/local.mk5
-rw-r--r--tests/restricted.sh12
-rw-r--r--tests/structured-attrs.nix66
-rw-r--r--tests/structured-attrs.sh7
13 files changed, 100 insertions, 52 deletions
diff --git a/tests/binary-cache.sh b/tests/binary-cache.sh
index 30d7cc6ba88c..2a044d2edc56 100644
--- a/tests/binary-cache.sh
+++ b/tests/binary-cache.sh
@@ -100,7 +100,7 @@ clearStore
 rm $(grep -l "StorePath:.*dependencies-input-2" $cacheDir/*.narinfo)
 
 nix-build --option binary-caches "file://$cacheDir" --option signed-binary-caches '' dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log
-grep -q "fetching path" $TEST_ROOT/log
+grep -q "copying path" $TEST_ROOT/log
 
 
 if [ -n "$HAVE_SODIUM" ]; then
diff --git a/tests/build-hook.hook.sh b/tests/build-hook.hook.sh
deleted file mode 100755
index c7472eab7600..000000000000
--- a/tests/build-hook.hook.sh
+++ /dev/null
@@ -1,23 +0,0 @@
-#! /bin/sh
-
-#set -x
-
-while read x y drv rest; do
-
-    echo "HOOK for $drv" >&2
-
-    outPath=`sed 's/Derive(\[("out",\"\([^\"]*\)\".*/\1/' $drv`
-
-    echo "output path is $outPath" >&2
-
-    if `echo $outPath | grep -q input-1`; then
-        echo "# accept" >&2
-        read inputs
-        read outputs
-        mkdir $outPath
-        echo "BAR" > $outPath/foo
-    else
-        echo "# decline" >&2
-    fi
-
-done
diff --git a/tests/build-hook.sh b/tests/build-hook.sh
deleted file mode 100644
index 2005c7cebdc4..000000000000
--- a/tests/build-hook.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-source common.sh
-
-clearStore
-
-outPath=$(nix-build build-hook.nix --no-out-link --option build-hook $(pwd)/build-hook.hook.sh)
-
-echo "output path is $outPath"
-
-text=$(cat "$outPath"/foobar)
-if test "$text" != "BARBAR"; then exit 1; fi
diff --git a/tests/build-remote.sh b/tests/build-remote.sh
index e27ce7e25a8e..cf3bb4633183 100644
--- a/tests/build-remote.sh
+++ b/tests/build-remote.sh
@@ -9,20 +9,15 @@ chmod -R u+w $TEST_ROOT/store0 || true
 chmod -R u+w $TEST_ROOT/store1 || true
 rm -rf $TEST_ROOT/store0 $TEST_ROOT/store1
 
-# FIXME: --option is not passed to build-remote, so have to create a config file.
-export NIX_CONF_DIR=$TEST_ROOT/etc2
-mkdir -p $NIX_CONF_DIR
-echo "
-sandbox-paths = /nix/store
-sandbox-build-dir = /build-tmp
-" > $NIX_CONF_DIR/nix.conf
+nix build -f build-hook.nix -o $TEST_ROOT/result --max-jobs 0 \
+  --sandbox-paths /nix/store --sandbox-build-dir /build-tmp \
+  --builders "$TEST_ROOT/store0; $TEST_ROOT/store1 - - 1 1 foo"
 
-outPath=$(nix-build build-hook.nix --no-out-link -j0 \
-  --option builders "local?root=$TEST_ROOT/store0; local?root=$TEST_ROOT/store1 - - 1 1 foo")
+outPath=$TEST_ROOT/result
 
 cat $outPath/foobar | grep FOOBAR
 
 # Ensure that input1 was built on store1 due to the required feature.
 p=$(readlink -f $outPath/input-2)
-(! nix path-info --store local?root=$TEST_ROOT/store0 --all | grep dependencies.builder1.sh)
-nix path-info --store local?root=$TEST_ROOT/store1 --all | grep dependencies.builder1.sh
+(! nix path-info --store $TEST_ROOT/store0 --all | grep dependencies.builder1.sh)
+nix path-info --store $TEST_ROOT/store1 --all | grep dependencies.builder1.sh
diff --git a/tests/common.sh.in b/tests/common.sh.in
index a8d56707e27d..04d605e34438 100644
--- a/tests/common.sh.in
+++ b/tests/common.sh.in
@@ -26,7 +26,6 @@ mkdir -p $TEST_HOME
 export PATH=@bindir@:$PATH
 coreutils=@coreutils@
 
-export NIX_BUILD_HOOK=
 export dot=@dot@
 export xmllint="@xmllint@"
 export SHELL="@bash@"
diff --git a/tests/config.nix b/tests/config.nix
index 76388fdd5b95..6ba91065b83d 100644
--- a/tests/config.nix
+++ b/tests/config.nix
@@ -13,7 +13,7 @@ rec {
     derivation ({
       inherit system;
       builder = shell;
-      args = ["-e" args.builder or (builtins.toFile "builder.sh" "eval \"$buildCommand\"")];
+      args = ["-e" args.builder or (builtins.toFile "builder.sh" "if [ -e .attrs.sh ]; then source .attrs.sh; fi; eval \"$buildCommand\"")];
       PATH = path;
     } // removeAttrs args ["builder" "meta"])
     // { meta = args.meta or {}; };
diff --git a/tests/lang/lib.nix b/tests/lang/lib.nix
index 028a538314b7..1c63b2f31d67 100644
--- a/tests/lang/lib.nix
+++ b/tests/lang/lib.nix
@@ -49,7 +49,7 @@ rec {
     if comp (head list2) (head list1) then [(head list2)] ++ mergeLists comp list1 (tail list2) else
     [(head list1)] ++ mergeLists comp (tail list1) list2;
 
-  id = x: x;
+  id = x:x; # sic
 
   const = x: y: x;
 
diff --git a/tests/lang/parse-okay-url.nix b/tests/lang/parse-okay-url.nix
index fce3b13ee64b..fb74d66f0923 100644
--- a/tests/lang/parse-okay-url.nix
+++ b/tests/lang/parse-okay-url.nix
@@ -1,7 +1,8 @@
-[ x:x
+[
   https://svn.cs.uu.nl:12443/repos/trace/trunk
   http://www2.mplayerhq.hu/MPlayer/releases/fonts/font-arial-iso-8859-1.tar.bz2
   http://losser.st-lab.cs.uu.nl/~armijn/.nix/gcc-3.3.4-static-nix.tar.gz
   http://fpdownload.macromedia.com/get/shockwave/flash/english/linux/7.0r25/install_flash_player_7_linux.tar.gz
   ftp://ftp.gtk.org/pub/gtk/v1.2/gtk+-1.2.10.tar.gz
+  channel:nixos-17.09
 ]
diff --git a/tests/linux-sandbox.sh b/tests/linux-sandbox.sh
index 7f4e83b560be..0691c30be1ce 100644
--- a/tests/linux-sandbox.sh
+++ b/tests/linux-sandbox.sh
@@ -14,7 +14,7 @@ chmod -R u+w $TEST_ROOT/store0 || true
 rm -rf $TEST_ROOT/store0
 
 export NIX_STORE_DIR=/my/store
-export NIX_REMOTE="local?root=$TEST_ROOT/store0"
+export NIX_REMOTE=$TEST_ROOT/store0
 
 outPath=$(nix-build dependencies.nix --no-out-link --option sandbox-paths /nix/store)
 
diff --git a/tests/local.mk b/tests/local.mk
index 7d99a0fc7675..6160b04c2598 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -3,7 +3,7 @@ check:
 
 nix_tests = \
   init.sh hash.sh lang.sh add.sh simple.sh dependencies.sh \
-  build-hook.sh gc.sh gc-concurrent.sh \
+  gc.sh gc-concurrent.sh \
   referrers.sh user-envs.sh logging.sh nix-build.sh misc.sh fixed.sh \
   gc-runtime.sh check-refs.sh filter-source.sh \
   remote-store.sh export.sh export-graph.sh \
@@ -14,7 +14,8 @@ nix_tests = \
   placeholders.sh nix-shell.sh \
   linux-sandbox.sh \
   build-remote.sh \
-  nar-index.sh
+  nar-index.sh \
+  structured-attrs.sh
   # parallel.sh
 
 install-tests += $(foreach x, $(nix_tests), tests/$(x))
diff --git a/tests/restricted.sh b/tests/restricted.sh
index 19096a9f8dd2..a297847cc8e3 100644
--- a/tests/restricted.sh
+++ b/tests/restricted.sh
@@ -16,3 +16,15 @@ nix-instantiate --option restrict-eval true --eval -E 'builtins.readDir ../src/b
 (! nix-instantiate --option restrict-eval true --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in <foo>')
 nix-instantiate --option restrict-eval true --eval -E 'let __nixPath = [ { prefix = "foo"; path = ./.; } ]; in <foo>' -I src=.
 
+p=$(nix eval --raw "(builtins.fetchurl file://$(pwd)/restricted.sh)" --restrict-eval --allowed-uris "file://$(pwd)")
+cmp $p restricted.sh
+
+(! nix eval --raw "(builtins.fetchurl file://$(pwd)/restricted.sh)" --restrict-eval)
+
+(! nix eval --raw "(builtins.fetchurl file://$(pwd)/restricted.sh)" --restrict-eval --allowed-uris "file://$(pwd)/restricted.sh/")
+
+nix eval --raw "(builtins.fetchurl file://$(pwd)/restricted.sh)" --restrict-eval --allowed-uris "file://$(pwd)/restricted.sh"
+
+(! nix eval --raw "(builtins.fetchurl https://github.com/NixOS/patchelf/archive/master.tar.gz)" --restrict-eval)
+(! nix eval --raw "(builtins.fetchTarball https://github.com/NixOS/patchelf/archive/master.tar.gz)" --restrict-eval)
+(! nix eval --raw "(fetchGit git://github.com/NixOS/patchelf.git)" --restrict-eval)
diff --git a/tests/structured-attrs.nix b/tests/structured-attrs.nix
new file mode 100644
index 000000000000..6c77a43913a7
--- /dev/null
+++ b/tests/structured-attrs.nix
@@ -0,0 +1,66 @@
+with import ./config.nix;
+
+let
+
+  dep = mkDerivation {
+    name = "dep";
+    buildCommand = ''
+      mkdir $out; echo bla > $out/bla
+    '';
+  };
+
+in
+
+mkDerivation {
+  name = "structured";
+
+  __structuredAttrs = true;
+
+  buildCommand = ''
+    set -x
+
+    [[ $int = 123456789 ]]
+    [[ -z $float ]]
+    [[ -n $boolTrue ]]
+    [[ -z $boolFalse ]]
+    [[ -n ''${hardening[format]} ]]
+    [[ -z ''${hardening[fortify]} ]]
+    [[ ''${#buildInputs[@]} = 7 ]]
+    [[ ''${buildInputs[2]} = c ]]
+    [[ -v nothing ]]
+    [[ -z $nothing ]]
+
+    mkdir ''${outputs[out]}
+    echo bar > $dest
+
+    json=$(cat .attrs.json)
+    [[ $json =~ '"narHash":"sha256:1r7yc43zqnzl5b0als5vnyp649gk17i37s7mj00xr8kc47rjcybk"' ]]
+    [[ $json =~ '"narSize":288' ]]
+    [[ $json =~ '"closureSize":288' ]]
+    [[ $json =~ '"references":[]' ]]
+  '';
+
+  buildInputs = [ "a" "b" "c" 123 "'" "\"" null ];
+
+  hardening.format = true;
+  hardening.fortify = false;
+
+  outer.inner = [ 1 2 3 ];
+
+  int = 123456789;
+
+  float = 123.456;
+
+  boolTrue = true;
+  boolFalse = false;
+
+  nothing = null;
+
+  dest = "${placeholder "out"}/foo";
+
+  "foo bar" = "BAD";
+  "1foobar" = "BAD";
+  "foo$" = "BAD";
+
+  exportReferencesGraph.refs = [ dep ];
+}
diff --git a/tests/structured-attrs.sh b/tests/structured-attrs.sh
new file mode 100644
index 000000000000..9ba2672b6833
--- /dev/null
+++ b/tests/structured-attrs.sh
@@ -0,0 +1,7 @@
+source common.sh
+
+clearStore
+
+outPath=$(nix-build structured-attrs.nix --no-out-link)
+
+[[ $(cat $outPath/foo) = bar ]]