mirror of
https://github.com/NixOS/nix.git
synced 2025-11-08 19:46:02 +01:00
shellcheck fix: tests/functional/multiple-outputs.sh
This commit is contained in:
parent
f2eef5b0a4
commit
e26b0c66b0
2 changed files with 37 additions and 32 deletions
|
|
@ -106,7 +106,6 @@
|
||||||
enable = true;
|
enable = true;
|
||||||
excludes = [
|
excludes = [
|
||||||
# We haven't linted these files yet
|
# We haven't linted these files yet
|
||||||
''^tests/functional/multiple-outputs\.sh$''
|
|
||||||
''^tests/functional/nested-sandboxing\.sh$''
|
''^tests/functional/nested-sandboxing\.sh$''
|
||||||
''^tests/functional/nested-sandboxing/command\.sh$''
|
''^tests/functional/nested-sandboxing/command\.sh$''
|
||||||
''^tests/functional/nix-build\.sh$''
|
''^tests/functional/nix-build\.sh$''
|
||||||
|
|
|
||||||
|
|
@ -6,15 +6,17 @@ TODO_NixOS
|
||||||
|
|
||||||
clearStoreIfPossible
|
clearStoreIfPossible
|
||||||
|
|
||||||
rm -f $TEST_ROOT/result*
|
rm -f "$TEST_ROOT"/result*
|
||||||
|
|
||||||
# Placeholder strings are opaque, so cannot do this check for floating
|
# Placeholder strings are opaque, so cannot do this check for floating
|
||||||
# content-addressing derivations.
|
# content-addressing derivations.
|
||||||
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
|
if [[ -z "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
|
||||||
# Test whether the output names match our expectations
|
# Test whether the output names match our expectations
|
||||||
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.out.outPath)
|
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.out.outPath)
|
||||||
|
# shellcheck disable=SC2016
|
||||||
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a" ]
|
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a" ]
|
||||||
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.dev.outPath)
|
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.dev.outPath)
|
||||||
|
# shellcheck disable=SC2016
|
||||||
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a-dev" ]
|
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a-dev" ]
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -27,16 +29,17 @@ 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" ]
|
||||||
grepQuiet 'multiple-outputs-a.drv",\["first","second"\]' $drvPath
|
grepQuiet 'multiple-outputs-a.drv",\["first","second"\]' "$drvPath"
|
||||||
grepQuiet '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)
|
||||||
drvPath=$(cat $outPath/drv)
|
drvPath=$(cat "$outPath"/drv)
|
||||||
if [[ -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
|
if [[ -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
|
||||||
expectStderr 1 nix-store -q $drvPath | grepQuiet "Cannot use output path of floating content-addressing derivation until we know what it is (e.g. by building it)"
|
expectStderr 1 nix-store -q "$drvPath" | grepQuiet "Cannot use output path of floating content-addressing derivation until we know what it is (e.g. by building it)"
|
||||||
else
|
else
|
||||||
outPath=$(nix-store -q $drvPath)
|
outPath=$(nix-store -q "$drvPath")
|
||||||
|
# shellcheck disable=SC2233
|
||||||
(! [ -e "$outPath" ])
|
(! [ -e "$outPath" ])
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -48,34 +51,37 @@ echo "output path is $outPath"
|
||||||
[ "$(cat "$outPath/file")" = "success" ]
|
[ "$(cat "$outPath/file")" = "success" ]
|
||||||
|
|
||||||
# Test nix-build on a derivation with multiple outputs.
|
# Test nix-build on a derivation with multiple outputs.
|
||||||
outPath1=$(nix-build multiple-outputs.nix -A a -o $TEST_ROOT/result)
|
outPath1=$(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 ])
|
# shellcheck disable=SC2235
|
||||||
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
|
(! [ -e "$TEST_ROOT"/result-second ])
|
||||||
[ "$(cat $TEST_ROOT/result-first/file)" = "first" ]
|
nix-build multiple-outputs.nix -A a.all -o "$TEST_ROOT"/result
|
||||||
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
|
[ "$(cat "$TEST_ROOT"/result-first/file)" = "first" ]
|
||||||
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
|
[ "$(cat "$TEST_ROOT"/result-second/file)" = "second" ]
|
||||||
hash1=$(nix-store -q --hash $TEST_ROOT/result-second)
|
[ "$(cat "$TEST_ROOT"/result-second/link/file)" = "first" ]
|
||||||
|
hash1=$(nix-store -q --hash "$TEST_ROOT"/result-second)
|
||||||
|
|
||||||
outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a) --no-out-link)
|
outPath2=$(nix-build "$(nix-instantiate multiple-outputs.nix -A a)" --no-out-link)
|
||||||
[[ $outPath1 = $outPath2 ]]
|
[[ $outPath1 = "$outPath2" ]]
|
||||||
|
|
||||||
outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a.first) --no-out-link)
|
outPath2=$(nix-build "$(nix-instantiate multiple-outputs.nix -A a.first)" --no-out-link)
|
||||||
[[ $outPath1 = $outPath2 ]]
|
[[ $outPath1 = "$outPath2" ]]
|
||||||
|
|
||||||
outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a.second) --no-out-link)
|
outPath2=$(nix-build "$(nix-instantiate multiple-outputs.nix -A a.second)" --no-out-link)
|
||||||
[[ $(cat $outPath2/file) = second ]]
|
[[ $(cat "$outPath2"/file) = second ]]
|
||||||
|
|
||||||
|
# FIXME: Fixing this shellcheck causes the test to fail.
|
||||||
|
# shellcheck disable=SC2046
|
||||||
[[ $(nix-build $(nix-instantiate multiple-outputs.nix -A a.all) --no-out-link | wc -l) -eq 2 ]]
|
[[ $(nix-build $(nix-instantiate multiple-outputs.nix -A a.all) --no-out-link | wc -l) -eq 2 ]]
|
||||||
|
|
||||||
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
|
if [[ -z "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
|
||||||
# Delete one of the outputs and rebuild it. This will cause a hash
|
# Delete one of the outputs and rebuild it. This will cause a hash
|
||||||
# rewrite.
|
# rewrite.
|
||||||
env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness
|
env -u NIX_REMOTE nix store delete "$TEST_ROOT"/result-second --ignore-liveness
|
||||||
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-second/file)" = "second" ]
|
[ "$(cat "$TEST_ROOT"/result-second/file)" = "second" ]
|
||||||
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
|
[ "$(cat "$TEST_ROOT"/result-second/link/file)" = "first" ]
|
||||||
hash2=$(nix-store -q --hash $TEST_ROOT/result-second)
|
hash2=$(nix-store -q --hash "$TEST_ROOT"/result-second)
|
||||||
[ "$hash1" = "$hash2" ]
|
[ "$hash1" = "$hash2" ]
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -92,15 +98,15 @@ fi
|
||||||
|
|
||||||
# Do a GC. This should leave an empty store.
|
# Do a GC. This should leave an empty store.
|
||||||
echo "collecting garbage..."
|
echo "collecting garbage..."
|
||||||
rm $TEST_ROOT/result*
|
rm "$TEST_ROOT"/result*
|
||||||
nix-store --gc --keep-derivations --keep-outputs
|
nix-store --gc --keep-derivations --keep-outputs
|
||||||
nix-store --gc --print-roots
|
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"
|
||||||
|
|
||||||
# TODO inspect why this doesn't work with floating content-addressing
|
# TODO inspect why this doesn't work with floating content-addressing
|
||||||
# derivations.
|
# derivations.
|
||||||
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
|
if [[ -z "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
|
||||||
expect 1 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'
|
||||||
expect 1 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'
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue