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.
|
# with a nicer diff display function.
|
||||||
check = { pkgs, tests }:
|
check = { pkgs, tests }:
|
||||||
let
|
let
|
||||||
system = pkgs.stdenv.targetPlatform.system;
|
|
||||||
formatValue = val:
|
formatValue = val:
|
||||||
if (builtins.isList val || builtins.isAttrs val) then builtins.toJSON val
|
if (builtins.isList val || builtins.isAttrs val) then builtins.toJSON val
|
||||||
else builtins.toString val;
|
else builtins.toString val;
|
||||||
|
|
||||||
resultToString = { name, expected, result }:
|
resultToString = { name, expected, result }:
|
||||||
pkgs.callPackage (pkgs.runCommand "nix-flake-tests-error" {
|
builtins.readFile (pkgs.runCommand "nix-flake-tests-error" {
|
||||||
expected = formatValue expected;
|
expected = formatValue expected;
|
||||||
result = formatValue result;
|
result = formatValue result;
|
||||||
passAsFile = [ "expected" "result" ];
|
passAsFile = [ "expected" "result" ];
|
||||||
} ''
|
} ''
|
||||||
echo "${name} failed (- expected, + result)"
|
echo "${name} failed (- expected, + result)" > $out
|
||||||
cp ''${expectedPath} ''${expectedPath}.json
|
cp ''${expectedPath} ''${expectedPath}.json
|
||||||
cp ''${resultPath} ''${resultPath}.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;
|
results = pkgs.lib.runTests tests;
|
||||||
in
|
in
|
||||||
if results != [ ] then
|
if results != [ ] then
|
||||||
builtins.throw (builtins.concatStringsSep "\n" (map resultToString results))
|
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
|
else
|
||||||
pkgs.runCommand "nix-flake-tests-success" { } "echo > $out";
|
pkgs.runCommand "nix-flake-tests-success" { } "echo > $out";
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue