forked from Fediversity/Fediversity
set up expression-level tests
This commit is contained in:
parent
22c7c3091f
commit
a8dcc9f298
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
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} "$@"
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
11
website/tests.nix
Normal file
11
website/tests.nix
Normal file
|
@ -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";
|
||||
};
|
||||
}
|
Loading…
Reference in a new issue