forked from lix-project/lix
Harden tests' bash
Use `set -u` and `set -o pipefail` to catch accidental mistakes and failures more strongly. - `set -u` catches the use of undefined variables - `set -o pipefail` catches failures (like `set -e`) earlier in the pipeline. This makes the tests a bit more robust. It is nice to read code not worrying about these spurious success paths (via uncaught) errors undermining the tests. Indeed, I caught some bugs doing this. There are a few tests where we run a command that should fail, and then search its output to make sure the failure message is one that we expect. Before, since the `grep` was the last command in the pipeline the exit code of those failing programs was silently ignored. Now with `set -o pipefail` it won't be, and we have to do something so the expected failure doesn't accidentally fail the test. To do that we use `expect` and a new `expectStderr` to check for the exact failing exit code. See the comments on each for why. `grep -q` is replaced with `grepQuiet`, see the comments on that function for why. `grep -v` when we just want the exit code is replaced with `grepInverse, see the comments on that function for why. `grep -q -v` together is, surprise surprise, replaced with `grepQuietInverse`, which is both combined. Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
This commit is contained in:
parent
0159dfad3f
commit
c11836126b
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -eu
|
set -eu -o pipefail
|
||||||
|
|
||||||
test=$1
|
test=$1
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -u
|
set -eu -o pipefail
|
||||||
|
|
||||||
red=""
|
red=""
|
||||||
green=""
|
green=""
|
||||||
|
@ -22,8 +22,7 @@ fi
|
||||||
|
|
||||||
run_test () {
|
run_test () {
|
||||||
(init_test 2>/dev/null > /dev/null)
|
(init_test 2>/dev/null > /dev/null)
|
||||||
log="$(run_test_proper 2>&1)"
|
log="$(run_test_proper 2>&1)" && status=0 || status=$?
|
||||||
status=$?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
run_test
|
run_test
|
||||||
|
|
|
@ -15,11 +15,11 @@ outPath=$(nix-build dependencies.nix --no-out-link)
|
||||||
nix copy --to file://$cacheDir $outPath
|
nix copy --to file://$cacheDir $outPath
|
||||||
|
|
||||||
# Test copying build logs to the binary cache.
|
# Test copying build logs to the binary cache.
|
||||||
nix log --store file://$cacheDir $outPath 2>&1 | grep 'is not available'
|
expect 1 nix log --store file://$cacheDir $outPath 2>&1 | grep 'is not available'
|
||||||
nix store copy-log --to file://$cacheDir $outPath
|
nix store copy-log --to file://$cacheDir $outPath
|
||||||
nix log --store file://$cacheDir $outPath | grep FOO
|
nix log --store file://$cacheDir $outPath | grep FOO
|
||||||
rm -rf $TEST_ROOT/var/log/nix
|
rm -rf $TEST_ROOT/var/log/nix
|
||||||
nix log $outPath 2>&1 | grep 'is not available'
|
expect 1 nix log $outPath 2>&1 | grep 'is not available'
|
||||||
nix log --substituters file://$cacheDir $outPath | grep FOO
|
nix log --substituters file://$cacheDir $outPath | grep FOO
|
||||||
|
|
||||||
# Test copying build logs from the binary cache.
|
# Test copying build logs from the binary cache.
|
||||||
|
@ -78,8 +78,8 @@ mv $nar $nar.good
|
||||||
mkdir -p $TEST_ROOT/empty
|
mkdir -p $TEST_ROOT/empty
|
||||||
nix-store --dump $TEST_ROOT/empty | xz > $nar
|
nix-store --dump $TEST_ROOT/empty | xz > $nar
|
||||||
|
|
||||||
nix-build --substituters "file://$cacheDir" --no-require-sigs dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log
|
expect 1 nix-build --substituters "file://$cacheDir" --no-require-sigs dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log
|
||||||
grep -q "hash mismatch" $TEST_ROOT/log
|
grepQuiet "hash mismatch" $TEST_ROOT/log
|
||||||
|
|
||||||
mv $nar.good $nar
|
mv $nar.good $nar
|
||||||
|
|
||||||
|
@ -126,9 +126,9 @@ clearStore
|
||||||
rm -v $(grep -l "StorePath:.*dependencies-input-2" $cacheDir/*.narinfo)
|
rm -v $(grep -l "StorePath:.*dependencies-input-2" $cacheDir/*.narinfo)
|
||||||
|
|
||||||
nix-build --substituters "file://$cacheDir" --no-require-sigs dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log
|
nix-build --substituters "file://$cacheDir" --no-require-sigs dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log
|
||||||
grep -q "copying path.*input-0" $TEST_ROOT/log
|
grepQuiet "copying path.*input-0" $TEST_ROOT/log
|
||||||
grep -q "copying path.*input-2" $TEST_ROOT/log
|
grepQuiet "copying path.*input-2" $TEST_ROOT/log
|
||||||
grep -q "copying path.*top" $TEST_ROOT/log
|
grepQuiet "copying path.*top" $TEST_ROOT/log
|
||||||
|
|
||||||
|
|
||||||
# Idem, but without cached .narinfo.
|
# Idem, but without cached .narinfo.
|
||||||
|
@ -136,11 +136,11 @@ clearStore
|
||||||
clearCacheCache
|
clearCacheCache
|
||||||
|
|
||||||
nix-build --substituters "file://$cacheDir" --no-require-sigs dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log
|
nix-build --substituters "file://$cacheDir" --no-require-sigs dependencies.nix -o $TEST_ROOT/result 2>&1 | tee $TEST_ROOT/log
|
||||||
grep -q "don't know how to build" $TEST_ROOT/log
|
grepQuiet "don't know how to build" $TEST_ROOT/log
|
||||||
grep -q "building.*input-1" $TEST_ROOT/log
|
grepQuiet "building.*input-1" $TEST_ROOT/log
|
||||||
grep -q "building.*input-2" $TEST_ROOT/log
|
grepQuiet "building.*input-2" $TEST_ROOT/log
|
||||||
grep -q "copying path.*input-0" $TEST_ROOT/log
|
grepQuiet "copying path.*input-0" $TEST_ROOT/log
|
||||||
grep -q "copying path.*top" $TEST_ROOT/log
|
grepQuiet "copying path.*top" $TEST_ROOT/log
|
||||||
|
|
||||||
|
|
||||||
# Create a signed binary cache.
|
# Create a signed binary cache.
|
||||||
|
|
|
@ -2,8 +2,6 @@ source common.sh
|
||||||
|
|
||||||
clearStore
|
clearStore
|
||||||
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
# https://github.com/NixOS/nix/issues/6572
|
# https://github.com/NixOS/nix/issues/6572
|
||||||
issue_6572_independent_outputs() {
|
issue_6572_independent_outputs() {
|
||||||
nix build -f multiple-outputs.nix --json independent --no-link > $TEST_ROOT/independent.json
|
nix build -f multiple-outputs.nix --json independent --no-link > $TEST_ROOT/independent.json
|
||||||
|
|
|
@ -54,7 +54,7 @@ clearCache
|
||||||
|
|
||||||
RES=$(nix build -f dependencies.nix --dry-run --json)
|
RES=$(nix build -f dependencies.nix --dry-run --json)
|
||||||
|
|
||||||
if [[ -z "$NIX_TESTS_CA_BY_DEFAULT" ]]; then
|
if [[ -z "${NIX_TESTS_CA_BY_DEFAULT-}" ]]; then
|
||||||
echo "$RES" | jq '.[0] | [
|
echo "$RES" | jq '.[0] | [
|
||||||
(.drvPath | test("'$NIX_STORE_DIR'.*\\.drv")),
|
(.drvPath | test("'$NIX_STORE_DIR'.*\\.drv")),
|
||||||
(.outputs.out | test("'$NIX_STORE_DIR'"))
|
(.outputs.out | test("'$NIX_STORE_DIR'"))
|
||||||
|
|
|
@ -7,7 +7,7 @@ unset NIX_STATE_DIR
|
||||||
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
|
function join_by { local d=$1; shift; echo -n "$1"; shift; printf "%s" "${@/#/$d}"; }
|
||||||
|
|
||||||
EXTRA_SYSTEM_FEATURES=()
|
EXTRA_SYSTEM_FEATURES=()
|
||||||
if [[ -n "$CONTENT_ADDRESSED" ]]; then
|
if [[ -n "${CONTENT_ADDRESSED-}" ]]; then
|
||||||
EXTRA_SYSTEM_FEATURES=("ca-derivations")
|
EXTRA_SYSTEM_FEATURES=("ca-derivations")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -42,25 +42,26 @@ testPrintOutPath=$(nix build -L -v -f $file --no-link --print-out-paths --max-jo
|
||||||
|
|
||||||
[[ $testPrintOutPath =~ store.*build-remote ]]
|
[[ $testPrintOutPath =~ store.*build-remote ]]
|
||||||
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
# Ensure that input1 was built on store1 due to the required feature.
|
# Ensure that input1 was built on store1 due to the required feature.
|
||||||
nix path-info --store $TEST_ROOT/machine1 --all \
|
output=$(nix path-info --store $TEST_ROOT/machine1 --all)
|
||||||
| grep builder-build-remote-input-1.sh \
|
echo "$output" | grepQuiet builder-build-remote-input-1.sh
|
||||||
| grep -v builder-build-remote-input-2.sh \
|
echo "$output" | grepQuietInverse builder-build-remote-input-2.sh
|
||||||
| grep -v builder-build-remote-input-3.sh
|
echo "$output" | grepQuietInverse builder-build-remote-input-3.sh
|
||||||
|
unset output
|
||||||
|
|
||||||
# Ensure that input2 was built on store2 due to the required feature.
|
# Ensure that input2 was built on store2 due to the required feature.
|
||||||
nix path-info --store $TEST_ROOT/machine2 --all \
|
output=$(nix path-info --store $TEST_ROOT/machine2 --all)
|
||||||
| grep -v builder-build-remote-input-1.sh \
|
echo "$output" | grepQuietInverse builder-build-remote-input-1.sh
|
||||||
| grep builder-build-remote-input-2.sh \
|
echo "$output" | grepQuiet builder-build-remote-input-2.sh
|
||||||
| grep -v builder-build-remote-input-3.sh
|
echo "$output" | grepQuietInverse builder-build-remote-input-3.sh
|
||||||
|
unset output
|
||||||
|
|
||||||
# Ensure that input3 was built on store3 due to the required feature.
|
# Ensure that input3 was built on store3 due to the required feature.
|
||||||
nix path-info --store $TEST_ROOT/machine3 --all \
|
output=$(nix path-info --store $TEST_ROOT/machine3 --all)
|
||||||
| grep -v builder-build-remote-input-1.sh \
|
echo "$output" | grepQuietInverse builder-build-remote-input-1.sh
|
||||||
| grep -v builder-build-remote-input-2.sh \
|
echo "$output" | grepQuietInverse builder-build-remote-input-2.sh
|
||||||
| grep builder-build-remote-input-3.sh
|
echo "$output" | grepQuiet builder-build-remote-input-3.sh
|
||||||
|
unset output
|
||||||
|
|
||||||
|
|
||||||
for i in input1 input3; do
|
for i in input1 input3; do
|
||||||
|
|
|
@ -2,8 +2,6 @@ source common.sh
|
||||||
|
|
||||||
clearStore
|
clearStore
|
||||||
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
# Make sure that 'nix build' returns all outputs by default.
|
# Make sure that 'nix build' returns all outputs by default.
|
||||||
nix build -f multiple-outputs.nix --json a b --no-link | jq --exit-status '
|
nix build -f multiple-outputs.nix --json a b --no-link | jq --exit-status '
|
||||||
(.[0] |
|
(.[0] |
|
||||||
|
|
|
@ -19,7 +19,7 @@ testRemoteCache () {
|
||||||
local outPath=$(buildAttr dependentNonCA 1)
|
local outPath=$(buildAttr dependentNonCA 1)
|
||||||
nix copy --to file://$cacheDir $outPath
|
nix copy --to file://$cacheDir $outPath
|
||||||
clearStore
|
clearStore
|
||||||
buildAttr dependentNonCA 1 --option substituters file://$cacheDir --no-require-sigs |& (! grep "building dependent-non-ca")
|
buildAttr dependentNonCA 1 --option substituters file://$cacheDir --no-require-sigs |& grepQuietInverse "building dependent-non-ca"
|
||||||
}
|
}
|
||||||
|
|
||||||
testDeterministicCA () {
|
testDeterministicCA () {
|
||||||
|
|
|
@ -8,14 +8,14 @@ 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 | grepQuietInverse $test1
|
||||||
nix-store -q --references $test1 | grep -q $dep
|
nix-store -q --references $test1 | grepQuiet $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 | grepQuietInverse $test2
|
||||||
(! nix-store -q --references $test2 | grep -q $dep)
|
nix-store -q --references $test2 | grepQuietInverse $dep
|
||||||
nix-store -q --references $test2 | grep -q aux-ref
|
nix-store -q --references $test2 | grepQuiet 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)
|
||||||
|
|
|
@ -8,8 +8,8 @@ nix-build -o $RESULT check-reqs.nix -A test1
|
||||||
|
|
||||||
(! nix-build -o $RESULT check-reqs.nix -A test2)
|
(! nix-build -o $RESULT check-reqs.nix -A test2)
|
||||||
(! nix-build -o $RESULT check-reqs.nix -A test3)
|
(! nix-build -o $RESULT check-reqs.nix -A test3)
|
||||||
(! nix-build -o $RESULT check-reqs.nix -A test4) 2>&1 | grep -q 'check-reqs-dep1'
|
(! nix-build -o $RESULT check-reqs.nix -A test4) 2>&1 | grepQuiet 'check-reqs-dep1'
|
||||||
(! nix-build -o $RESULT check-reqs.nix -A test4) 2>&1 | grep -q 'check-reqs-dep2'
|
(! nix-build -o $RESULT check-reqs.nix -A test4) 2>&1 | grepQuiet 'check-reqs-dep2'
|
||||||
(! nix-build -o $RESULT check-reqs.nix -A test5)
|
(! nix-build -o $RESULT check-reqs.nix -A test5)
|
||||||
(! nix-build -o $RESULT check-reqs.nix -A test6)
|
(! nix-build -o $RESULT check-reqs.nix -A test6)
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ checkBuildTempDirRemoved $TEST_ROOT/log
|
||||||
|
|
||||||
nix-build check.nix -A deterministic --argstr checkBuildId $checkBuildId \
|
nix-build check.nix -A deterministic --argstr checkBuildId $checkBuildId \
|
||||||
--no-out-link --check --keep-failed 2> $TEST_ROOT/log
|
--no-out-link --check --keep-failed 2> $TEST_ROOT/log
|
||||||
if grep -q 'may not be deterministic' $TEST_ROOT/log; then false; fi
|
if grepQuiet 'may not be deterministic' $TEST_ROOT/log; then false; fi
|
||||||
checkBuildTempDirRemoved $TEST_ROOT/log
|
checkBuildTempDirRemoved $TEST_ROOT/log
|
||||||
|
|
||||||
nix-build check.nix -A nondeterministic --argstr checkBuildId $checkBuildId \
|
nix-build check.nix -A nondeterministic --argstr checkBuildId $checkBuildId \
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
set -e
|
set -eu -o pipefail
|
||||||
|
|
||||||
if [[ -z "${COMMON_SH_SOURCED-}" ]]; then
|
if [[ -z "${COMMON_SH_SOURCED-}" ]]; then
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
set -e
|
set -eu -o pipefail
|
||||||
|
|
||||||
if [[ -z "${COMMON_VARS_AND_FUNCTIONS_SH_SOURCED-}" ]]; then
|
if [[ -z "${COMMON_VARS_AND_FUNCTIONS_SH_SOURCED-}" ]]; then
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ requireDaemonNewerThan () {
|
||||||
}
|
}
|
||||||
|
|
||||||
canUseSandbox() {
|
canUseSandbox() {
|
||||||
if [[ ! $_canUseSandbox ]]; then
|
if [[ ! ${_canUseSandbox-} ]]; then
|
||||||
echo "Sandboxing not supported, skipping this test..."
|
echo "Sandboxing not supported, skipping this test..."
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
@ -170,13 +170,38 @@ fail() {
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Run a command failing if it didn't exit with the expected exit code.
|
||||||
|
#
|
||||||
|
# Has two advantages over the built-in `!`:
|
||||||
|
#
|
||||||
|
# 1. `!` conflates all non-0 codes. `expect` allows testing for an exact
|
||||||
|
# code.
|
||||||
|
#
|
||||||
|
# 2. `!` unexpectedly negates `set -e`, and cannot be used on individual
|
||||||
|
# pipeline stages with `set -o pipefail`. It only works on the entire
|
||||||
|
# pipeline, which is useless if we want, say, `nix ...` invocation to
|
||||||
|
# *fail*, but a grep on the error message it outputs to *succeed*.
|
||||||
expect() {
|
expect() {
|
||||||
local expected res
|
local expected res
|
||||||
expected="$1"
|
expected="$1"
|
||||||
shift
|
shift
|
||||||
"$@" || res="$?"
|
"$@" && res=0 || res="$?"
|
||||||
if [[ $res -ne $expected ]]; then
|
if [[ $res -ne $expected ]]; then
|
||||||
echo "Expected '$expected' but got '$res' while running '$*'"
|
echo "Expected '$expected' but got '$res' while running '${*@Q}'" >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
# Better than just doing `expect ... >&2` because the "Expected..."
|
||||||
|
# message below will *not* be redirected.
|
||||||
|
expectStderr() {
|
||||||
|
local expected res
|
||||||
|
expected="$1"
|
||||||
|
shift
|
||||||
|
"$@" 2>&1 && res=0 || res="$?"
|
||||||
|
if [[ $res -ne $expected ]]; then
|
||||||
|
echo "Expected '$expected' but got '$res' while running '${*@Q}'" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
return 0
|
return 0
|
||||||
|
@ -191,7 +216,7 @@ needLocalStore() {
|
||||||
|
|
||||||
# Just to make it easy to find which tests should be fixed
|
# Just to make it easy to find which tests should be fixed
|
||||||
buggyNeedLocalStore() {
|
buggyNeedLocalStore() {
|
||||||
needLocalStore
|
needLocalStore "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
enableFeatures() {
|
enableFeatures() {
|
||||||
|
@ -210,6 +235,35 @@ onError() {
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# `grep -v` doesn't work well for exit codes. We want `!(exist line l. l
|
||||||
|
# matches)`. It gives us `exist line l. !(l matches)`.
|
||||||
|
#
|
||||||
|
# `!` normally doesn't work well with `set -e`, but when we wrap in a
|
||||||
|
# function it *does*.
|
||||||
|
grepInverse() {
|
||||||
|
! grep "$@"
|
||||||
|
}
|
||||||
|
|
||||||
|
# A shorthand, `> /dev/null` is a bit noisy.
|
||||||
|
#
|
||||||
|
# `grep -q` would seem to do this, no function necessary, but it is a
|
||||||
|
# bad fit with pipes and `set -o pipefail`: `-q` will exit after the
|
||||||
|
# first match, and then subsequent writes will result in broken pipes.
|
||||||
|
#
|
||||||
|
# Note that reproducing the above is a bit tricky as it depends on
|
||||||
|
# non-deterministic properties such as the timing between the match and
|
||||||
|
# the closing of the pipe, the buffering of the pipe, and the speed of
|
||||||
|
# the producer into the pipe. But rest assured we've seen it happen in
|
||||||
|
# CI reliably.
|
||||||
|
grepQuiet() {
|
||||||
|
grep "$@" > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
|
# The previous two, combined
|
||||||
|
grepQuietInverse() {
|
||||||
|
! grep "$@" > /dev/null
|
||||||
|
}
|
||||||
|
|
||||||
trap onError ERR
|
trap onError ERR
|
||||||
|
|
||||||
fi # COMMON_VARS_AND_FUNCTIONS_SH_SOURCED
|
fi # COMMON_VARS_AND_FUNCTIONS_SH_SOURCED
|
||||||
|
|
|
@ -3,5 +3,5 @@ source common.sh
|
||||||
if [[ $(uname -ms) = "Linux x86_64" ]]; then
|
if [[ $(uname -ms) = "Linux x86_64" ]]; then
|
||||||
# x86_64 CPUs must always support the baseline
|
# x86_64 CPUs must always support the baseline
|
||||||
# microarchitecture level.
|
# microarchitecture level.
|
||||||
nix -vv --version | grep -q "x86_64-v1-linux"
|
nix -vv --version | grepQuiet "x86_64-v1-linux"
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
# Only run this if we have an older Nix available
|
# Only run this if we have an older Nix available
|
||||||
# XXX: This assumes that the `daemon` package is older than the `client` one
|
# XXX: This assumes that the `daemon` package is older than the `client` one
|
||||||
if [[ -z "$NIX_DAEMON_PACKAGE" ]]; then
|
if [[ -z "${NIX_DAEMON_PACKAGE-}" ]]; then
|
||||||
exit 99
|
exit 99
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ killDaemon
|
||||||
|
|
||||||
# Fill the db using the older Nix
|
# Fill the db using the older Nix
|
||||||
PATH_WITH_NEW_NIX="$PATH"
|
PATH_WITH_NEW_NIX="$PATH"
|
||||||
export PATH="$NIX_DAEMON_PACKAGE/bin:$PATH"
|
export PATH="${NIX_DAEMON_PACKAGE}/bin:$PATH"
|
||||||
clearStore
|
clearStore
|
||||||
nix-build simple.nix --no-out-link
|
nix-build simple.nix --no-out-link
|
||||||
nix-store --generate-binary-cache-key cache1.example.org $TEST_ROOT/sk1 $TEST_ROOT/pk1
|
nix-store --generate-binary-cache-key cache1.example.org $TEST_ROOT/sk1 $TEST_ROOT/pk1
|
||||||
|
|
|
@ -36,10 +36,10 @@ deps=$(nix-store -quR "$drvPath")
|
||||||
echo "output closure contains $deps"
|
echo "output closure contains $deps"
|
||||||
|
|
||||||
# The output path should be in the closure.
|
# The output path should be in the closure.
|
||||||
echo "$deps" | grep -q "$outPath"
|
echo "$deps" | grepQuiet "$outPath"
|
||||||
|
|
||||||
# Input-1 is not retained.
|
# Input-1 is not retained.
|
||||||
if echo "$deps" | grep -q "dependencies-input-1"; then exit 1; fi
|
if echo "$deps" | grepQuiet "dependencies-input-1"; then exit 1; fi
|
||||||
|
|
||||||
# Input-2 is retained.
|
# Input-2 is retained.
|
||||||
input2OutPath=$(echo "$deps" | grep "dependencies-input-2")
|
input2OutPath=$(echo "$deps" | grep "dependencies-input-2")
|
||||||
|
@ -49,4 +49,4 @@ nix-store -q --referrers-closure "$input2OutPath" | grep "$outPath"
|
||||||
|
|
||||||
# Check that the derivers are set properly.
|
# Check that the derivers are set properly.
|
||||||
test $(nix-store -q --deriver "$outPath") = "$drvPath"
|
test $(nix-store -q --deriver "$outPath") = "$drvPath"
|
||||||
nix-store -q --deriver "$input2OutPath" | grep -q -- "-input-2.drv"
|
nix-store -q --deriver "$input2OutPath" | grepQuiet -- "-input-2.drv"
|
||||||
|
|
|
@ -2,7 +2,7 @@ source common.sh
|
||||||
|
|
||||||
# Using `--eval-store` with the daemon will eventually copy everything
|
# Using `--eval-store` with the daemon will eventually copy everything
|
||||||
# to the build store, invalidating most of the tests here
|
# to the build store, invalidating most of the tests here
|
||||||
needLocalStore
|
needLocalStore "“--eval-store” doesn't achieve much with the daemon"
|
||||||
|
|
||||||
eval_store=$TEST_ROOT/eval-store
|
eval_store=$TEST_ROOT/eval-store
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ clearStore
|
||||||
clearProfiles
|
clearProfiles
|
||||||
|
|
||||||
checkRef() {
|
checkRef() {
|
||||||
nix-store -q --references $TEST_ROOT/result | grep -q "$1"'$' || fail "missing reference $1"
|
nix-store -q --references $TEST_ROOT/result | grepQuiet "$1"'$' || fail "missing reference $1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Test the export of the runtime dependency graph.
|
# Test the export of the runtime dependency graph.
|
||||||
|
|
|
@ -42,13 +42,13 @@ if [[ "$NIX_REMOTE" != "daemon" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 'toPath' set to empty string should fail but print the expected path.
|
# 'toPath' set to empty string should fail but print the expected path.
|
||||||
nix eval -v --json --expr "
|
expectStderr 1 nix eval -v --json --expr "
|
||||||
builtins.fetchClosure {
|
builtins.fetchClosure {
|
||||||
fromStore = \"file://$cacheDir\";
|
fromStore = \"file://$cacheDir\";
|
||||||
fromPath = $nonCaPath;
|
fromPath = $nonCaPath;
|
||||||
toPath = \"\";
|
toPath = \"\";
|
||||||
}
|
}
|
||||||
" 2>&1 | grep "error: rewriting.*$nonCaPath.*yielded.*$caPath"
|
" | grep "error: rewriting.*$nonCaPath.*yielded.*$caPath"
|
||||||
|
|
||||||
# If fromPath is CA, then toPath isn't needed.
|
# If fromPath is CA, then toPath isn't needed.
|
||||||
nix copy --to file://$cacheDir $caPath
|
nix copy --to file://$cacheDir $caPath
|
||||||
|
|
|
@ -56,7 +56,7 @@ invalid_ref() {
|
||||||
else
|
else
|
||||||
(! git check-ref-format --branch "$1" >/dev/null 2>&1)
|
(! git check-ref-format --branch "$1" >/dev/null 2>&1)
|
||||||
fi
|
fi
|
||||||
nix --debug eval --raw --impure --expr "(builtins.fetchGit { url = $repo; ref = ''$1''; }).outPath" 2>&1 | grep 'invalid Git branch/tag name' >/dev/null
|
expect 1 nix --debug eval --raw --impure --expr "(builtins.fetchGit { url = $repo; ref = ''$1''; }).outPath" 2>&1 | grep 'invalid Git branch/tag name' >/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -79,7 +79,7 @@ EOF
|
||||||
EOF
|
EOF
|
||||||
popd
|
popd
|
||||||
|
|
||||||
[[ -z "${NIX_DAEMON_PACKAGE}" ]] && return 0
|
[[ -z "${NIX_DAEMON_PACKAGE-}" ]] && return 0
|
||||||
|
|
||||||
# Ensure that a lockfile generated by the current Nix for tarball inputs
|
# Ensure that a lockfile generated by the current Nix for tarball inputs
|
||||||
# can still be read by an older Nix
|
# can still be read by an older Nix
|
||||||
|
@ -91,7 +91,7 @@ EOF
|
||||||
flake = false;
|
flake = false;
|
||||||
};
|
};
|
||||||
outputs = { self, tarball }: {
|
outputs = { self, tarball }: {
|
||||||
foo = builtins.readFile "${tarball}/test_input_file";
|
foo = builtins.readFile "\${tarball}/test_input_file";
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
nix flake update
|
nix flake update
|
||||||
|
|
|
@ -62,7 +62,7 @@ hash=$(nix-hash --flat --type sha256 $nar)
|
||||||
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$nar --argstr sha256 $hash \
|
outPath=$(nix-build -vvvvv --expr 'import <nix/fetchurl.nix>' --argstr url file://$nar --argstr sha256 $hash \
|
||||||
--arg unpack true --argstr name xyzzy --no-out-link)
|
--arg unpack true --argstr name xyzzy --no-out-link)
|
||||||
|
|
||||||
echo $outPath | grep -q 'xyzzy'
|
echo $outPath | grepQuiet 'xyzzy'
|
||||||
|
|
||||||
test -x $outPath/fetchurl.sh
|
test -x $outPath/fetchurl.sh
|
||||||
test -L $outPath/symlink
|
test -L $outPath/symlink
|
||||||
|
|
|
@ -35,7 +35,7 @@ cat > $flake1Dir/flake.nix <<EOF
|
||||||
a6 = flake2.outPath;
|
a6 = flake2.outPath;
|
||||||
|
|
||||||
# FIXME
|
# FIXME
|
||||||
a7 = "${flake2}/config.nix";
|
a7 = "\${flake2}/config.nix";
|
||||||
|
|
||||||
# This is only allowed in impure mode.
|
# This is only allowed in impure mode.
|
||||||
a8 = builtins.storePath $dep;
|
a8 = builtins.storePath $dep;
|
||||||
|
|
|
@ -73,5 +73,5 @@ cat > $flakeDir/flake.nix <<EOF
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
checkRes=$(nix flake check --keep-going $flakeDir 2>&1 && fail "nix flake check should have failed" || true)
|
checkRes=$(nix flake check --keep-going $flakeDir 2>&1 && fail "nix flake check should have failed" || true)
|
||||||
echo "$checkRes" | grep -q "packages.system-1.default"
|
echo "$checkRes" | grepQuiet "packages.system-1.default"
|
||||||
echo "$checkRes" | grep -q "packages.system-2.default"
|
echo "$checkRes" | grepQuiet "packages.system-2.default"
|
||||||
|
|
|
@ -66,7 +66,7 @@ EOF
|
||||||
|
|
||||||
createGitRepo() {
|
createGitRepo() {
|
||||||
local repo="$1"
|
local repo="$1"
|
||||||
local extraArgs="$2"
|
local extraArgs="${2-}"
|
||||||
|
|
||||||
rm -rf $repo $repo.tmp
|
rm -rf $repo $repo.tmp
|
||||||
mkdir -p $repo
|
mkdir -p $repo
|
||||||
|
|
|
@ -76,17 +76,17 @@ nix registry add --registry $registry nixpkgs flake1
|
||||||
|
|
||||||
# Test 'nix registry list'.
|
# Test 'nix registry list'.
|
||||||
[[ $(nix registry list | wc -l) == 5 ]]
|
[[ $(nix registry list | wc -l) == 5 ]]
|
||||||
nix registry list | grep -q '^global'
|
nix registry list | grep '^global'
|
||||||
nix registry list | grep -q -v '^user' # nothing in user registry
|
nix registry list | grepInverse '^user' # nothing in user registry
|
||||||
|
|
||||||
# Test 'nix flake metadata'.
|
# Test 'nix flake metadata'.
|
||||||
nix flake metadata flake1
|
nix flake metadata flake1
|
||||||
nix flake metadata flake1 | grep -q 'Locked URL:.*flake1.*'
|
nix flake metadata flake1 | grepQuiet 'Locked URL:.*flake1.*'
|
||||||
|
|
||||||
# Test 'nix flake metadata' on a local flake.
|
# Test 'nix flake metadata' on a local flake.
|
||||||
(cd $flake1Dir && nix flake metadata) | grep -q 'URL:.*flake1.*'
|
(cd $flake1Dir && nix flake metadata) | grepQuiet 'URL:.*flake1.*'
|
||||||
(cd $flake1Dir && nix flake metadata .) | grep -q 'URL:.*flake1.*'
|
(cd $flake1Dir && nix flake metadata .) | grepQuiet 'URL:.*flake1.*'
|
||||||
nix flake metadata $flake1Dir | grep -q 'URL:.*flake1.*'
|
nix flake metadata $flake1Dir | grepQuiet 'URL:.*flake1.*'
|
||||||
|
|
||||||
# Test 'nix flake metadata --json'.
|
# Test 'nix flake metadata --json'.
|
||||||
json=$(nix flake metadata flake1 --json | jq .)
|
json=$(nix flake metadata flake1 --json | jq .)
|
||||||
|
@ -134,11 +134,11 @@ nix build -o $TEST_ROOT/result flake2#bar --impure --no-write-lock-file
|
||||||
nix eval --expr "builtins.getFlake \"$flake2Dir\"" --impure
|
nix eval --expr "builtins.getFlake \"$flake2Dir\"" --impure
|
||||||
|
|
||||||
# Building a local flake with an unlocked dependency should fail with --no-update-lock-file.
|
# Building a local flake with an unlocked dependency should fail with --no-update-lock-file.
|
||||||
nix build -o $TEST_ROOT/result $flake2Dir#bar --no-update-lock-file 2>&1 | grep 'requires lock file changes'
|
expect 1 nix build -o $TEST_ROOT/result $flake2Dir#bar --no-update-lock-file 2>&1 | grep 'requires lock file changes'
|
||||||
|
|
||||||
# But it should succeed without that flag.
|
# But it should succeed without that flag.
|
||||||
nix build -o $TEST_ROOT/result $flake2Dir#bar --no-write-lock-file
|
nix build -o $TEST_ROOT/result $flake2Dir#bar --no-write-lock-file
|
||||||
nix build -o $TEST_ROOT/result $flake2Dir#bar --no-update-lock-file 2>&1 | grep 'requires lock file changes'
|
expect 1 nix build -o $TEST_ROOT/result $flake2Dir#bar --no-update-lock-file 2>&1 | grep 'requires lock file changes'
|
||||||
nix build -o $TEST_ROOT/result $flake2Dir#bar --commit-lock-file
|
nix build -o $TEST_ROOT/result $flake2Dir#bar --commit-lock-file
|
||||||
[[ -e $flake2Dir/flake.lock ]]
|
[[ -e $flake2Dir/flake.lock ]]
|
||||||
[[ -z $(git -C $flake2Dir diff main || echo failed) ]]
|
[[ -z $(git -C $flake2Dir diff main || echo failed) ]]
|
||||||
|
@ -196,10 +196,10 @@ git -C $flake3Dir add flake.lock
|
||||||
git -C $flake3Dir commit -m 'Add lockfile'
|
git -C $flake3Dir commit -m 'Add lockfile'
|
||||||
|
|
||||||
# Test whether registry caching works.
|
# Test whether registry caching works.
|
||||||
nix registry list --flake-registry file://$registry | grep -q flake3
|
nix registry list --flake-registry file://$registry | grepQuiet flake3
|
||||||
mv $registry $registry.tmp
|
mv $registry $registry.tmp
|
||||||
nix store gc
|
nix store gc
|
||||||
nix registry list --flake-registry file://$registry --refresh | grep -q flake3
|
nix registry list --flake-registry file://$registry --refresh | grepQuiet flake3
|
||||||
mv $registry.tmp $registry
|
mv $registry.tmp $registry
|
||||||
|
|
||||||
# Test whether flakes are registered as GC roots for offline use.
|
# Test whether flakes are registered as GC roots for offline use.
|
||||||
|
@ -346,8 +346,8 @@ nix registry remove flake1
|
||||||
nix registry add user-flake1 git+file://$flake1Dir
|
nix registry add user-flake1 git+file://$flake1Dir
|
||||||
nix registry add user-flake2 git+file://$flake2Dir
|
nix registry add user-flake2 git+file://$flake2Dir
|
||||||
[[ $(nix --flake-registry "" registry list | wc -l) == 2 ]]
|
[[ $(nix --flake-registry "" registry list | wc -l) == 2 ]]
|
||||||
nix --flake-registry "" registry list | grep -q -v '^global' # nothing in global registry
|
nix --flake-registry "" registry list | grepQuietInverse '^global' # nothing in global registry
|
||||||
nix --flake-registry "" registry list | grep -q '^user'
|
nix --flake-registry "" registry list | grepQuiet '^user'
|
||||||
nix registry remove user-flake1
|
nix registry remove user-flake1
|
||||||
nix registry remove user-flake2
|
nix registry remove user-flake2
|
||||||
[[ $(nix registry list | wc -l) == 5 ]]
|
[[ $(nix registry list | wc -l) == 5 ]]
|
||||||
|
@ -454,7 +454,7 @@ url=$(nix flake metadata --json file://$TEST_ROOT/flake.tar.gz | jq -r .url)
|
||||||
nix build -o $TEST_ROOT/result $url
|
nix build -o $TEST_ROOT/result $url
|
||||||
|
|
||||||
# Building with an incorrect SRI hash should fail.
|
# Building with an incorrect SRI hash should fail.
|
||||||
nix build -o $TEST_ROOT/result "file://$TEST_ROOT/flake.tar.gz?narHash=sha256-qQ2Zz4DNHViCUrp6gTS7EE4+RMqFQtUfWF2UNUtJKS0=" 2>&1 | grep 'NAR hash mismatch'
|
expectStderr 102 nix build -o $TEST_ROOT/result "file://$TEST_ROOT/flake.tar.gz?narHash=sha256-qQ2Zz4DNHViCUrp6gTS7EE4+RMqFQtUfWF2UNUtJKS0=" | grep 'NAR hash mismatch'
|
||||||
|
|
||||||
# Test --override-input.
|
# Test --override-input.
|
||||||
git -C $flake3Dir reset --hard
|
git -C $flake3Dir reset --hard
|
||||||
|
|
|
@ -128,7 +128,7 @@ EOF
|
||||||
|
|
||||||
git -C $flakeFollowsA add flake.nix
|
git -C $flakeFollowsA add flake.nix
|
||||||
|
|
||||||
nix flake lock $flakeFollowsA 2>&1 | grep 'points outside'
|
expect 1 nix flake lock $flakeFollowsA 2>&1 | grep 'points outside'
|
||||||
|
|
||||||
# Non-existant follows should print a warning.
|
# Non-existant follows should print a warning.
|
||||||
cat >$flakeFollowsA/flake.nix <<EOF
|
cat >$flakeFollowsA/flake.nix <<EOF
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
source common.sh
|
source common.sh
|
||||||
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
clearStore
|
clearStore
|
||||||
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
|
rm -rf $TEST_HOME/.cache $TEST_HOME/.config $TEST_HOME/.local
|
||||||
|
|
||||||
|
|
|
@ -10,17 +10,15 @@ expect_trace() {
|
||||||
--trace-function-calls \
|
--trace-function-calls \
|
||||||
--expr "$expr" 2>&1 \
|
--expr "$expr" 2>&1 \
|
||||||
| grep "function-trace" \
|
| grep "function-trace" \
|
||||||
| sed -e 's/ [0-9]*$//'
|
| sed -e 's/ [0-9]*$//' \
|
||||||
|
|| true
|
||||||
)
|
)
|
||||||
|
|
||||||
echo -n "Tracing expression '$expr'"
|
echo -n "Tracing expression '$expr'"
|
||||||
set +e
|
|
||||||
msg=$(diff -swB \
|
msg=$(diff -swB \
|
||||||
<(echo "$expect") \
|
<(echo "$expect") \
|
||||||
<(echo "$actual")
|
<(echo "$actual")
|
||||||
);
|
) && result=0 || result=$?
|
||||||
result=$?
|
|
||||||
set -e
|
|
||||||
if [ $result -eq 0 ]; then
|
if [ $result -eq 0 ]; then
|
||||||
echo " ok."
|
echo " ok."
|
||||||
else
|
else
|
||||||
|
@ -67,5 +65,3 @@ expect_trace '1 2' "
|
||||||
function-trace entered «string»:1:1 at
|
function-trace entered «string»:1:1 at
|
||||||
function-trace exited «string»:1:1 at
|
function-trace exited «string»:1:1 at
|
||||||
"
|
"
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ source common.sh
|
||||||
|
|
||||||
try () {
|
try () {
|
||||||
printf "%s" "$2" > $TEST_ROOT/vector
|
printf "%s" "$2" > $TEST_ROOT/vector
|
||||||
hash=$(nix hash file --base16 $EXTRA --type "$1" $TEST_ROOT/vector)
|
hash=$(nix hash file --base16 ${EXTRA-} --type "$1" $TEST_ROOT/vector)
|
||||||
if test "$hash" != "$3"; then
|
if test "$hash" != "$3"; then
|
||||||
echo "hash $1, expected $3, got $hash"
|
echo "hash $1, expected $3, got $hash"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -5,8 +5,6 @@ requireDaemonNewerThan "2.8pre20220311"
|
||||||
enableFeatures "ca-derivations impure-derivations"
|
enableFeatures "ca-derivations impure-derivations"
|
||||||
restartDaemon
|
restartDaemon
|
||||||
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
clearStore
|
clearStore
|
||||||
|
|
||||||
# Basic test of impure derivations: building one a second time should not use the previous result.
|
# Basic test of impure derivations: building one a second time should not use the previous result.
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
set -eu -o pipefail
|
|
||||||
|
|
||||||
# Don't start the daemon
|
# Don't start the daemon
|
||||||
source common/vars-and-functions.sh
|
source common/vars-and-functions.sh
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ set -eux
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
PLIST="/Library/LaunchDaemons/org.nixos.nix-daemon.plist"
|
PLIST="/Library/LaunchDaemons/org.nixos.nix-daemon.plist"
|
||||||
if sudo launchctl list | grep -q nix-daemon; then
|
if sudo launchctl list | grepQuiet nix-daemon; then
|
||||||
sudo launchctl unload "$PLIST"
|
sudo launchctl unload "$PLIST"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -4,12 +4,12 @@ export TEST_VAR=foo # for eval-okay-getenv.nix
|
||||||
export NIX_REMOTE=dummy://
|
export NIX_REMOTE=dummy://
|
||||||
export NIX_STORE_DIR=/nix/store
|
export NIX_STORE_DIR=/nix/store
|
||||||
|
|
||||||
nix-instantiate --eval -E 'builtins.trace "Hello" 123' 2>&1 | grep -q Hello
|
nix-instantiate --eval -E 'builtins.trace "Hello" 123' 2>&1 | grepQuiet Hello
|
||||||
nix-instantiate --eval -E 'builtins.addErrorContext "Hello" 123' 2>&1
|
nix-instantiate --eval -E 'builtins.addErrorContext "Hello" 123' 2>&1
|
||||||
nix-instantiate --trace-verbose --eval -E 'builtins.traceVerbose "Hello" 123' 2>&1 | grep -q Hello
|
nix-instantiate --trace-verbose --eval -E 'builtins.traceVerbose "Hello" 123' 2>&1 | grepQuiet Hello
|
||||||
(! nix-instantiate --eval -E 'builtins.traceVerbose "Hello" 123' 2>&1 | grep -q Hello)
|
nix-instantiate --eval -E 'builtins.traceVerbose "Hello" 123' 2>&1 | grepQuietInverse 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 | grepQuietInverse Hello
|
||||||
nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello" (throw "Foo")' 2>&1 | grep -q Hello
|
expectStderr 1 nix-instantiate --show-trace --eval -E 'builtins.addErrorContext "Hello" (throw "Foo")' | grepQuiet Hello
|
||||||
|
|
||||||
set +x
|
set +x
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,8 @@ nix-build dependencies.nix --no-out-link --check --sandbox-paths /nix/store
|
||||||
nix-build check.nix -A nondeterministic --sandbox-paths /nix/store --no-out-link
|
nix-build check.nix -A nondeterministic --sandbox-paths /nix/store --no-out-link
|
||||||
|
|
||||||
(! nix-build check.nix -A nondeterministic --sandbox-paths /nix/store --no-out-link --check -K 2> $TEST_ROOT/log)
|
(! nix-build check.nix -A nondeterministic --sandbox-paths /nix/store --no-out-link --check -K 2> $TEST_ROOT/log)
|
||||||
if grep -q 'error: renaming' $TEST_ROOT/log; then false; fi
|
if grepQuiet 'error: renaming' $TEST_ROOT/log; then false; fi
|
||||||
grep -q 'may not be deterministic' $TEST_ROOT/log
|
grepQuiet 'may not be deterministic' $TEST_ROOT/log
|
||||||
|
|
||||||
# Test that sandboxed builds cannot write to /etc easily
|
# Test that sandboxed builds cannot write to /etc easily
|
||||||
(! nix-build -E 'with import ./config.nix; mkDerivation { name = "etc-write"; buildCommand = "echo > /etc/test"; }' --no-out-link --sandbox-paths /nix/store)
|
(! nix-build -E 'with import ./config.nix; mkDerivation { name = "etc-write"; buildCommand = "echo > /etc/test"; }' --no-out-link --sandbox-paths /nix/store)
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
nix_tests = \
|
nix_tests = \
|
||||||
|
test-infra.sh \
|
||||||
init.sh \
|
init.sh \
|
||||||
flakes/flakes.sh \
|
flakes/flakes.sh \
|
||||||
flakes/run.sh \
|
flakes/run.sh \
|
||||||
|
@ -132,7 +133,7 @@ install-tests += $(foreach x, $(nix_tests), tests/$(x))
|
||||||
|
|
||||||
clean-files += $(d)/tests/common/vars-and-functions.sh $(d)/config.nix $(d)/ca/config.nix
|
clean-files += $(d)/tests/common/vars-and-functions.sh $(d)/config.nix $(d)/ca/config.nix
|
||||||
|
|
||||||
test-deps += tests/common/vars-and-functions.sh tests/config.nix tests/ca/config.nix tests/plugins/libplugintest.$(SO_EXT)
|
test-deps += tests/common/vars-and-functions.sh tests/config.nix tests/ca/config.nix
|
||||||
|
|
||||||
ifeq ($(BUILD_SHARED_LIBS), 1)
|
ifeq ($(BUILD_SHARED_LIBS), 1)
|
||||||
test-deps += tests/plugins/libplugintest.$(SO_EXT)
|
test-deps += tests/plugins/libplugintest.$(SO_EXT)
|
||||||
|
|
|
@ -3,17 +3,17 @@ source common.sh
|
||||||
# Tests miscellaneous commands.
|
# Tests miscellaneous commands.
|
||||||
|
|
||||||
# Do all commands have help?
|
# Do all commands have help?
|
||||||
#nix-env --help | grep -q install
|
#nix-env --help | grepQuiet install
|
||||||
#nix-store --help | grep -q realise
|
#nix-store --help | grepQuiet realise
|
||||||
#nix-instantiate --help | grep -q eval
|
#nix-instantiate --help | grepQuiet eval
|
||||||
#nix-hash --help | grep -q base32
|
#nix-hash --help | grepQuiet base32
|
||||||
|
|
||||||
# Can we ask for the version number?
|
# Can we ask for the version number?
|
||||||
nix-env --version | grep "$version"
|
nix-env --version | grep "$version"
|
||||||
|
|
||||||
# Usage errors.
|
# Usage errors.
|
||||||
nix-env --foo 2>&1 | grep "no operation"
|
expect 1 nix-env --foo 2>&1 | grep "no operation"
|
||||||
nix-env -q --foo 2>&1 | grep "unknown flag"
|
expect 1 nix-env -q --foo 2>&1 | grep "unknown flag"
|
||||||
|
|
||||||
# Eval Errors.
|
# Eval Errors.
|
||||||
eval_arg_res=$(nix-instantiate --eval -E 'let a = {} // a; in a.foo' 2>&1 || true)
|
eval_arg_res=$(nix-instantiate --eval -E 'let a = {} // a; in a.foo' 2>&1 || true)
|
||||||
|
|
|
@ -19,8 +19,8 @@ echo "evaluating c..."
|
||||||
# outputs.
|
# outputs.
|
||||||
drvPath=$(nix-instantiate multiple-outputs.nix -A c)
|
drvPath=$(nix-instantiate multiple-outputs.nix -A c)
|
||||||
#[ "$drvPath" = "$drvPath2" ]
|
#[ "$drvPath" = "$drvPath2" ]
|
||||||
grep -q 'multiple-outputs-a.drv",\["first","second"\]' $drvPath
|
grepQuiet 'multiple-outputs-a.drv",\["first","second"\]' $drvPath
|
||||||
grep -q 'multiple-outputs-b.drv",\["out"\]' $drvPath
|
grepQuiet 'multiple-outputs-b.drv",\["out"\]' $drvPath
|
||||||
|
|
||||||
# While we're at it, test the ‘unsafeDiscardOutputDependency’ primop.
|
# While we're at it, test the ‘unsafeDiscardOutputDependency’ primop.
|
||||||
outPath=$(nix-build multiple-outputs.nix -A d --no-out-link)
|
outPath=$(nix-build multiple-outputs.nix -A d --no-out-link)
|
||||||
|
@ -84,5 +84,5 @@ nix-store --gc --print-roots
|
||||||
rm -rf $NIX_STORE_DIR/.links
|
rm -rf $NIX_STORE_DIR/.links
|
||||||
rmdir $NIX_STORE_DIR
|
rmdir $NIX_STORE_DIR
|
||||||
|
|
||||||
nix build -f multiple-outputs.nix invalid-output-name-1 2>&1 | grep 'contains illegal character'
|
expect 1 nix build -f multiple-outputs.nix invalid-output-name-1 2>&1 | grep 'contains illegal character'
|
||||||
nix build -f multiple-outputs.nix invalid-output-name-2 2>&1 | grep 'contains illegal character'
|
expect 1 nix build -f multiple-outputs.nix invalid-output-name-2 2>&1 | grep 'contains illegal character'
|
||||||
|
|
|
@ -46,8 +46,8 @@ diff -u \
|
||||||
<(echo '{"type":"regular","size":0}' | jq -S)
|
<(echo '{"type":"regular","size":0}' | jq -S)
|
||||||
|
|
||||||
# Test missing files.
|
# Test missing files.
|
||||||
nix store ls --json -R $storePath/xyzzy 2>&1 | grep 'does not exist in NAR'
|
expect 1 nix store ls --json -R $storePath/xyzzy 2>&1 | grep 'does not exist in NAR'
|
||||||
nix store ls $storePath/xyzzy 2>&1 | grep 'does not exist'
|
expect 1 nix store ls $storePath/xyzzy 2>&1 | grep 'does not exist'
|
||||||
|
|
||||||
# Test failure to dump.
|
# Test failure to dump.
|
||||||
if nix-store --dump $storePath >/dev/full ; then
|
if nix-store --dump $storePath >/dev/full ; then
|
||||||
|
|
|
@ -6,7 +6,7 @@ rm -f $TEST_HOME/.nix-channels $TEST_HOME/.nix-profile
|
||||||
|
|
||||||
# Test add/list/remove.
|
# Test add/list/remove.
|
||||||
nix-channel --add http://foo/bar xyzzy
|
nix-channel --add http://foo/bar xyzzy
|
||||||
nix-channel --list | grep -q http://foo/bar
|
nix-channel --list | grepQuiet http://foo/bar
|
||||||
nix-channel --remove xyzzy
|
nix-channel --remove xyzzy
|
||||||
|
|
||||||
[ -e $TEST_HOME/.nix-channels ]
|
[ -e $TEST_HOME/.nix-channels ]
|
||||||
|
@ -17,7 +17,7 @@ nix-channel --remove xyzzy
|
||||||
export NIX_CONFIG="use-xdg-base-directories = true"
|
export NIX_CONFIG="use-xdg-base-directories = true"
|
||||||
|
|
||||||
nix-channel --add http://foo/bar xyzzy
|
nix-channel --add http://foo/bar xyzzy
|
||||||
nix-channel --list | grep -q http://foo/bar
|
nix-channel --list | grepQuiet http://foo/bar
|
||||||
nix-channel --remove xyzzy
|
nix-channel --remove xyzzy
|
||||||
|
|
||||||
unset NIX_CONFIG
|
unset NIX_CONFIG
|
||||||
|
@ -41,8 +41,8 @@ nix-channel --update
|
||||||
|
|
||||||
# Do a query.
|
# Do a query.
|
||||||
nix-env -qa \* --meta --xml --out-path > $TEST_ROOT/meta.xml
|
nix-env -qa \* --meta --xml --out-path > $TEST_ROOT/meta.xml
|
||||||
grep -q 'meta.*description.*Random test package' $TEST_ROOT/meta.xml
|
grepQuiet 'meta.*description.*Random test package' $TEST_ROOT/meta.xml
|
||||||
grep -q 'item.*attrPath="foo".*name="dependencies-top"' $TEST_ROOT/meta.xml
|
grepQuiet 'item.*attrPath="foo".*name="dependencies-top"' $TEST_ROOT/meta.xml
|
||||||
|
|
||||||
# Do an install.
|
# Do an install.
|
||||||
nix-env -i dependencies-top
|
nix-env -i dependencies-top
|
||||||
|
@ -54,9 +54,9 @@ nix-channel --update
|
||||||
|
|
||||||
# Do a query.
|
# Do a query.
|
||||||
nix-env -qa \* --meta --xml --out-path > $TEST_ROOT/meta.xml
|
nix-env -qa \* --meta --xml --out-path > $TEST_ROOT/meta.xml
|
||||||
grep -q 'meta.*description.*Random test package' $TEST_ROOT/meta.xml
|
grepQuiet 'meta.*description.*Random test package' $TEST_ROOT/meta.xml
|
||||||
grep -q 'item.*attrPath="bar".*name="dependencies-top"' $TEST_ROOT/meta.xml
|
grepQuiet 'item.*attrPath="bar".*name="dependencies-top"' $TEST_ROOT/meta.xml
|
||||||
grep -q 'item.*attrPath="foo".*name="dependencies-top"' $TEST_ROOT/meta.xml
|
grepQuiet 'item.*attrPath="foo".*name="dependencies-top"' $TEST_ROOT/meta.xml
|
||||||
|
|
||||||
# Do an install.
|
# Do an install.
|
||||||
nix-env -i dependencies-top
|
nix-env -i dependencies-top
|
||||||
|
|
|
@ -88,14 +88,16 @@ output=$($TEST_ROOT/spaced\ \\\'\"shell.shebang.rb abc ruby)
|
||||||
nix develop -f "$shellDotNix" shellDrv -c bash -c '[[ -n $stdenv ]]'
|
nix develop -f "$shellDotNix" shellDrv -c bash -c '[[ -n $stdenv ]]'
|
||||||
|
|
||||||
# Ensure `nix develop -c` preserves stdin
|
# Ensure `nix develop -c` preserves stdin
|
||||||
echo foo | nix develop -f "$shellDotNix" shellDrv -c cat | grep -q foo
|
echo foo | nix develop -f "$shellDotNix" shellDrv -c cat | grepQuiet foo
|
||||||
|
|
||||||
# Ensure `nix develop -c` actually executes the command if stdout isn't a terminal
|
# Ensure `nix develop -c` actually executes the command if stdout isn't a terminal
|
||||||
nix develop -f "$shellDotNix" shellDrv -c echo foo |& grep -q foo
|
nix develop -f "$shellDotNix" shellDrv -c echo foo |& grepQuiet foo
|
||||||
|
|
||||||
# Test 'nix print-dev-env'.
|
# Test 'nix print-dev-env'.
|
||||||
[[ $(nix print-dev-env -f "$shellDotNix" shellDrv --json | jq -r .variables.arr1.value[2]) = '3 4' ]]
|
[[ $(nix print-dev-env -f "$shellDotNix" shellDrv --json | jq -r .variables.arr1.value[2]) = '3 4' ]]
|
||||||
|
|
||||||
|
set +u # FIXME: Make print-dev-env `set -u` compliant (issue #7951)
|
||||||
|
|
||||||
source <(nix print-dev-env -f "$shellDotNix" shellDrv)
|
source <(nix print-dev-env -f "$shellDotNix" shellDrv)
|
||||||
[[ -n $stdenv ]]
|
[[ -n $stdenv ]]
|
||||||
[[ ${arr1[2]} = "3 4" ]]
|
[[ ${arr1[2]} = "3 4" ]]
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
source common.sh
|
source common.sh
|
||||||
|
|
||||||
set -o pipefail
|
|
||||||
|
|
||||||
if [[ $BUILD_SHARED_LIBS != 1 ]]; then
|
if [[ $BUILD_SHARED_LIBS != 1 ]]; then
|
||||||
echo "plugins are not supported"
|
echo "plugins are not supported"
|
||||||
exit 99
|
exit 99
|
||||||
|
|
|
@ -8,7 +8,7 @@ nix eval --expr 'assert 1 + 2 == 3; true'
|
||||||
|
|
||||||
missingImpureErrorMsg=$(! nix eval --expr 'builtins.readFile ./pure-eval.sh' 2>&1)
|
missingImpureErrorMsg=$(! nix eval --expr 'builtins.readFile ./pure-eval.sh' 2>&1)
|
||||||
|
|
||||||
echo "$missingImpureErrorMsg" | grep -q -- --impure || \
|
echo "$missingImpureErrorMsg" | grepQuiet -- --impure || \
|
||||||
fail "The error message should mention the “--impure” flag to unblock users"
|
fail "The error message should mention the “--impure” flag to unblock users"
|
||||||
|
|
||||||
[[ $(nix eval --expr 'builtins.pathExists ./pure-eval.sh') == false ]] || \
|
[[ $(nix eval --expr 'builtins.pathExists ./pure-eval.sh') == false ]] || \
|
||||||
|
|
|
@ -33,14 +33,14 @@ testRepl () {
|
||||||
nix repl "${nixArgs[@]}" <<< "$replCmds" || fail "nix repl does not work twice with the same inputs"
|
nix repl "${nixArgs[@]}" <<< "$replCmds" || fail "nix repl does not work twice with the same inputs"
|
||||||
|
|
||||||
# simple.nix prints a PATH during build
|
# simple.nix prints a PATH during build
|
||||||
echo "$replOutput" | grep -qs 'PATH=' || fail "nix repl :log doesn't output logs"
|
echo "$replOutput" | grepQuiet -s 'PATH=' || fail "nix repl :log doesn't output logs"
|
||||||
local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replFailingCmds" 2>&1)"
|
local replOutput="$(nix repl "${nixArgs[@]}" <<< "$replFailingCmds" 2>&1)"
|
||||||
echo "$replOutput"
|
echo "$replOutput"
|
||||||
echo "$replOutput" | grep -qs 'This should fail' \
|
echo "$replOutput" | grepQuiet -s 'This should fail' \
|
||||||
|| fail "nix repl :log doesn't output logs for a failed derivation"
|
|| fail "nix repl :log doesn't output logs for a failed derivation"
|
||||||
local replOutput="$(nix repl --show-trace "${nixArgs[@]}" <<< "$replUndefinedVariable" 2>&1)"
|
local replOutput="$(nix repl --show-trace "${nixArgs[@]}" <<< "$replUndefinedVariable" 2>&1)"
|
||||||
echo "$replOutput"
|
echo "$replOutput"
|
||||||
echo "$replOutput" | grep -qs "while evaluating the file" \
|
echo "$replOutput" | grepQuiet -s "while evaluating the file" \
|
||||||
|| fail "nix repl --show-trace doesn't show the trace"
|
|| fail "nix repl --show-trace doesn't show the trace"
|
||||||
|
|
||||||
nix repl "${nixArgs[@]}" --option pure-eval true 2>&1 <<< "builtins.currentSystem" \
|
nix repl "${nixArgs[@]}" --option pure-eval true 2>&1 <<< "builtins.currentSystem" \
|
||||||
|
@ -58,7 +58,7 @@ testReplResponse () {
|
||||||
local commands="$1"; shift
|
local commands="$1"; shift
|
||||||
local expectedResponse="$1"; shift
|
local expectedResponse="$1"; shift
|
||||||
local response="$(nix repl "$@" <<< "$commands")"
|
local response="$(nix repl "$@" <<< "$commands")"
|
||||||
echo "$response" | grep -qs "$expectedResponse" \
|
echo "$response" | grepQuiet -s "$expectedResponse" \
|
||||||
|| fail "repl command set:
|
|| fail "repl command set:
|
||||||
|
|
||||||
$commands
|
$commands
|
||||||
|
@ -121,5 +121,5 @@ sed -i 's/beforeChange/afterChange/' flake/flake.nix
|
||||||
echo ":reload"
|
echo ":reload"
|
||||||
echo "changingThing"
|
echo "changingThing"
|
||||||
) | nix repl ./flake --experimental-features 'flakes repl-flake')
|
) | nix repl ./flake --experimental-features 'flakes repl-flake')
|
||||||
echo "$replResult" | grep -qs beforeChange
|
echo "$replResult" | grepQuiet -s beforeChange
|
||||||
echo "$replResult" | grep -qs afterChange
|
echo "$replResult" | grepQuiet -s afterChange
|
||||||
|
|
|
@ -48,4 +48,4 @@ output="$(nix eval --raw --restrict-eval -I "$traverseDir" \
|
||||||
--expr "builtins.readFile \"$traverseDir/$goUp$(pwd)/restricted-innocent\"" \
|
--expr "builtins.readFile \"$traverseDir/$goUp$(pwd)/restricted-innocent\"" \
|
||||||
2>&1 || :)"
|
2>&1 || :)"
|
||||||
echo "$output" | grep "is forbidden"
|
echo "$output" | grep "is forbidden"
|
||||||
! echo "$output" | grep -F restricted-secret
|
echo "$output" | grepInverse -F restricted-secret
|
||||||
|
|
|
@ -20,9 +20,9 @@ clearCache
|
||||||
## Search expressions
|
## Search expressions
|
||||||
|
|
||||||
# Check that empty search string matches all
|
# Check that empty search string matches all
|
||||||
nix search -f search.nix '' |grep -q foo
|
nix search -f search.nix '' |grepQuiet foo
|
||||||
nix search -f search.nix '' |grep -q bar
|
nix search -f search.nix '' |grepQuiet bar
|
||||||
nix search -f search.nix '' |grep -q hello
|
nix search -f search.nix '' |grepQuiet hello
|
||||||
|
|
||||||
## Tests for multiple regex/match highlighting
|
## Tests for multiple regex/match highlighting
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ test_tarball() {
|
||||||
tarball=$TEST_ROOT/tarball.tar$ext
|
tarball=$TEST_ROOT/tarball.tar$ext
|
||||||
(cd $TEST_ROOT && tar cf - tarball) | $compressor > $tarball
|
(cd $TEST_ROOT && tar cf - tarball) | $compressor > $tarball
|
||||||
|
|
||||||
nix-env -f file://$tarball -qa --out-path | grep -q dependencies
|
nix-env -f file://$tarball -qa --out-path | grepQuiet dependencies
|
||||||
|
|
||||||
nix-build -o $TEST_ROOT/result file://$tarball
|
nix-build -o $TEST_ROOT/result file://$tarball
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ test_tarball() {
|
||||||
nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })"
|
nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })"
|
||||||
# Do not re-fetch paths already present
|
# Do not re-fetch paths already present
|
||||||
nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file:///does-not-exist/must-remain-unused/$tarball; narHash = \"$hash\"; })"
|
nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file:///does-not-exist/must-remain-unused/$tarball; narHash = \"$hash\"; })"
|
||||||
nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"sha256-xdKv2pq/IiwLSnBBJXW8hNowI4MrdZfW+SYqDQs7Tzc=\"; })" 2>&1 | grep 'NAR hash mismatch in input'
|
expectStderr 102 nix-build -o $TEST_ROOT/result -E "import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"sha256-xdKv2pq/IiwLSnBBJXW8hNowI4MrdZfW+SYqDQs7Tzc=\"; })" | grep 'NAR hash mismatch in input'
|
||||||
|
|
||||||
nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" >&2
|
nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" >&2
|
||||||
nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" 2>&1 | grep 'true'
|
nix-instantiate --strict --eval -E "!((import (fetchTree { type = \"tarball\"; url = file://$tarball; narHash = \"$hash\"; })) ? submodules)" 2>&1 | grep 'true'
|
||||||
|
|
85
tests/test-infra.sh
Normal file
85
tests/test-infra.sh
Normal file
|
@ -0,0 +1,85 @@
|
||||||
|
# Test the functions for testing themselves!
|
||||||
|
# Also test some assumptions on how bash works that they rely on.
|
||||||
|
source common.sh
|
||||||
|
|
||||||
|
# `true` should exit with 0
|
||||||
|
expect 0 true
|
||||||
|
|
||||||
|
# `false` should exit with 1
|
||||||
|
expect 1 false
|
||||||
|
|
||||||
|
# `expect` will fail when we get it wrong
|
||||||
|
expect 1 expect 0 false
|
||||||
|
|
||||||
|
noisyTrue () {
|
||||||
|
echo YAY! >&2
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
noisyFalse () {
|
||||||
|
echo NAY! >&2
|
||||||
|
false
|
||||||
|
}
|
||||||
|
|
||||||
|
# These should redirect standard error to standard output
|
||||||
|
expectStderr 0 noisyTrue | grepQuiet YAY
|
||||||
|
expectStderr 1 noisyFalse | grepQuiet NAY
|
||||||
|
|
||||||
|
# `set -o pipefile` is enabled
|
||||||
|
|
||||||
|
pipefailure () {
|
||||||
|
# shellcheck disable=SC2216
|
||||||
|
true | false | true
|
||||||
|
}
|
||||||
|
expect 1 pipefailure
|
||||||
|
unset pipefailure
|
||||||
|
|
||||||
|
pipefailure () {
|
||||||
|
# shellcheck disable=SC2216
|
||||||
|
false | true | true
|
||||||
|
}
|
||||||
|
expect 1 pipefailure
|
||||||
|
unset pipefailure
|
||||||
|
|
||||||
|
commandSubstitutionPipeFailure () {
|
||||||
|
# shellcheck disable=SC2216
|
||||||
|
res=$(set -eu -o pipefail; false | true | echo 0)
|
||||||
|
}
|
||||||
|
expect 1 commandSubstitutionPipeFailure
|
||||||
|
|
||||||
|
# `set -u` is enabled
|
||||||
|
|
||||||
|
# note (...), making function use subshell, as unbound variable errors
|
||||||
|
# in the outer shell are *rightly* not recoverable.
|
||||||
|
useUnbound () (
|
||||||
|
set -eu
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
echo "$thisVariableIsNotBound"
|
||||||
|
)
|
||||||
|
expect 1 useUnbound
|
||||||
|
|
||||||
|
# ! alone unfortunately negates `set -e`, but it works in functions:
|
||||||
|
# shellcheck disable=SC2251
|
||||||
|
! true
|
||||||
|
funBang () {
|
||||||
|
! true
|
||||||
|
}
|
||||||
|
expect 1 funBang
|
||||||
|
unset funBang
|
||||||
|
|
||||||
|
# `grep -v -q` is not what we want for exit codes, but `grepInverse` is
|
||||||
|
# Avoid `grep -v -q`. The following line proves the point, and if it fails,
|
||||||
|
# we'll know that `grep` had a breaking change or `-v -q` may not be portable.
|
||||||
|
{ echo foo; echo bar; } | grep -v -q foo
|
||||||
|
{ echo foo; echo bar; } | expect 1 grepInverse foo
|
||||||
|
|
||||||
|
# `grepQuiet` is quiet
|
||||||
|
res=$(set -eu -o pipefail; echo foo | grepQuiet foo | wc -c)
|
||||||
|
(( res == 0 ))
|
||||||
|
unset res
|
||||||
|
|
||||||
|
# `greqQietInverse` is both
|
||||||
|
{ echo foo; echo bar; } | expect 1 grepQuietInverse foo
|
||||||
|
res=$(set -eu -o pipefail; echo foo | expect 1 grepQuietInverse foo | wc -c)
|
||||||
|
(( res == 0 ))
|
||||||
|
unset res
|
|
@ -5,17 +5,14 @@ source common.sh
|
||||||
# XXX: This shouldn’t be, but #4813 cause this test to fail
|
# XXX: This shouldn’t be, but #4813 cause this test to fail
|
||||||
needLocalStore "see #4813"
|
needLocalStore "see #4813"
|
||||||
|
|
||||||
set +e
|
messages=$(nix-build -Q timeout.nix -A infiniteLoop --timeout 2 2>&1) && status=0 || status=$?
|
||||||
messages=$(nix-build -Q timeout.nix -A infiniteLoop --timeout 2 2>&1)
|
|
||||||
status=$?
|
|
||||||
set -e
|
|
||||||
|
|
||||||
if [ $status -ne 101 ]; then
|
if [ $status -ne 101 ]; then
|
||||||
echo "error: 'nix-store' exited with '$status'; should have exited 101"
|
echo "error: 'nix-store' exited with '$status'; should have exited 101"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! echo "$messages" | grep -q "timed out"; then
|
if echo "$messages" | grepQuietInvert "timed out"; then
|
||||||
echo "error: build may have failed for reasons other than timeout; output:"
|
echo "error: build may have failed for reasons other than timeout; output:"
|
||||||
echo "$messages" >&2
|
echo "$messages" >&2
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
source common.sh
|
source common.sh
|
||||||
|
|
||||||
if [ -z "$storeCleared" ]; then
|
if [ -z "${storeCleared-}" ]; then
|
||||||
clearStore
|
clearStore
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -28,13 +28,13 @@ nix-env -f ./user-envs.nix -qa --json --out-path | jq -e '.[] | select(.name ==
|
||||||
] | all'
|
] | all'
|
||||||
|
|
||||||
# Query descriptions.
|
# Query descriptions.
|
||||||
nix-env -f ./user-envs.nix -qa '*' --description | grep -q silly
|
nix-env -f ./user-envs.nix -qa '*' --description | grepQuiet silly
|
||||||
rm -rf $HOME/.nix-defexpr
|
rm -rf $HOME/.nix-defexpr
|
||||||
ln -s $(pwd)/user-envs.nix $HOME/.nix-defexpr
|
ln -s $(pwd)/user-envs.nix $HOME/.nix-defexpr
|
||||||
nix-env -qa '*' --description | grep -q silly
|
nix-env -qa '*' --description | grepQuiet silly
|
||||||
|
|
||||||
# Query the system.
|
# Query the system.
|
||||||
nix-env -qa '*' --system | grep -q $system
|
nix-env -qa '*' --system | grepQuiet $system
|
||||||
|
|
||||||
# Install "foo-1.0".
|
# Install "foo-1.0".
|
||||||
nix-env -i foo-1.0
|
nix-env -i foo-1.0
|
||||||
|
@ -42,19 +42,19 @@ nix-env -i foo-1.0
|
||||||
# Query installed: should contain foo-1.0 now (which should be
|
# Query installed: should contain foo-1.0 now (which should be
|
||||||
# executable).
|
# executable).
|
||||||
test "$(nix-env -q '*' | wc -l)" -eq 1
|
test "$(nix-env -q '*' | wc -l)" -eq 1
|
||||||
nix-env -q '*' | grep -q foo-1.0
|
nix-env -q '*' | grepQuiet foo-1.0
|
||||||
test "$($profiles/test/bin/foo)" = "foo-1.0"
|
test "$($profiles/test/bin/foo)" = "foo-1.0"
|
||||||
|
|
||||||
# Test nix-env -qc to compare installed against available packages, and vice versa.
|
# Test nix-env -qc to compare installed against available packages, and vice versa.
|
||||||
nix-env -qc '*' | grep -q '< 2.0'
|
nix-env -qc '*' | grepQuiet '< 2.0'
|
||||||
nix-env -qac '*' | grep -q '> 1.0'
|
nix-env -qac '*' | grepQuiet '> 1.0'
|
||||||
|
|
||||||
# Test the -b flag to filter out source-only packages.
|
# Test the -b flag to filter out source-only packages.
|
||||||
[ "$(nix-env -qab | wc -l)" -eq 1 ]
|
[ "$(nix-env -qab | wc -l)" -eq 1 ]
|
||||||
|
|
||||||
# Test the -s flag to get package status.
|
# Test the -s flag to get package status.
|
||||||
nix-env -qas | grep -q 'IP- foo-1.0'
|
nix-env -qas | grepQuiet 'IP- foo-1.0'
|
||||||
nix-env -qas | grep -q -- '--- bar-0.1'
|
nix-env -qas | grepQuiet -- '--- bar-0.1'
|
||||||
|
|
||||||
# Disable foo.
|
# Disable foo.
|
||||||
nix-env --set-flag active false foo
|
nix-env --set-flag active false foo
|
||||||
|
@ -74,15 +74,15 @@ nix-env -i foo-2.0pre1
|
||||||
|
|
||||||
# Query installed: should contain foo-2.0pre1 now.
|
# Query installed: should contain foo-2.0pre1 now.
|
||||||
test "$(nix-env -q '*' | wc -l)" -eq 1
|
test "$(nix-env -q '*' | wc -l)" -eq 1
|
||||||
nix-env -q '*' | grep -q foo-2.0pre1
|
nix-env -q '*' | grepQuiet foo-2.0pre1
|
||||||
test "$($profiles/test/bin/foo)" = "foo-2.0pre1"
|
test "$($profiles/test/bin/foo)" = "foo-2.0pre1"
|
||||||
|
|
||||||
# Upgrade "foo": should install foo-2.0.
|
# Upgrade "foo": should install foo-2.0.
|
||||||
NIX_PATH=nixpkgs=./user-envs.nix:$NIX_PATH nix-env -f '<nixpkgs>' -u foo
|
NIX_PATH=nixpkgs=./user-envs.nix:${NIX_PATH-} nix-env -f '<nixpkgs>' -u foo
|
||||||
|
|
||||||
# Query installed: should contain foo-2.0 now.
|
# Query installed: should contain foo-2.0 now.
|
||||||
test "$(nix-env -q '*' | wc -l)" -eq 1
|
test "$(nix-env -q '*' | wc -l)" -eq 1
|
||||||
nix-env -q '*' | grep -q foo-2.0
|
nix-env -q '*' | grepQuiet foo-2.0
|
||||||
test "$($profiles/test/bin/foo)" = "foo-2.0"
|
test "$($profiles/test/bin/foo)" = "foo-2.0"
|
||||||
|
|
||||||
# Store the path of foo-2.0.
|
# Store the path of foo-2.0.
|
||||||
|
@ -94,20 +94,20 @@ nix-env -i bar-0.1
|
||||||
nix-env -e foo
|
nix-env -e foo
|
||||||
|
|
||||||
# Query installed: should only contain bar-0.1 now.
|
# Query installed: should only contain bar-0.1 now.
|
||||||
if nix-env -q '*' | grep -q foo; then false; fi
|
if nix-env -q '*' | grepQuiet foo; then false; fi
|
||||||
nix-env -q '*' | grep -q bar
|
nix-env -q '*' | grepQuiet bar
|
||||||
|
|
||||||
# Rollback: should bring "foo" back.
|
# Rollback: should bring "foo" back.
|
||||||
oldGen="$(nix-store -q --resolve $profiles/test)"
|
oldGen="$(nix-store -q --resolve $profiles/test)"
|
||||||
nix-env --rollback
|
nix-env --rollback
|
||||||
[ "$(nix-store -q --resolve $profiles/test)" != "$oldGen" ]
|
[ "$(nix-store -q --resolve $profiles/test)" != "$oldGen" ]
|
||||||
nix-env -q '*' | grep -q foo-2.0
|
nix-env -q '*' | grepQuiet foo-2.0
|
||||||
nix-env -q '*' | grep -q bar
|
nix-env -q '*' | grepQuiet bar
|
||||||
|
|
||||||
# Rollback again: should remove "bar".
|
# Rollback again: should remove "bar".
|
||||||
nix-env --rollback
|
nix-env --rollback
|
||||||
nix-env -q '*' | grep -q foo-2.0
|
nix-env -q '*' | grepQuiet foo-2.0
|
||||||
if nix-env -q '*' | grep -q bar; then false; fi
|
if nix-env -q '*' | grepQuiet bar; then false; fi
|
||||||
|
|
||||||
# Count generations.
|
# Count generations.
|
||||||
nix-env --list-generations
|
nix-env --list-generations
|
||||||
|
@ -129,7 +129,7 @@ nix-env --switch-generation 7
|
||||||
|
|
||||||
# Install foo-1.0, now using its store path.
|
# Install foo-1.0, now using its store path.
|
||||||
nix-env -i "$outPath10"
|
nix-env -i "$outPath10"
|
||||||
nix-env -q '*' | grep -q foo-1.0
|
nix-env -q '*' | grepQuiet foo-1.0
|
||||||
nix-store -qR $profiles/test | grep "$outPath10"
|
nix-store -qR $profiles/test | grep "$outPath10"
|
||||||
nix-store -q --referrers-closure $profiles/test | grep "$(nix-store -q --resolve $profiles/test)"
|
nix-store -q --referrers-closure $profiles/test | grep "$(nix-store -q --resolve $profiles/test)"
|
||||||
[ "$(nix-store -q --deriver "$outPath10")" = $drvPath10 ]
|
[ "$(nix-store -q --deriver "$outPath10")" = $drvPath10 ]
|
||||||
|
@ -137,12 +137,12 @@ nix-store -q --referrers-closure $profiles/test | grep "$(nix-store -q --resolve
|
||||||
# Uninstall foo-1.0, using a symlink to its store path.
|
# Uninstall foo-1.0, using a symlink to its store path.
|
||||||
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 '*' | grepQuiet foo; then false; fi
|
||||||
(! nix-store -qR $profiles/test | grep "$outPath10")
|
nix-store -qR $profiles/test | grepInverse "$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
|
||||||
nix-env -q '*' | grep -q foo
|
nix-env -q '*' | grepQuiet foo
|
||||||
|
|
||||||
# Delete all old generations.
|
# Delete all old generations.
|
||||||
nix-env --delete-generations old
|
nix-env --delete-generations old
|
||||||
|
@ -160,7 +160,7 @@ test "$(nix-env -q '*' | wc -l)" -eq 0
|
||||||
# Installing "foo" should only install the newest foo.
|
# Installing "foo" should only install the newest foo.
|
||||||
nix-env -i foo
|
nix-env -i foo
|
||||||
test "$(nix-env -q '*' | grep foo- | wc -l)" -eq 1
|
test "$(nix-env -q '*' | grep foo- | wc -l)" -eq 1
|
||||||
nix-env -q '*' | grep -q foo-2.0
|
nix-env -q '*' | grepQuiet 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).
|
||||||
|
@ -171,8 +171,8 @@ nix-env -e '*'
|
||||||
nix-env -e '*'
|
nix-env -e '*'
|
||||||
nix-env -i '*'
|
nix-env -i '*'
|
||||||
test "$(nix-env -q '*' | wc -l)" -eq 2
|
test "$(nix-env -q '*' | wc -l)" -eq 2
|
||||||
nix-env -q '*' | grep -q foo-2.0
|
nix-env -q '*' | grepQuiet foo-2.0
|
||||||
nix-env -q '*' | grep -q bar-0.1.1
|
nix-env -q '*' | grepQuiet bar-0.1.1
|
||||||
|
|
||||||
# Test priorities: foo-0.1 has a lower priority than foo-1.0, so it
|
# Test priorities: foo-0.1 has a lower priority than foo-1.0, so it
|
||||||
# should be possible to install both without a collision. Also test
|
# should be possible to install both without a collision. Also test
|
||||||
|
|
|
@ -16,9 +16,9 @@ FAST_WHY_DEPENDS_OUTPUT=$(nix why-depends ./toplevel ./dep)
|
||||||
PRECISE_WHY_DEPENDS_OUTPUT=$(nix why-depends ./toplevel ./dep --precise)
|
PRECISE_WHY_DEPENDS_OUTPUT=$(nix why-depends ./toplevel ./dep --precise)
|
||||||
|
|
||||||
# Both outputs should show that `input-2` is in the dependency chain
|
# Both outputs should show that `input-2` is in the dependency chain
|
||||||
echo "$FAST_WHY_DEPENDS_OUTPUT" | grep -q input-2
|
echo "$FAST_WHY_DEPENDS_OUTPUT" | grepQuiet input-2
|
||||||
echo "$PRECISE_WHY_DEPENDS_OUTPUT" | grep -q input-2
|
echo "$PRECISE_WHY_DEPENDS_OUTPUT" | grepQuiet input-2
|
||||||
|
|
||||||
# But only the “precise” one should refere to `reference-to-input-2`
|
# But only the “precise” one should refer to `reference-to-input-2`
|
||||||
echo "$FAST_WHY_DEPENDS_OUTPUT" | (! grep -q reference-to-input-2)
|
echo "$FAST_WHY_DEPENDS_OUTPUT" | grepQuietInverse reference-to-input-2
|
||||||
echo "$PRECISE_WHY_DEPENDS_OUTPUT" | grep -q reference-to-input-2
|
echo "$PRECISE_WHY_DEPENDS_OUTPUT" | grepQuiet reference-to-input-2
|
||||||
|
|
Loading…
Reference in a new issue