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:
@@ -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
|
||||
'';
|
||||
})
|
||||
@@ -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 { });
|
||||
|
||||
Reference in New Issue
Block a user