From f4e7653e8f255bc61d58cf69bf5412b00a782b12 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Tue, 25 Jul 2023 17:37:55 +0000 Subject: [PATCH] nix: introduce single-page tests --- default.nix | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/default.nix b/default.nix index 0ed484d..21ca540 100644 --- a/default.nix +++ b/default.nix @@ -4,9 +4,14 @@ , ghostscript ? pkgs.ghostscript , ref ? null , doPdfGeneration ? true + # Attempts to render every page individually to make sure the dependencies + # are set correctly. +, doCheck ? true # Checks whether the generated output matches the checked-in SSS32.ps. # When doing development you may want to shut this off to obtain the # output file that you need to check in. + # + # Has no effect if doChecks is not set. , doOutputDiff ? true }: @@ -199,23 +204,50 @@ let %%EOF ''; }; + checkSinglePage = page: renderBooklet { + name = "test-single-page.ps"; + pages = [ page ]; + }; in stdenv.mkDerivation { name = "codex32${shortId}"; nativeBuildInputs = if doPdfGeneration then [ ghostscript ] else [ ]; - phases = [ "buildPhase" ]; + phases = [ "buildPhase" ] ++ lib.optionals doCheck [ "checkPhase" ]; + buildPhase = '' set -e + FULL_BW="${renderBooklet fullBooklet}" + + # Copy output Postscript into place mkdir "$out" cd "$out" - ln -s ${renderBooklet fullBooklet} SSS32.ps - - ${lib.optionalString doOutputDiff "diff -C 5 ${src}/SSS32.ps SSS32.ps"} + ln -s "$FULL_BW" SSS32.ps + # Patch to include version sed -i 's/(revision \(.*\))/(revision \1${shortId})/' ./SSS32.ps + # Produce PDF, if requested. ${lib.optionalString doPdfGeneration "ps2pdf -dPDFSETTINGS=/prepress SSS32.ps"} ''; + + checkPhase = toString + (map + (page: "ghostscriptTest ${checkSinglePage page}") + fullBooklet.pages + ) + '' + ghostscriptTest() { + echo "Ghostscript testing $1" + local output; + if ! output="$(gs -dNOPAUSE -dNODISPLAY "$1" < /dev/null 2>&1)"; then + echo "Failed to run ghostscript on $1" + echo "$output" + exit 1 + fi + } + + ghostscriptTest "$FULL_BW" + ${lib.optionalString doOutputDiff "diff -C 5 ${src}/SSS32.ps SSS32.ps"} + ''; }