flakelight-php/nix-tests.nix
2025-10-25 18:27:45 +02:00

27 lines
876 B
Nix

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"