test watch, split commands
This commit is contained in:
parent
6b84ecb806
commit
d146127911
|
@ -15,11 +15,16 @@
|
|||
./test/it.test.nix
|
||||
./test/test.test.nix
|
||||
./test/describe.test.nix
|
||||
./test/watch.test.nix
|
||||
];
|
||||
packages.x86_64-linux.example = tix.run [
|
||||
./mytest.nix
|
||||
];
|
||||
packages.x86_64-linux.watch =
|
||||
tix.watch "nix run .#test --show-trace | ${pkgs.fx}/bin/fx" "fx";
|
||||
tix.watch {
|
||||
cmd = "nix run .#test --show-trace";
|
||||
view = "${pkgs.fx}/bin/fx";
|
||||
stop = "pkill fx";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
52
test/watch.test.nix
Normal file
52
test/watch.test.nix
Normal file
|
@ -0,0 +1,52 @@
|
|||
{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" ({
|
||||
actual = watch {
|
||||
cmd = "run me";
|
||||
};
|
||||
expected = ''
|
||||
while true
|
||||
do
|
||||
run me &
|
||||
inotify-tools/bin/inotifywait -e modify -r .
|
||||
|
||||
done
|
||||
'';
|
||||
}))
|
||||
(it "runs the command provided to stop execution" ({
|
||||
actual = watch {
|
||||
cmd = "run me";
|
||||
stop = "kill me";
|
||||
};
|
||||
expected = ''
|
||||
while true
|
||||
do
|
||||
run me &
|
||||
inotify-tools/bin/inotifywait -e modify -r .
|
||||
kill me
|
||||
done
|
||||
'';
|
||||
}))
|
||||
(it "pipes output to given command" ({
|
||||
actual = watch {
|
||||
cmd = "run me";
|
||||
stop = "kill me";
|
||||
view = "less";
|
||||
};
|
||||
expected = ''
|
||||
while true
|
||||
do
|
||||
run me | less &
|
||||
inotify-tools/bin/inotifywait -e modify -r .
|
||||
kill me
|
||||
done
|
||||
'';
|
||||
}))
|
||||
]
|
|
@ -1,9 +1,13 @@
|
|||
pkgs: cmd: pname:
|
||||
pkgs: {
|
||||
cmd,
|
||||
stop ? null,
|
||||
view ? null,
|
||||
}:
|
||||
pkgs.writeShellScriptBin "watch" ''
|
||||
while true
|
||||
do
|
||||
${cmd} &
|
||||
${cmd} ${if view == null then "" else "| ${view} "}&
|
||||
${pkgs.inotify-tools}/bin/inotifywait -e modify -r .
|
||||
pkill ${pname}
|
||||
${toString stop}
|
||||
done
|
||||
''
|
||||
|
|
Loading…
Reference in a new issue