extract testing lib

This commit is contained in:
tristan 2024-01-02 09:18:30 +00:00
parent 02557783c1
commit 195f8a60ae
11 changed files with 46 additions and 93 deletions

View file

@ -1,8 +1,7 @@
let
{it,...}:let
elems = import ../nixite/elems.nix;
style = import ../nixite/style.nix;
html = import ../nixite/html.nix;
it = import ./it.nix;
in with elems; [
(it "makes a p tag" {
expected = html.tag "p" { } "foobar";

View file

@ -1,6 +1,5 @@
let
{it, ...}: let
html = import ../nixite/html.nix;
it = import ./it.nix;
in with html; [
(it "keeps info in the tag" (let p = tag "p";

View file

@ -1,7 +0,0 @@
path:
builtins.trace ("testing " + builtins.baseNameOf path)
{
inherit path;
results = (import path);
}

View file

@ -1,41 +0,0 @@
msg:
{ actual, expected ? { }, asString ? false, asJSON ? false
, removeDunders ? false, safeToPrint ? true, throws ? false }:
let
preProcess = v:
if removeDunders then
undunder v
else if asString then
toString v
else if asJSON then
builtins.toJSON v
else
v;
a = preProcess actual;
e = preProcess expected;
undunder = v:
if builtins.isAttrs v then
builtins.removeAttrs v [ "__toString" "__functor" ]
else
v;
out = (if safeToPrint then
builtins.toJSON (undunder (if throws then
(builtins.tryEval actual).value
else {
inherit actual expected;
}))
else
''{"msg": "cannot be stringified ):"}'');
success =
if throws then (builtins.tryEval actual).success == false else (a == e);
in {
inherit success msg;
} // (if success then
{ }
else
builtins.trace "FAILED ${msg}" { inherit actual expected; })

View file

@ -1,7 +1,6 @@
let
{it,...}: let
md = import ../nixite/md.nix;
elems = import ../nixite/elems.nix;
it = import ./it.nix;
in with md; [
(it "matches a list of one element" ({

View file

@ -1,16 +0,0 @@
pkgs: files:
let
test = import ./import.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
}
}
'';
in (pkgs.writeShellScriptBin "test" ''
cat '${resFile}' | ${pkgs.jq}/bin/jq '${filter}' | ${pkgs.fx}/bin/fx
'')

View file

@ -1,9 +1,8 @@
let
{it,...}:let
html = import ../nixite/html.nix;
elems = import ../nixite/elems.nix;
site = import ../nixite/site.nix;
style = import ../nixite/style.nix;
it = import ./it.nix;
in with site; [
(it "applies a style" {
expected = {

View file

@ -1,8 +1,6 @@
let
{it,...}: let
style = import ../nixite/style.nix;
elems = import ../nixite/elems.nix;
it = import ./it.nix;
in [
(it "fetches empty style" (let para = (style.component elems.p "para" { });

View file

@ -1,10 +0,0 @@
pkgs: cmd: pname:
pkgs.writeShellScriptBin "watch" ''
while true
do
${cmd} &
${pkgs.inotify-tools}/bin/inotifywait -e modify -r . --exclude .git
pkill ${pname}
done
''