From 81509d78225d4d3c546d0767ec5a2d1f7af4ec89 Mon Sep 17 00:00:00 2001 From: Andrew Poelstra Date: Mon, 20 Mar 2023 22:04:12 +0000 Subject: [PATCH] nix: introduce single-page tests --- default.nix | 42 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 37 insertions(+), 5 deletions(-) diff --git a/default.nix b/default.nix index 0dab52e..6bf2827 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}"; - buildInputs = if doPdfGeneration then [ ghostscript ] else [ ]; + buildInputs = if doCheck || doPdfGeneration then [ ghostscript ] else [ ]; + + phases = [ "buildPhase" ] ++ lib.optionals doCheck [ "checkPhase" ]; - phases = [ "buildPhase" ]; buildPhase = '' set -e + 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 + } + + FULL_BW="${renderBooklet fullBooklet}" + + # Copy output Postscript into place mkdir "$out" cd "$out" - cp ${renderBooklet fullBooklet} SSS32.ps - - ${lib.optionalString doOutputDiff "diff -C 5 ${src}/SSS32.ps SSS32.ps"} + cp "$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 "$FULL_BW" + ${lib.optionalString doOutputDiff "diff -C 5 ${src}/SSS32.ps SSS32.ps"} + ''; }