Skip to content

Commit 1074a2e

Browse files
committed
Create test for issue 13247
This test ends up being skipped, since the bug has not yet been fixed. A future commit will fix the bug. Progress on #13247, naturally.
1 parent 3c610df commit 1074a2e

File tree

3 files changed

+115
-0
lines changed

3 files changed

+115
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
with import ./config.nix;
2+
3+
rec {
4+
5+
a = mkDerivation {
6+
name = "issue-13247-a";
7+
builder = builtins.toFile "builder.sh" ''
8+
mkdir $out
9+
test -z $all
10+
echo "output" > $out/file
11+
'';
12+
};
13+
14+
# Same output, different drv
15+
a-prime = mkDerivation {
16+
name = "issue-13247-a";
17+
builder = builtins.toFile "builder.sh" ''
18+
echo 'will make the same stuff as `a`, but different drv hash'
19+
20+
mkdir $out
21+
test -z $all
22+
echo "output" > $out/file
23+
'';
24+
};
25+
26+
# Multiple outputs in a derivation that depends on other derivations
27+
f =
28+
dep:
29+
mkDerivation {
30+
name = "use-a-more-outputs";
31+
outputs = [
32+
"first"
33+
"second"
34+
];
35+
inherit dep;
36+
builder = builtins.toFile "builder.sh" ''
37+
ln -s $dep/file $first
38+
ln -s $first $second
39+
'';
40+
};
41+
42+
use-a-more-outputs = f a;
43+
44+
use-a-prime-more-outputs = f a-prime;
45+
46+
}

tests/functional/ca/issue-13247.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
3+
# https://github.com/NixOS/nix/issues/13247
4+
5+
export NIX_TESTS_CA_BY_DEFAULT=1
6+
7+
source common.sh
8+
9+
clearStoreIfPossible
10+
11+
set -x
12+
13+
# Build derivation (both outputs)
14+
nix build -f issue-13247.nix --json a a-prime use-a-more-outputs --no-link > "$TEST_ROOT"/a.json
15+
16+
cache="file://$TEST_ROOT/cache"
17+
18+
# Copy all outputs and realisations to cache
19+
declare -a drvs
20+
for d in "$NIX_STORE_DIR"/*-issue-13247-a.drv "$NIX_STORE_DIR"/*-use-a-more-outputs.drv; do
21+
drvs+=("$d" "$d"^*)
22+
done
23+
nix copy --to "$cache" "${drvs[@]}"
24+
25+
function delete () {
26+
# Delete local copy
27+
# shellcheck disable=SC2046
28+
nix-store --delete \
29+
$(jq -r <"$TEST_ROOT"/a.json '.[] | .drvPath, .outputs.[]') \
30+
"$NIX_STORE_DIR"/*-issue-13247-a.drv \
31+
"$NIX_STORE_DIR"/*-use-a-more-outputs.drv
32+
33+
[[ ! -e "$(jq -r <"$TEST_ROOT"/a.json '.[0].outputs.out')" ]]
34+
[[ ! -e "$(jq -r <"$TEST_ROOT"/a.json '.[1].outputs.out')" ]]
35+
[[ ! -e "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.first')" ]]
36+
[[ ! -e "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.second')" ]]
37+
}
38+
39+
delete
40+
41+
buildViaSubstitute () {
42+
nix build -f issue-13247.nix "$1" --no-link --max-jobs 0 --substituters "$cache" --no-require-sigs --offline --substitute
43+
}
44+
45+
# Substitue just the first output
46+
buildViaSubstitute use-a-more-outputs^first
47+
48+
# Should only fetch the output we asked for
49+
[[ -d "$(jq -r <"$TEST_ROOT"/a.json '.[0].outputs.out')" ]]
50+
[[ -f "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.first')" ]]
51+
[[ ! -e "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.second')" ]]
52+
53+
delete
54+
55+
# Substitue just the first output
56+
#
57+
# This derivation is the same after normalization, so we should get
58+
# early cut-off, and thus a chance to download just the output we want
59+
# rather than building more
60+
buildViaSubstitute use-a-prime-more-outputs^first
61+
62+
# Should only fetch the output we asked for
63+
[[ -d "$(jq -r <"$TEST_ROOT"/a.json '.[0].outputs.out')" ]]
64+
[[ -f "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.first')" ]]
65+
66+
# Output should *not* be here, this is the bug
67+
[[ -e "$(jq -r <"$TEST_ROOT"/a.json '.[2].outputs.second')" ]]
68+
skipTest "bug is not yet fixed"

tests/functional/ca/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ suites += {
1919
'eval-store.sh',
2020
'gc.sh',
2121
'import-from-derivation.sh',
22+
'issue-13247.sh',
2223
'multiple-outputs.sh',
2324
'new-build-cmd.sh',
2425
'nix-copy.sh',

0 commit comments

Comments
 (0)