better testing experience
This commit is contained in:
parent
4f28cbfda7
commit
9421a0a910
|
@ -26,12 +26,18 @@ The default package will serve the site locally (using caddy)
|
||||||
nix run .
|
nix run .
|
||||||
```
|
```
|
||||||
|
|
||||||
Or you can build it raw:
|
Or you can build it raw (dumps the produced site into ./result)
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
nix build .#raw
|
nix build .#raw
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Run the tests and watch for changes
|
||||||
|
|
||||||
|
```sh
|
||||||
|
nix run .#watch
|
||||||
|
```
|
||||||
|
|
||||||
## features
|
## features
|
||||||
|
|
||||||
- [X] file paths
|
- [X] file paths
|
||||||
|
|
|
@ -52,6 +52,12 @@
|
||||||
./testing/site.test.nix
|
./testing/site.test.nix
|
||||||
./testing/style.test.nix
|
./testing/style.test.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
|
watch = let w = import ./testing/watch.nix pkgs;
|
||||||
|
in w "nix run .#test" "fx";
|
||||||
|
|
||||||
|
dev = let w = import ./testing/watch.nix pkgs;
|
||||||
|
in w "nix run .#" "caddy";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ let
|
||||||
builtins.trace "Skipping ${key} as it is a set" ""
|
builtins.trace "Skipping ${key} as it is a set" ""
|
||||||
else if value == "" || value == [ ] || value == false then
|
else if value == "" || value == [ ] || value == false then
|
||||||
""
|
""
|
||||||
else if value == true then key
|
else if value == true then
|
||||||
|
key
|
||||||
else
|
else
|
||||||
''${key}="${toString value}"'';
|
''${key}="${toString value}"'';
|
||||||
in rec {
|
in rec {
|
||||||
|
|
|
@ -69,25 +69,31 @@ in rec {
|
||||||
matchThen "(```)(.*)(```)" block (m: elems.code (builtins.elemAt m 1));
|
matchThen "(```)(.*)(```)" block (m: elems.code (builtins.elemAt m 1));
|
||||||
|
|
||||||
list = block:
|
list = block:
|
||||||
matchThen (
|
matchThen (''
|
||||||
''
|
|
||||||
(- .+
|
(- .+
|
||||||
)*(- .+
|
)*(- .+
|
||||||
?)'') block (m:
|
?)'') block (m: elems.List (splitList block));
|
||||||
elems.List ( splitList block ));
|
|
||||||
|
|
||||||
splitList = block: map (listItem) (builtins.filter
|
splitList = block:
|
||||||
(s: builtins.isString s && s != "")
|
map (listItem) (builtins.filter (s: builtins.isString s && s != "")
|
||||||
(builtins.split "\n" block));
|
(builtins.split "\n" block));
|
||||||
|
|
||||||
listItem = str:
|
listItem = str:
|
||||||
let
|
let
|
||||||
li = builtins.match "- (.*)" str;
|
li = builtins.match "- (.*)" str;
|
||||||
checkbox = builtins.match "- \\[(.)] (.*)" str;
|
checkbox = builtins.match "- \\[(.)] (.*)" str;
|
||||||
checked = builtins.elemAt checkbox 0;
|
checked = builtins.elemAt checkbox 0;
|
||||||
content = builtins.elemAt checkbox 1;
|
content = builtins.elemAt checkbox 1;
|
||||||
in if checkbox == null then li else
|
in if checkbox == null then
|
||||||
[(elems.input {type = "checkbox"; checked = checked != " "; disabled = true;}) content];
|
li
|
||||||
|
else [
|
||||||
|
(elems.input {
|
||||||
|
type = "checkbox";
|
||||||
|
checked = checked != " ";
|
||||||
|
disabled = true;
|
||||||
|
})
|
||||||
|
content
|
||||||
|
];
|
||||||
|
|
||||||
replace = matcher: apply: block:
|
replace = matcher: apply: block:
|
||||||
(let
|
(let
|
||||||
|
|
|
@ -133,7 +133,10 @@ in with html; [
|
||||||
}))
|
}))
|
||||||
|
|
||||||
(it "renders on / off attrs" ({
|
(it "renders on / off attrs" ({
|
||||||
actual = toString (tag "p" {on = true; off = false;});
|
actual = toString (tag "p" {
|
||||||
|
on = true;
|
||||||
|
off = false;
|
||||||
|
});
|
||||||
expected = "<p on></p>";
|
expected = "<p on></p>";
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
path:
|
path:
|
||||||
builtins.trace ("testing " + builtins.baseNameOf path) ''
|
builtins.trace ("testing " + builtins.baseNameOf path)
|
||||||
echo
|
|
||||||
echo 'TEST: ${builtins.baseNameOf path}'
|
{
|
||||||
echo
|
inherit path;
|
||||||
'' + builtins.concatStringsSep "\n" (import path)
|
results = (import path);
|
||||||
|
}
|
||||||
|
|
|
@ -33,12 +33,9 @@ let
|
||||||
success =
|
success =
|
||||||
if throws then (builtins.tryEval actual).success == false else (a == e);
|
if throws then (builtins.tryEval actual).success == false else (a == e);
|
||||||
|
|
||||||
in if success then ''
|
in {
|
||||||
echo 'it ${msg}'
|
inherit success msg;
|
||||||
'' else
|
} // (if success then
|
||||||
builtins.trace "FAILED ${msg}" (let file = builtins.toFile "value" out;
|
{ }
|
||||||
in ''
|
else
|
||||||
echo FAILED ${msg}
|
builtins.trace "FAILED ${msg}" { inherit actual expected; })
|
||||||
echo '${file}'
|
|
||||||
cat '${file}' | jq '.'
|
|
||||||
'')
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ in with md; [
|
||||||
'';
|
'';
|
||||||
expected = {
|
expected = {
|
||||||
matched = true;
|
matched = true;
|
||||||
block = elems.List ["something"];
|
block = elems.List [ "something" ];
|
||||||
};
|
};
|
||||||
asJSON = true;
|
asJSON = true;
|
||||||
}))
|
}))
|
||||||
|
@ -46,10 +46,7 @@ in with md; [
|
||||||
'';
|
'';
|
||||||
expected = {
|
expected = {
|
||||||
matched = true;
|
matched = true;
|
||||||
block = elems.List [
|
block = elems.List [ "something" "something else" ];
|
||||||
"something"
|
|
||||||
"something else"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
asJSON = true;
|
asJSON = true;
|
||||||
}))
|
}))
|
||||||
|
@ -62,10 +59,22 @@ in with md; [
|
||||||
expected = {
|
expected = {
|
||||||
matched = true;
|
matched = true;
|
||||||
block = elems.List [
|
block = elems.List [
|
||||||
[(elems.input {type = "checkbox"; disabled = true; checked = false; } "")
|
[
|
||||||
"something"]
|
(elems.input {
|
||||||
[(elems.input {type = "checkbox"; disabled = true; checked = true; } "")
|
type = "checkbox";
|
||||||
"something else"]
|
disabled = true;
|
||||||
|
checked = false;
|
||||||
|
} "")
|
||||||
|
"something"
|
||||||
|
]
|
||||||
|
[
|
||||||
|
(elems.input {
|
||||||
|
type = "checkbox";
|
||||||
|
disabled = true;
|
||||||
|
checked = true;
|
||||||
|
} "")
|
||||||
|
"something else"
|
||||||
|
]
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
asJSON = true;
|
asJSON = true;
|
||||||
|
@ -77,10 +86,7 @@ in with md; [
|
||||||
- something else'';
|
- something else'';
|
||||||
expected = {
|
expected = {
|
||||||
matched = true;
|
matched = true;
|
||||||
block = elems.List [
|
block = elems.List [ "something" "something else" ];
|
||||||
"something"
|
|
||||||
"something else"
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
asJSON = true;
|
asJSON = true;
|
||||||
}))
|
}))
|
||||||
|
|
|
@ -1,5 +1,16 @@
|
||||||
pkgs:
|
pkgs: files:
|
||||||
let test = import ./import.nix;
|
let
|
||||||
in files:
|
test = import ./import.nix;
|
||||||
(pkgs.writeShellScriptBin "test"
|
res = map test files;
|
||||||
(builtins.concatStringsSep "\n" (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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
in (pkgs.writeShellScriptBin "test" ''
|
||||||
|
cat '${resFile}' | ${pkgs.jq}/bin/jq '${filter}' | ${pkgs.fx}/bin/fx
|
||||||
|
'')
|
||||||
|
|
10
testing/watch.nix
Normal file
10
testing/watch.nix
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
pkgs: cmd: pname:
|
||||||
|
pkgs.writeShellScriptBin "watch" ''
|
||||||
|
while true
|
||||||
|
do
|
||||||
|
${cmd} &
|
||||||
|
${pkgs.inotify-tools}/bin/inotifywait -e modify -r .
|
||||||
|
pkill ${pname}
|
||||||
|
done
|
||||||
|
''
|
||||||
|
|
Loading…
Reference in a new issue