Skip to content

Commit 4b9735b

Browse files
edolstraEricson2314
authored andcommitted
Test against uncacheable paths
This is to test the non-functional property that most paths should be cacheable. We've had frequent cases where caching broken but we didn't notice.
1 parent 1d13049 commit 4b9735b

File tree

7 files changed

+19
-10
lines changed

7 files changed

+19
-10
lines changed

src/libfetchers/fetch-to-store.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "nix/fetchers/fetch-to-store.hh"
22
#include "nix/fetchers/fetchers.hh"
33
#include "nix/fetchers/fetch-settings.hh"
4+
#include "nix/util/environment-variables.hh"
45

56
namespace nix {
67

@@ -37,6 +38,9 @@ StorePath fetchToStore(
3738
return res->storePath;
3839
}
3940
} else {
41+
static auto barf = getEnv("_NIX_TEST_BARF_ON_UNCACHEABLE").value_or("") == "1";
42+
if (barf && !filter)
43+
throw Error("source path '%s' is uncacheable (filter=%d)", path, (bool) filter);
4044
// FIXME: could still provide in-memory caching keyed on `SourcePath`.
4145
debug("source path '%s' is uncacheable", path);
4246
}

tests/functional/flakes/common.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
source ../common.sh
44

5+
export _NIX_TEST_BARF_ON_UNCACHEABLE=1
6+
57
# shellcheck disable=SC2034 # this variable is used by tests that source this file
68
registry=$TEST_ROOT/registry.json
79

tests/functional/flakes/flake-in-submodule.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ flakeref=git+file://$rootRepo\?submodules=1\&dir=submodule
6262
# Check that dirtying a submodule makes the entire thing dirty.
6363
[[ $(nix flake metadata --json "$flakeref" | jq -r .locked.rev) != null ]]
6464
echo '"foo"' > "$rootRepo"/submodule/sub.nix
65-
[[ $(nix eval --json "$flakeref#sub" ) = '"foo"' ]]
66-
[[ $(nix flake metadata --json "$flakeref" | jq -r .locked.rev) = null ]]
65+
[[ $(_NIX_TEST_BARF_ON_UNCACHEABLE='' nix eval --json "$flakeref#sub" ) = '"foo"' ]]
66+
[[ $(_NIX_TEST_BARF_ON_UNCACHEABLE='' nix flake metadata --json "$flakeref" | jq -r .locked.rev) = null ]]
6767

6868
# Test that `nix flake metadata` parses `submodule` correctly.
6969
cat > "$rootRepo"/flake.nix <<EOF
@@ -75,7 +75,7 @@ EOF
7575
git -C "$rootRepo" add flake.nix
7676
git -C "$rootRepo" commit -m "Add flake.nix"
7777

78-
storePath=$(nix flake prefetch --json "$rootRepo?submodules=1" | jq -r .storePath)
78+
storePath=$(_NIX_TEST_BARF_ON_UNCACHEABLE='' nix flake prefetch --json "$rootRepo?submodules=1" | jq -r .storePath)
7979
[[ -e "$storePath/submodule" ]]
8080

8181
# Test the use of inputs.self.

tests/functional/flakes/follow-paths.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ EOF
131131
git -C $flakeFollowsA add flake.nix
132132

133133
expect 1 nix flake lock $flakeFollowsA 2>&1 | grep '/flakeB.*is forbidden in pure evaluation mode'
134-
expect 1 nix flake lock --impure $flakeFollowsA 2>&1 | grep '/flakeB.*does not exist'
134+
expect 1 nix flake lock --impure $flakeFollowsA 2>&1 | grep "'flakeB' is too short to be a valid store path"
135135

136136
# Test relative non-flake inputs.
137137
cat > $flakeFollowsA/flake.nix <<EOF

tests/functional/flakes/mercurial.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ nix build -o "$TEST_ROOT/result" "hg+file://$flake2Dir"
2727

2828
(! nix flake metadata --json "hg+file://$flake2Dir" | jq -e -r .revision)
2929

30-
nix eval "hg+file://$flake2Dir"#expr
30+
_NIX_TEST_BARF_ON_UNCACHEABLE='' nix eval "hg+file://$flake2Dir"#expr
3131

32-
nix eval "hg+file://$flake2Dir"#expr
32+
_NIX_TEST_BARF_ON_UNCACHEABLE='' nix eval "hg+file://$flake2Dir"#expr
3333

3434
(! nix eval "hg+file://$flake2Dir"#expr --no-allow-dirty)
3535

tests/functional/flakes/non-flake-inputs.sh

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ nix build -o "$TEST_ROOT/result" "$flake3Dir#sth" --commit-lock-file
8181

8282
nix registry add --registry "$registry" flake3 "git+file://$flake3Dir"
8383

84-
nix build -o "$TEST_ROOT/result" flake3#fnord
84+
_NIX_TEST_BARF_ON_UNCACHEABLE='' nix build -o "$TEST_ROOT/result" flake3#fnord
8585
[[ $(cat "$TEST_ROOT/result") = FNORD ]]
8686

8787
# Check whether flake input fetching is lazy: flake3#sth does not
@@ -91,16 +91,17 @@ clearStore
9191
mv "$flake2Dir" "$flake2Dir.tmp"
9292
mv "$nonFlakeDir" "$nonFlakeDir.tmp"
9393
nix build -o "$TEST_ROOT/result" flake3#sth
94-
(! nix build -o "$TEST_ROOT/result" flake3#xyzzy)
95-
(! nix build -o "$TEST_ROOT/result" flake3#fnord)
94+
(! _NIX_TEST_BARF_ON_UNCACHEABLE='' nix build -o "$TEST_ROOT/result" flake3#xyzzy)
95+
(! _NIX_TEST_BARF_ON_UNCACHEABLE='' nix build -o "$TEST_ROOT/result" flake3#fnord)
9696
mv "$flake2Dir.tmp" "$flake2Dir"
9797
mv "$nonFlakeDir.tmp" "$nonFlakeDir"
98-
nix build -o "$TEST_ROOT/result" flake3#xyzzy flake3#fnord
98+
_NIX_TEST_BARF_ON_UNCACHEABLE='' nix build -o "$TEST_ROOT/result" flake3#xyzzy flake3#fnord
9999

100100
# Check non-flake inputs have a sourceInfo and an outPath
101101
#
102102
# This may look redundant, but the other checks below happen in a command
103103
# substitution subshell, so failures there will not exit this shell
104+
export _NIX_TEST_BARF_ON_UNCACHEABLE='' # FIXME
104105
nix eval --raw flake3#inputs.nonFlake.outPath
105106
nix eval --raw flake3#inputs.nonFlake.sourceInfo.outPath
106107
nix eval --raw flake3#inputs.nonFlakeFile.outPath

tests/functional/flakes/relative-paths-lockfile.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ source ./common.sh
44

55
requireGit
66

7+
unset _NIX_TEST_BARF_ON_UNCACHEABLE
8+
79
# Test a "vendored" subflake dependency. This is a relative path flake
810
# which doesn't reference the root flake and has its own lock file.
911
#

0 commit comments

Comments
 (0)