diff --git a/flake.nix b/flake.nix index 554d259..1dcc622 100644 --- a/flake.nix +++ b/flake.nix @@ -7,10 +7,17 @@ }: let system = "x86_64-linux"; pkgs = import nixpkgs {inherit system;}; - tix = import ./testing/. {inherit pkgs;}; + tix = import ./tix/. {inherit pkgs;}; in - tix - // { - packages.x86_64-linux.test = tix.run [./mytest.nix]; + tix // { + packages.x86_64-linux.test = tix.run [ + ./test/it.test.nix + ./test/test.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"; }; } diff --git a/result b/result new file mode 120000 index 0000000..209b32f --- /dev/null +++ b/result @@ -0,0 +1 @@ +/nix/store/xzz6wx11f5qsc34n1fw68cc6ba38wqrl-test \ No newline at end of file diff --git a/test/bad/string.nix b/test/bad/string.nix new file mode 100644 index 0000000..682935d --- /dev/null +++ b/test/bad/string.nix @@ -0,0 +1 @@ +"This isn't a test suite!" diff --git a/test/it.test.nix b/test/it.test.nix new file mode 100644 index 0000000..82c4e98 --- /dev/null +++ b/test/it.test.nix @@ -0,0 +1,11 @@ +{ it, ... }: +[ + (it "test's itself???" rec { + expected = {success = true; msg = "test's itself???";}; + actual = + (it "test's itself???" { + expected = expected; + actual = expected; + }); + }) +] diff --git a/test/run.test.nix b/test/run.test.nix new file mode 100644 index 0000000..ea49311 --- /dev/null +++ b/test/run.test.nix @@ -0,0 +1,12 @@ +{ 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/test.test.nix b/test/test.test.nix new file mode 100644 index 0000000..f792a7a --- /dev/null +++ b/test/test.test.nix @@ -0,0 +1,18 @@ +{ it, ... }: +let + test = import ../tix/test.nix; +in +[ + (it "get's test results" { + expected = [{"msg" = "test's itself???"; "success"= true;}]; + actual = ( test ./it.test.nix ).results; + }) + (it "has a path" { + actual = builtins.typeOf ( test ./it.test.nix ).path; + expected = "path"; + }) + (it "fails to build non test" { + actual = ( test ./bad/string.nix ); + throws = true; + }) +] diff --git a/testing/import.nix b/testing/import.nix deleted file mode 100644 index d59f086..0000000 --- a/testing/import.nix +++ /dev/null @@ -1,7 +0,0 @@ -path: let - it = import ./it.nix; -in - builtins.trace ("testing " + builtins.baseNameOf path) { - inherit path; - results = import path {inherit it;}; - } diff --git a/testing/default.nix b/tix/default.nix similarity index 79% rename from testing/default.nix rename to tix/default.nix index e0c1e05..9436ea1 100644 --- a/testing/default.nix +++ b/tix/default.nix @@ -1,6 +1,6 @@ {pkgs ? import {}}: { run = import ./run.nix pkgs; it = import ./it.nix; - import = import ./import.nix; + test = import ./test.nix; watch = import ./watch.nix pkgs; } diff --git a/testing/it.nix b/tix/it.nix similarity index 100% rename from testing/it.nix rename to tix/it.nix diff --git a/testing/run.nix b/tix/run.nix similarity index 58% rename from testing/run.nix rename to tix/run.nix index 7399a8d..57b99a2 100644 --- a/testing/run.nix +++ b/tix/run.nix @@ -1,12 +1,12 @@ pkgs: files: let - test = import ./import.nix; + test = import ./test.nix; res = map test files; resFile = builtins.toFile "results" (builtins.toJSON res); filter = '' .[] | { (.path): { - failures: [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}], - success: .results | map(select(.success) | .msg) | length + "❌": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}], + "✔️": .results | map(select(.success) | .msg) | length } } ''; diff --git a/tix/test.nix b/tix/test.nix new file mode 100644 index 0000000..8a2897b --- /dev/null +++ b/tix/test.nix @@ -0,0 +1,14 @@ +path: let + it = import ./it.nix; + suite = import path; +in + builtins.trace ("testing " + builtins.baseNameOf path) + ( + if !builtins.isFunction suite + then throw "A test suite should be in the form { it }: [ ]." + else + { + inherit path; + results = suite {inherit it;}; + } + ) diff --git a/testing/watch.nix b/tix/watch.nix similarity index 61% rename from testing/watch.nix rename to tix/watch.nix index 3144fcd..f9d797e 100644 --- a/testing/watch.nix +++ b/tix/watch.nix @@ -3,7 +3,7 @@ pkgs.writeShellScriptBin "watch" '' while true do ${cmd} & - ${pkgs.inotify-tools}/bin/inotifywait -e modify -r . --exclude .git + ${pkgs.inotify-tools}/bin/inotifywait -e modify -r . pkill ${pname} done ''