Fix tests

So all these years I was totally deluded about the meaning of "set
-e". You might think that it causes statements like "false && true" or
"! true" to fail, but it doesn't...
This commit is contained in:
Eelco Dolstra 2014-08-21 21:50:19 +02:00
parent 809ca33806
commit 3f80060500
9 changed files with 20 additions and 26 deletions

View file

@ -16,4 +16,4 @@ cmp case.nar $TEST_ROOT/case.nar
# Check whether we detect true collisions (e.g. those remaining after # Check whether we detect true collisions (e.g. those remaining after
# removal of the suffix). # removal of the suffix).
touch "$TEST_ROOT/case/xt_CONNMARK.h~nix~case~hack~3" touch "$TEST_ROOT/case/xt_CONNMARK.h~nix~case~hack~3"
! nix-store $opts --dump $TEST_ROOT/case > /dev/null (! nix-store $opts --dump $TEST_ROOT/case > /dev/null)

View file

@ -1,24 +1,22 @@
source common.sh source common.sh
set -x
RESULT=$TEST_ROOT/result RESULT=$TEST_ROOT/result
dep=$(nix-build -o $RESULT check-refs.nix -A dep) dep=$(nix-build -o $RESULT check-refs.nix -A dep)
# test1 references dep, not itself. # test1 references dep, not itself.
test1=$(nix-build -o $RESULT check-refs.nix -A test1) test1=$(nix-build -o $RESULT check-refs.nix -A test1)
! nix-store -q --references $test1 | grep -q $test1 (! nix-store -q --references $test1 | grep -q $test1)
nix-store -q --references $test1 | grep -q $dep nix-store -q --references $test1 | grep -q $dep
# test2 references src, not itself nor dep. # test2 references src, not itself nor dep.
test2=$(nix-build -o $RESULT check-refs.nix -A test2) test2=$(nix-build -o $RESULT check-refs.nix -A test2)
! nix-store -q --references $test2 | grep -q $test2 (! nix-store -q --references $test2 | grep -q $test2)
! nix-store -q --references $test2 | grep -q $dep (! nix-store -q --references $test2 | grep -q $dep)
nix-store -q --references $test2 | grep -q aux-ref nix-store -q --references $test2 | grep -q aux-ref
# test3 should fail (unallowed ref). # test3 should fail (unallowed ref).
! nix-build -o $RESULT check-refs.nix -A test3 (! nix-build -o $RESULT check-refs.nix -A test3)
# test4 should succeed. # test4 should succeed.
nix-build -o $RESULT check-refs.nix -A test4 nix-build -o $RESULT check-refs.nix -A test4
@ -27,10 +25,10 @@ nix-build -o $RESULT check-refs.nix -A test4
nix-build -o $RESULT check-refs.nix -A test5 nix-build -o $RESULT check-refs.nix -A test5
# test6 should fail (unallowed self-ref). # test6 should fail (unallowed self-ref).
! nix-build -o $RESULT check-refs.nix -A test6 (! nix-build -o $RESULT check-refs.nix -A test6)
# test7 should succeed (allowed self-ref). # test7 should succeed (allowed self-ref).
nix-build -o $RESULT check-refs.nix -A test7 nix-build -o $RESULT check-refs.nix -A test7
# test8 should fail (toFile depending on derivation output). # test8 should fail (toFile depending on derivation output).
! nix-build -o $RESULT check-refs.nix -A test8 (! nix-build -o $RESULT check-refs.nix -A test8)

View file

@ -12,7 +12,6 @@ ln -s xyzzy $TEST_ROOT/filterin/link
nix-build ./filter-source.nix -o $TEST_ROOT/filterout nix-build ./filter-source.nix -o $TEST_ROOT/filterout
set -x
test ! -e $TEST_ROOT/filterout/foo/bar test ! -e $TEST_ROOT/filterout/foo/bar
test -e $TEST_ROOT/filterout/xyzzy test -e $TEST_ROOT/filterout/xyzzy
test -e $TEST_ROOT/filterout/bak test -e $TEST_ROOT/filterout/bak

View file

@ -11,7 +11,7 @@ outPath2=$(nix-store -q $drvPath2)
drvPath3=$(nix-instantiate simple.nix) drvPath3=$(nix-instantiate simple.nix)
outPath3=$(nix-store -r $drvPath3) outPath3=$(nix-store -r $drvPath3)
! test -e $outPath3.lock (! test -e $outPath3.lock)
touch $outPath3.lock touch $outPath3.lock
rm -f "$NIX_STATE_DIR"/gcroots/foo* rm -f "$NIX_STATE_DIR"/gcroots/foo*
@ -50,9 +50,9 @@ rm -f "$NIX_STATE_DIR"/gcroots/foo*
# The collector should have deleted lock files for paths that have # The collector should have deleted lock files for paths that have
# been built previously. # been built previously.
! test -e $outPath3.lock (! test -e $outPath3.lock)
# If we run the collector now, it should delete outPath1/2. # If we run the collector now, it should delete outPath1/2.
nix-collect-garbage nix-collect-garbage
! test -e $outPath1 (! test -e $outPath1)
! test -e $outPath2 (! test -e $outPath2)

View file

@ -3,7 +3,7 @@ source common.sh
export TEST_VAR=foo # for eval-okay-getenv.nix export TEST_VAR=foo # for eval-okay-getenv.nix
nix-instantiate --eval -E 'builtins.trace "Hello" 123' 2>&1 | grep -q Hello nix-instantiate --eval -E 'builtins.trace "Hello" 123' 2>&1 | grep -q Hello
! nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello" 123' 2>&1 | grep -q Hello (! nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello" 123' 2>&1 | grep -q Hello)
nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello" (throw "Foo")' 2>&1 | grep -q Hello nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello" (throw "Foo")' 2>&1 | grep -q Hello
set +x set +x

View file

@ -3,7 +3,6 @@ source common.sh
clearStore clearStore
# Produce an escaped log file. # Produce an escaped log file.
set -x
path=$(nix-build --log-type escapes -vv dependencies.nix --no-out-link 2> $TEST_ROOT/log.esc) path=$(nix-build --log-type escapes -vv dependencies.nix --no-out-link 2> $TEST_ROOT/log.esc)
# Convert it to an XML representation. # Convert it to an XML representation.
@ -20,6 +19,6 @@ fi
# Test compressed logs. # Test compressed logs.
clearStore clearStore
rm -rf $NIX_LOG_DIR rm -rf $NIX_LOG_DIR
! nix-store -l $path (! nix-store -l $path)
nix-build dependencies.nix --no-out-link --option build-compress-log true nix-build dependencies.nix --no-out-link --option build-compress-log true
[ "$(nix-store -l $path)" = FOO ] [ "$(nix-store -l $path)" = FOO ]

View file

@ -18,7 +18,7 @@ grep -q 'multiple-outputs-b.drv",\["out"\]' $drvPath
outPath=$(nix-build multiple-outputs.nix -A d --no-out-link) outPath=$(nix-build multiple-outputs.nix -A d --no-out-link)
drvPath=$(cat $outPath/drv) drvPath=$(cat $outPath/drv)
outPath=$(nix-store -q $drvPath) outPath=$(nix-store -q $drvPath)
! [ -e "$outPath" ] (! [ -e "$outPath" ])
# Do a build of something that depends on a derivation with multiple # Do a build of something that depends on a derivation with multiple
# outputs. # outputs.
@ -30,7 +30,7 @@ echo "output path is $outPath"
# Test nix-build on a derivation with multiple outputs. # Test nix-build on a derivation with multiple outputs.
nix-build multiple-outputs.nix -A a -o $TEST_ROOT/result nix-build multiple-outputs.nix -A a -o $TEST_ROOT/result
[ -e $TEST_ROOT/result-first ] [ -e $TEST_ROOT/result-first ]
! [ -e $TEST_ROOT/result-second ] (! [ -e $TEST_ROOT/result-second ])
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
[ "$(cat $TEST_ROOT/result-first/file)" = "first" ] [ "$(cat $TEST_ROOT/result-first/file)" = "first" ]
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ] [ "$(cat $TEST_ROOT/result-second/file)" = "second" ]

View file

@ -3,8 +3,6 @@ source common.sh
clearStore clearStore
clearProfiles clearProfiles
set -x
# Query installed: should be empty. # Query installed: should be empty.
test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 0 test "$(nix-env -p $profiles/test -q '*' | wc -l)" -eq 0
@ -46,7 +44,7 @@ nix-env -qas | grep -q -- '--- bar-0.1'
# Disable foo. # Disable foo.
nix-env --set-flag active false foo nix-env --set-flag active false foo
! [ -e "$profiles/test/bin/foo" ] (! [ -e "$profiles/test/bin/foo" ])
# Enable foo. # Enable foo.
nix-env --set-flag active true foo nix-env --set-flag active true foo
@ -116,7 +114,7 @@ nix-store -q --referrers-closure $profiles/test | grep "$(nix-store -q --resolve
ln -sfn $outPath10/bin/foo $TEST_ROOT/symlink ln -sfn $outPath10/bin/foo $TEST_ROOT/symlink
nix-env -e $TEST_ROOT/symlink nix-env -e $TEST_ROOT/symlink
if nix-env -q '*' | grep -q foo; then false; fi if nix-env -q '*' | grep -q foo; then false; fi
! nix-store -qR $profiles/test | grep "$outPath10" (! nix-store -qR $profiles/test | grep "$outPath10")
# Install foo-1.0, now using a symlink to its store path. # Install foo-1.0, now using a symlink to its store path.
nix-env -i $TEST_ROOT/symlink nix-env -i $TEST_ROOT/symlink
@ -129,7 +127,7 @@ nix-env --delete-generations old
# foo-1.0. # foo-1.0.
nix-collect-garbage nix-collect-garbage
test -e "$outPath10" test -e "$outPath10"
! [ -e "$outPath20" ] (! [ -e "$outPath20" ])
# Uninstall everything # Uninstall everything
nix-env -e '*' nix-env -e '*'
@ -143,7 +141,7 @@ nix-env -q '*' | grep -q foo-2.0
# On the other hand, this should install both (and should fail due to # On the other hand, this should install both (and should fail due to
# a collision). # a collision).
nix-env -e '*' nix-env -e '*'
! nix-env -i foo-1.0 foo-2.0 (! nix-env -i foo-1.0 foo-2.0)
# Installing "*" should install one foo and one bar. # Installing "*" should install one foo and one bar.
nix-env -e '*' nix-env -e '*'