1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
|
{
lib,
stdenv,
buildEnv,
runCommand,
fetchurl,
file,
texlive,
writeShellScript,
writeText,
texliveInfraOnly,
texliveConTeXt,
texliveSmall,
texliveMedium,
texliveFull,
}:
rec {
mkTeXTest = lib.makeOverridable (
{
name,
format,
text,
texLive ? texliveSmall,
options ? "-interaction=errorstopmode",
preTest ? "",
postTest ? "",
...
}@attrs:
runCommand "texlive-test-tex-${name}"
(
{
nativeBuildInputs = [ texLive ] ++ attrs.nativeBuildInputs or [ ];
text = builtins.toFile "${name}.tex" text;
}
// removeAttrs attrs [
"nativeBuildInputs"
"text"
"texLive"
]
)
''
export HOME="$(mktemp -d)"
mkdir "$out"
cd "$out"
cp "$text" "$name.tex"
${preTest}
$format $options "$name.tex"
${postTest}
''
);
tlpdbNix =
runCommand "texlive-test-tlpdb-nix"
{
nixpkgsTlpdbNix = ../../tools/typesetting/tex/texlive/tlpdb.nix;
tlpdbNix = texlive.tlpdb.nix;
}
''
mkdir -p "$out"
diff -u "''${nixpkgsTlpdbNix}" "''${tlpdbNix}" | tee "$out/tlpdb.nix.patch"
'';
# test two completely different font discovery mechanisms, both of which were once broken:
# - lualatex uses its own luaotfload script (#220228)
# - xelatex uses fontconfig (#228196)
opentype-fonts = lib.recurseIntoAttrs rec {
lualatex = mkTeXTest {
name = "opentype-fonts-lualatex";
format = "lualatex";
texLive = texliveSmall.withPackages (ps: [ ps.libertinus-fonts ]);
text = ''
\documentclass{article}
\usepackage{fontspec}
\setmainfont{Libertinus Serif}
\begin{document}
\LaTeX{} is great
\end{document}
'';
};
xelatex = lualatex.override {
name = "opentype-fonts-xelatex";
format = "xelatex";
};
};
chktex =
runCommand "texlive-test-chktex"
{
nativeBuildInputs = [
(texlive.withPackages (ps: [ ps.chktex ]))
];
input = builtins.toFile "chktex-sample.tex" ''
\documentclass{article}
\begin{document}
\LaTeX is great
\end{document}
'';
}
''
# chktex is supposed to return 2 when it (successfully) finds warnings, but no errors,
# see http://git.savannah.nongnu.org/cgit/chktex.git/commit/?id=ec0fb9b58f02a62ff0bfec98b997208e9d7a5998
(set +e; chktex -v -nall -w1 "$input" 2>&1; [ $? = 2 ] || exit 1; set -e) | tee "$out"
# also check that the output does indeed contain "One warning printed"
grep "One warning printed" "$out"
'';
context = mkTeXTest {
name = "texlive-test-context";
format = "context";
texLive = texliveConTeXt;
# check that the PDF has been created: we have hit cases of context
# failing with exit status 0 due to a misconfigured texlive
postTest = ''
if [[ ! -f "$name".pdf ]] ; then
echo "ConTeXt test failed: file '$name.pdf' not found"
exit 1
fi
'';
text = ''
\starttext
\startsection[title={ConTeXt test document}]
This is an {\em incredibly} simple ConTeXt document.
\stopsection
\stoptext
'';
};
dvipng = lib.recurseIntoAttrs {
# https://github.com/NixOS/nixpkgs/issues/75605
basic =
runCommand "texlive-test-dvipng-basic"
{
nativeBuildInputs = [
file
texliveMedium
];
input = fetchurl {
name = "test_dvipng.tex";
url = "http://git.savannah.nongnu.org/cgit/dvipng.git/plain/test_dvipng.tex?id=b872753590a18605260078f56cbd6f28d39dc035";
sha256 = "1pjpf1jvwj2pv5crzdgcrzvbmn7kfmgxa39pcvskl4pa0c9hl88n";
};
}
''
cp "$input" ./document.tex
latex document.tex
dvipng -T tight -strict -picky document.dvi
for f in document*.png; do
file "$f" | tee output
grep PNG output
done
mkdir "$out"
mv document*.png "$out"/
'';
# test dvipng's limited capability to render postscript specials via GS
ghostscript =
runCommand "texlive-test-ghostscript"
{
nativeBuildInputs = [
file
(texliveSmall.withPackages (ps: [ ps.dvipng ]))
];
input = builtins.toFile "postscript-sample.tex" ''
\documentclass{minimal}
\begin{document}
Ni
\special{ps:
newpath
0 0 moveto
7 7 rlineto
0 7 moveto
7 -7 rlineto
stroke
showpage
}
\end{document}
'';
gs_trap = writeShellScript "gs_trap.sh" ''
exit 1
'';
}
''
cp "$gs_trap" ./gs
export PATH=$PWD:$PATH
# check that the trap works
gs && exit 1
cp "$input" ./document.tex
latex document.tex
dvipng -T 1in,1in -strict -picky document.dvi
for f in document*.png; do
file "$f" | tee output
grep PNG output
done
mkdir "$out"
mv document*.png "$out"/
'';
};
# https://github.com/NixOS/nixpkgs/issues/75070
dvisvgm =
runCommand "texlive-test-dvisvgm"
{
nativeBuildInputs = [
file
texliveMedium
];
input = builtins.toFile "dvisvgm-sample.tex" ''
\documentclass{article}
\begin{document}
mwe
\end{document}
'';
}
''
cp "$input" ./document.tex
latex document.tex
dvisvgm document.dvi -n -o document_dvi.svg
cat document_dvi.svg
file document_dvi.svg | grep SVG
pdflatex document.tex
dvisvgm -P document.pdf -n -o document_pdf.svg
cat document_pdf.svg
file document_pdf.svg | grep SVG
mkdir "$out"
mv document*.svg "$out"/
'';
texdoc =
runCommand "texlive-test-texdoc"
{
nativeBuildInputs = [
((texlive.withPackages (ps: [ ps.texdoc ])).overrideAttrs { withDocs = true; })
];
}
''
texdoc --version
texdoc --debug --list texdoc | tee "$out"
grep texdoc.pdf "$out"
'';
# check that the default language is US English
defaultLanguage = lib.recurseIntoAttrs rec {
# language.def
etex = mkTeXTest {
name = "default-language-etex";
format = "etex";
text = ''
\catcode`\@=11
\ifnum\language=\lang@USenglish \message{[tests.texlive] Default language is US English.}
\else\errmessage{[tests.texlive] Error: default language is NOT US English.}\fi
\ifnum\language=0\message{[tests.texlive] Default language has id 0.}
\else\errmessage{[tests.texlive] Error: default language does NOT have id 0.}\fi
\bye
'';
};
# language.dat
latex = mkTeXTest {
name = "default-language-latex";
format = "latex";
text = ''
\makeatletter
\ifnum\language=\l@USenglish \GenericWarning{}{[tests.texlive] Default language is US English}
\else\GenericError{}{[tests.texlive] Error: default language is NOT US English}{}{}\fi
\ifnum\language=0\GenericWarning{}{[tests.texlive] Default language has id 0}
\else\GenericError{}{[tests.texlive] Error: default language does NOT have id 0}{}{}\fi
\stop
'';
};
# language.dat.lua
luatex = etex.override {
name = "default-language-luatex";
format = "luatex";
};
};
# check that all languages are available, including synonyms
allLanguages =
let
hyphenBase = texlive.pkgs.hyphen-base;
texLive = texliveFull;
in
lib.recurseIntoAttrs {
# language.def
etex = mkTeXTest {
name = "all-languages-etex";
format = "etex";
inherit hyphenBase texLive;
text = ''
\catcode`\@=11
\input kvsetkeys.sty
\def\CheckLang#1{
\ifcsname lang@#1\endcsname\message{[tests.texlive] Found language #1}
\else\errmessage{[tests.texlive] Error: missing language #1}\fi
}
\comma@parse{@texLanguages@}\CheckLang
\bye
'';
preTest = ''
texLanguages="$(sed -n -E 's/^\\addlanguage\s*\{([^}]+)\}.*$/\1/p' < "$hyphenBase"/tex/generic/config/language.def)"
texLanguages="''${texLanguages//$'\n'/,}"
substituteInPlace "$name.tex" --subst-var texLanguages
'';
};
# language.dat
latex = mkTeXTest {
name = "all-languages-latex";
format = "latex";
inherit hyphenBase texLive;
text = ''
\makeatletter
\@for\Lang:=italian,@texLanguages@\do{
\ifcsname l@\Lang\endcsname
\GenericWarning{}{[tests.texlive] Found language \Lang}
\else
\GenericError{}{[tests.texlive] Error: missing language \Lang}{}{}
\fi
}
\stop
'';
preTest = ''
texLanguages="$(sed -n -E 's/^([^%= \t]+).*$/\1/p' < "$hyphenBase"/tex/generic/config/language.dat)"
texLanguages="''${texLanguages//$'\n'/,}"
substituteInPlace "$name.tex" --subst-var texLanguages
'';
};
# language.dat.lua
luatex = mkTeXTest {
name = "all-languages-luatex";
format = "luatex";
inherit hyphenBase texLive;
text = ''
\directlua{
require('luatex-hyphen.lua')
langs = '@texLanguages@,'
texio.write('\string\n')
for l in langs:gmatch('([^,]+),') do
if luatexhyphen.lookupname(l) \string~= nil then
texio.write('[tests.texlive] Found language '..l..'.\string\n')
else
error('[tests.texlive] Error: missing language '..l..'.', 2)
end
end
}
\bye
'';
preTest = ''
texLanguages="$(sed -n -E 's/^.*\[("|'\''')(.*)("|'\''')].*$/\2/p' < "$hyphenBase"/tex/generic/config/language.dat.lua)"
texLanguages="''${texLanguages//$'\n'/,}"
substituteInPlace "$name.tex" --subst-var texLanguages
'';
};
};
# test that language files are generated as expected
hyphen-base =
runCommand "texlive-test-hyphen-base"
{
hyphenBase = texlive.pkgs.hyphen-base;
schemeFull = texliveFull;
schemeInfraOnly = texliveInfraOnly;
}
''
mkdir -p "$out"/{scheme-infraonly,scheme-full}
# create language files with no hyphenation patterns
cat "$hyphenBase"/tex/generic/config/language.us >language.dat
cat "$hyphenBase"/tex/generic/config/language.us.def >language.def
cat "$hyphenBase"/tex/generic/config/language.us.lua >language.dat.lua
cat >>language.dat.lua <<EOF
}
EOF
cat >>language.def <<EOF
%%% No changes may be made beyond this point.
\uselanguage {USenglish} %%% This MUST be the last line of the file.
EOF
for fname in language.{dat,def,dat.lua} ; do
diff --ignore-matching-lines='^\(%\|--\) Generated by ' -u \
{"$hyphenBase","$schemeFull"/share/texmf-var}/tex/generic/config/"$fname" \
| tee "$out/scheme-full/$fname.patch"
diff --ignore-matching-lines='^\(%\|--\) Generated by ' -u \
{,"$schemeInfraOnly"/share/texmf-var/tex/generic/config/}"$fname" \
| tee "$out/scheme-infraonly/$fname.patch"
done
'';
# verify that l3build works correctly
l3build =
runCommand "texlive-test-l3build"
{
nativeBuildInputs = [ (texliveSmall.withPackages (ps: [ ps.l3build ])) ];
}
''
cat >>build.lua <<EOF
module = "texlive-test-l3build"
typesetfiles = {"*.tex"}
EOF
cat >>test-l3build.tex <<EOF
\documentclass{article}
\begin{document}
l3build ran successfully.
\end{document}
EOF
l3build doc
l3build install --full --texmfhome "$out"
'';
# verify that the restricted mode gets enabled when
# needed (detected by checking if it disallows --gscmd)
repstopdf =
runCommand "texlive-test-repstopdf"
{
nativeBuildInputs = [ (texlive.withPackages (ps: [ ps.epstopdf ])) ];
}
''
! (epstopdf --gscmd echo /dev/null 2>&1 || true) | grep forbidden >/dev/null
(repstopdf --gscmd echo /dev/null 2>&1 || true) | grep forbidden >/dev/null
mkdir "$out"
'';
# verify that the restricted mode gets enabled when
# needed (detected by checking if it disallows --gscmd)
rpdfcrop =
runCommand "texlive-test-rpdfcrop"
{
nativeBuildInputs = [ (texlive.withPackages (ps: [ ps.pdfcrop ])) ];
}
''
! (pdfcrop --gscmd echo $(command -v pdfcrop) 2>&1 || true) | grep 'restricted mode' >/dev/null
(rpdfcrop --gscmd echo $(command -v pdfcrop) 2>&1 || true) | grep 'restricted mode' >/dev/null
mkdir "$out"
'';
# check that all binaries run successfully, in the following sense:
# (1) run --version, -v, --help, -h successfully; or
# (2) run --help, -h, or no argument with error code but show help text; or
# (3) run successfully on a test.tex or similar file
# we ignore the binaries that cannot be tested as above, and are either
# compiled binaries or trivial shell wrappers
binaries =
let
# TODO known broken binaries
broken = [
# do not know how to test without a valid build.lua
"ppmcheckpdf"
# 'Error initialising QuantumRenderer: no suitable pipeline found'
"tlcockpit"
]
++ lib.optional stdenv.hostPlatform.isDarwin "epspdftk"; # wish shebang is a script, not a binary!
# (1) binaries requiring -v
shortVersion = [
"devnag"
"diadia"
"pmxchords"
"ptex2pdf"
"simpdftex"
"ttf2afm"
];
# (1) binaries requiring --help or -h
help = [
"arlatex"
"bundledoc"
"cachepic"
"checklistings"
"dtxgen"
"dvipos"
"extractres"
"fig4latex"
"fragmaster"
"kpsewhere"
"latex-git-log"
"ltxfileinfo"
"mendex"
"pdflatexpicscale"
"perltex"
"pn2pdf"
"psbook"
"psnup"
"psresize"
"purifyeps"
"simpdftex"
"tex2xindy"
"texluac"
"texluajitc"
"upmendex"
"urlbst"
"yplan"
];
shortHelp = [
"adhocfilelist"
"authorindex"
"bbl2bib"
"bibdoiadd"
"bibmradd"
"biburl2doi"
"bibzbladd"
"bookshelf-listallfonts"
"bookshelf-mkfontsel"
"ctanupload"
"disdvi"
"dvibook"
"dviconcat"
"getmapdl"
"latex2man"
"listings-ext.sh"
"pygmentex"
];
# (2) binaries that return non-zero exit code even if correctly asked for help
ignoreExitCode = [
"authorindex"
"bookshelf-listallfonts"
"bookshelf-mkfontsel"
"dvibook"
"dviconcat"
"dvipos"
"extractres"
"fig4latex"
"fragmaster"
"latex2man"
"latex-git-log"
"listings-ext.sh"
"psbook"
"psnup"
"psresize"
"purifyeps"
"tex2xindy"
"texluac"
"texluajitc"
];
# (2) binaries that print help on no argument, returning non-zero exit code
noArg = [
"a2ping"
"bg5+latex"
"bg5+pdflatex"
"bg5latex"
"bg5pdflatex"
"cef5latex"
"cef5pdflatex"
"ceflatex"
"cefpdflatex"
"cefslatex"
"cefspdflatex"
"chkdvifont"
"dvi2fax"
"dvired"
"dviselect"
"dvitodvi"
"epsffit"
"findhyph"
"gbklatex"
"gbkpdflatex"
"komkindex"
"kpsepath"
"listbib"
"listings-ext"
"mag"
"mathspic"
"mf2pt1"
"mk4ht"
"mkt1font"
"mkgrkindex"
"musixflx"
"pdf2ps"
"pdfclose"
"pdftosrc"
"pdfxup"
"pedigree"
"pfb2pfa"
"pk2bm"
"prepmx"
"ps2pk"
"psselect"
"pstops"
"rubibtex"
"rubikrotation"
"sjislatex"
"sjispdflatex"
"srcredact"
"t4ht"
"teckit_compile"
"tex4ht"
"texdiff"
"texdirflatten"
"texplate"
"tie"
"ttf2kotexfont"
"ttfdump"
"vlna"
"vpl2ovp"
"vpl2vpl"
"yplan"
];
# (3) binaries requiring a .tex file
contextTest = [ "htcontext" ];
latexTest = [
"de-macro"
"e2pall"
"htlatex"
"htxelatex"
"makeindex"
"pslatex"
"rumakeindex"
"tpic2pdftex"
"wordcount"
"xhlatex"
];
texTest = [
"fontinst"
"htmex"
"httex"
"httexi"
"htxetex"
];
# tricky binaries or scripts that are obviously working but are hard to test
# (e.g. because they expect user input no matter the arguments)
# (printafm comes from ghostscript, not texlive)
ignored = [
# compiled binaries
"dt2dv"
"dv2dt"
"dvi2tty"
"dvidvi"
"dvispc"
"otp2ocp"
"outocp"
"pmxab"
# GUI scripts that accept no argument or crash without a graphics server; please test manually
"epspdftk"
"texdoctk"
"tlshell"
"xasy"
# requires Cinderella, not open source and not distributed via Nixpkgs
"ketcindy"
];
# binaries that need a combined scheme and cannot work standalone
needScheme = [
# pfarrei: require working kpse to find lua module
"a5toa4"
# show-pdf-tags: require working kpse to find lualatex and lua modules
"show-pdf-tags"
# bibexport: requires kpsewhich
"bibexport"
# crossrefware: require bibtexperllibs under TEXMFROOT
"bbl2bib"
"bibdoiadd"
"bibmradd"
"biburl2doi"
"bibzbladd"
"checkcites"
"ltx2crossrefxml"
# epstopdf: requires kpsewhich
"epstopdf"
"repstopdf"
# requires kpsewhich
"memoize-extract.pl"
"memoize-extract.py"
"git-latexdiff"
# require other texlive binaries in PATH
"allcm"
"allec"
"chkweb"
"dtxgen"
"explcheck"
"extractbb"
"fontinst"
"git-latexdiff"
"ht*"
"installfont-tl"
"kanji-config-updmap-sys"
"kanji-config-updmap-user"
"kpse*"
"latexfileversion"
"mkocp"
"mkofm"
"mtxrunjit"
"pdftex-quiet"
"pslatex"
"rumakeindex"
"runtexfile"
"texconfig"
"texconfig-sys"
"texlinks"
"texmfstart"
"typeoutfileinfo"
"wordcount"
"xdvi"
"xhlatex"
# misc luatex binaries searching for luatex in PATH
"citeproc-lua"
"context"
"contextjit"
"ctanbib"
"digestif"
"epspdf"
"l3build"
"luafindfont"
"luaotfload-tool"
"luatools"
"make4ht"
"pmxchords"
"runtexfile"
"tex4ebook"
"texblend"
"texdoc"
"texfindpkg"
"texlogsieve"
"xindex"
# requires full TEXMFROOT (e.g. for config)
"mktexfmt"
"mktexmf"
"mktexpk"
"mktextfm"
"psnup"
"psresize"
"pstops"
"tlmgr"
"updmap"
"webquiz"
# texlive-scripts: requires texlive.infra's TeXLive::TLUtils under TEXMFROOT
"fmtutil"
"fmtutil-sys"
"fmtutil-user"
# texlive-scripts: not used in nixpkgs, need updmap in PATH
"updmap-sys"
"updmap-user"
];
# simple test files
contextTestTex = writeText "context-test.tex" ''
\starttext
A simple test file.
\stoptext
'';
latexTestTex = writeText "latex-test.tex" ''
\documentclass{article}
\begin{document}
A simple test file.
\end{document}
'';
texTestTex = writeText "tex-test.tex" ''
Hello.
\bye
'';
# link all binaries in single derivation
binPackages = lib.catAttrs "out" (lib.attrValues texlive.pkgs);
binaries = buildEnv {
name = "texlive-binaries";
paths = binPackages;
};
in
runCommand "texlive-test-binaries"
{
inherit
binaries
contextTestTex
latexTestTex
texTestTex
;
texliveScheme = texliveFull;
}
''
loadables="$(command -v bash)"
loadables="''${loadables%/bin/bash}/lib/bash"
enable -f "$loadables/realpath" realpath
mkdir -p "$out"
export HOME="$(mktemp -d)"
declare -i binCount=0 ignoredCount=0 brokenCount=0 failedCount=0
cp "$contextTestTex" context-test.tex
cp "$latexTestTex" latex-test.tex
cp "$texTestTex" tex-test.tex
testBin () {
path="$(realpath "$bin")"
path="''${path##*/}"
if [[ -z "$ignoreExitCode" ]] ; then
PATH="$path" "$bin" $args >"$out/$base.log" 2>&1
ret=$?
if [[ $ret == 0 ]] && grep -i 'command not found' "$out/$base.log" >/dev/null ; then
echo "command not found when running '$base''${args:+ $args}'"
return 1
fi
return $ret
else
PATH="$path" "$bin" $args >"$out/$base.log" 2>&1
ret=$?
if [[ $ret == 0 ]] && grep -i 'command not found' "$out/$base.log" >/dev/null ; then
echo "command not found when running '$base''${args:+ $args}'"
return 1
fi
if ! grep -Ei '(Example:|Options:|Syntax:|Usage:|improper command|SYNOPSIS)' "$out/$base.log" >/dev/null ; then
echo "did not find usage info when running '$base''${args:+ $args}'"
return $ret
fi
fi
}
for bin in "$binaries"/bin/* ; do
base="''${bin##*/}"
args=
ignoreExitCode=
binCount=$((binCount + 1))
# ignore non-executable files (such as context.lua)
if [[ ! -x "$bin" ]] ; then
ignoredCount=$((ignoredCount + 1))
continue
fi
case "$base" in
${lib.concatStringsSep "|" ignored})
ignoredCount=$((ignoredCount + 1))
continue ;;
${lib.concatStringsSep "|" broken})
brokenCount=$((brokenCount + 1))
continue ;;
${lib.concatStringsSep "|" help})
args=--help ;;
${lib.concatStringsSep "|" shortHelp})
args=-h ;;
${lib.concatStringsSep "|" noArg})
;;
${lib.concatStringsSep "|" contextTest})
args=context-test.tex ;;
${lib.concatStringsSep "|" latexTest})
args=latex-test.tex ;;
${lib.concatStringsSep "|" texTest})
args=tex-test.tex ;;
${lib.concatStringsSep "|" shortVersion})
args=-v ;;
ebong)
touch empty
args=empty ;;
ht)
args='latex latex-test.tex' ;;
pdf2dsc)
args='--help --help --help' ;;
typeoutfileinfo)
args=/dev/null ;;
*)
args=--version ;;
esac
case "$base" in
${lib.concatStringsSep "|" (ignoreExitCode ++ noArg)})
ignoreExitCode=1 ;;
esac
case "$base" in
${lib.concatStringsSep "|" needScheme})
bin="$texliveScheme/bin/$base"
if [[ ! -f "$bin" ]] ; then
ignoredCount=$((ignoredCount + 1))
continue
fi ;;
esac
if testBin ; then : ; else # preserve exit code
echo "failed '$base''${args:+ $args}' (exit code: $?)"
sed 's/^/ > /' < "$out/$base.log"
failedCount=$((failedCount + 1))
fi
done
echo "tested $binCount binaries: $ignoredCount ignored, $brokenCount broken, $failedCount failed"
[[ $failedCount = 0 ]]
'';
# check that all scripts have a Nix shebang
shebangs =
let
binPackages = lib.catAttrs "out" (lib.attrValues texlive.pkgs);
in
runCommand "texlive-test-shebangs" { } (
''
echo "checking that all texlive scripts shebangs are in '$NIX_STORE'"
declare -i scriptCount=0 invalidCount=0
''
+ (lib.concatMapStrings (pkg: ''
for bin in '${pkg.outPath}'/bin/* ; do
grep -I -q . "$bin" || continue # ignore binary files
[[ -x "$bin" ]] || continue # ignore non-executable files (such as context.lua)
scriptCount=$((scriptCount + 1))
read -r cmdline < "$bin"
read -r interp <<< "$cmdline"
if [[ "$interp" != "#!$NIX_STORE"/* && "$interp" != "#! $NIX_STORE"/* ]] ; then
echo "error: non-nix shebang '$interp' in script '$bin'"
invalidCount=$((invalidCount + 1))
fi
done
'') binPackages)
+ ''
echo "checked $scriptCount scripts, found $invalidCount non-nix shebangs"
[[ $invalidCount -gt 0 ]] && exit 1
mkdir -p "$out"
''
);
# verify that the precomputed licensing information in default.nix
# does indeed match the metadata of the individual packages.
#
# This is part of the test suite (and not the normal evaluation) to save
# time for "normal" evaluations. To be more in line with the other tests, this
# also builds a derivation, even though it is essentially an eval-time assertion.
licenses =
let
concatLicenses = builtins.foldl' (acc: el: if builtins.elem el acc then acc else acc ++ [ el ]);
# converts a license to its attribute name in lib.licenses
licenseToAttrName =
license: builtins.head (builtins.attrNames (lib.filterAttrs (n: v: license == v) lib.licenses));
lt = (a: b: a < b);
savedLicenses = scheme: scheme.meta.license;
savedLicensesAttrNames = scheme: map licenseToAttrName (savedLicenses scheme);
correctLicenses =
scheme:
builtins.foldl' (
acc: pkg: concatLicenses acc (lib.toList (pkg.meta.license or [ ]))
) [ ] scheme.passthru.includedTeXPackages;
correctLicensesAttrNames = scheme: lib.sort lt (map licenseToAttrName (correctLicenses scheme));
hasLicenseMismatch =
scheme:
(lib.isDerivation scheme) && (savedLicensesAttrNames scheme) != (correctLicensesAttrNames scheme);
incorrectSchemes = lib.filterAttrs (n: hasLicenseMismatch) (texlive.combined // texlive.schemes);
prettyPrint = name: scheme: ''
license info for ${name} is incorrect! Note that order is enforced.
saved: [ ${lib.concatStringsSep " " (savedLicensesAttrNames scheme)} ]
correct: [ ${lib.concatStringsSep " " (correctLicensesAttrNames scheme)} ]
'';
errorText = lib.concatStringsSep "\n\n" (lib.mapAttrsToList prettyPrint incorrectSchemes);
in
runCommand "texlive-test-license"
{
inherit errorText;
}
(
if (incorrectSchemes == { }) then
"echo everything is fine! > $out"
else
''
echo "$errorText"
false
''
);
# verify that all fixed hashes are present
# this is effectively an eval-time assertion, converted into a derivation for
# ease of testing
fixedHashes =
let
fods = lib.concatMap (
p:
lib.optional (p ? tex && lib.isDerivation p.tex) p.tex
++ lib.optional (p ? texdoc) p.texdoc
++ lib.optional (p ? texsource) p.texsource
++ lib.optional (p ? tlpkg) p.tlpkg
) (lib.attrValues texlive.pkgs);
errorText = lib.concatMapStrings (
p:
lib.optionalString (
!p ? outputHash
) "${p.pname}-${p.tlOutputName} does not have a fixed output hash\n"
) fods;
in
runCommand "texlive-test-fixed-hashes"
{
inherit errorText;
passAsFile = [ "errorText" ];
}
''
if [[ -s "$errorTextPath" ]] ; then
cat "$errorTextPath"
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.
exit 1
else
touch "$out"
fi
'';
}
|