1
0
Fork 0

fix pretty printing check function

This commit is contained in:
ibizaman 2024-05-29 14:17:01 -07:00 committed by Pierre Penninckx
parent cae83153c8
commit 5700d1e27c

View file

@ -209,41 +209,26 @@ rec {
# with a nicer diff display function.
check = { pkgs, tests }:
let
system = pkgs.stdenv.targetPlatform.system;
formatValue = val:
if (builtins.isList val || builtins.isAttrs val) then builtins.toJSON val
else builtins.toString val;
resultToString = { name, expected, result }:
pkgs.callPackage (pkgs.runCommand "nix-flake-tests-error" {
builtins.readFile (pkgs.runCommand "nix-flake-tests-error" {
expected = formatValue expected;
result = formatValue result;
passAsFile = [ "expected" "result" ];
} ''
echo "${name} failed (- expected, + result)"
echo "${name} failed (- expected, + result)" > $out
cp ''${expectedPath} ''${expectedPath}.json
cp ''${resultPath} ''${resultPath}.json
${pkgs.deepdiff}/bin/deep diff ''${expectedPath}.json ''${resultPath}.json
'') {};
${pkgs.deepdiff}/bin/deep diff ''${expectedPath}.json ''${resultPath}.json >> $out
'');
# ''
# ${name} failed: expected ${formatValue expected}, but got ${
# formatValue result
# }
# '';
results = pkgs.lib.runTests tests;
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";