tests.buildenv: init test harness

Add an eval-time test harness for buildEnv following the pattern established by `tests.overriding`.
Uses `lib.runTests` to compare expr/expected pairs, and the buildCommand reports pass/fail.

No tests yet; subsequent commits add them individually.
This commit is contained in:
Philip Taron
2026-03-19 13:17:18 -07:00
parent fa78dd9141
commit d63fab02b0
2 changed files with 54 additions and 0 deletions
+52
View File
@@ -0,0 +1,52 @@
{
lib,
pkgs,
stdenvNoCC,
}:
let
inherit (pkgs) buildEnv;
testingThrow = expr: {
expr = (builtins.tryEval (builtins.seq expr "didn't throw"));
expected = {
success = false;
value = false;
};
};
tests = { };
in
stdenvNoCC.mkDerivation (finalAttrs: {
__structuredAttrs = true;
name = "test-buildenv";
passthru = {
inherit tests;
failures = lib.runTests finalAttrs.passthru.tests;
};
testResults = lib.mapAttrs (_: test: test.expr == test.expected) finalAttrs.passthru.tests;
buildCommand = ''
touch $out
for testName in "''${!testResults[@]}"; do
if [[ -n "''${testResults[$testName]}" ]]; then
echo "$testName success"
else
echo "$testName fail"
fi
done
''
+ lib.optionalString (lib.any (v: !v) (lib.attrValues finalAttrs.testResults)) ''
{
echo "ERROR: tests.buildenv: Encountering failed tests."
for testName in "''${!testResults[@]}"; do
if [[ -z "''${testResults[$testName]}" ]]; then
echo "- $testName"
fi
done
echo "To inspect the expected and actual result, "
echo ' evaluate `tests.buildenv.tests.''${testName}`.'
} >&2
exit 1
'';
})
+2
View File
@@ -183,6 +183,8 @@ in
nixosOptionsDoc = recurseIntoAttrs (callPackage ../../nixos/lib/make-options-doc/tests.nix { });
buildenv = callPackage ./buildenv.nix { };
overriding = callPackage ./overriding.nix { };
texlive = recurseIntoAttrs (callPackage ./texlive { });