chore: add more helpers & add pos to test suite

This commit is contained in:
technofab 2025-06-13 20:47:26 +02:00
parent 3f1b6317b4
commit 4a55db9797
No known key found for this signature in database
2 changed files with 82 additions and 76 deletions

View file

@ -2,4 +2,6 @@
path = pkgs: "export PATH=${lib.makeBinPath pkgs}"; path = pkgs: "export PATH=${lib.makeBinPath pkgs}";
pathAdd = pkgs: "export PATH=$PATH:${lib.makeBinPath pkgs}"; pathAdd = pkgs: "export PATH=$PATH:${lib.makeBinPath pkgs}";
scriptHelpers = builtins.readFile ./scriptHelpers.sh; scriptHelpers = builtins.readFile ./scriptHelpers.sh;
toJsonFile = any: builtins.toFile "actual" (builtins.toJSON any);
toPrettyFile = any: builtins.toFile "actual" (lib.generators.toPretty {} any);
} }

View file

@ -1,24 +1,25 @@
{ {
lib,
pkgs, pkgs,
ntlib, ntlib,
... ...
}: { }: {
suites."Lib Tests".tests = [ suites."Lib Tests" = {
pos = __curPos;
tests = [
{ {
name = "autodiscovery"; name = "autodiscovery";
type = "script"; type = "script";
script = let script = let
actual = builtins.toFile "actual" (builtins.toJSON (ntlib.autodiscover { actual = ntlib.helpers.toPrettyFile (ntlib.autodiscover {
dir = ./fixtures; dir = ./fixtures;
})); });
in in
# sh # sh
'' ''
${ntlib.helpers.path [pkgs.gnugrep]} ${ntlib.helpers.path [pkgs.gnugrep]}
${ntlib.helpers.scriptHelpers} ${ntlib.helpers.scriptHelpers}
assert_file_contains ${actual} "sample_test.nix" "should find sample_test.nix" assert_file_contains ${actual} "sample_test.nix" "should find sample_test.nix"
assert_file_contains ${actual} "\"base\":\"/nix/store/.*-source/tests/fixtures" "should set base to fixtures dir" assert_file_contains ${actual} "base = \"/nix/store/.*-source/tests/fixtures/\"" "should set base to fixtures dir"
''; '';
} }
{ {
@ -66,11 +67,13 @@
${ntlib.helpers.scriptHelpers} ${ntlib.helpers.scriptHelpers}
TMPDIR=$(tmpdir) TMPDIR=$(tmpdir)
# start without nix & env binaries to expect errors
run "${binary} --pure --junit=$TMPDIR/junit.xml" run "${binary} --pure --junit=$TMPDIR/junit.xml"
assert "$exit_code -eq 2" "should exit 2" assert "$exit_code -eq 2" "should exit 2"
assert "-f $TMPDIR/junit.xml" "should create junit.xml" assert "-f $TMPDIR/junit.xml" "should create junit.xml"
assert_contains "$output" "executable file not found" "nix should not be found in pure mode" assert_contains "$output" "executable file not found" "nix should not be found in pure mode"
# now add required deps
${ntlib.helpers.pathAdd [pkgs.nix pkgs.coreutils]} ${ntlib.helpers.pathAdd [pkgs.nix pkgs.coreutils]}
run "${binary} --pure --junit=$TMPDIR/junit2.xml" run "${binary} --pure --junit=$TMPDIR/junit2.xml"
assert "$exit_code -eq 2" "should exit 2" assert "$exit_code -eq 2" "should exit 2"
@ -83,4 +86,5 @@
''; '';
} }
]; ];
};
} }