Skip to content

Commit d9de675

Browse files
authored
Merge pull request #14027 from obsidiansystems/more-ca-tests
More floating content-addressing derivation tests
2 parents af82c84 + 7ea31c6 commit d9de675

File tree

6 files changed

+53
-17
lines changed

6 files changed

+53
-17
lines changed

maintainers/flake-module.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,10 +233,12 @@
233233
# Content-addressed test files that use recursive-*looking* sourcing
234234
# (cd .. && source <self>), causing shellcheck to loop
235235
# They're small wrapper scripts with not a lot going on
236+
''^tests/functional/ca/build-delete\.sh$''
236237
''^tests/functional/ca/build-dry\.sh$''
237238
''^tests/functional/ca/eval-store\.sh$''
238239
''^tests/functional/ca/gc\.sh$''
239240
''^tests/functional/ca/import-from-derivation\.sh$''
241+
''^tests/functional/ca/multiple-outputs\.sh$''
240242
''^tests/functional/ca/new-build-cmd\.sh$''
241243
''^tests/functional/ca/nix-shell\.sh$''
242244
''^tests/functional/ca/post-hook\.sh$''

tests/functional/build-delete.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ issue_6572_dependent_outputs() {
4343
nix-store --delete "$p" # Clean up for next test
4444

4545
# Make sure that 'nix build' tracks input-outputs correctly when a single output is already present.
46+
if [[ -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
47+
# Resolved derivations interferre with the deletion
48+
nix-store --delete "${NIX_STORE_DIR}"/*.drv
49+
fi
4650
nix-store --delete "$(jq -r <"$TEST_ROOT"/a.json .[0].outputs.second)"
4751
p=$(nix build -f multiple-outputs.nix use-a --no-link --print-out-paths)
4852
cmp "$p" <<EOF
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
source common.sh
4+
5+
export NIX_TESTS_CA_BY_DEFAULT=1
6+
cd ..
7+
source ./build-delete.sh

tests/functional/ca/meson.build

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ suites += {
99
'deps' : [],
1010
'tests' : [
1111
'build-cache.sh',
12+
'build-delete.sh',
1213
'build-with-garbage-path.sh',
1314
'build.sh',
1415
'concurrent-builds.sh',
@@ -18,6 +19,7 @@ suites += {
1819
'eval-store.sh',
1920
'gc.sh',
2021
'import-from-derivation.sh',
22+
'multiple-outputs.sh',
2123
'new-build-cmd.sh',
2224
'nix-copy.sh',
2325
'nix-run.sh',
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env bash
2+
3+
source common.sh
4+
5+
export NIX_TESTS_CA_BY_DEFAULT=1
6+
cd ..
7+
source ./multiple-outputs.sh

tests/functional/multiple-outputs.sh

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@ clearStoreIfPossible
88

99
rm -f $TEST_ROOT/result*
1010

11-
# Test whether the output names match our expectations
12-
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.out.outPath)
13-
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a" ]
14-
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.dev.outPath)
15-
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a-dev" ]
11+
# Placeholder strings are opaque, so cannot do this check for floating
12+
# content-addressing derivations.
13+
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
14+
# Test whether the output names match our expectations
15+
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.out.outPath)
16+
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a" ]
17+
outPath=$(nix-instantiate multiple-outputs.nix --eval -A nameCheck.dev.outPath)
18+
[ "$(echo "$outPath" | sed -E 's_^".*/[^-/]*-([^/]*)"$_\1_')" = "multiple-outputs-a-dev" ]
19+
fi
1620

1721
# Test whether read-only evaluation works when referring to the
1822
# ‘drvPath’ attribute.
@@ -29,8 +33,12 @@ grepQuiet 'multiple-outputs-b.drv",\["out"\]' $drvPath
2933
# While we're at it, test the ‘unsafeDiscardOutputDependency’ primop.
3034
outPath=$(nix-build multiple-outputs.nix -A d --no-out-link)
3135
drvPath=$(cat $outPath/drv)
32-
outPath=$(nix-store -q $drvPath)
33-
(! [ -e "$outPath" ])
36+
if [[ -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
37+
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)"
38+
else
39+
outPath=$(nix-store -q $drvPath)
40+
(! [ -e "$outPath" ])
41+
fi
3442

3543
# Do a build of something that depends on a derivation with multiple
3644
# outputs.
@@ -60,14 +68,16 @@ outPath2=$(nix-build $(nix-instantiate multiple-outputs.nix -A a.second) --no-ou
6068

6169
[[ $(nix-build $(nix-instantiate multiple-outputs.nix -A a.all) --no-out-link | wc -l) -eq 2 ]]
6270

63-
# Delete one of the outputs and rebuild it. This will cause a hash
64-
# rewrite.
65-
env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness
66-
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
67-
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
68-
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
69-
hash2=$(nix-store -q --hash $TEST_ROOT/result-second)
70-
[ "$hash1" = "$hash2" ]
71+
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
72+
# Delete one of the outputs and rebuild it. This will cause a hash
73+
# rewrite.
74+
env -u NIX_REMOTE nix store delete $TEST_ROOT/result-second --ignore-liveness
75+
nix-build multiple-outputs.nix -A a.all -o $TEST_ROOT/result
76+
[ "$(cat $TEST_ROOT/result-second/file)" = "second" ]
77+
[ "$(cat $TEST_ROOT/result-second/link/file)" = "first" ]
78+
hash2=$(nix-store -q --hash $TEST_ROOT/result-second)
79+
[ "$hash1" = "$hash2" ]
80+
fi
7181

7282
# Make sure that nix-build works on derivations with multiple outputs.
7383
echo "building a.first..."
@@ -88,5 +98,9 @@ nix-store --gc --print-roots
8898
rm -rf $NIX_STORE_DIR/.links
8999
rmdir $NIX_STORE_DIR
90100

91-
expect 1 nix build -f multiple-outputs.nix invalid-output-name-1 2>&1 | grep 'contains illegal character'
92-
expect 1 nix build -f multiple-outputs.nix invalid-output-name-2 2>&1 | grep 'contains illegal character'
101+
# TODO inspect why this doesn't work with floating content-addressing
102+
# derivations.
103+
if [[ ! -n "${NIX_TESTS_CA_BY_DEFAULT:-}" ]]; then
104+
expect 1 nix build -f multiple-outputs.nix invalid-output-name-1 2>&1 | grep 'contains illegal character'
105+
expect 1 nix build -f multiple-outputs.nix invalid-output-name-2 2>&1 | grep 'contains illegal character'
106+
fi

0 commit comments

Comments
 (0)