Skip to content

Commit f4e7653

Browse files
committed
nix: introduce single-page tests
1 parent 8ca47b3 commit f4e7653

File tree

1 file changed

+36
-4
lines changed

1 file changed

+36
-4
lines changed

default.nix

+36-4
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

206215
nativeBuildInputs = if doPdfGeneration then [ ghostscript ] else [ ];
207216

208-
phases = [ "buildPhase" ];
217+
phases = [ "buildPhase" ] ++ lib.optionals doCheck [ "checkPhase" ];
218+
209219
buildPhase = ''
210220
set -e
211221
222+
FULL_BW="${renderBooklet fullBooklet}"
223+
224+
# Copy output Postscript into place
212225
mkdir "$out"
213226
cd "$out"
214-
ln -s ${renderBooklet fullBooklet} SSS32.ps
215-
216-
${lib.optionalString doOutputDiff "diff -C 5 ${src}/SSS32.ps SSS32.ps"}
227+
ln -s "$FULL_BW" SSS32.ps
228+
# Patch to include version
217229
sed -i 's/(revision \(.*\))/(revision \1${shortId})/' ./SSS32.ps
230+
# Produce PDF, if requested.
218231
${lib.optionalString doPdfGeneration "ps2pdf -dPDFSETTINGS=/prepress SSS32.ps"}
219232
'';
233+
234+
checkPhase = toString
235+
(map
236+
(page: "ghostscriptTest ${checkSinglePage page}")
237+
fullBooklet.pages
238+
) + ''
239+
ghostscriptTest() {
240+
echo "Ghostscript testing $1"
241+
local output;
242+
if ! output="$(gs -dNOPAUSE -dNODISPLAY "$1" < /dev/null 2>&1)"; then
243+
echo "Failed to run ghostscript on $1"
244+
echo "$output"
245+
exit 1
246+
fi
247+
}
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)