about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/lang/eval-fail-path-slash.nix6
-rw-r--r--tests/lang/eval-okay-comments.exp1
-rw-r--r--tests/lang/eval-okay-comments.nix59
-rw-r--r--tests/local.mk2
-rw-r--r--tests/nix-shell.sh21
-rw-r--r--tests/shell.nix46
-rwxr-xr-xtests/shell.shebang.sh4
-rw-r--r--tests/timeout.builder.sh2
-rw-r--r--tests/timeout.nix28
-rw-r--r--tests/timeout.sh14
10 files changed, 175 insertions, 8 deletions
diff --git a/tests/lang/eval-fail-path-slash.nix b/tests/lang/eval-fail-path-slash.nix
new file mode 100644
index 000000000000..530105b3210b
--- /dev/null
+++ b/tests/lang/eval-fail-path-slash.nix
@@ -0,0 +1,6 @@
+# Trailing slashes in paths are not allowed.
+# This restriction could be lifted sometime,
+# for example if we make '/' a path concatenation operator.
+# See https://github.com/NixOS/nix/issues/1138
+# and http://lists.science.uu.nl/pipermail/nix-dev/2016-June/020829.html
+/nix/store/
diff --git a/tests/lang/eval-okay-comments.exp b/tests/lang/eval-okay-comments.exp
new file mode 100644
index 000000000000..7182dc2f9b8e
--- /dev/null
+++ b/tests/lang/eval-okay-comments.exp
@@ -0,0 +1 @@
+"abcdefghijklmnopqrstuvwxyz"
diff --git a/tests/lang/eval-okay-comments.nix b/tests/lang/eval-okay-comments.nix
new file mode 100644
index 000000000000..cb2cce218029
--- /dev/null
+++ b/tests/lang/eval-okay-comments.nix
@@ -0,0 +1,59 @@
+# A simple comment
+"a"+ # And another
+## A double comment
+"b"+  ## And another
+# Nested # comments #
+"c"+   # and # some # other #
+# An empty line, following here:
+
+"d"+      # and a comment not starting the line !
+
+"e"+
+/* multiline comments */
+"f" +
+/* multiline
+   comments,
+   on
+   multiple
+   lines
+*/
+"g" +
+# Small, tricky comments
+/**/ "h"+ /*/*/ "i"+ /***/ "j"+ /* /*/ "k"+ /*/* /*/ "l"+
+# Comments with an even number of ending '*' used to fail:
+"m"+
+/* */ /* **/ /* ***/ /* ****/ "n"+
+/* */ /** */ /*** */ /**** */ "o"+
+/** **/ /*** ***/ /**** ****/ "p"+
+/* * ** *** **** ***** */     "q"+
+# Random comments
+/* ***** ////// * / * / /* */ "r"+
+# Mixed comments
+/* # */
+"s"+
+# /* #
+"t"+
+# /* # */
+"u"+
+# /*********/
+"v"+
+## */*
+"w"+
+/*
+ * Multiline, decorated comments
+ * # This ain't a nest'd comm'nt
+ */
+"x"+
+''${/** with **/"y"
+  # real
+  /* comments
+     inside ! # */
+
+  # (and empty lines)
+
+}''+          /* And a multiline comment,
+                 on the same line,
+                 after some spaces
+*/             # followed by a one-line comment
+"z"
+/* EOF */
diff --git a/tests/local.mk b/tests/local.mk
index 2ca52144baee..b3ce39cda806 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -11,7 +11,7 @@ nix_tests = \
   multiple-outputs.sh import-derivation.sh fetchurl.sh optimise-store.sh \
   binary-cache.sh nix-profile.sh repair.sh dump-db.sh case-hack.sh \
   check-reqs.sh pass-as-file.sh tarball.sh restricted.sh \
-  placeholders.sh
+  placeholders.sh nix-shell.sh
   # parallel.sh
 
 install-tests += $(foreach x, $(nix_tests), tests/$(x))
diff --git a/tests/nix-shell.sh b/tests/nix-shell.sh
new file mode 100644
index 000000000000..26cc521bbcbf
--- /dev/null
+++ b/tests/nix-shell.sh
@@ -0,0 +1,21 @@
+source common.sh
+
+clearStore
+
+# Test nix-shell -A
+export IMPURE_VAR=foo
+output=$(nix-shell --pure shell.nix -A shellDrv --run \
+    'echo "$IMPURE_VAR - $VAR_FROM_STDENV_SETUP - $VAR_FROM_NIX"')
+
+[ "$output" = " - foo - bar" ]
+
+# Test nix-shell -p
+output=$(NIX_PATH=nixpkgs=shell.nix nix-shell --pure -p foo bar --run 'echo "$(foo) $(bar)"')
+[ "$output" = "foo bar" ]
+
+# Test nix-shell shebang mode
+sed -e "s|@ENV_PROG@|$(type -p env)|" shell.shebang.sh > $TEST_ROOT/shell.shebang.sh
+chmod a+rx $TEST_ROOT/shell.shebang.sh
+
+output=$($TEST_ROOT/shell.shebang.sh abc def)
+[ "$output" = "foo bar abc def" ]
diff --git a/tests/shell.nix b/tests/shell.nix
new file mode 100644
index 000000000000..ed4d6fbaaa0b
--- /dev/null
+++ b/tests/shell.nix
@@ -0,0 +1,46 @@
+{ }:
+
+with import ./config.nix;
+
+rec {
+  setupSh = builtins.toFile "setup" ''
+    export VAR_FROM_STDENV_SETUP=foo
+    for pkg in $buildInputs; do
+      export PATH=$PATH:$pkg/bin
+    done
+  '';
+
+  stdenv = mkDerivation {
+    name = "stdenv";
+    buildCommand = ''
+      mkdir -p $out
+      ln -s ${setupSh} $out/setup
+    '';
+  };
+
+  shellDrv = mkDerivation {
+    name = "shellDrv";
+    builder = "/does/not/exist";
+    VAR_FROM_NIX = "bar";
+    inherit stdenv;
+  };
+
+  # Used by nix-shell -p
+  runCommand = name: args: buildCommand: mkDerivation (args // {
+    inherit name buildCommand stdenv;
+  });
+
+  foo = runCommand "foo" {} ''
+    mkdir -p $out/bin
+    echo 'echo foo' > $out/bin/foo
+    chmod a+rx $out/bin/foo
+  '';
+
+  bar = runCommand "bar" {} ''
+    mkdir -p $out/bin
+    echo 'echo bar' > $out/bin/bar
+    chmod a+rx $out/bin/bar
+  '';
+
+  bash = shell;
+}
diff --git a/tests/shell.shebang.sh b/tests/shell.shebang.sh
new file mode 100755
index 000000000000..3dadd591572d
--- /dev/null
+++ b/tests/shell.shebang.sh
@@ -0,0 +1,4 @@
+#! @ENV_PROG@ nix-shell
+#! nix-shell -I nixpkgs=shell.nix --option use-binary-caches false
+#! nix-shell --pure -i bash -p foo bar
+echo "$(foo) $(bar) $@"
diff --git a/tests/timeout.builder.sh b/tests/timeout.builder.sh
deleted file mode 100644
index 3fbdd57946ad..000000000000
--- a/tests/timeout.builder.sh
+++ /dev/null
@@ -1,2 +0,0 @@
-echo "‘timeout’ builder entering an infinite loop"
-while true ; do echo -n .; done
diff --git a/tests/timeout.nix b/tests/timeout.nix
index b41368bb38e2..540fba934ff6 100644
--- a/tests/timeout.nix
+++ b/tests/timeout.nix
@@ -1,6 +1,28 @@
 with import ./config.nix;
 
-mkDerivation {
-  name = "timeout";
-  builder = ./timeout.builder.sh;
+{
+
+  infiniteLoop = mkDerivation {
+    name = "timeout";
+    buildCommand = ''
+      echo "‘timeout’ builder entering an infinite loop"
+      while true ; do echo -n .; done
+    '';
+  };
+
+  silent = mkDerivation {
+    name = "silent";
+    buildCommand = ''
+      sleep 60
+    '';
+  };
+
+  closeLog = mkDerivation {
+    name = "silent";
+    buildCommand = ''
+      exec > /dev/null 2>&1
+      sleep 1000000000
+    '';
+  };
+
 }
diff --git a/tests/timeout.sh b/tests/timeout.sh
index 2ebd06b9330c..ce1ae7d674a1 100644
--- a/tests/timeout.sh
+++ b/tests/timeout.sh
@@ -3,7 +3,7 @@
 source common.sh
 
 failed=0
-messages="`nix-build -Q timeout.nix --timeout 2 2>&1 || failed=1`"
+messages="`nix-build -Q timeout.nix -A infiniteLoop --timeout 2 2>&1 || failed=1`"
 if [ $failed -ne 0 ]; then
     echo "error: ‘nix-store’ succeeded; should have timed out"
     exit 1
@@ -15,7 +15,17 @@ if ! echo "$messages" | grep -q "timed out"; then
     exit 1
 fi
 
-if nix-build -Q timeout.nix --option build-max-log-size 100; then
+if nix-build -Q timeout.nix -A infiniteLoop --option build-max-log-size 100; then
+    echo "build should have failed"
+    exit 1
+fi
+
+if nix-build timeout.nix -A silent --max-silent-time 2; then
+    echo "build should have failed"
+    exit 1
+fi
+
+if nix-build timeout.nix -A closeLog; then
     echo "build should have failed"
     exit 1
 fi