aboutsummaryrefslogtreecommitdiffstats
path: root/tests.nix
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-10-12 16:29:05 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-10-12 17:10:53 +0200
commitf59cd4349c974c8ab7907b4852f5dc86ce4daeed (patch)
tree7eaed9115b8ca5ae46792bbf4471bf007480d174 /tests.nix
parent29d9251b15d56f66d06551e158e992ace1856110 (diff)
add doc tests
Diffstat (limited to 'tests.nix')
-rw-r--r--tests.nix83
1 files changed, 83 insertions, 0 deletions
diff --git a/tests.nix b/tests.nix
new file mode 100644
index 0000000..c7955fb
--- /dev/null
+++ b/tests.nix
@@ -0,0 +1,83 @@
+{ pkgs ? import sources.nixpkgs { overlays = [ (import ./pkgs { }) ]; }
+, sources ? import ./nix/sources.nix
+}:
+let
+ haskellPackages = pkgs.haskell.packages.ghc98;
+ makeDocTest = n: i: (import (sources.nixpkgs + "/nixos/lib") { }).runTest {
+ name = "doc-test-${n}";
+ imports = [{
+ nodes =
+ {
+ machine = { lib, pkgs, nodes, ... }: {
+ environment.systemPackages = [ ];
+ systemd.services.backend.wantedBy = [ "multi-user.target" ];
+ systemd.services.backend.preStart = ''
+ export HOME=$(mktemp -d)
+ ${pkgs.git}/bin/git config --global user.email "you@example.com"
+ ${pkgs.git}/bin/git config --global user.name "Your Name"
+ ${pkgs.git}/bin/git init
+ ${pkgs.git}/bin/git commit -m init --allow-empty
+ '';
+ systemd.services.backend.script = ''
+ UUID_SEED=0 ${haskellPackages.backend}/bin/backend serve .
+ '';
+ };
+ };
+ testScript = ''
+ start_all();
+ machine.wait_for_unit("backend");
+ machine.succeed("${pkgs.bash}/bin/bash ${makeDocTestScript n i}");
+ '';
+
+ }];
+ hostPkgs = pkgs;
+ defaults.networking.firewall.enable = false;
+ };
+ makeDocTestScript = n: i: pkgs.runCommand "doc-test-script-${n}" { } ''
+ set -efu
+ export PATH=${pkgs.lib.makeBinPath [
+ pkgs.coreutils
+ pkgs.glow
+ pkgs.jq
+ pkgs.pandoc
+ ]}
+ (
+ cat <<'EOF'
+ set -efux
+ readonly tmp=$(mktemp -d)
+ trap 'rm -rf "$tmp"' EXIT
+ cd "$tmp"
+ export ACMS_CONTENT=$PWD/content # TODO
+ export PATH=${pkgs.lib.makeBinPath [
+ haskellPackages.cli
+ pkgs.jq
+ ]}''${PATH+:$PATH}
+ EOF
+ cat ${i} | pandoc --to json | jq -c '
+ .blocks | map(select(.t == "CodeBlock") | .c |
+ {
+ t: .[0].[1].[0],
+ v: .[1]
+ }
+ ) | .[]
+ ' | while read -r l; do
+ t=$(echo "$l" | jq -r .t)
+ v=$(echo "$l" | jq -r .v)
+ if test "$t" = console; then
+ cat <<EOF
+ LASTOUT=\$(
+ $v
+ )
+ EOF
+ else
+ cat <<EOF
+ test "\$LASTOUT" = '$v'
+ EOF
+ fi
+ done
+ ) > $out
+ '';
+in
+{
+ get-started-cli = makeDocTest "get-started-cli" ./docs/get-started-cli.md;
+}