From 5007770e88c4d5f67c3790761a1125904a9ef257 Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 3 Jan 2024 19:18:54 +0000 Subject: [PATCH] list to attrs, restructure output --- flake.nix | 4 +++- test/describe.test.nix | 15 ++++++--------- test/example.test.nix | 10 ++++++++++ test/it.test.nix | 6 ++++-- test/test.test.nix | 27 +++++++++++---------------- tix/describe.nix | 11 ++--------- tix/filters.nix | 4 +++- tix/it.nix | 41 ++++++++++++++++++++++++----------------- tix/run.nix | 2 +- tix/test.nix | 4 ++-- 10 files changed, 66 insertions(+), 58 deletions(-) create mode 100644 test/example.test.nix diff --git a/flake.nix b/flake.nix index 0b45933..5af2f2a 100644 --- a/flake.nix +++ b/flake.nix @@ -11,6 +11,8 @@ in tix // { + formatter.x86_64-linux = pkgs.alejandra; + packages.x86_64-linux.test = tix.run [ ./test/it.test.nix ./test/test.test.nix @@ -28,7 +30,7 @@ }; packages.x86_64-linux.watch = tix.watch { - cmd = "nix run --show-trace .#test"; + cmd = "nix run --show-trace .#test $2"; view = "cat"; }; diff --git a/test/describe.test.nix b/test/describe.test.nix index 3d9148c..aded1d9 100644 --- a/test/describe.test.nix +++ b/test/describe.test.nix @@ -6,18 +6,15 @@ (describe "the describe function" [ (it "returns an array with the message changed" { expected = { - component = "the describe function"; - results = [ - { - success = true; - msg = "works"; - } - ]; + name = "the describe function"; + value = { + "works" = {success = true;}; + }; }; actual = describe "the describe function" [ { - success = true; - msg = "works"; + value = {success = true;}; + name = "works"; } ]; }) diff --git a/test/example.test.nix b/test/example.test.nix new file mode 100644 index 0000000..0f1b3e0 --- /dev/null +++ b/test/example.test.nix @@ -0,0 +1,10 @@ +{...}: [ + { + name = "an example"; + value = { + "succeeds" = { + success = true; + }; + }; + } +] diff --git a/test/it.test.nix b/test/it.test.nix index a0347d2..b36c211 100644 --- a/test/it.test.nix +++ b/test/it.test.nix @@ -6,8 +6,10 @@ (describe "it" [ (it "test's itself???" rec { expected = { - success = true; - msg = "test's itself???"; + value = { + success = true; + }; + name = "test's itself???"; }; actual = it "test's itself???" { expected = expected; diff --git a/test/test.test.nix b/test/test.test.nix index c30db57..0cfc993 100644 --- a/test/test.test.nix +++ b/test/test.test.nix @@ -7,22 +7,17 @@ in [ (describe "the test function" [ (it "get's test results" { - expected = [ - { - "component" = "it"; - results = [ - { - "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"; + expected = { + name = toString ./example.test.nix; + value = { + "an example" = { + succeeds = { + success = true; + }; + }; + }; + }; + actual = test ./example.test.nix; }) (it "fails to build non test" { actual = test ./bad/string.nix; diff --git a/tix/describe.nix b/tix/describe.nix index 6694fa8..238256e 100644 --- a/tix/describe.nix +++ b/tix/describe.nix @@ -1,13 +1,6 @@ name: tests: builtins.trace "tix: ├── ${name}" { - component = name; - results = map ({ - msg, - success, - actual ? null, - expected ? null, - } @ result: - result) - tests; + inherit name; + value = builtins.listToAttrs tests; } diff --git a/tix/filters.nix b/tix/filters.nix index 99d6339..5dd1f7c 100644 --- a/tix/filters.nix +++ b/tix/filters.nix @@ -10,5 +10,7 @@ in rec { }] | add }] | add ''; - overview = failures; + overview = '' + . + ''; } diff --git a/tix/it.nix b/tix/it.nix index 58ddefa..2ed4d5a 100644 --- a/tix/it.nix +++ b/tix/it.nix @@ -1,4 +1,4 @@ -msg: { +name: { actual, expected ? {}, asString ? false, @@ -6,6 +6,7 @@ msg: { removeDunders ? false, safeToPrint ? true, throws ? false, + debug ? false, }: let emotes = import ./emotes.nix; @@ -27,20 +28,26 @@ msg: { else v; success = - builtins.trace "tix: │ ├── ${msg}" - ( - if throws - then (builtins.tryEval actual).success == false - else (a == e) - ); -in - { - inherit success msg; - } - // ( - if success - then builtins.trace "tix: │ │ ${emotes.pass}" {} + if debug + then break else - builtins.trace "tix: │ │ ${emotes.fail}" - {inherit actual expected;} - ) + builtins.trace "tix: │ ├── ${name}" + ( + if throws + then (builtins.tryEval actual).success == false + else (a == e) + ); +in { + inherit name; + value = + { + inherit success; + } + // ( + if success + then builtins.trace "tix: │ │ ${emotes.pass}" {} + else + builtins.trace "tix: │ │ ${emotes.fail}" + {inherit actual expected;} + ); +} diff --git a/tix/run.nix b/tix/run.nix index 8598edb..d16f6f0 100644 --- a/tix/run.nix +++ b/tix/run.nix @@ -1,6 +1,6 @@ pkgs: files: let test = import ./test.nix; - res = map test files; + res = builtins.listToAttrs (map test files); 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 ea3727c..0fc14c6 100644 --- a/tix/test.nix +++ b/tix/test.nix @@ -8,7 +8,7 @@ in if !builtins.isFunction suite then throw "A test suite should be in the form { it }: [ ]." else { - inherit path; - results = suite {inherit it describe;}; + name = toString path; + value = builtins.listToAttrs (suite {inherit it describe;}); } )