test output options
This commit is contained in:
parent
d146127911
commit
4f6c21ec77
|
@ -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";
|
||||
|
|
|
@ -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,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
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;
|
||||
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
|
||||
'')
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue