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
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";
};

View file

@ -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";
}
];
})

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" [
(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;

View file

@ -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;

View file

@ -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;
}

View file

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

View file

@ -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;}
);
}

View file

@ -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}";

View file

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