Add outPath short-circuiting tests
This commit is contained in:
parent
7a023a99ca
commit
dc93a4d278
2 changed files with 28 additions and 6 deletions
|
|
@ -1,4 +1,4 @@
|
|||
{ pkgs ? import <nixpkgs> {} }:
|
||||
{ pkgs ? import <nixpkgs> {}, lib ? pkgs.lib }:
|
||||
|
||||
let
|
||||
testdata = import ./testdata.nix { inherit pkgs; };
|
||||
|
|
@ -22,13 +22,31 @@ in
|
|||
subdir-9 = runner.makeTest { name = "subdir-9"; rootDir = testdata.sourceUnfiltered + "/test-tree"; subpath = "9-expected"; };
|
||||
subdir-10 = runner.makeTest { name = "subdir-10"; rootDir = testdata.sourceUnfiltered + "/test-tree"; subpath = "10-subdir-ignoring-itself"; };
|
||||
|
||||
# Make sure the files aren't added to the store before filtering.
|
||||
shortcircuit = runner.makeTest {
|
||||
name = "nested";
|
||||
rootDir = testdata.sourceUnfilteredRecursive + "/test-tree";
|
||||
preCheck = ''
|
||||
# Instead of a file, create a fifo so that the filter would error out if it tries to add it to the store.
|
||||
rm 1-simpl/1
|
||||
mkfifo 1-simpl/1
|
||||
'';
|
||||
};
|
||||
|
||||
unit-tests =
|
||||
let gitignoreNix = import ../default.nix { inherit (pkgs) lib; };
|
||||
inherit (gitignoreNix) gitignoreFilterWith;
|
||||
inherit (gitignoreNix) gitignoreFilterWith gitignoreSourceWith;
|
||||
example = gitignoreFilterWith { basePath = ./.; extraRules = ''
|
||||
*.foo
|
||||
!*.bar
|
||||
''; };
|
||||
shortcircuit = gitignoreSourceWith {
|
||||
path = {
|
||||
inherit (lib.cleanSource ./.) _isLibCleanSourceWith filter name;
|
||||
outPath = throw "do not use outPath";
|
||||
origSrc = ./.;
|
||||
};
|
||||
};
|
||||
in
|
||||
|
||||
# Test that extraRules works:
|
||||
|
|
@ -36,6 +54,9 @@ in
|
|||
assert example ./x.bar "regular" == true;
|
||||
assert example ./x.qux "regular" == true;
|
||||
|
||||
# Make sure outPath is not used. (It's not about the store path)
|
||||
assert lib.hasPrefix builtins.storeDir "${shortcircuit}";
|
||||
|
||||
# End of test. (a drv to show a buildable attr when successful)
|
||||
pkgs.emptyFile or null;
|
||||
}
|
||||
|
|
@ -24,11 +24,11 @@ let
|
|||
discover rootDir by itself.
|
||||
|
||||
*/
|
||||
makeTest = {name ? "source", rootDir, subpath ? ""}:
|
||||
makeTest = {name ? "source", rootDir, subpath ? "", preCheck ? ""}:
|
||||
pkgs.runCommand "test-${name}" {
|
||||
inherit name;
|
||||
viaGit = listingViaGit { inherit name rootDir subpath; };
|
||||
viaNix = listingViaNixGitignore { inherit name rootDir subpath; };
|
||||
viaNix = listingViaNixGitignore { inherit name rootDir subpath preCheck; };
|
||||
} ''
|
||||
if diff $viaNix $viaGit; then
|
||||
touch $out
|
||||
|
|
@ -64,7 +64,7 @@ let
|
|||
installPhase = ":";
|
||||
};
|
||||
|
||||
listingViaNixGitignore = {name ? "source", rootDir, subpath}:
|
||||
listingViaNixGitignore = {name ? "source", rootDir, subpath, preCheck}:
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "${name}-listing-via-nix";
|
||||
src = rootDir;
|
||||
|
|
@ -79,6 +79,7 @@ let
|
|||
export NIX_LOG_DIR=$TMPDIR
|
||||
export NIX_STATE_DIR=$TMPDIR
|
||||
test -n "$subpath" && cd $subpath
|
||||
${preCheck}
|
||||
nix-instantiate --eval --expr --json \
|
||||
--readonly-mode --option sandbox false \
|
||||
'(import ${gitignoreSource ../.}/tests/runner.nix {}).toStringNixGitignore ./.' \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue