add test help text
This commit is contained in:
parent
bfa12db1db
commit
cf125cc808
27
flake.nix
27
flake.nix
|
@ -18,9 +18,22 @@
|
|||
./test/test.test.nix
|
||||
./test/describe.test.nix
|
||||
./test/watch.test.nix
|
||||
({describe, it, ...}: [(describe "suite" [
|
||||
(it "runs this test" {actual = true; expected = true;})
|
||||
])])
|
||||
({
|
||||
describe,
|
||||
it,
|
||||
...
|
||||
}: [
|
||||
(describe "suite" [
|
||||
(it "runs this test" {
|
||||
actual = true;
|
||||
expected = true;
|
||||
})
|
||||
])
|
||||
(it "runs another test" {
|
||||
actual = true;
|
||||
expected = true;
|
||||
})
|
||||
])
|
||||
];
|
||||
|
||||
packages.x86_64-linux.example = tix.run [
|
||||
|
@ -28,13 +41,15 @@
|
|||
];
|
||||
|
||||
packages.x86_64-linux.watchpipe = tix.watch {
|
||||
cmd = "nix run --show-trace .#test file";
|
||||
cmd = "nix run --show-trace .#test -- file";
|
||||
view = "tee -a /tmp/tix-output";
|
||||
};
|
||||
|
||||
packages.x86_64-linux.watch = tix.watch {
|
||||
cmd = "nix run --show-trace .#test $2";
|
||||
view = "cat";
|
||||
cmd = "nix run --show-trace .#test -- $2";
|
||||
view = ''
|
||||
${pkgs.lib.getExe pkgs.bat} \
|
||||
--paging=never --language=''${2:-json} --file-name="test results"'';
|
||||
};
|
||||
|
||||
packages.x86_64-linux.results = pkgs.writeShellScriptBin "results" ''
|
||||
|
|
|
@ -7,16 +7,7 @@
|
|||
in [
|
||||
(describe "the test function" [
|
||||
(it "get's test results" {
|
||||
expected = {
|
||||
name = builtins.baseNameOf ./example.test.nix;
|
||||
value = {
|
||||
"an example" = {
|
||||
succeeds = {
|
||||
success = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
expected."an example".succeeds.success = true;
|
||||
actual = test ./example.test.nix;
|
||||
})
|
||||
(it "fails to build non test" {
|
||||
|
@ -25,7 +16,7 @@ in [
|
|||
})
|
||||
(it "tests suite that is not a file" {
|
||||
actual = test ({...}: []);
|
||||
expected = {name = "anonymous"; value = {};};
|
||||
expected = {};
|
||||
})
|
||||
])
|
||||
]
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
pass = "✔️";
|
||||
fail = "❌";
|
||||
pass = "✅";
|
||||
fail = "❎";
|
||||
}
|
||||
|
|
|
@ -8,9 +8,7 @@ in rec {
|
|||
(.msg): select(.success == false) | {expected, actual, success}
|
||||
}] | add
|
||||
}] | add
|
||||
}] | add
|
||||
'';
|
||||
}] | add'';
|
||||
overview = ''
|
||||
.
|
||||
'';
|
||||
.'';
|
||||
}
|
||||
|
|
42
tix/run.nix
42
tix/run.nix
|
@ -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
|
||||
'')
|
||||
|
|
19
tix/test.nix
19
tix/test.nix
|
@ -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}"
|
||||
(
|
||||
in (
|
||||
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;});
|
||||
}
|
||||
)
|
||||
then throw "A test suite should be in the form { it, describe }: [ <tests> ]."
|
||||
else builtins.listToAttrs (suite {inherit it describe;})
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue