From 195f8a60ae327b57145eb717f07583752629daaf Mon Sep 17 00:00:00 2001 From: tristan Date: Tue, 2 Jan 2024 09:18:30 +0000 Subject: [PATCH] extract testing lib --- flake.lock | 34 +++++++++++++++++++++++++++++++++- flake.nix | 15 ++++++++------- testing/elems.test.nix | 3 +-- testing/html.test.nix | 3 +-- testing/import.nix | 7 ------- testing/it.nix | 41 ----------------------------------------- testing/md.test.nix | 3 +-- testing/run.nix | 16 ---------------- testing/site.test.nix | 3 +-- testing/style.test.nix | 4 +--- testing/watch.nix | 10 ---------- 11 files changed, 46 insertions(+), 93 deletions(-) delete mode 100644 testing/import.nix delete mode 100644 testing/it.nix delete mode 100644 testing/run.nix delete mode 100644 testing/watch.nix diff --git a/flake.lock b/flake.lock index 1623a6b..80017ca 100644 --- a/flake.lock +++ b/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" } } }, diff --git a/flake.nix b/flake.nix index 05996ca..bff1a0b 100644 --- a/flake.nix +++ b/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"; }; }; } diff --git a/testing/elems.test.nix b/testing/elems.test.nix index 774ff37..6ada732 100644 --- a/testing/elems.test.nix +++ b/testing/elems.test.nix @@ -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"; diff --git a/testing/html.test.nix b/testing/html.test.nix index a0cb2f7..d64332b 100644 --- a/testing/html.test.nix +++ b/testing/html.test.nix @@ -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"; diff --git a/testing/import.nix b/testing/import.nix deleted file mode 100644 index f3d3cc7..0000000 --- a/testing/import.nix +++ /dev/null @@ -1,7 +0,0 @@ -path: -builtins.trace ("testing " + builtins.baseNameOf path) - -{ - inherit path; - results = (import path); -} diff --git a/testing/it.nix b/testing/it.nix deleted file mode 100644 index a3cb9d0..0000000 --- a/testing/it.nix +++ /dev/null @@ -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; }) diff --git a/testing/md.test.nix b/testing/md.test.nix index a358cf9..a35ee2e 100644 --- a/testing/md.test.nix +++ b/testing/md.test.nix @@ -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" ({ diff --git a/testing/run.nix b/testing/run.nix deleted file mode 100644 index 7c214bb..0000000 --- a/testing/run.nix +++ /dev/null @@ -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 -'') diff --git a/testing/site.test.nix b/testing/site.test.nix index 15a00d4..0c89044 100644 --- a/testing/site.test.nix +++ b/testing/site.test.nix @@ -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 = { diff --git a/testing/style.test.nix b/testing/style.test.nix index 5b0e333..a2da79b 100644 --- a/testing/style.test.nix +++ b/testing/style.test.nix @@ -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" { }); diff --git a/testing/watch.nix b/testing/watch.nix deleted file mode 100644 index dfec78d..0000000 --- a/testing/watch.nix +++ /dev/null @@ -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 -'' -