From 2df95bbc56605fa6d6f6601b46117b9426882c6d Mon Sep 17 00:00:00 2001 From: tristan Date: Wed, 3 Jan 2024 10:14:28 +0000 Subject: [PATCH] rework describe function --- flake.nix | 7 ++++++- test/describe.test.nix | 36 ++++++++++++++++++++---------------- test/it.test.nix | 25 +++++++++++++------------ test/test.test.nix | 16 +++++++++++----- tix/describe.nix | 20 ++++++++++++-------- tix/filters.nix | 13 +++++++++---- tix/it.nix | 12 ++++++------ 7 files changed, 77 insertions(+), 52 deletions(-) diff --git a/flake.nix b/flake.nix index f8a8704..0b45933 100644 --- a/flake.nix +++ b/flake.nix @@ -22,11 +22,16 @@ ./mytest.nix ]; - packages.x86_64-linux.watch = tix.watch { + packages.x86_64-linux.watchpipe = tix.watch { cmd = "nix run --show-trace .#test file"; view = "tee -a /tmp/tix-output"; }; + packages.x86_64-linux.watch = tix.watch { + cmd = "nix run --show-trace .#test"; + view = "cat"; + }; + packages.x86_64-linux.results = pkgs.writeShellScriptBin "results" '' tail -f -n1 /tmp/tix-output | { while read out diff --git a/test/describe.test.nix b/test/describe.test.nix index efd6395..3d9148c 100644 --- a/test/describe.test.nix +++ b/test/describe.test.nix @@ -2,20 +2,24 @@ describe, it, ... -}: -describe "the describe function" [ - (it "returns an array with the message changed" { - expected = [ - { - success = true; - msg = "the describe function: works"; - } - ]; - actual = describe "the describe function" [ - { - success = true; - msg = "works"; - } - ]; - }) +}: [ + (describe "the describe function" [ + (it "returns an array with the message changed" { + expected = { + component = "the describe function"; + results = [ + { + success = true; + msg = "works"; + } + ]; + }; + actual = describe "the describe function" [ + { + success = true; + msg = "works"; + } + ]; + }) + ]) ] diff --git a/test/it.test.nix b/test/it.test.nix index 6daf1a2..a0347d2 100644 --- a/test/it.test.nix +++ b/test/it.test.nix @@ -2,16 +2,17 @@ it, describe, ... -}: -describe "it" [ - (it "test's itself???" rec { - expected = { - success = true; - msg = "test's itself???"; - }; - actual = it "test's itself???" { - expected = expected; - actual = expected; - }; - }) +}: [ + (describe "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/test.test.nix b/test/test.test.nix index a6a6807..c30db57 100644 --- a/test/test.test.nix +++ b/test/test.test.nix @@ -4,13 +4,18 @@ ... }: let test = import ../tix/test.nix; -in - describe "the test function" [ +in [ + (describe "the test function" [ (it "get's test results" { expected = [ { - "msg" = "it: test's itself???"; - "success" = true; + "component" = "it"; + results = [ + { + "msg" = "test's itself???"; + "success" = true; + } + ]; } ]; actual = (test ./it.test.nix).results; @@ -23,4 +28,5 @@ in actual = test ./bad/string.nix; throws = true; }) - ] + ]) +] diff --git a/tix/describe.nix b/tix/describe.nix index 0a78fc6..6694fa8 100644 --- a/tix/describe.nix +++ b/tix/describe.nix @@ -1,9 +1,13 @@ -name: +name: tests: builtins.trace "tix: ├── ${name}" -map ({ - msg, - success, - actual ? null, - expected ? null, - } @ result: - result // {msg = "${name}: ${msg}";}) +{ + component = name; + results = map ({ + msg, + success, + actual ? null, + expected ? null, + } @ result: + result) + tests; +} diff --git a/tix/filters.nix b/tix/filters.nix index ea8354c..2880425 100644 --- a/tix/filters.nix +++ b/tix/filters.nix @@ -3,10 +3,15 @@ let in { overview = '' .[] | { - (.path): { - "${emotes.fail}": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}], - "${emotes.pass}": .results | map(select(.success) | .msg) | length - } + (.path): + .results[] | { + (.component): { + "${emotes.fail}": [ + .results | map(select(.success==false))[] | {(.msg): {actual, expected}} + ], + "${emotes.pass}": .results | map(select(.success) | .msg) | length + } + } } ''; } diff --git a/tix/it.nix b/tix/it.nix index b1a4705..58ddefa 100644 --- a/tix/it.nix +++ b/tix/it.nix @@ -26,13 +26,13 @@ msg: { then builtins.removeAttrs v ["__toString" "__functor"] else v; - success = + success = builtins.trace "tix: │ ├── ${msg}" - ( - if throws - then (builtins.tryEval actual).success == false - else (a == e) - ); + ( + if throws + then (builtins.tryEval actual).success == false + else (a == e) + ); in { inherit success msg;