test output options
This commit is contained in:
parent
d146127911
commit
4f6c21ec77
|
@ -20,8 +20,7 @@
|
||||||
packages.x86_64-linux.example = tix.run [
|
packages.x86_64-linux.example = tix.run [
|
||||||
./mytest.nix
|
./mytest.nix
|
||||||
];
|
];
|
||||||
packages.x86_64-linux.watch =
|
packages.x86_64-linux.watch = tix.watch {
|
||||||
tix.watch {
|
|
||||||
cmd = "nix run .#test --show-trace";
|
cmd = "nix run .#test --show-trace";
|
||||||
view = "${pkgs.fx}/bin/fx";
|
view = "${pkgs.fx}/bin/fx";
|
||||||
stop = "pkill fx";
|
stop = "pkill fx";
|
||||||
|
|
|
@ -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;
|
|
||||||
})
|
|
||||||
]
|
|
|
@ -1,5 +1,8 @@
|
||||||
{describe, it, ... }:
|
{
|
||||||
let
|
describe,
|
||||||
|
it,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
mockpkgs = {
|
mockpkgs = {
|
||||||
writeShellScriptBin = name: content: content;
|
writeShellScriptBin = name: content: content;
|
||||||
inotify-tools = "inotify-tools";
|
inotify-tools = "inotify-tools";
|
||||||
|
@ -7,7 +10,7 @@ let
|
||||||
watch = import ../tix/watch.nix mockpkgs;
|
watch = import ../tix/watch.nix mockpkgs;
|
||||||
in
|
in
|
||||||
describe "watch" [
|
describe "watch" [
|
||||||
(it "watches a the local directory and runs command on change" ({
|
(it "watches a the local directory and runs command on change" {
|
||||||
actual = watch {
|
actual = watch {
|
||||||
cmd = "run me";
|
cmd = "run me";
|
||||||
};
|
};
|
||||||
|
@ -16,11 +19,11 @@ describe "watch" [
|
||||||
do
|
do
|
||||||
run me &
|
run me &
|
||||||
inotify-tools/bin/inotifywait -e modify -r .
|
inotify-tools/bin/inotifywait -e modify -r .
|
||||||
|
${""}
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
}))
|
})
|
||||||
(it "runs the command provided to stop execution" ({
|
(it "runs the command provided to stop execution" {
|
||||||
actual = watch {
|
actual = watch {
|
||||||
cmd = "run me";
|
cmd = "run me";
|
||||||
stop = "kill me";
|
stop = "kill me";
|
||||||
|
@ -33,8 +36,8 @@ describe "watch" [
|
||||||
kill me
|
kill me
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
}))
|
})
|
||||||
(it "pipes output to given command" ({
|
(it "pipes output to given command" {
|
||||||
actual = watch {
|
actual = watch {
|
||||||
cmd = "run me";
|
cmd = "run me";
|
||||||
stop = "kill me";
|
stop = "kill me";
|
||||||
|
@ -48,5 +51,5 @@ describe "watch" [
|
||||||
kill me
|
kill me
|
||||||
done
|
done
|
||||||
'';
|
'';
|
||||||
}))
|
})
|
||||||
]
|
]
|
||||||
|
|
2
tix/eval.nix
Normal file
2
tix/eval.nix
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
resFile:
|
||||||
|
builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile resFile))
|
10
tix/filters.nix
Normal file
10
tix/filters.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
overview = ''
|
||||||
|
.[] | {
|
||||||
|
(.path): {
|
||||||
|
"❌": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}],
|
||||||
|
"✔️": .results | map(select(.success) | .msg) | length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
}
|
22
tix/run.nix
22
tix/run.nix
|
@ -2,14 +2,18 @@ pkgs: files: let
|
||||||
test = import ./test.nix;
|
test = import ./test.nix;
|
||||||
res = map test files;
|
res = map test files;
|
||||||
resFile = builtins.toFile "results" (builtins.toJSON res);
|
resFile = builtins.toFile "results" (builtins.toJSON res);
|
||||||
filter = ''
|
filters = import ./filters.nix;
|
||||||
.[] | {
|
getNix = "import ${./eval.nix} ${resFile}";
|
||||||
(.path): {
|
extractNix = "nix eval --impure --quiet --expr 'let r = ${getNix}; in builtins.trace r r'";
|
||||||
"❌": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}],
|
nixRepl = "nix repl --expr '{ r = ${getNix}; }'";
|
||||||
"✔️": .results | map(select(.success) | .msg) | length
|
|
||||||
}
|
|
||||||
}
|
|
||||||
'';
|
|
||||||
in (pkgs.writeShellScriptBin "test" ''
|
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
|
||||||
'')
|
'')
|
||||||
|
|
|
@ -6,7 +6,11 @@ pkgs: {
|
||||||
pkgs.writeShellScriptBin "watch" ''
|
pkgs.writeShellScriptBin "watch" ''
|
||||||
while true
|
while true
|
||||||
do
|
do
|
||||||
${cmd} ${if view == null then "" else "| ${view} "}&
|
${cmd} ${
|
||||||
|
if view == null
|
||||||
|
then ""
|
||||||
|
else "| ${view} "
|
||||||
|
}&
|
||||||
${pkgs.inotify-tools}/bin/inotifywait -e modify -r .
|
${pkgs.inotify-tools}/bin/inotifywait -e modify -r .
|
||||||
${toString stop}
|
${toString stop}
|
||||||
done
|
done
|
||||||
|
|
Loading…
Reference in a new issue