diff --git a/website/README.md b/website/README.md index 7944591..bc5ac99 100644 --- a/website/README.md +++ b/website/README.md @@ -30,6 +30,26 @@ Structured content is managed through Nix expressions, and copy is written in [C - Edit any of the files, see [repository layout](#repository-layout) for guidance +# Testing + +As a derivation, e.g. for CI: + +```bash +nix-build -A tests +``` + +In the development shell: + +```bash +run-tests +``` + +Running tests in a loop on source code changes: + +```bash +test-loop +``` + # Repository layout - [content](./content) diff --git a/website/default.nix b/website/default.nix index b8a99f4..dc4c662 100644 --- a/website/default.nix +++ b/website/default.nix @@ -14,12 +14,7 @@ let in new // { types = prev.recursiveUpdate prev.types new.types; }; lib'' = lib.extend lib'; - # TODO: update when the PR to expose `pkgs.devmode` is merged - # https://github.com/NixOS/nixpkgs/pull/354556 - devmode = pkgs.callPackage "${sources.devmode-reusable}/pkgs/by-name/de/devmode/package.nix" { - buildArgs = "${toString ./.} -A build --show-trace"; - open = "/index.html"; - }; + in rec { lib = lib''; @@ -38,11 +33,36 @@ rec { inherit (result.config) build; - shell = pkgs.mkShellNoCC { - packages = with pkgs; [ - cmark - npins - devmode - ]; - }; + shell = + let + run-tests = pkgs.writeShellApplication { + name = "run-tests"; + text = with pkgs; with lib; '' + ${getExe nix-unit} ${toString ./tests.nix} "$@" + ''; + }; + test-loop = pkgs.writeShellApplication { + name = "test-loop"; + text = with pkgs; with lib; '' + ${getExe watchexec} -w ${toString ./.} -- ${getExe nix-unit} ${toString ./tests.nix} + ''; + }; + devmode = pkgs.devmode.override { + buildArgs = "${toString ./.} -A build --show-trace"; + open = "/index.html"; + }; + in + pkgs.mkShellNoCC { + packages = [ + pkgs.npins + run-tests + test-loop + devmode + ]; + }; + + tests = with pkgs; with lib; runCommand "run-tests" { } '' + touch $out + ${getExe nix-unit} ${./tests.nix} "$@" + ''; } diff --git a/website/lib.nix b/website/lib.nix index 4b6ea34..6dcff3a 100644 --- a/website/lib.nix +++ b/website/lib.nix @@ -104,7 +104,7 @@ rec { path1 = subpath.components path1'; prefix1 = with lib; take (length path1 - 1) path1; path2 = subpath.components path2'; - prefix2 = with lib; take (length path1 - 1) path2; + prefix2 = with lib; take (length path2 - 1) path2; commonPrefixLength = with lists; findFirstIndex (i: i.fst != i.snd) diff --git a/website/npins/sources.json b/website/npins/sources.json index ebb34b2..37368b4 100644 --- a/website/npins/sources.json +++ b/website/npins/sources.json @@ -1,22 +1,22 @@ { "pins": { - "devmode-reusable": { + "nix-unit": { "type": "Git", "repository": { "type": "GitHub", - "owner": "fricklerhandwerk", - "repo": "nixpkgs" + "owner": "nix-community", + "repo": "nix-unit" }, - "branch": "refactor-devmode", - "revision": "f0746a6690939987734d6519a2e3daf28ed36d87", - "url": "https://github.com/fricklerhandwerk/nixpkgs/archive/f0746a6690939987734d6519a2e3daf28ed36d87.tar.gz", - "hash": "011kg3c2mfy7y808llpmq3hf6vv6rlazx8m11w41pnym4kwr3ivz" + "branch": "main", + "revision": "2071bbb765681ac3d8194ec560c8b27ff2a3b541", + "url": "https://github.com/nix-community/nix-unit/archive/2071bbb765681ac3d8194ec560c8b27ff2a3b541.tar.gz", + "hash": "0blz1kcmn9vnr9q3iqp2mv13hv3pdccljmmc54f8j7ybf5v0wgmp" }, "nixpkgs": { "type": "Channel", "name": "nixpkgs-unstable", - "url": "https://releases.nixos.org/nixpkgs/nixpkgs-24.11pre691017.b69de56fac8c/nixexprs.tar.xz", - "hash": "0z32pj0lh5ng2a6cn0qfmka8cynnygckn5615mkaxq2aplkvgzx3" + "url": "https://releases.nixos.org/nixpkgs/nixpkgs-25.05pre711046.8edf06bea5bc/nixexprs.tar.xz", + "hash": "1mwsn0rvfm603svrq3pca4c51zlix5gkyr4gl6pxhhq3q6xs5s8y" } }, "version": 3 diff --git a/website/tests.nix b/website/tests.nix new file mode 100644 index 0000000..5fe31b6 --- /dev/null +++ b/website/tests.nix @@ -0,0 +1,11 @@ +# tests written for running with `nix-unit` +# https://github.com/nix-community/nix-unit +let + inherit (import ./. { }) lib; +in +{ + test-relativePath = { + expr = with lib; relativePath "bar" "baz"; + expected = "./baz"; + }; +}