fix builder tests

This commit is contained in:
Tristan 2024-01-04 05:23:06 +00:00
parent 669fccd57e
commit 28f8cfe612
6 changed files with 76 additions and 65 deletions

47
testing/builder.test.nix Normal file
View file

@ -0,0 +1,47 @@
{
describe,
it,
...
}: let
builder = import ../nixite/builder.nix;
in
with builder; [
(describe "buildSiteTo" [
(it "copies all the files" {
actual = buildSiteTo "." {
page = "this is a page";
subdir = {
page = "this page is in a subdir";
link = ./src;
};
};
expected = ''
cp /nix/store/crirfz0n6f8dgl1si3x7pwyw7fqm0r8l-page ./page
mkdir -p ./subdir
cp -r /nix/store/q95cn7ccixzi9w22aic4bl0ykk40ka7v-src ./subdir/link
cp /nix/store/ic6fyy8wg8r4338a3m5kinmg11igxsyj-page ./subdir/page
'';
})
(it "throws with a list for a page" {
actual = buildSiteTo "." {page = [];};
throws = true;
})
(it "throws with null for a page" {
actual = buildSiteTo "." {page = null;};
throws = true;
})
(it "throws with a bool for a page" {
actual = buildSiteTo "." {page = true;};
throws = true;
})
(it "throws with a number for a page" {
actual = buildSiteTo "." {page = 5;};
throws = true;
})
])
]

View file

@ -235,44 +235,6 @@ in
};
}))
])
(describe "copyTo" [
(it "copies all the files" {
actual = copyTo "." {
page = "this is a page";
subdir = {
page = "this page is in a subdir";
link = ./src;
};
};
expected = ''
cp /nix/store/crirfz0n6f8dgl1si3x7pwyw7fqm0r8l-page ./page
mkdir -p ./subdir
cp -r /nix/store/q95cn7ccixzi9w22aic4bl0ykk40ka7v-src ./subdir/link
cp /nix/store/ic6fyy8wg8r4338a3m5kinmg11igxsyj-page ./subdir/page
'';
})
(it "throws with a list for a page" {
actual = copyTo "." {page = [];};
throws = true;
})
(it "throws with null for a page" {
actual = copyTo "." {page = null;};
throws = true;
})
(it "throws with a bool for a page" {
actual = copyTo "." {page = true;};
throws = true;
})
(it "throws with a number for a page" {
actual = copyTo "." {page = 5;};
throws = true;
})
])
(describe "prepare" [
(it "prepares the site" {
actual = prepare {favicon = ./src/favicon.png;} my-site;