add tests
This commit is contained in:
parent
aeb174ac65
commit
0b7f5ad721
15
flake.nix
15
flake.nix
|
@ -7,10 +7,17 @@
|
|||
}: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs {inherit system;};
|
||||
tix = import ./testing/. {inherit pkgs;};
|
||||
tix = import ./tix/. {inherit pkgs;};
|
||||
in
|
||||
tix
|
||||
// {
|
||||
packages.x86_64-linux.test = tix.run [./mytest.nix];
|
||||
tix // {
|
||||
packages.x86_64-linux.test = tix.run [
|
||||
./test/it.test.nix
|
||||
./test/test.test.nix
|
||||
];
|
||||
packages.x86_64-linux.example = tix.run [
|
||||
./mytest.nix
|
||||
];
|
||||
packages.x86_64-linux.watch =
|
||||
tix.watch "nix run .#test --show-trace | ${pkgs.fx}/bin/fx" "fx";
|
||||
};
|
||||
}
|
||||
|
|
1
test/bad/string.nix
Normal file
1
test/bad/string.nix
Normal file
|
@ -0,0 +1 @@
|
|||
"This isn't a test suite!"
|
11
test/it.test.nix
Normal file
11
test/it.test.nix
Normal file
|
@ -0,0 +1,11 @@
|
|||
{ it, ... }:
|
||||
[
|
||||
(it "test's itself???" rec {
|
||||
expected = {success = true; msg = "test's itself???";};
|
||||
actual =
|
||||
(it "test's itself???" {
|
||||
expected = expected;
|
||||
actual = expected;
|
||||
});
|
||||
})
|
||||
]
|
12
test/run.test.nix
Normal file
12
test/run.test.nix
Normal file
|
@ -0,0 +1,12 @@
|
|||
{ it, ... }:
|
||||
let
|
||||
pkgs = import <nixpkgs> {}; # impure ¯\_(ツ)_/¯
|
||||
run = import ../tix/run.nix pkgs;
|
||||
output = run [ ./it.test.nix ];
|
||||
in
|
||||
[
|
||||
(it "makes a derivation called test" {
|
||||
expected = "test";
|
||||
actual = output.name;
|
||||
})
|
||||
]
|
18
test/test.test.nix
Normal file
18
test/test.test.nix
Normal file
|
@ -0,0 +1,18 @@
|
|||
{ it, ... }:
|
||||
let
|
||||
test = import ../tix/test.nix;
|
||||
in
|
||||
[
|
||||
(it "get's test results" {
|
||||
expected = [{"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";
|
||||
})
|
||||
(it "fails to build non test" {
|
||||
actual = ( test ./bad/string.nix );
|
||||
throws = true;
|
||||
})
|
||||
]
|
|
@ -1,7 +0,0 @@
|
|||
path: let
|
||||
it = import ./it.nix;
|
||||
in
|
||||
builtins.trace ("testing " + builtins.baseNameOf path) {
|
||||
inherit path;
|
||||
results = import path {inherit it;};
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
{pkgs ? import <nixpkgs> {}}: {
|
||||
run = import ./run.nix pkgs;
|
||||
it = import ./it.nix;
|
||||
import = import ./import.nix;
|
||||
test = import ./test.nix;
|
||||
watch = import ./watch.nix pkgs;
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
pkgs: files: let
|
||||
test = import ./import.nix;
|
||||
test = import ./test.nix;
|
||||
res = map test files;
|
||||
resFile = builtins.toFile "results" (builtins.toJSON res);
|
||||
filter = ''
|
||||
.[] | {
|
||||
(.path): {
|
||||
failures: [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}],
|
||||
success: .results | map(select(.success) | .msg) | length
|
||||
"❌": [.results | map(select(.success==false))[] | {(.msg): {actual, expected}}],
|
||||
"✔️": .results | map(select(.success) | .msg) | length
|
||||
}
|
||||
}
|
||||
'';
|
14
tix/test.nix
Normal file
14
tix/test.nix
Normal file
|
@ -0,0 +1,14 @@
|
|||
path: let
|
||||
it = import ./it.nix;
|
||||
suite = import path;
|
||||
in
|
||||
builtins.trace ("testing " + builtins.baseNameOf path)
|
||||
(
|
||||
if !builtins.isFunction suite
|
||||
then throw "A test suite should be in the form { it }: [ <tests> ]."
|
||||
else
|
||||
{
|
||||
inherit path;
|
||||
results = suite {inherit it;};
|
||||
}
|
||||
)
|
|
@ -3,7 +3,7 @@ pkgs.writeShellScriptBin "watch" ''
|
|||
while true
|
||||
do
|
||||
${cmd} &
|
||||
${pkgs.inotify-tools}/bin/inotifywait -e modify -r . --exclude .git
|
||||
${pkgs.inotify-tools}/bin/inotifywait -e modify -r .
|
||||
pkill ${pname}
|
||||
done
|
||||
''
|
Loading…
Reference in a new issue