initial version

This commit is contained in:
Robin Appelman 2025-10-25 15:23:20 +02:00
commit 1eceb2ce73
8 changed files with 428 additions and 0 deletions

27
nix-tests.nix Normal file
View file

@ -0,0 +1,27 @@
pkgs: tests: let
formatValue = val:
if (builtins.isList val || builtins.isAttrs val)
then builtins.toJSON val
else builtins.toString val;
resultToString = {
name,
expected,
result,
}: ''
${name} failed: expected ${formatValue expected}, but got ${
formatValue result
}
'';
results = pkgs.lib.runTests (tests pkgs);
in
if results != []
then builtins.throw (builtins.concatStringsSep "\n" (map resultToString results))
## TODO: The derivation below is preferable but "nix flake check" hangs with it:
## (it's preferable because "examples/many-failures" would then show all errors.)
# pkgs.runCommand "nix-flake-tests-failure" { } ''
# cat <<EOF
# ${builtins.concatStringsSep "\n" (map resultToString results)}
# EOF
# exit 1
# ''
else pkgs.runCommand "nix-flake-tests-success" {} "echo > $out"