Skip to content

Commit 81509d7

Browse files
committed
nix: introduce single-page tests
1 parent 88cceb2 commit 81509d7

File tree

1 file changed

+37
-5
lines changed

1 file changed

+37
-5
lines changed

default.nix

+37-5
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@
44
, ghostscript ? pkgs.ghostscript
55
, ref ? null
66
, doPdfGeneration ? true
7+
# Attempts to render every page individually to make sure the dependencies
8+
# are set correctly.
9+
, doCheck ? true
710
# Checks whether the generated output matches the checked-in SSS32.ps.
811
# When doing development you may want to shut this off to obtain the
912
# output file that you need to check in.
13+
#
14+
# Has no effect if doChecks is not set.
1015
, doOutputDiff ? true
1116
}:
1217

@@ -199,23 +204,50 @@ let
199204
%%EOF
200205
'';
201206
};
207+
checkSinglePage = page: renderBooklet {
208+
name = "test-single-page.ps";
209+
pages = [ page ];
210+
};
202211
in
203212
stdenv.mkDerivation {
204213
name = "codex32${shortId}";
205214

206-
buildInputs = if doPdfGeneration then [ ghostscript ] else [ ];
215+
buildInputs = if doCheck || doPdfGeneration then [ ghostscript ] else [ ];
216+
217+
phases = [ "buildPhase" ] ++ lib.optionals doCheck [ "checkPhase" ];
207218

208-
phases = [ "buildPhase" ];
209219
buildPhase = ''
210220
set -e
211221
222+
ghostscriptTest() {
223+
echo "Ghostscript testing $1"
224+
local output;
225+
if ! output="$(gs -dNOPAUSE -dNODISPLAY "$1" < /dev/null 2>&1)"; then
226+
echo "Failed to run ghostscript on $1"
227+
echo "$output"
228+
exit 1
229+
fi
230+
}
231+
232+
FULL_BW="${renderBooklet fullBooklet}"
233+
234+
# Copy output Postscript into place
212235
mkdir "$out"
213236
cd "$out"
214-
cp ${renderBooklet fullBooklet} SSS32.ps
215-
216-
${lib.optionalString doOutputDiff "diff -C 5 ${src}/SSS32.ps SSS32.ps"}
237+
cp "$FULL_BW" SSS32.ps
238+
# Patch to include version
217239
sed -i 's/(revision \(.*\))/(revision \1${shortId})/' ./SSS32.ps
240+
# Produce PDF, if requested.
218241
${lib.optionalString doPdfGeneration "ps2pdf -dPDFSETTINGS=/prepress SSS32.ps"}
219242
'';
243+
244+
checkPhase = toString
245+
(map
246+
(page: "ghostscriptTest ${checkSinglePage page}")
247+
fullBooklet.pages
248+
) + ''
249+
ghostscriptTest "$FULL_BW"
250+
${lib.optionalString doOutputDiff "diff -C 5 ${src}/SSS32.ps SSS32.ps"}
251+
'';
220252
}
221253

0 commit comments

Comments
 (0)