add test help text

This commit is contained in:
tristan 2024-12-08 21:27:18 +00:00
parent bfa12db1db
commit cf125cc808
6 changed files with 64 additions and 49 deletions

View file

@ -1,4 +1,4 @@
{
pass = "";
fail = "";
pass = "";
fail = "";
}

View file

@ -8,9 +8,7 @@ in rec {
(.msg): select(.success == false) | {expected, actual, success}
}] | add
}] | add
}] | add
'';
}] | add'';
overview = ''
.
'';
.'';
}

View file

@ -1,22 +1,38 @@
pkgs: suite: let
test = import ./test.nix;
res = builtins.listToAttrs (map test suite);
res = builtins.listToAttrs (pkgs.lib.imap0 (
i: t: let
name =
if builtins.typeOf t == "path"
then builtins.baseNameOf t
else "test suite ${toString i} (anonymous)";
in {
inherit name;
value = test t;
}
)
suite);
resFile = builtins.toFile "results" (builtins.toJSON res);
filters = import ./filters.nix;
getNix = "import ${./eval.nix} ${resFile}";
extractNix = "nix eval --impure --quiet --expr 'let r = ${getNix}; in builtins.trace r r'";
nixRepl = "nix repl --expr '{ r = ${getNix}; }'";
opts = {
nix-raw = "nix eval --impure --quiet --expr '${getNix}'";
nix-repl = "nix repl --expr '{ r = ${getNix}; }'";
file = "echo '${resFile}'";
json-raw = "cat '${resFile}'";
json = "${pkgs.jq}/bin/jq '.' '${resFile}'";
explore = "${pkgs.fx}/bin/fx '${resFile}'";
nix = "${opts.nix-raw} | ${pkgs.alejandra}/bin/alejandra -q";
overview = "${pkgs.jq}/bin/jq '${filters.overview}' '${resFile}'";
};
in (pkgs.writeShellScriptBin "test" ''
t=''${1:-overview}
t=''${1:-json}
case "$t" in
"file") echo '${resFile}' ;;
"raw") cat '${resFile}' ;;
"json") ${pkgs.jq}/bin/jq '.' '${resFile}' ;;
"explore") ${pkgs.fx}/bin/fx '${resFile}' ;;
"nix") ${extractNix} | ${pkgs.alejandra}/bin/alejandra -q ;;
"nixrepl") ${nixRepl} ;;
"nixraw") ${extractNix} ;;
"overview") ${pkgs.jq}/bin/jq '${filters.overview}' '${resFile}' ;;
*) echo format "$t" not recognised! ;;
${pkgs.lib.pipe opts [
(builtins.mapAttrs (name: cmd: ''"${name}") ${cmd}''))
(builtins.attrValues)
(builtins.concatStringsSep " ;;\n ")
]};;
*) echo options: ${builtins.concatStringsSep ", " (builtins.attrNames opts)} ;;
esac
'')

View file

@ -1,17 +1,12 @@
path: let
it = import ./it.nix;
describe = import ./describe.nix;
suite = if builtins.typeOf path == "path" then import path
suite =
if builtins.typeOf path == "path"
then import path
else path;
name = if builtins.typeOf path == "path" then builtins.baseNameOf path
else "anonymous";
in
builtins.trace "tix: ${name}"
(
if !builtins.isFunction suite
then throw "A test suite should be in the form { it }: [ <tests> ]."
else {
inherit name;
value = builtins.listToAttrs (suite {inherit it describe;});
}
)
in (
if !builtins.isFunction suite
then throw "A test suite should be in the form { it, describe }: [ <tests> ]."
else builtins.listToAttrs (suite {inherit it describe;})
)