extract testing lib
This commit is contained in:
parent
02557783c1
commit
195f8a60ae
34
flake.lock
34
flake.lock
|
@ -13,9 +13,41 @@
|
|||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1703013332,
|
||||
"narHash": "sha256-+tFNwMvlXLbJZXiMHqYq77z/RfmpfpiI3yjL6o/Zo9M=",
|
||||
"path": "/nix/store/50bgi74d890mpkp90w1jwc5g0dw4dccr-source",
|
||||
"rev": "54aac082a4d9bb5bbc5c4e899603abfb76a3f6d6",
|
||||
"type": "path"
|
||||
},
|
||||
"original": {
|
||||
"id": "nixpkgs",
|
||||
"type": "indirect"
|
||||
}
|
||||
},
|
||||
"root": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs"
|
||||
"nixpkgs": "nixpkgs",
|
||||
"tix": "tix"
|
||||
}
|
||||
},
|
||||
"tix": {
|
||||
"inputs": {
|
||||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1704187012,
|
||||
"narHash": "sha256-td0PQa1cTvjurjBmLpCynAgDV425Mh8sRObRtbTGxiQ=",
|
||||
"ref": "refs/heads/master",
|
||||
"rev": "249bd9cda4fe9b02f3c85b22179109794eb57256",
|
||||
"revCount": 2,
|
||||
"type": "git",
|
||||
"url": "https://git.tristans.cloud/tristan/tix"
|
||||
},
|
||||
"original": {
|
||||
"type": "git",
|
||||
"url": "https://git.tristans.cloud/tristan/tix"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
15
flake.nix
15
flake.nix
|
@ -1,7 +1,11 @@
|
|||
{
|
||||
description = "A site in nix?";
|
||||
|
||||
outputs = { self, nixpkgs, }:
|
||||
inputs = {
|
||||
tix.url = "git+https://git.tristans.cloud/tristan/tix";
|
||||
};
|
||||
|
||||
outputs = { self, nixpkgs, tix }:
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
pkgs = import nixpkgs { inherit system; };
|
||||
|
@ -44,8 +48,7 @@
|
|||
|
||||
default = nixite.serve self.packages.${system}.raw;
|
||||
|
||||
test = let run = import ./testing/run.nix pkgs;
|
||||
in run [
|
||||
test = tix.run [
|
||||
./testing/md.test.nix
|
||||
./testing/html.test.nix
|
||||
./testing/elems.test.nix
|
||||
|
@ -53,11 +56,9 @@
|
|||
./testing/style.test.nix
|
||||
];
|
||||
|
||||
watch = let w = import ./testing/watch.nix pkgs;
|
||||
in w "nix run .#test --show-trace" "fx";
|
||||
watch = tix.watch "nix run .#test --show-trace" "fx";
|
||||
|
||||
dev = let w = import ./testing/watch.nix pkgs;
|
||||
in w "nix run .# --show-trace" "caddy";
|
||||
dev = tix.watch "nix run .# --show-trace" "caddy";
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
path:
|
||||
builtins.trace ("testing " + builtins.baseNameOf path)
|
||||
|
||||
{
|
||||
inherit path;
|
||||
results = (import path);
|
||||
}
|
|
@ -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; })
|
|
@ -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" ({
|
||||
|
|
|
@ -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
|
||||
'')
|
|
@ -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 = {
|
||||
|
|
|
@ -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" { });
|
||||
|
|
|
@ -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
|
||||
''
|
||||
|
Loading…
Reference in a new issue