diff --git a/flake.nix b/flake.nix index a279bde..20042b1 100644 --- a/flake.nix +++ b/flake.nix @@ -20,11 +20,10 @@ packages.x86_64-linux.example = tix.run [ ./mytest.nix ]; - packages.x86_64-linux.watch = - tix.watch { - cmd = "nix run .#test --show-trace"; - view = "${pkgs.fx}/bin/fx"; - stop = "pkill fx"; - }; + packages.x86_64-linux.watch = tix.watch { + cmd = "nix run .#test --show-trace"; + view = "${pkgs.fx}/bin/fx"; + stop = "pkill fx"; + }; }; } diff --git a/test/run.test.nix b/test/run.test.nix deleted file mode 100644 index ed03dea..0000000 --- a/test/run.test.nix +++ /dev/null @@ -1,10 +0,0 @@ -{it, ...}: let - pkgs = import {}; # impure ¯\_(ツ)_/¯ - run = import ../tix/run.nix pkgs; - output = run [./it.test.nix]; -in [ - (it "makes a derivation called test" { - expected = "test"; - actual = output.name; - }) -] diff --git a/test/watch.test.nix b/test/watch.test.nix index 600c94f..1175cc5 100644 --- a/test/watch.test.nix +++ b/test/watch.test.nix @@ -1,52 +1,55 @@ -{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" ({ - 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 - ''; - })) -] + 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 + ''; + }) + ] diff --git a/tix/eval.nix b/tix/eval.nix new file mode 100644 index 0000000..d73c963 --- /dev/null +++ b/tix/eval.nix @@ -0,0 +1,2 @@ +resFile: +builtins.fromJSON (builtins.unsafeDiscardStringContext (builtins.readFile resFile)) diff --git a/tix/filters.nix b/tix/filters.nix new file mode 100644 index 0000000..cdc95e8 --- /dev/null +++ b/tix/filters.nix @@ -0,0 +1,10 @@ +{ + overview = '' + .[] | { + (.path): { + "❌": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}], + "✔️": .results | map(select(.success) | .msg) | length + } + } + ''; +} diff --git a/tix/run.nix b/tix/run.nix index 57b99a2..fc291df 100644 --- a/tix/run.nix +++ b/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 '') diff --git a/tix/watch.nix b/tix/watch.nix index 46b29d9..6c701f6 100644 --- a/tix/watch.nix +++ b/tix/watch.nix @@ -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