test output options

This commit is contained in:
Tristan 2024-01-03 03:07:39 +00:00
parent d146127911
commit 4f6c21ec77
7 changed files with 84 additions and 72 deletions

View file

@ -20,8 +20,7 @@
packages.x86_64-linux.example = tix.run [
./mytest.nix
];
packages.x86_64-linux.watch =
tix.watch {
packages.x86_64-linux.watch = tix.watch {
cmd = "nix run .#test --show-trace";
view = "${pkgs.fx}/bin/fx";
stop = "pkill fx";

View file

@ -1,10 +0,0 @@
{it, ...}: let
pkgs = import <nixpkgs> {}; # impure ¯\_(ツ)_/¯
run = import ../tix/run.nix pkgs;
output = run [./it.test.nix];
in [
(it "makes a derivation called test" {
expected = "test";
actual = output.name;
})
]

View file

@ -1,13 +1,16 @@
{describe, it, ... }:
let
{
describe,
it,
...
}: let
mockpkgs = {
writeShellScriptBin = name: content: content;
inotify-tools = "inotify-tools";
};
watch = import ../tix/watch.nix mockpkgs;
in
describe "watch" [
(it "watches a the local directory and runs command on change" ({
describe "watch" [
(it "watches a the local directory and runs command on change" {
actual = watch {
cmd = "run me";
};
@ -16,11 +19,11 @@ describe "watch" [
do
run me &
inotify-tools/bin/inotifywait -e modify -r .
${""}
done
'';
}))
(it "runs the command provided to stop execution" ({
})
(it "runs the command provided to stop execution" {
actual = watch {
cmd = "run me";
stop = "kill me";
@ -33,8 +36,8 @@ describe "watch" [
kill me
done
'';
}))
(it "pipes output to given command" ({
})
(it "pipes output to given command" {
actual = watch {
cmd = "run me";
stop = "kill me";
@ -48,5 +51,5 @@ describe "watch" [
kill me
done
'';
}))
]
})
]

2
tix/eval.nix Normal file
View file

@ -0,0 +1,2 @@
resFile:
builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile resFile))

10
tix/filters.nix Normal file
View file

@ -0,0 +1,10 @@
{
overview = ''
.[] | {
(.path): {
"": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}],
"": .results | map(select(.success) | .msg) | length
}
}
'';
}

View file

@ -2,14 +2,18 @@ pkgs: files: let
test = import ./test.nix;
res = map test files;
resFile = builtins.toFile "results" (builtins.toJSON res);
filter = ''
.[] | {
(.path): {
"": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}],
"": .results | map(select(.success) | .msg) | length
}
}
'';
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}; }'";
in (pkgs.writeShellScriptBin "test" ''
cat '${resFile}' | ${pkgs.jq}/bin/jq '${filter}'
t=$1
case "$t" in
"raw") cat '${resFile}' ;;
"json") jq '.' '${resFile}' ;;
"nix") ${extractNix} | ${pkgs.alejandra}/bin/alejandra -q ;;
"nixrepl") ${nixRepl} ;;
"nixraw") ${extractNix} ;;
*) ${pkgs.jq}/bin/jq '${filters.overview}' '${resFile}' ;;
esac
'')

View file

@ -6,7 +6,11 @@ pkgs: {
pkgs.writeShellScriptBin "watch" ''
while true
do
${cmd} ${if view == null then "" else "| ${view} "}&
${cmd} ${
if view == null
then ""
else "| ${view} "
}&
${pkgs.inotify-tools}/bin/inotifywait -e modify -r .
${toString stop}
done