1 { lib, stdenv, buildEnv, runCommand, fetchurl, file, texlive, writeShellScript, writeText, texliveInfraOnly, texliveSmall, texliveMedium, texliveFull }:
5 mkTeXTest = lib.makeOverridable (
9 , texLive ? texliveSmall
10 , options ? "-interaction=errorstopmode"
14 }@attrs: runCommand "texlive-test-tex-${name}"
16 nativeBuildInputs = [ texLive ] ++ attrs.nativeBuildInputs or [ ];
17 text = builtins.toFile "${name}.tex" text;
18 } // builtins.removeAttrs attrs [ "nativeBuildInputs" "text" "texLive" ])
20 export HOME="$(mktemp -d)"
23 cp "$text" "$name.tex"
25 $format $options "$name.tex"
30 tlpdbNix = runCommand "texlive-test-tlpdb-nix" {
31 nixpkgsTlpdbNix = ../../tools/typesetting/tex/texlive/tlpdb.nix;
32 tlpdbNix = texlive.tlpdb.nix;
36 diff -u "''${nixpkgsTlpdbNix}" "''${tlpdbNix}" | tee "$out/tlpdb.nix.patch"
39 # test two completely different font discovery mechanisms, both of which were once broken:
40 # - lualatex uses its own luaotfload script (#220228)
41 # - xelatex uses fontconfig (#228196)
42 opentype-fonts = lib.recurseIntoAttrs rec {
43 lualatex = mkTeXTest {
44 name = "opentype-fonts-lualatex";
46 texLive = texliveSmall.withPackages (ps: [ ps.libertinus-fonts ]);
48 \documentclass{article}
50 \setmainfont{Libertinus Serif}
56 xelatex = lualatex.override {
57 name = "opentype-fonts-xelatex";
62 chktex = runCommand "texlive-test-chktex" {
64 (texlive.withPackages (ps: [ ps.chktex ]))
66 input = builtins.toFile "chktex-sample.tex" ''
67 \documentclass{article}
73 chktex -v -nall -w1 "$input" 2>&1 | tee "$out"
74 grep "One warning printed" "$out"
77 dvipng = lib.recurseIntoAttrs {
78 # https://github.com/NixOS/nixpkgs/issues/75605
79 basic = runCommand "texlive-test-dvipng-basic" {
80 nativeBuildInputs = [ file texliveMedium ];
82 name = "test_dvipng.tex";
83 url = "http://git.savannah.nongnu.org/cgit/dvipng.git/plain/test_dvipng.tex?id=b872753590a18605260078f56cbd6f28d39dc035";
84 sha256 = "1pjpf1jvwj2pv5crzdgcrzvbmn7kfmgxa39pcvskl4pa0c9hl88n";
87 cp "$input" ./document.tex
90 dvipng -T tight -strict -picky document.dvi
91 for f in document*.png; do
92 file "$f" | tee output
97 mv document*.png "$out"/
100 # test dvipng's limited capability to render postscript specials via GS
101 ghostscript = runCommand "texlive-test-ghostscript" {
102 nativeBuildInputs = [ file (texliveSmall.withPackages (ps: [ ps.dvipng ])) ];
103 input = builtins.toFile "postscript-sample.tex" ''
104 \documentclass{minimal}
118 gs_trap = writeShellScript "gs_trap.sh" ''
123 export PATH=$PWD:$PATH
124 # check that the trap works
127 cp "$input" ./document.tex
130 dvipng -T 1in,1in -strict -picky document.dvi
131 for f in document*.png; do
132 file "$f" | tee output
137 mv document*.png "$out"/
141 # https://github.com/NixOS/nixpkgs/issues/75070
142 dvisvgm = runCommand "texlive-test-dvisvgm" {
143 nativeBuildInputs = [ file texliveMedium ];
144 input = builtins.toFile "dvisvgm-sample.tex" ''
145 \documentclass{article}
151 cp "$input" ./document.tex
154 dvisvgm document.dvi -n -o document_dvi.svg
156 file document_dvi.svg | grep SVG
158 pdflatex document.tex
159 dvisvgm -P document.pdf -n -o document_pdf.svg
161 file document_pdf.svg | grep SVG
164 mv document*.svg "$out"/
167 texdoc = runCommand "texlive-test-texdoc" {
168 nativeBuildInputs = [
169 (texlive.withPackages (ps: with ps; [ luatex ps.texdoc ps.texdoc.texdoc ]))
174 texdoc --debug --list texdoc | tee "$out"
175 grep texdoc.pdf "$out"
178 # check that the default language is US English
179 defaultLanguage = lib.recurseIntoAttrs rec {
182 name = "default-language-etex";
186 \ifnum\language=\lang@USenglish \message{[tests.texlive] Default language is US English.}
187 \else\errmessage{[tests.texlive] Error: default language is NOT US English.}\fi
188 \ifnum\language=0\message{[tests.texlive] Default language has id 0.}
189 \else\errmessage{[tests.texlive] Error: default language does NOT have id 0.}\fi
195 name = "default-language-latex";
199 \ifnum\language=\l@USenglish \GenericWarning{}{[tests.texlive] Default language is US English}
200 \else\GenericError{}{[tests.texlive] Error: default language is NOT US English}{}{}\fi
201 \ifnum\language=0\GenericWarning{}{[tests.texlive] Default language has id 0}
202 \else\GenericError{}{[tests.texlive] Error: default language does NOT have id 0}{}{}\fi
207 luatex = etex.override {
208 name = "default-language-luatex";
213 # check that all languages are available, including synonyms
214 allLanguages = let hyphenBase = texlive.pkgs.hyphen-base; texLive = texliveFull; in
215 lib.recurseIntoAttrs {
218 name = "all-languages-etex";
220 inherit hyphenBase texLive;
225 \ifcsname lang@#1\endcsname\message{[tests.texlive] Found language #1}
226 \else\errmessage{[tests.texlive] Error: missing language #1}\fi
228 \comma@parse{@texLanguages@}\CheckLang
232 texLanguages="$(sed -n -E 's/^\\addlanguage\s*\{([^}]+)\}.*$/\1/p' < "$hyphenBase"/tex/generic/config/language.def)"
233 texLanguages="''${texLanguages//$'\n'/,}"
234 substituteInPlace "$name.tex" --subst-var texLanguages
239 name = "all-languages-latex";
241 inherit hyphenBase texLive;
244 \@for\Lang:=italian,@texLanguages@\do{
245 \ifcsname l@\Lang\endcsname
246 \GenericWarning{}{[tests.texlive] Found language \Lang}
248 \GenericError{}{[tests.texlive] Error: missing language \Lang}{}{}
254 texLanguages="$(sed -n -E 's/^([^%= \t]+).*$/\1/p' < "$hyphenBase"/tex/generic/config/language.dat)"
255 texLanguages="''${texLanguages//$'\n'/,}"
256 substituteInPlace "$name.tex" --subst-var texLanguages
261 name = "all-languages-luatex";
263 inherit hyphenBase texLive;
266 require('luatex-hyphen.lua')
267 langs = '@texLanguages@,'
268 texio.write('\string\n')
269 for l in langs:gmatch('([^,]+),') do
270 if luatexhyphen.lookupname(l) \string~= nil then
271 texio.write('[tests.texlive] Found language '..l..'.\string\n')
273 error('[tests.texlive] Error: missing language '..l..'.', 2)
280 texLanguages="$(sed -n -E 's/^.*\[("|'\''')(.*)("|'\''')].*$/\2/p' < "$hyphenBase"/tex/generic/config/language.dat.lua)"
281 texLanguages="''${texLanguages//$'\n'/,}"
282 substituteInPlace "$name.tex" --subst-var texLanguages
287 # test that language files are generated as expected
288 hyphen-base = runCommand "texlive-test-hyphen-base" {
289 hyphenBase = texlive.pkgs.hyphen-base;
290 schemeFull = texliveFull;
291 schemeInfraOnly = texliveInfraOnly;
293 mkdir -p "$out"/{scheme-infraonly,scheme-full}
295 # create language files with no hyphenation patterns
296 cat "$hyphenBase"/tex/generic/config/language.us >language.dat
297 cat "$hyphenBase"/tex/generic/config/language.us.def >language.def
298 cat "$hyphenBase"/tex/generic/config/language.us.lua >language.dat.lua
300 cat >>language.dat.lua <<EOF
304 cat >>language.def <<EOF
305 %%% No changes may be made beyond this point.
307 \uselanguage {USenglish} %%% This MUST be the last line of the file.
310 for fname in language.{dat,def,dat.lua} ; do
311 diff --ignore-matching-lines='^\(%\|--\) Generated by ' -u \
312 {"$hyphenBase","$schemeFull"/share/texmf-var}/tex/generic/config/"$fname" \
313 | tee "$out/scheme-full/$fname.patch"
314 diff --ignore-matching-lines='^\(%\|--\) Generated by ' -u \
315 {,"$schemeInfraOnly"/share/texmf-var/tex/generic/config/}"$fname" \
316 | tee "$out/scheme-infraonly/$fname.patch"
320 # test that fmtutil.cnf is fully regenerated on scheme-full
321 fmtutilCnf = runCommand "texlive-test-fmtutil.cnf" {
322 kpathsea = texlive.pkgs.kpathsea.tex;
323 schemeFull = texliveFull;
327 diff --ignore-matching-lines='^# Generated by ' -u \
328 {"$kpathsea","$schemeFull"/share/texmf-var}/web2c/fmtutil.cnf \
329 | tee "$out/fmtutil.cnf.patch"
332 # verify that the restricted mode gets enabled when
333 # needed (detected by checking if it disallows --gscmd)
334 repstopdf = runCommand "texlive-test-repstopdf" {
335 nativeBuildInputs = [ (texlive.withPackages (ps: [ ps.epstopdf ])) ];
337 ! (epstopdf --gscmd echo /dev/null 2>&1 || true) | grep forbidden >/dev/null
338 (repstopdf --gscmd echo /dev/null 2>&1 || true) | grep forbidden >/dev/null
342 # verify that the restricted mode gets enabled when
343 # needed (detected by checking if it disallows --gscmd)
344 rpdfcrop = runCommand "texlive-test-rpdfcrop" {
345 nativeBuildInputs = [ (texlive.withPackages (ps: [ ps.pdfcrop ])) ];
347 ! (pdfcrop --gscmd echo $(command -v pdfcrop) 2>&1 || true) | grep 'restricted mode' >/dev/null
348 (rpdfcrop --gscmd echo $(command -v pdfcrop) 2>&1 || true) | grep 'restricted mode' >/dev/null
352 # check that all binaries run successfully, in the following sense:
353 # (1) run --version, -v, --help, -h successfully; or
354 # (2) run --help, -h, or no argument with error code but show help text; or
355 # (3) run successfully on a test.tex or similar file
356 # we ignore the binaries that cannot be tested as above, and are either
357 # compiled binaries or trivial shell wrappers
359 # TODO known broken binaries
361 # *.inc files in source container rather than run
364 # 'Error initialising QuantumRenderer: no suitable pipeline found'
366 ] ++ lib.optional stdenv.isDarwin "epspdftk"; # wish shebang is a script, not a binary!
368 # (1) binaries requiring -v
369 shortVersion = [ "devnag" "diadia" "pmxchords" "ptex2pdf" "simpdftex" "ttf2afm" ];
370 # (1) binaries requiring --help or -h
371 help = [ "arlatex" "bundledoc" "cachepic" "checklistings" "dvipos" "extractres" "fig4latex" "fragmaster"
372 "kpsewhere" "latex-git-log" "ltxfileinfo" "mendex" "perltex" "pn2pdf" "psbook" "psnup" "psresize" "purifyeps"
373 "simpdftex" "tex2xindy" "texluac" "texluajitc" "upmendex" "urlbst" "yplan" ];
374 shortHelp = [ "adhocfilelist" "authorindex" "bbl2bib" "bibdoiadd" "bibmradd" "biburl2doi" "bibzbladd" "ctanupload"
375 "disdvi" "dvibook" "dviconcat" "getmapdl" "latex2man" "listings-ext.sh" "pygmentex" ];
376 # (2) binaries that return non-zero exit code even if correctly asked for help
377 ignoreExitCode = [ "authorindex" "dvibook" "dviconcat" "dvipos" "extractres" "fig4latex" "fragmaster" "latex2man"
378 "latex-git-log" "listings-ext.sh" "psbook" "psnup" "psresize" "purifyeps" "tex2xindy" "texluac"
380 # (2) binaries that print help on no argument, returning non-zero exit code
381 noArg = [ "a2ping" "bg5+latex" "bg5+pdflatex" "bg5latex" "bg5pdflatex" "cef5latex" "cef5pdflatex" "ceflatex"
382 "cefpdflatex" "cefslatex" "cefspdflatex" "chkdvifont" "dvi2fax" "dvired" "dviselect" "dvitodvi" "epsffit"
383 "findhyph" "gbklatex" "gbkpdflatex" "komkindex" "kpsepath" "listbib" "listings-ext" "mag" "mathspic" "mf2pt1"
384 "mk4ht" "mkt1font" "mkgrkindex" "musixflx" "pdf2ps" "pdfclose" "pdftosrc" "pdfxup" "pedigree" "pfb2pfa" "pk2bm"
385 "prepmx" "ps2pk" "psselect" "pstops" "rubibtex" "rubikrotation" "sjislatex" "sjispdflatex" "srcredact" "t4ht"
386 "teckit_compile" "tex4ht" "texdiff" "texdirflatten" "texplate" "tie" "ttf2kotexfont" "ttfdump" "vlna" "vpl2ovp"
388 # (3) binaries requiring a .tex file
389 contextTest = [ "htcontext" ];
390 latexTest = [ "de-macro" "e2pall" "htlatex" "htxelatex" "makeindex" "pslatex" "rumakeindex" "tpic2pdftex"
391 "wordcount" "xhlatex" ];
392 texTest = [ "fontinst" "htmex" "httex" "httexi" "htxetex" ];
393 # tricky binaries or scripts that are obviously working but are hard to test
394 # (e.g. because they expect user input no matter the arguments)
395 # (printafm comes from ghostscript, not texlive)
398 "dt2dv" "dv2dt" "dvi2tty" "dvidvi" "dvispc" "otp2ocp" "outocp" "pmxab"
400 # GUI scripts that accept no argument or crash without a graphics server; please test manualy
401 "epspdftk" "texdoctk" "tlshell" "xasy"
403 # requires Cinderella, not open source and not distributed via Nixpkgs
406 # binaries that need a combined scheme and cannot work standalone
408 # pfarrei: require working kpse to find lua module
411 # bibexport: requires kpsewhich
414 # crossrefware: require bibtexperllibs under TEXMFROOT
415 "bbl2bib" "bibdoiadd" "bibmradd" "biburl2doi" "bibzbladd" "checkcites" "ltx2crossrefxml"
417 # require other texlive binaries in PATH
418 "allcm" "allec" "chkweb" "fontinst" "ht*" "installfont-tl" "kanji-config-updmap-sys" "kanji-config-updmap-user"
419 "kpse*" "latexfileversion" "mkocp" "mkofm" "mtxrunjit" "pdftex-quiet" "pslatex" "rumakeindex" "texconfig"
420 "texconfig-sys" "texexec" "texlinks" "texmfstart" "typeoutfileinfo" "wordcount" "xdvi" "xhlatex"
422 # misc luatex binaries searching for luatex in PATH
423 "citeproc-lua" "context" "contextjit" "ctanbib" "digestif" "epspdf" "l3build" "luafindfont" "luaotfload-tool"
424 "luatools" "make4ht" "pmxchords" "tex4ebook" "texdoc" "texlogsieve" "xindex"
426 # requires full TEXMFROOT (e.g. for config)
427 "mktexfmt" "mktexmf" "mktexpk" "mktextfm" "psnup" "psresize" "pstops" "tlmgr" "updmap" "webquiz"
429 # texlive-scripts: requires texlive.infra's TeXLive::TLUtils under TEXMFROOT
430 "fmtutil" "fmtutil-sys" "fmtutil-user"
432 # texlive-scripts: not used in nixpkgs, need updmap in PATH
433 "updmap-sys" "updmap-user"
437 contextTestTex = writeText "context-test.tex" ''
442 latexTestTex = writeText "latex-test.tex" ''
443 \documentclass{article}
448 texTestTex = writeText "tex-test.tex" ''
453 # link all binaries in single derivation
454 binPackages = lib.catAttrs "out" (lib.attrValues texlive.pkgs);
455 binaries = buildEnv { name = "texlive-binaries"; paths = binPackages; };
457 runCommand "texlive-test-binaries"
459 inherit binaries contextTestTex latexTestTex texTestTex;
460 texliveScheme = texliveFull;
463 loadables="$(command -v bash)"
464 loadables="''${loadables%/bin/bash}/lib/bash"
465 enable -f "$loadables/realpath" realpath
467 export HOME="$(mktemp -d)"
468 declare -i binCount=0 ignoredCount=0 brokenCount=0 failedCount=0
469 cp "$contextTestTex" context-test.tex
470 cp "$latexTestTex" latex-test.tex
471 cp "$texTestTex" tex-test.tex
474 path="$(realpath "$bin")"
476 if [[ -z "$ignoreExitCode" ]] ; then
477 PATH="$path" "$bin" $args >"$out/$base.log" 2>&1
479 if [[ $ret == 0 ]] && grep -i 'command not found' "$out/$base.log" >/dev/null ; then
480 echo "command not found when running '$base''${args:+ $args}'"
485 PATH="$path" "$bin" $args >"$out/$base.log" 2>&1
487 if [[ $ret == 0 ]] && grep -i 'command not found' "$out/$base.log" >/dev/null ; then
488 echo "command not found when running '$base''${args:+ $args}'"
491 if ! grep -Ei '(Example:|Options:|Syntax:|Usage:|improper command|SYNOPSIS)' "$out/$base.log" >/dev/null ; then
492 echo "did not find usage info when running '$base''${args:+ $args}'"
498 for bin in "$binaries"/bin/* ; do
502 binCount=$((binCount + 1))
504 ${lib.concatStringsSep "|" ignored})
505 ignoredCount=$((ignoredCount + 1))
507 ${lib.concatStringsSep "|" broken})
508 brokenCount=$((brokenCount + 1))
510 ${lib.concatStringsSep "|" help})
512 ${lib.concatStringsSep "|" shortHelp})
514 ${lib.concatStringsSep "|" noArg})
516 ${lib.concatStringsSep "|" contextTest})
517 args=context-test.tex ;;
518 ${lib.concatStringsSep "|" latexTest})
519 args=latex-test.tex ;;
520 ${lib.concatStringsSep "|" texTest})
522 ${lib.concatStringsSep "|" shortVersion})
528 args='latex latex-test.tex' ;;
530 args='--help --help --help' ;;
538 ${lib.concatStringsSep "|" (ignoreExitCode ++ noArg)})
543 ${lib.concatStringsSep "|" needScheme})
544 bin="$texliveScheme/bin/$base"
545 if [[ ! -f "$bin" ]] ; then
546 ignoredCount=$((ignoredCount + 1))
551 if testBin ; then : ; else # preserve exit code
552 echo "failed '$base''${args:+ $args}' (exit code: $?)"
553 sed 's/^/ > /' < "$out/$base.log"
554 failedCount=$((failedCount + 1))
558 echo "tested $binCount binaries: $ignoredCount ignored, $brokenCount broken, $failedCount failed"
559 [[ $failedCount = 0 ]]
562 # check that all scripts have a Nix shebang
564 binPackages = lib.catAttrs "out" (lib.attrValues texlive.pkgs);
566 runCommand "texlive-test-shebangs" { }
568 echo "checking that all texlive scripts shebangs are in '$NIX_STORE'"
569 declare -i scriptCount=0 invalidCount=0
571 (lib.concatMapStrings
573 for bin in '${pkg.outPath}'/bin/* ; do
574 grep -I -q . "$bin" || continue # ignore binary files
575 scriptCount=$((scriptCount + 1))
576 read -r cmdline < "$bin"
577 read -r interp <<< "$cmdline"
578 if [[ "$interp" != "#!$NIX_STORE"/* && "$interp" != "#! $NIX_STORE"/* ]] ; then
579 echo "error: non-nix shebang '$interp' in script '$bin'"
580 invalidCount=$((invalidCount + 1))
586 echo "checked $scriptCount scripts, found $invalidCount non-nix shebangs"
587 [[ $invalidCount -gt 0 ]] && exit 1
592 # verify that the precomputed licensing information in default.nix
593 # does indeed match the metadata of the individual packages.
595 # This is part of the test suite (and not the normal evaluation) to save
596 # time for "normal" evaluations. To be more in line with the other tests, this
597 # also builds a derivation, even though it is essentially an eval-time assertion.
600 concatLicenses = builtins.foldl' (acc: el: if builtins.elem el acc then acc else acc ++ [ el ]);
601 # converts a license to its attribute name in lib.licenses
602 licenseToAttrName = license:
603 builtins.head (builtins.attrNames
604 (lib.filterAttrs (n: v: license == v) lib.licenses));
607 savedLicenses = scheme: scheme.meta.license;
608 savedLicensesAttrNames = scheme: map licenseToAttrName (savedLicenses scheme);
610 correctLicenses = scheme: builtins.foldl'
611 (acc: pkg: concatLicenses acc (lib.toList (pkg.meta.license or [])))
613 scheme.passthru.requiredTeXPackages;
614 correctLicensesAttrNames = scheme:
616 (map licenseToAttrName (correctLicenses scheme));
618 hasLicenseMismatch = scheme:
619 (lib.isDerivation scheme) &&
620 (savedLicensesAttrNames scheme) != (correctLicensesAttrNames scheme);
621 incorrectSchemes = lib.filterAttrs
622 (n: hasLicenseMismatch)
623 (texlive.combined // texlive.schemes);
624 prettyPrint = name: scheme:
626 license info for ${name} is incorrect! Note that order is enforced.
627 saved: [ ${lib.concatStringsSep " " (savedLicensesAttrNames scheme)} ]
628 correct: [ ${lib.concatStringsSep " " (correctLicensesAttrNames scheme)} ]
630 errorText = lib.concatStringsSep "\n\n" (lib.mapAttrsToList prettyPrint incorrectSchemes);
632 runCommand "texlive-test-license" {
635 (if (incorrectSchemes == {})
636 then "echo everything is fine! > $out"
642 # verify that all fixed hashes are present
643 # this is effectively an eval-time assertion, converted into a derivation for
645 fixedHashes = with lib; let
647 (p: lib.optional (p ? tex && isDerivation p.tex) p.tex
648 ++ lib.optional (p ? texdoc) p.texdoc
649 ++ lib.optional (p ? texsource) p.texsource
650 ++ lib.optional (p ? tlpkg) p.tlpkg)
651 (attrValues texlive.pkgs);
652 errorText = concatMapStrings (p: optionalString (! p ? outputHash) "${p.pname}-${p.tlOutputName} does not have a fixed output hash\n") fods;
653 in runCommand "texlive-test-fixed-hashes" {
655 passAsFile = [ "errorText" ];
657 if [[ -s "$errorTextPath" ]] ; then
659 echo Failed: some TeX Live packages do not have fixed output hashes. Please read UPGRADING.md for how to generate a new fixed-hashes.nix.