From 5700d1e27ce7613435169740c2cf6e0eee009b07 Mon Sep 17 00:00:00 2001 From: ibizaman Date: Wed, 29 May 2024 14:17:01 -0700 Subject: [PATCH] fix pretty printing check function --- lib/default.nix | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/lib/default.nix b/lib/default.nix index de48d55..dde07f6 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -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 < $out";