add describe function

This commit is contained in:
tristan 2024-01-02 13:15:50 +00:00
parent 0b7f5ad721
commit 0dd646775e
7 changed files with 80 additions and 37 deletions

View file

@ -9,10 +9,12 @@
pkgs = import nixpkgs {inherit system;}; pkgs = import nixpkgs {inherit system;};
tix = import ./tix/. {inherit pkgs;}; tix = import ./tix/. {inherit pkgs;};
in in
tix // { tix
// {
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
./test/describe.test.nix
]; ];
packages.x86_64-linux.example = tix.run [ packages.x86_64-linux.example = tix.run [
./mytest.nix ./mytest.nix

21
test/describe.test.nix Normal file
View file

@ -0,0 +1,21 @@
{
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";
}
];
})
]

View file

@ -1,11 +1,17 @@
{ it, ... }: {
[ it,
describe,
...
}:
describe "it" [
(it "test's itself???" rec { (it "test's itself???" rec {
expected = {success = true; msg = "test's itself???";}; expected = {
actual = success = true;
(it "test's itself???" { msg = "test's itself???";
};
actual = it "test's itself???" {
expected = expected; expected = expected;
actual = expected; actual = expected;
}); };
}) })
] ]

View file

@ -1,10 +1,8 @@
{ it, ... }: {it, ...}: let
let
pkgs = import <nixpkgs> {}; # impure ¯\_(ツ)_/¯ pkgs = import <nixpkgs> {}; # impure ¯\_(ツ)_/¯
run = import ../tix/run.nix pkgs; run = import ../tix/run.nix pkgs;
output = run [./it.test.nix]; output = run [./it.test.nix];
in in [
[
(it "makes a derivation called test" { (it "makes a derivation called test" {
expected = "test"; expected = "test";
actual = output.name; actual = output.name;

View file

@ -1,10 +1,18 @@
{ it, ... }: {
let describe,
it,
...
}: let
test = import ../tix/test.nix; test = import ../tix/test.nix;
in in
[ describe "the test function" [
(it "get's test results" { (it "get's test results" {
expected = [{"msg" = "test's itself???"; "success"= true;}]; expected = [
{
"msg" = "it: test's itself???";
"success" = true;
}
];
actual = (test ./it.test.nix).results; actual = (test ./it.test.nix).results;
}) })
(it "has a path" { (it "has a path" {
@ -12,7 +20,7 @@ in
expected = "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;
throws = true; throws = true;
}) })
] ]

8
tix/describe.nix Normal file
View file

@ -0,0 +1,8 @@
name:
map ({
msg,
success,
actual ? null,
expected ? null,
} @ result:
result // {msg = "${name}: ${msg}";})

View file

@ -1,14 +1,14 @@
path: let path: let
it = import ./it.nix; it = import ./it.nix;
describe = import ./describe.nix;
suite = import path; suite = import path;
in in
builtins.trace ("testing " + builtins.baseNameOf path) builtins.trace ("testing " + builtins.baseNameOf path)
( (
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; inherit path;
results = suite {inherit it;}; results = suite {inherit it describe;};
} }
) )