From 550ba9ebb4b1b2415c9930879cfa6937f7fa916a Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 13 Aug 2007 13:15:02 +0000 Subject: [PATCH] * Fix the tests. --- tests/Makefile.am | 9 ++------- tests/common.sh.in | 4 ++++ tests/fallback.nix.in | 7 ------- tests/fallback.sh | 12 ++++++++---- tests/nix-pull.sh | 4 +++- tests/simple.builder.sh | 2 +- tests/substituter.sh | 27 ++++++++++++++++++--------- tests/substituter2.sh | 21 ++++++++++++++++++--- tests/substitutes.nix.in | 6 ------ tests/substitutes.sh | 14 ++++++-------- tests/substitutes2.nix.in | 6 ------ tests/substitutes2.sh | 18 +++++++----------- 12 files changed, 67 insertions(+), 63 deletions(-) delete mode 100644 tests/fallback.nix.in delete mode 100644 tests/substitutes.nix.in delete mode 100644 tests/substitutes2.nix.in diff --git a/tests/Makefile.am b/tests/Makefile.am index bfb8508a0..31ad159b0 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -2,14 +2,11 @@ TESTS_ENVIRONMENT = $(SHELL) -e extra1 = $(shell pwd)/test-tmp/shared -simple.sh: simple.nix +simple.sh substitutes.sh substitutes2.sh fallback.sh: simple.nix dependencies.sh gc.sh nix-push.sh nix-pull.in logging.sh nix-build.sh install-package.sh check-refs.sh: dependencies.nix locking.sh: locking.nix parallel.sh: parallel.nix build-hook.sh: build-hook.nix -substitutes.sh: substitutes.nix -substitutes2.sh: substitutes2.nix -fallback.sh: fallback.nix gc-concurrent.sh: gc-concurrent.nix gc-concurrent2.nix user-envs.sh: user-envs.nix fixed.sh: fixed.nix @@ -36,11 +33,9 @@ EXTRA_DIST = $(TESTS) \ locking.nix.in locking.builder.sh \ parallel.nix.in parallel.builder.sh \ build-hook.nix.in build-hook.hook.sh \ - substitutes.nix.in substituter.sh \ - substitutes2.nix.in substituter2.sh \ + substituter.sh substituter2.sh \ gc-concurrent.nix.in gc-concurrent.builder.sh \ gc-concurrent2.nix.in gc-concurrent2.builder.sh \ - fallback.nix.in \ user-envs.nix.in user-envs.builder.sh \ fixed.nix.in fixed.builder1.sh fixed.builder2.sh \ gc-runtime.nix.in \ diff --git a/tests/common.sh.in b/tests/common.sh.in index 32759bab0..1b8bb3e7d 100644 --- a/tests/common.sh.in +++ b/tests/common.sh.in @@ -65,3 +65,7 @@ clearProfiles() { profiles="$NIX_STATE_DIR"/profiles rm -f $profiles/* } + +clearManifests() { + rm -f $NIX_STATE_DIR/manifests/* +} diff --git a/tests/fallback.nix.in b/tests/fallback.nix.in deleted file mode 100644 index e47b59823..000000000 --- a/tests/fallback.nix.in +++ /dev/null @@ -1,7 +0,0 @@ -derivation { - name = "fall-back"; - system = "@system@"; - builder = "@shell@"; - args = ["-e" "-x" ./simple.builder.sh]; - goodPath = "@testPath@"; -} diff --git a/tests/fallback.sh b/tests/fallback.sh index 482e4ce5b..24889a452 100644 --- a/tests/fallback.sh +++ b/tests/fallback.sh @@ -1,15 +1,19 @@ source common.sh -drvPath=$($nixinstantiate fallback.nix) +clearStore + +drvPath=$($nixinstantiate simple.nix) echo "derivation is $drvPath" outPath=$($nixstore -q --fallback "$drvPath") echo "output path is $outPath" -# Register a non-existant substitute -(echo $outPath && echo "" && echo $TOP/no-such-program && echo 0 && echo 0) | $nixstore --register-substitutes +# Build with a substitute that fails. This should fail. +export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh +if $nixstore -r "$drvPath"; then echo unexpected fallback; exit 1; fi -# Build the derivation +# Build with a substitute that fails. This should fall back to a source build. +export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh $nixstore -r --fallback "$drvPath" text=$(cat "$outPath"/hello) diff --git a/tests/nix-pull.sh b/tests/nix-pull.sh index a847510ce..5ef3e55ca 100644 --- a/tests/nix-pull.sh +++ b/tests/nix-pull.sh @@ -6,6 +6,7 @@ pullCache () { } clearStore +clearManifests pullCache drvPath=$($nixinstantiate dependencies.nix) @@ -17,6 +18,7 @@ $nixstore -r $outPath cat $outPath/input-2/bar clearStore +clearManifests pullCache echo "building $drvPath using substitutes..." @@ -28,4 +30,4 @@ cat $outPath/input-2/bar test $($nixstore -q --deriver "$outPath") = "$drvPath" $nixstore -q --deriver $(readLink $outPath/input-2) | grep -q -- "-input-2.drv" -$nixstore --clear-substitutes +clearManifests diff --git a/tests/simple.builder.sh b/tests/simple.builder.sh index 536faec14..569e8ca88 100644 --- a/tests/simple.builder.sh +++ b/tests/simple.builder.sh @@ -1,7 +1,7 @@ echo "PATH=$PATH" # Verify that the PATH is empty. -if mkdir foo; then exit 1; fi +if mkdir foo 2> /dev/null; then exit 1; fi # Set a PATH (!!! impure). export PATH=$goodPath diff --git a/tests/substituter.sh b/tests/substituter.sh index 005e97605..96fb95b91 100755 --- a/tests/substituter.sh +++ b/tests/substituter.sh @@ -1,10 +1,19 @@ -#! /bin/sh -ex -echo $* - -case $* in - *) - mkdir $1 - echo $3 $4 > $1/hello - ;; -esac +#! /bin/sh -e +echo substituter args: $* >&2 +if test $1 = "--query-paths"; then + cat $TEST_ROOT/sub-paths +elif test $1 = "--query-info"; then + shift + for i in in $@; do + echo $i + echo "" # deriver + echo 0 # nr of refs + done +elif test $1 = "--substitute"; then + mkdir $2 + echo "Hallo Wereld" > $2/hello +else + echo "unknown substituter operation" + exit 1 +fi diff --git a/tests/substituter2.sh b/tests/substituter2.sh index c4e1bfec7..1bcf65a54 100755 --- a/tests/substituter2.sh +++ b/tests/substituter2.sh @@ -1,3 +1,18 @@ -#! /bin/sh -ex -echo $* -exit 1 +#! /bin/sh -e +echo substituter2 args: $* >&2 + +if test $1 = "--query-paths"; then + cat $TEST_ROOT/sub-paths +elif test $1 = "--query-info"; then + shift + for i in in $@; do + echo $i + echo "" # deriver + echo 0 # nr of refs + done +elif test $1 = "--substitute"; then + exit 1 +else + echo "unknown substituter operation" + exit 1 +fi diff --git a/tests/substitutes.nix.in b/tests/substitutes.nix.in deleted file mode 100644 index e34736216..000000000 --- a/tests/substitutes.nix.in +++ /dev/null @@ -1,6 +0,0 @@ -derivation { - name = "substitutes"; - system = "@system@"; - builder = "@shell@"; - args = ["-e" "-x" ./simple.builder.sh]; -} \ No newline at end of file diff --git a/tests/substitutes.sh b/tests/substitutes.sh index c44f012f5..042827314 100644 --- a/tests/substitutes.sh +++ b/tests/substitutes.sh @@ -1,22 +1,20 @@ source common.sh +clearStore + # Instantiate. -drvPath=$($nixinstantiate substitutes.nix) +drvPath=$($nixinstantiate simple.nix) echo "derivation is $drvPath" # Find the output path. outPath=$($nixstore -qvv "$drvPath") echo "output path is $outPath" -regSub() { - (echo $1 && echo "" && echo $2 && echo 3 && echo $outPath && echo Hallo && echo Wereld && echo 0) | $nixstore --register-substitutes -} - -# Register a substitute for the output path. -regSub $outPath $(pwd)/substituter.sh +echo $outPath > $TEST_ROOT/sub-paths +export NIX_SUBSTITUTERS=$(pwd)/substituter.sh $nixstore -rvv "$drvPath" text=$(cat "$outPath"/hello) -if test "$text" != "Hallo Wereld"; then exit 1; fi +if test "$text" != "Hallo Wereld"; then echo "wrong substitute output: $text"; exit 1; fi diff --git a/tests/substitutes2.nix.in b/tests/substitutes2.nix.in deleted file mode 100644 index 8ade1ba11..000000000 --- a/tests/substitutes2.nix.in +++ /dev/null @@ -1,6 +0,0 @@ -derivation { - name = "substitutes-2"; - system = "@system@"; - builder = "@shell@"; - args = ["-e" "-x" ./simple.builder.sh]; -} \ No newline at end of file diff --git a/tests/substitutes2.sh b/tests/substitutes2.sh index 416e81536..0bbc13913 100644 --- a/tests/substitutes2.sh +++ b/tests/substitutes2.sh @@ -1,25 +1,21 @@ source common.sh +clearStore + # Instantiate. -drvPath=$($nixinstantiate substitutes2.nix) +drvPath=$($nixinstantiate simple.nix) echo "derivation is $drvPath" # Find the output path. outPath=$($nixstore -qvvvvv "$drvPath") echo "output path is $outPath" -regSub() { - (echo $1 && echo "" && echo $2 && echo 3 && echo $outPath && echo Hallo && echo Wereld && echo 0) | $nixstore --register-substitutes -} +echo $outPath > $TEST_ROOT/sub-paths -# Register a substitute for the output path. -regSub $outPath $(pwd)/substituter.sh - -# Register another substitute for the output path. This one takes -# precedence over the previous one. It will fail. -regSub $outPath $(pwd)/substituter2.sh +# First try a substituter that fails, then one that succeeds +export NIX_SUBSTITUTERS=$(pwd)/substituter2.sh:$(pwd)/substituter.sh $nixstore -rvv "$drvPath" text=$(cat "$outPath"/hello) -if test "$text" != "Hallo Wereld"; then exit 1; fi +if test "$text" != "Hallo Wereld"; then echo "wrong substitute output: $text"; exit 1; fi