From dc93a4d2782b4f73b04bb18641d9f29feb8913da Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Fri, 23 Feb 2024 11:27:18 +0100 Subject: [PATCH] Add outPath short-circuiting tests --- tests/default.nix | 27 ++++++++++++++++++++++++--- tests/runner.nix | 7 ++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/tests/default.nix b/tests/default.nix index a02acfa..18844be 100644 --- a/tests/default.nix +++ b/tests/default.nix @@ -1,4 +1,4 @@ -{ pkgs ? import {} }: +{ pkgs ? import {}, 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; -} \ No newline at end of file +} diff --git a/tests/runner.nix b/tests/runner.nix index cca3d89..dac3a99 100644 --- a/tests/runner.nix +++ b/tests/runner.nix @@ -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 ./.' \