mirror of
https://gitlab.com/TECHNOFAB/nixtest.git
synced 2025-12-12 10:10:09 +01:00
test: nest sample tests as fixtures in real tests
also use new test helpers
This commit is contained in:
parent
bed029f4a9
commit
006537e6ab
4 changed files with 186 additions and 142 deletions
97
tests/fixtures/sample_test.nix
vendored
Normal file
97
tests/fixtures/sample_test.nix
vendored
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
{
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}: {
|
||||
skip = "skip.*d";
|
||||
suites = {
|
||||
"suite-one" = {
|
||||
# required to figure out file and line, but optional
|
||||
pos = __curPos;
|
||||
tests = [
|
||||
{
|
||||
name = "test-one";
|
||||
expected = 1;
|
||||
actual = 1;
|
||||
}
|
||||
{
|
||||
name = "fail";
|
||||
expected = 0;
|
||||
actual = "meow";
|
||||
}
|
||||
{
|
||||
name = "snapshot-test";
|
||||
type = "snapshot";
|
||||
actual = "test";
|
||||
}
|
||||
{
|
||||
name = "test-snapshot-drv";
|
||||
type = "snapshot";
|
||||
actualDrv = pkgs.runCommand "test-snapshot" {} ''
|
||||
echo '"snapshot drv"' > $out
|
||||
'';
|
||||
}
|
||||
{
|
||||
name = "test-error-drv";
|
||||
expected = null;
|
||||
actualDrv = pkgs.runCommand "test-error-drv" {} ''
|
||||
echo "This works, but its better to just write 'fail' to \$out and expect 'success' or sth."
|
||||
exit 1
|
||||
'';
|
||||
}
|
||||
{
|
||||
name = "test-script";
|
||||
type = "script";
|
||||
script = ''
|
||||
echo Test something here
|
||||
# required in pure mode:
|
||||
export PATH="${lib.makeBinPath [pkgs.gnugrep]}"
|
||||
grep -q "test" ${builtins.toFile "test" "test"}
|
||||
'';
|
||||
}
|
||||
];
|
||||
};
|
||||
"other-suite".tests = [
|
||||
{
|
||||
name = "obj-snapshot";
|
||||
type = "snapshot";
|
||||
pos = __curPos;
|
||||
actual = {hello = "world";};
|
||||
}
|
||||
{
|
||||
name = "pretty-snapshot";
|
||||
type = "snapshot";
|
||||
format = "pretty";
|
||||
pos = __curPos;
|
||||
actual = {
|
||||
example = args: {};
|
||||
example2 = {
|
||||
drv = pkgs.hello;
|
||||
};
|
||||
};
|
||||
}
|
||||
{
|
||||
name = "pretty-unit";
|
||||
format = "pretty";
|
||||
pos = __curPos;
|
||||
expected = pkgs.hello;
|
||||
actual = pkgs.hello;
|
||||
}
|
||||
{
|
||||
name = "test-drv";
|
||||
pos = __curPos;
|
||||
expected = {a = "b";};
|
||||
actualDrv = pkgs.runCommand "test-something" {} ''
|
||||
echo "Simulating taking some time"
|
||||
sleep 1
|
||||
echo '{"a":"b"}' > $out
|
||||
'';
|
||||
}
|
||||
{
|
||||
name = "skipped";
|
||||
expected = null;
|
||||
actual = null;
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue