list to attrs, restructure output

This commit is contained in:
tristan 2024-01-03 19:18:54 +00:00
parent cc834eda99
commit 5007770e88
10 changed files with 66 additions and 58 deletions

View file

@ -11,6 +11,8 @@
in in
tix tix
// { // {
formatter.x86_64-linux = pkgs.alejandra;
packages.x86_64-linux.test = tix.run [ packages.x86_64-linux.test = tix.run [
./test/it.test.nix ./test/it.test.nix
./test/test.test.nix ./test/test.test.nix
@ -28,7 +30,7 @@
}; };
packages.x86_64-linux.watch = tix.watch { packages.x86_64-linux.watch = tix.watch {
cmd = "nix run --show-trace .#test"; cmd = "nix run --show-trace .#test $2";
view = "cat"; view = "cat";
}; };

View file

@ -6,18 +6,15 @@
(describe "the describe function" [ (describe "the describe function" [
(it "returns an array with the message changed" { (it "returns an array with the message changed" {
expected = { expected = {
component = "the describe function"; name = "the describe function";
results = [ value = {
{ "works" = {success = true;};
success = true; };
msg = "works";
}
];
}; };
actual = describe "the describe function" [ actual = describe "the describe function" [
{ {
success = true; value = {success = true;};
msg = "works"; name = "works";
} }
]; ];
}) })

10
test/example.test.nix Normal file
View file

@ -0,0 +1,10 @@
{...}: [
{
name = "an example";
value = {
"succeeds" = {
success = true;
};
};
}
]

View file

@ -6,8 +6,10 @@
(describe "it" [ (describe "it" [
(it "test's itself???" rec { (it "test's itself???" rec {
expected = { expected = {
success = true; value = {
msg = "test's itself???"; success = true;
};
name = "test's itself???";
}; };
actual = it "test's itself???" { actual = it "test's itself???" {
expected = expected; expected = expected;

View file

@ -7,22 +7,17 @@
in [ in [
(describe "the test function" [ (describe "the test function" [
(it "get's test results" { (it "get's test results" {
expected = [ expected = {
{ name = toString ./example.test.nix;
"component" = "it"; value = {
results = [ "an example" = {
{ succeeds = {
"msg" = "test's itself???"; success = true;
"success" = true; };
} };
]; };
} };
]; actual = test ./example.test.nix;
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" { (it "fails to build non test" {
actual = test ./bad/string.nix; actual = test ./bad/string.nix;

View file

@ -1,13 +1,6 @@
name: tests: name: tests:
builtins.trace "tix: ${name}" builtins.trace "tix: ${name}"
{ {
component = name; inherit name;
results = map ({ value = builtins.listToAttrs tests;
msg,
success,
actual ? null,
expected ? null,
} @ result:
result)
tests;
} }

View file

@ -10,5 +10,7 @@ in rec {
}] | add }] | add
}] | add }] | add
''; '';
overview = failures; overview = ''
.
'';
} }

View file

@ -1,4 +1,4 @@
msg: { name: {
actual, actual,
expected ? {}, expected ? {},
asString ? false, asString ? false,
@ -6,6 +6,7 @@ msg: {
removeDunders ? false, removeDunders ? false,
safeToPrint ? true, safeToPrint ? true,
throws ? false, throws ? false,
debug ? false,
}: let }: let
emotes = import ./emotes.nix; emotes = import ./emotes.nix;
@ -27,20 +28,26 @@ msg: {
else v; else v;
success = success =
builtins.trace "tix: ${msg}" if debug
( then break
if throws
then (builtins.tryEval actual).success == false
else (a == e)
);
in
{
inherit success msg;
}
// (
if success
then builtins.trace "tix: ${emotes.pass}" {}
else else
builtins.trace "tix: ${emotes.fail}" builtins.trace "tix: ${name}"
{inherit actual expected;} (
) 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;}
);
}

View file

@ -1,6 +1,6 @@
pkgs: files: let pkgs: files: let
test = import ./test.nix; test = import ./test.nix;
res = map test files; res = builtins.listToAttrs (map test files);
resFile = builtins.toFile "results" (builtins.toJSON res); resFile = builtins.toFile "results" (builtins.toJSON res);
filters = import ./filters.nix; filters = import ./filters.nix;
getNix = "import ${./eval.nix} ${resFile}"; getNix = "import ${./eval.nix} ${resFile}";

View file

@ -8,7 +8,7 @@ in
if !builtins.isFunction suite if !builtins.isFunction suite
then throw "A test suite should be in the form { it }: [ <tests> ]." then throw "A test suite should be in the form { it }: [ <tests> ]."
else { else {
inherit path; name = toString path;
results = suite {inherit it describe;}; value = builtins.listToAttrs (suite {inherit it describe;});
} }
) )