diff --git a/README.md b/README.md index ebc8974..282dc97 100644 --- a/README.md +++ b/README.md @@ -26,12 +26,18 @@ The default package will serve the site locally (using caddy) nix run . ``` -Or you can build it raw: +Or you can build it raw (dumps the produced site into ./result) ```sh nix build .#raw ``` +Run the tests and watch for changes + +```sh +nix run .#watch +``` + ## features - [X] file paths diff --git a/flake.nix b/flake.nix index c1ffeee..deeeb97 100644 --- a/flake.nix +++ b/flake.nix @@ -52,6 +52,12 @@ ./testing/site.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"; }; }; } diff --git a/nixite/html.nix b/nixite/html.nix index 9534c4c..e940612 100644 --- a/nixite/html.nix +++ b/nixite/html.nix @@ -5,7 +5,8 @@ let builtins.trace "Skipping ${key} as it is a set" "" else if value == "" || value == [ ] || value == false then "" - else if value == true then key + else if value == true then + key else ''${key}="${toString value}"''; in rec { diff --git a/nixite/md.nix b/nixite/md.nix index a197ea7..b36be1c 100644 --- a/nixite/md.nix +++ b/nixite/md.nix @@ -69,25 +69,31 @@ in rec { matchThen "(```)(.*)(```)" block (m: elems.code (builtins.elemAt m 1)); list = block: - matchThen ( - '' + matchThen ('' (- .+ )*(- .+ - ?)'') block (m: - elems.List ( splitList block )); + ?)'') block (m: elems.List (splitList block)); - splitList = block: map (listItem) (builtins.filter - (s: builtins.isString s && s != "") - (builtins.split "\n" block)); + splitList = block: + map (listItem) (builtins.filter (s: builtins.isString s && s != "") + (builtins.split "\n" block)); - listItem = str: + listItem = str: let - li = builtins.match "- (.*)" str; - checkbox = builtins.match "- \\[(.)] (.*)" str; - checked = builtins.elemAt checkbox 0; - content = builtins.elemAt checkbox 1; - in if checkbox == null then li else - [(elems.input {type = "checkbox"; checked = checked != " "; disabled = true;}) content]; + li = builtins.match "- (.*)" str; + checkbox = builtins.match "- \\[(.)] (.*)" str; + checked = builtins.elemAt checkbox 0; + content = builtins.elemAt checkbox 1; + in if checkbox == null then + li + else [ + (elems.input { + type = "checkbox"; + checked = checked != " "; + disabled = true; + }) + content + ]; replace = matcher: apply: block: (let diff --git a/testing/html.test.nix b/testing/html.test.nix index b291e24..a0cb2f7 100644 --- a/testing/html.test.nix +++ b/testing/html.test.nix @@ -133,7 +133,10 @@ in with html; [ })) (it "renders on / off attrs" ({ - actual = toString (tag "p" {on = true; off = false;}); + actual = toString (tag "p" { + on = true; + off = false; + }); expected = "
"; })) diff --git a/testing/import.nix b/testing/import.nix index eaf4ede..f3d3cc7 100644 --- a/testing/import.nix +++ b/testing/import.nix @@ -1,6 +1,7 @@ path: -builtins.trace ("testing " + builtins.baseNameOf path) '' - echo - echo 'TEST: ${builtins.baseNameOf path}' - echo -'' + builtins.concatStringsSep "\n" (import path) +builtins.trace ("testing " + builtins.baseNameOf path) + +{ + inherit path; + results = (import path); +} diff --git a/testing/it.nix b/testing/it.nix index 5205845..a3cb9d0 100644 --- a/testing/it.nix +++ b/testing/it.nix @@ -33,12 +33,9 @@ let success = if throws then (builtins.tryEval actual).success == false else (a == e); -in if success then '' - echo 'it ${msg}' -'' else - builtins.trace "FAILED ${msg}" (let file = builtins.toFile "value" out; - in '' - echo FAILED ${msg} - echo '${file}' - cat '${file}' | jq '.' - '') +in { + inherit success msg; +} // (if success then + { } +else + builtins.trace "FAILED ${msg}" { inherit actual expected; }) diff --git a/testing/md.test.nix b/testing/md.test.nix index c6d53c6..c2b58e7 100644 --- a/testing/md.test.nix +++ b/testing/md.test.nix @@ -34,7 +34,7 @@ in with md; [ ''; expected = { matched = true; - block = elems.List ["something"]; + block = elems.List [ "something" ]; }; asJSON = true; })) @@ -46,10 +46,7 @@ in with md; [ ''; expected = { matched = true; - block = elems.List [ - "something" - "something else" - ]; + block = elems.List [ "something" "something else" ]; }; asJSON = true; })) @@ -62,10 +59,22 @@ in with md; [ expected = { matched = true; block = elems.List [ - [(elems.input {type = "checkbox"; disabled = true; checked = false; } "") - "something"] - [(elems.input {type = "checkbox"; disabled = true; checked = true; } "") - "something else"] + [ + (elems.input { + type = "checkbox"; + disabled = true; + checked = false; + } "") + "something" + ] + [ + (elems.input { + type = "checkbox"; + disabled = true; + checked = true; + } "") + "something else" + ] ]; }; asJSON = true; @@ -77,10 +86,7 @@ in with md; [ - something else''; expected = { matched = true; - block = elems.List [ - "something" - "something else" - ]; + block = elems.List [ "something" "something else" ]; }; asJSON = true; })) diff --git a/testing/run.nix b/testing/run.nix index 0e54bb7..7c214bb 100644 --- a/testing/run.nix +++ b/testing/run.nix @@ -1,5 +1,16 @@ -pkgs: -let test = import ./import.nix; -in files: -(pkgs.writeShellScriptBin "test" - (builtins.concatStringsSep "\n" (map test files))) +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 +'') diff --git a/testing/watch.nix b/testing/watch.nix new file mode 100644 index 0000000..5ac1e59 --- /dev/null +++ b/testing/watch.nix @@ -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 +'' +