diff --git a/flake.nix b/flake.nix index 5af2f2a..fae18e3 100644 --- a/flake.nix +++ b/flake.nix @@ -18,6 +18,9 @@ ./test/test.test.nix ./test/describe.test.nix ./test/watch.test.nix + ({describe, it, ...}: [(describe "suite" [ + (it "runs this test" {actual = true; expected = true;}) + ])]) ]; packages.x86_64-linux.example = tix.run [ diff --git a/test/test.test.nix b/test/test.test.nix index 0cfc993..5509fd0 100644 --- a/test/test.test.nix +++ b/test/test.test.nix @@ -8,7 +8,7 @@ in [ (describe "the test function" [ (it "get's test results" { expected = { - name = toString ./example.test.nix; + name = builtins.baseNameOf ./example.test.nix; value = { "an example" = { succeeds = { @@ -23,5 +23,9 @@ in [ actual = test ./bad/string.nix; throws = true; }) + (it "tests suite that is not a file" { + actual = test ({...}: []); + expected = {name = "anonymous"; value = {};}; + }) ]) ] diff --git a/tix/run.nix b/tix/run.nix index d16f6f0..9068f19 100644 --- a/tix/run.nix +++ b/tix/run.nix @@ -1,6 +1,6 @@ -pkgs: files: let +pkgs: suite: let test = import ./test.nix; - res = builtins.listToAttrs (map test files); + res = builtins.listToAttrs (map test suite); resFile = builtins.toFile "results" (builtins.toJSON res); filters = import ./filters.nix; getNix = "import ${./eval.nix} ${resFile}"; diff --git a/tix/test.nix b/tix/test.nix index 0fc14c6..cc81c76 100644 --- a/tix/test.nix +++ b/tix/test.nix @@ -1,14 +1,17 @@ path: let it = import ./it.nix; describe = import ./describe.nix; - suite = import path; + suite = if builtins.typeOf path == "path" then import path + else path; + name = if builtins.typeOf path == "path" then builtins.baseNameOf path + else "anonymous"; in - builtins.trace ("tix: " + builtins.baseNameOf path) + builtins.trace "tix: ${name}" ( if !builtins.isFunction suite then throw "A test suite should be in the form { it }: [ ]." else { - name = toString path; + inherit name; value = builtins.listToAttrs (suite {inherit it describe;}); } )