Path: blob/main/tests/unit/latexmk/parse-error.test.ts
6451 views
/*1* parse-error.test.ts2*3* Copyright (C) 2023 Posit Software, PBC4*5*/67import { findMissingFontsAndPackages, findMissingHyphenationFiles } from "../../../src/command/render/latexmk/parse-error.ts"8import { unitTest } from "../../test.ts";9import { assert } from "testing/asserts";1011function fontSearchTerm(font: string): string {12const fontPattern = font.replace(/\s+/g, '\\s*');13return `${fontPattern}(-(Bold|Italic|Regular).*)?[.](tfm|afm|mf|otf|ttf)`;14}1516function assertFound(logText: string, expected: string, file?: string) {17assert(18findMissingFontsAndPackages(logText, ".")[0] === expected,19`Expected \`${expected}\` in \"${file ?? logText}\" but not found.`20)21}2223unitTest("Detect missing files with `findMissingFontsAndPackages`", async () => {24// No package found25assert(findMissingFontsAndPackages("asdf qwer", ".").length === 0);26// Mismatched LaTeX support (https://github.com/quarto-dev/quarto#7417)27assertFound(Deno.readTextFileSync("expl3-aborted.log"), "expl3.sty", "expl3-aborted.log");28// fonts29assertFound("! Font U/psy/m/n/10=psyr at 10.0pt not loadable: Metric (TFM) file not found", fontSearchTerm("psyr"));30assertFound('! The font "FandolSong-Regular" cannot be found.', fontSearchTerm("FandolSong-Regular"));31assertFound('! Package fontspec Error: The font "Caladea" cannot be found.', fontSearchTerm("Caladea"));32assertFound('!pdfTeX error: /usr/local/bin/pdflatex (file tcrm0700): Font tcrm0700 at 600 not found', fontSearchTerm("tcrm0700"))33assertFound('(fontspec) The font "LibertinusSerif-Regular" cannot be', fontSearchTerm("LibertinusSerif-Regular"));34assertFound('! Font \\JY3/mc/m/n/10=file:HaranoAjiMincho-Regular.otf:-kern;jfm=ujis at 9.24713pt not loadable: metric data not found or bad.', "HaranoAjiMincho-Regular.otf");35assertFound('! The font "Noto Emoji" cannot be found.', fontSearchTerm("Noto Emoji"));36assertFound('! Package fontspec Error: The font "DejaVu Sans" cannot be found.', fontSearchTerm("DejaVu Sans"));37assertFound("! LaTeX Error: File `framed.sty' not found.", "framed.sty");38assertFound("! LaTeX Error: File 'framed.sty' not found.", "framed.sty");39assertFound("/usr/local/bin/mktexpk: line 123: mf: command not found", "mf");40assertFound("or the language definition file ngerman.ldf was not found", "ngerman.ldf");41assertFound(`Package babel Error: Unknown option 'ngerman'. Either you misspelled it42(babel) or the language definition file ngerman.ldf43(babel) was not found.44(babel) There is a locale ini file for this language.45(babel) If it’s the main language, try adding \`provide=*'46(babel) to the babel package options.`, "ngerman.ldf")47assertFound("! Package babel Error: Unknown option 'english'.", "english.ldf");48assertFound(`! Package babel Error: Unknown option 'ngerman'.49(babel) Suggested actions:50(babel) * Make sure you haven't misspelled it`, "ngerman.ldf");51assertFound("!pdfTeX error: pdflatex (file 8r.enc): cannot open encoding file for reading", "8r.enc");52assertFound("! CTeX fontset `fandol' is unavailable in current mode", "fandol");53assertFound("! CTeX fontset 'fandol' is unavailable in current mode", "fandol");54assertFound('Package widetext error: Install the flushend package which is a part of sttools', "flushend.sty");55assertFound('! Package isodate.sty Error: Package file substr.sty not found.', "substr.sty");56assertFound("! Package fontenc Error: Encoding file `t2aenc.def' not found.", "t2aenc.def");57assertFound("! I can't find file `hyph-de-1901.ec.tex'.", "hyph-de-1901.ec.tex");58assertFound("! I can't find file 'hyph-de-1901.ec.tex'.", "hyph-de-1901.ec.tex");59assertFound("luaotfload-features.lua:835: module 'lua-uni-normalize' not found:", "lua-uni-algos.lua");60assertFound("! LuaTeX-ja error: File 'jfm-zh_CN.lua' not found.", "jfm-zh_CN.lua");6162// Additional test cases from tinytex R package examples (latex.R lines 537-607)63// https://github.com/rstudio/tinytex/blob/e96be3143b9af07768a124215b5fb5a1e6d183d3/R/latex.R#L538-L55864assertFound('xdvipdfmx:fatal: Unable to find TFM file "rsfs10"', fontSearchTerm("rsfs10"));65assertFound("Package biblatex Info: ... file 'trad-abbrv.bbx' not found", "trad-abbrv.bbx");66assertFound("! Package pdftex.def Error: File `logo-mdpi-eps-converted-to.pdf' not found", "epstopdf");67assertFound("! Package pdftex.def Error: File 'logo-mdpi-eps-converted-to.pdf' not found", "epstopdf");68assertFound("! xdvipdfmx:fatal: pdf_ref_obj(): passed invalid object.", "epstopdf");69assertFound(70"! Package tikz Error: I did not find the tikz library 'hobby'. This error message was issued because the library or one of its sublibraries could not be found, probably because of a misspelling. Processed options: \"library={hobby}\". The possibly misspelled library name is \"hobby\". The library name should be one of the following (or you misspelled it): named tikzlibraryhobby.code.tex",71"tikzlibraryhobby.code.tex"72);73assertFound("support file `supp-pdf.mkii' (supp-pdf.tex) is missing", "supp-pdf.mkii");74assertFound("support file 'supp-pdf.mkii' (supp-pdf.tex) is missing", "supp-pdf.mkii");75assertFound("! Package pdfx Error: No color profile sRGB_IEC61966-2-1_black_scaled.icc found", "colorprofiles.sty");76assertFound("No file LGRcmr.fd. ! LaTeX Error: This NFSS system isn't set up properly.", "lgrcmr.fd");77},{78cwd: () => "unit/latexmk/"79})8081unitTest("Detect missing hyphenation with babel warnings", async () => {82// Test backtick-quote format (old format)83const logWithBacktick = `Package babel Warning: No hyphenation patterns were preloaded for84(babel) the language \`Spanish' into the format.85(babel) Please, configure your TeX system to add them and86(babel) rebuild the format. Now I will use the patterns87(babel) preloaded for \\language=0 instead on input line 51.`;88assert(89findMissingHyphenationFiles(logWithBacktick) === "hyphen-spanish",90"Should detect hyphen-spanish from backtick-quote format"91);9293// Test straight-quote format (new format - the bug we're fixing)94const logWithStraightQuotes = `Package babel Warning: No hyphenation patterns were preloaded for95(babel) the language 'Spanish' into the format.96(babel) Please, configure your TeX system to add them and97(babel) rebuild the format. Now I will use the patterns98(babel) preloaded for \\language=0 instead on input line 51.`;99assert(100findMissingHyphenationFiles(logWithStraightQuotes) === "hyphen-spanish",101"Should detect hyphen-spanish from straight-quote format"102);103104// Test ngerman special case (should return hyphen-german, not hyphen-ngerman)105const logGerman = `Package babel Warning: No hyphenation patterns were preloaded for106(babel) the language 'ngerman' into the format.`;107assert(108findMissingHyphenationFiles(logGerman) === "hyphen-german",109"Should map ngerman to hyphen-german"110);111112// Test Chinese - no hyphen package exists113const logChinese = `Package babel Warning: No hyphenation patterns were preloaded for114(babel) the language 'chinese' into the format.`;115assert(116findMissingHyphenationFiles(logChinese) === undefined,117"Should return undefined for Chinese (no hyphen package)"118);119120// Test alternative Info pattern (issue #10291)121const logInfoChinese = `Package babel Info: Hyphen rules for 'chinese-hans' set to \\l@nil122(babel) (\\language10). Reported on input line 143.`;123assert(124findMissingHyphenationFiles(logInfoChinese) === undefined,125"Should return undefined for chinese-hans via Info pattern"126);127128// Test no warning present129const logNoWarning = "Some other log text without babel warnings";130assert(131findMissingHyphenationFiles(logNoWarning) === undefined,132"Should return undefined when no babel warning present"133);134}, {135cwd: () => "unit/latexmk/"136})137138