tix/tix/run.nix
2024-12-08 21:27:18 +00:00

38 lines
1.2 KiB
Nix

pkgs: suite: let
test = import ./test.nix;
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}";
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:-json}
case "$t" in
${pkgs.lib.pipe opts [
(builtins.mapAttrs (name: cmd: ''"${name}") ${cmd}''))
(builtins.attrValues)
(builtins.concatStringsSep " ;;\n ")
]};;
*) echo options: ${builtins.concatStringsSep ", " (builtins.attrNames opts)} ;;
esac
'')