fix pretty printing check function
This commit is contained in:
parent
cae83153c8
commit
5700d1e27c
1 changed files with 5 additions and 20 deletions
|
@ -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";
|
||||
|
||||
|
|
Loading…
Reference in a new issue