logParserTests.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. import { expect } from 'chai'
  2. import LatexLogParser from '../../../../frontend/js/ide/log-parser/latex-log-parser'
  3. import BibLogParser from '../../../../frontend/js/ide/log-parser/bib-log-parser'
  4. const fixturePath = '../../helpers/fixtures/logs/'
  5. const fs = require('fs')
  6. const path = require('path')
  7. describe('logParser', function () {
  8. it('should parse errors', function () {
  9. const { errors } = parseLatexLog('errors.log', { ignoreDuplicates: true })
  10. expect(errors.map(e => [e.line, e.message])).to.deep.equal([
  11. [29, 'Undefined control sequence.'],
  12. [
  13. 30,
  14. 'LaTeX Error: \\begin{equation} on input line 28 ended by \\end{equaion}.',
  15. ],
  16. [30, 'Missing $ inserted.'],
  17. [30, 'Display math should end with $$.'],
  18. [46, 'Extra }, or forgotten \\right.'],
  19. [46, 'Missing \\right. inserted.'],
  20. [46, 'Missing } inserted.'],
  21. ])
  22. })
  23. it('should parse Badbox errors', function () {
  24. const { typesetting } = parseLatexLog('bad-boxes.log')
  25. expect(typesetting.map(e => [e.line, e.message])).to.deep.equal([
  26. [9, 'Overfull \\hbox (29.11179pt too wide) in paragraph at lines 9--10'],
  27. [11, 'Underfull \\hbox (badness 10000) in paragraph at lines 11--13'],
  28. [27, 'Overfull \\vbox (12.00034pt too high) detected at line 27'],
  29. [46, 'Underfull \\vbox (badness 10000) detected at line 46'],
  30. [54, 'Underfull \\hbox (badness 10000) in paragraph at lines 54--55'],
  31. [58, 'Underfull \\hbox (badness 10000) in paragraph at lines 58--60'],
  32. ])
  33. })
  34. it('should parse Warnings', function () {
  35. const { warnings } = parseLatexLog('warnings.log')
  36. expect(warnings.map(e => [e.line, e.message, e.file])).to.deep.equal([
  37. [
  38. 7,
  39. "Citation `Lambert:2010iw' on page 1 undefined on input line 7.",
  40. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/introduction.tex',
  41. ],
  42. [
  43. 7,
  44. "Citation `Lambert:2010iw' on page 1 undefined on input line 7.",
  45. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/introduction.tex',
  46. ],
  47. [
  48. 72,
  49. "Citation `Manton:2004tk' on page 3 undefined on input line 72.",
  50. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/instantons.tex',
  51. ],
  52. [
  53. 108,
  54. "Citation `Atiyah1978' on page 4 undefined on input line 108.",
  55. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/instantons.tex',
  56. ],
  57. [
  58. 176,
  59. "Citation `Dorey:1996hu' on page 5 undefined on input line 176.",
  60. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/instantons.tex',
  61. ],
  62. [
  63. 3,
  64. "Citation `Manton1982' on page 8 undefined on input line 3.",
  65. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/moduli_space_approximation.tex',
  66. ],
  67. [
  68. 21,
  69. "Citation `Weinberg:2006rq' on page 9 undefined on input line 21.",
  70. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/moduli_space_approximation.tex',
  71. ],
  72. [
  73. 192,
  74. "Citation `Bak:1999sv' on page 12 undefined on input line 192.",
  75. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/moduli_space_approximation.tex',
  76. ],
  77. [
  78. 9,
  79. "Citation `Peeters:2001np' on page 13 undefined on input line 9.",
  80. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/dynamics_of_single_instanton.tex',
  81. ],
  82. [
  83. 27,
  84. "Citation `Osborn:1981yf' on page 15 undefined on input line 27.",
  85. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/dynamics_of_two_instantons.tex',
  86. ],
  87. [
  88. 27,
  89. "Citation `Peeters:2001np' on page 15 undefined on input line 27.",
  90. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/dynamics_of_two_instantons.tex',
  91. ],
  92. [
  93. 20,
  94. "Citation `Osborn:1981yf' on page 22 undefined on input line 20.",
  95. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/appendices.tex',
  96. ],
  97. [
  98. 103,
  99. "Citation `Osborn:1981yf' on page 23 undefined on input line 103.",
  100. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/appendices.tex',
  101. ],
  102. [
  103. 103,
  104. "Citation `Peeters:2001np' on page 23 undefined on input line 103.",
  105. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/appendices.tex',
  106. ],
  107. [
  108. 352,
  109. "Citation `Peeters:2001np' on page 27 undefined on input line 352.",
  110. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/appendices.tex',
  111. ],
  112. // the logs display an additional summary error for undefined references
  113. [
  114. null,
  115. 'There were undefined references.',
  116. 'compiles/d1585ce575dea4cab55f784a22a88652/instantons.tex',
  117. ],
  118. ])
  119. })
  120. it('should parse Biber warnings', function () {
  121. const { warnings } = parseLatexLog('biber-warnings.log')
  122. expect(warnings.map(w => [w.line, w.message, w.file])).to.deep.equal([
  123. [
  124. null,
  125. 'Package biblatex Warning: No "backend" specified, using Biber backend. To use BibTeX, load biblatex with the "backend=bibtex" option.',
  126. '/usr/local/texlive/2013/texmf-dist/tex/latex/biblatex/biblatex.sty',
  127. ],
  128. [
  129. null,
  130. 'Package biblatex Warning: The following entry could not be found in the database: Missing3 Please verify the spelling and rerun LaTeX afterwards.',
  131. '/compile/output.bbl',
  132. ],
  133. [
  134. null,
  135. 'Package biblatex Warning: The following entry could not be found in the database: Missing2 Please verify the spelling and rerun LaTeX afterwards.',
  136. '/compile/output.bbl',
  137. ],
  138. [
  139. null,
  140. 'Package biblatex Warning: The following entry could not be found in the database: Missing1 Please verify the spelling and rerun LaTeX afterwards.',
  141. '/compile/output.bbl',
  142. ],
  143. ])
  144. })
  145. it('should parse Natbib warnings', function () {
  146. const { warnings } = parseLatexLog('natbib-warnings.log')
  147. expect(warnings.map(w => [w.line, w.message, w.file])).to.deep.equal([
  148. [
  149. 6,
  150. "Package natbib Warning: Citation `blah' on page 1 undefined on input line 6.",
  151. '/compile/main.tex',
  152. ],
  153. [
  154. null,
  155. 'Package natbib Warning: There were undefined citations.',
  156. '/compile/main.tex',
  157. ],
  158. ])
  159. })
  160. it('should parse Geometry warnings', function () {
  161. const { warnings } = parseLatexLog('geometry-warnings.log')
  162. expect(warnings.map(w => [w.line, w.message, w.file])).to.deep.equal([
  163. [
  164. null,
  165. "Package geometry Warning: Over-specification in `h'-direction. `width' (597.50787pt) is ignored.",
  166. '/compile/main.tex',
  167. ],
  168. [
  169. null,
  170. "Package geometry Warning: Over-specification in `v'-direction. `height' (845.04684pt) is ignored.",
  171. '/compile/main.tex',
  172. ],
  173. ])
  174. })
  175. it('should parse Caption warnings', function () {
  176. const { warnings } = parseLatexLog('caption-warnings.log')
  177. expect(warnings.map(w => [w.line, w.message, w.file])).to.deep.equal([
  178. [
  179. null,
  180. 'Package caption Warning: Unsupported document class (or package) detected, usage of the caption package is not recommended. See the caption package documentation for explanation.',
  181. '/usr/local/texlive/2014/texmf-dist/tex/latex/caption/caption.sty',
  182. ],
  183. [
  184. 46,
  185. "Package caption Warning: The option `hypcap=true' will be ignored for this particular \\caption on input line 46. See the caption package documentation for explanation.",
  186. '/compile/main.tex',
  187. ],
  188. ])
  189. })
  190. it('should parse Runaway Arguments', function () {
  191. const { errors } = parseLatexLog('runaway-arguments.log')
  192. expect(errors.map(e => [e.line, e.message, e.file])).to.deep.equal([
  193. [null, 'Runaway argument?', '/compile/runaway_argument.tex'],
  194. [null, 'Emergency stop.', '/compile/runaway_argument.tex'],
  195. ])
  196. })
  197. it('should parse filenames', function () {
  198. const { errors, warnings, typesetting } = parseLatexLog('filenames.log')
  199. expect(errors.map(e => [e.line, e.message, e.file])).to.deep.equal([
  200. [
  201. 1,
  202. 'Undefined control sequence.',
  203. '/compile/a folder with spaces/a subfolder with spaces/a subsubfolder with spaces/another file with spaces.tex',
  204. ],
  205. ])
  206. expect(warnings.map(w => [w.line, w.message, w.file])).to.deep.equal([
  207. [
  208. 9,
  209. "Citation `Peeters:2001np' on page 13 undefined on input line 9.",
  210. '/compile/main',
  211. ],
  212. ])
  213. expect(typesetting.map(e => [e.line, e.message, e.file])).to.deep.equal([
  214. [
  215. 123,
  216. 'Overfull \\hbox (4.56pt too wide) in paragraph at lines 123--456',
  217. '/compile/otherfile',
  218. ],
  219. ])
  220. })
  221. it('should perform file line error parsing', function () {
  222. const { errors } = parseLatexLog('file-line-error.log')
  223. expect(errors.map(e => [e.line, e.message, e.file])).to.deep.equal([
  224. [
  225. '1',
  226. 'Undefined control sequence.',
  227. '/compile/a folder with spaces/a subfolder with spaces/a subsubfolder with spaces/another file with spaces.tex',
  228. ],
  229. ])
  230. })
  231. it('should perform more complex file line error parsing', function () {
  232. const { errors } = parseLatexLog('file-line-error-2.log')
  233. expect(errors.map(e => [e.line, e.message, e.file])).to.deep.equal([
  234. [1, 'Misplaced alignment tab character &.', './acks/name.tex'],
  235. [14, 'Misplaced alignment tab character &.', './main.tex'],
  236. ])
  237. })
  238. it('should ignore duplicates', function () {
  239. // duplicates included
  240. const { errors } = parseLatexLog('errors.log')
  241. expect(errors.length).to.equal(10)
  242. // duplicates excluded
  243. const { errors: errorsDeduplicated } = parseLatexLog('errors.log', {
  244. ignoreDuplicates: true,
  245. })
  246. expect(errorsDeduplicated.length).to.equal(7)
  247. })
  248. it('should get file paths', function () {
  249. const { errors } = parseLatexLog('errors.log')
  250. for (const error of errors) {
  251. expect(error.file).to.equal(
  252. 'compiles/dff0c37d892f346e58fc14975a16bf69/sections/appendices.tex'
  253. )
  254. }
  255. const { all: badBoxesErrors } = parseLatexLog('bad-boxes.log')
  256. for (const error of badBoxesErrors) {
  257. expect(error.file).to.equal(
  258. 'compiles/b6cf470376785e64ad84c57e3296c912/logs/bad-boxes.tex'
  259. )
  260. }
  261. })
  262. it('should parse a typical biber .blg file', function () {
  263. const log = readLog('biber.blg')
  264. const bibParser = new BibLogParser(log, {})
  265. const result = bibParser.parse()
  266. expect(typeof result).to.equal('object')
  267. expect(result.all.length).to.equal(14)
  268. expect(result.errors.length).to.equal(1)
  269. expect(result.warnings.length).to.equal(2)
  270. const error = result.errors[0]
  271. expect(error.level).to.equal('error')
  272. expect(error.line).to.equal('8')
  273. expect(error.file).to.equal('bibliography.bib')
  274. expect(error.message).to.equal(
  275. 'syntax error: at end of input, expected end of entry ("}" or ")") (skipping to next "@")'
  276. )
  277. })
  278. it('should throw an error when non-biblog passed to BibLogParser', function () {
  279. const log = readLog('caption-warnings.log')
  280. const bibParser = new BibLogParser(log, {})
  281. expect(() => bibParser.parse()).to.throw()
  282. })
  283. it('should throw an error when empty string passed to BibLogParser', function () {
  284. const bibParser = new BibLogParser('', {})
  285. expect(() => bibParser.parse()).to.throw()
  286. })
  287. it('should throw an error when non-string passed to BibLogParser', function () {
  288. expect(() => new BibLogParser({ a: 1 }, {})).to.throw()
  289. })
  290. it('should parse a typical bibtex .blg file', function () {
  291. const log = readLog('bibtex.blg')
  292. const bibParser = new BibLogParser(log, {})
  293. const result = bibParser.parse()
  294. expect(typeof result).to.equal('object')
  295. expect(result.all.length).to.equal(13)
  296. expect(result.warnings.length).to.equal(6)
  297. const firstWarning = result.warnings[0]
  298. expect(firstWarning.file).to.equal('references.bib')
  299. expect(firstWarning.line).to.equal('152')
  300. expect(firstWarning.level).to.equal('warning')
  301. expect(firstWarning.message).to.equal(
  302. 'string name "something" is undefined'
  303. )
  304. const thirdWarning = result.warnings[2]
  305. expect(thirdWarning.message).to.equal(
  306. "can't use both author and editor fields in Binney87"
  307. )
  308. expect(result.errors.length).to.equal(7)
  309. const firstError = result.errors[0]
  310. expect(firstError.file).to.equal('references.bib')
  311. expect(firstError.line).to.equal('196')
  312. expect(firstError.level).to.equal('error')
  313. expect(
  314. firstError.message.indexOf("I was expecting a `,' or a `}'")
  315. ).to.equal(0)
  316. expect(
  317. firstError.message.indexOf('(Error may have been on previous line)') > 0
  318. ).to.equal(true)
  319. const crossReferenceError = result.errors[5]
  320. expect(crossReferenceError.level).to.equal('error')
  321. expect(
  322. crossReferenceError.message.indexOf('A bad cross reference')
  323. ).to.equal(0)
  324. const styleError = result.errors[6]
  325. expect(styleError.level).to.equal('error')
  326. expect(
  327. styleError.message.indexOf("I couldn't open style file aa.bst")
  328. ).to.equal(0)
  329. })
  330. // https://github.com/overleaf/overleaf/issues/1023
  331. it('should parse logs from issue 1023', function () {
  332. const { errors, warnings } = parseLatexLog('open-source-issue-1023.log')
  333. expect(errors.map(x => [x.line, x.message, x.file])).to.deep.equal([
  334. [38, 'Package PACKAGE Error: TEXT PackageError.', './main.tex'],
  335. [45, 'Class PACKAGE Error: TEXT ClassError.', './main.tex'],
  336. [53, 'LaTeX Error: TEXT @latex@error.', './main.tex'],
  337. [72, 'Package PACKAGE Error: TEXT msg_error package', './main.tex'],
  338. [84, 'Class PACKAGE Error: TEXT msg_error class', './main.tex'],
  339. [97, 'LaTeX3 Error: TEXT msg_error latex3', './main.tex'],
  340. [
  341. 6,
  342. 'Critical LaTeX3 Error: TEXT msg_critical latex3',
  343. './output-critical.tex',
  344. ],
  345. [
  346. 133,
  347. 'Missing character: There is no 3 ("33) in font nullfont.',
  348. './main.tex',
  349. ],
  350. ])
  351. expect(warnings.map(x => [x.line, x.message, x.file])).to.deep.equal([
  352. [
  353. 37,
  354. 'Package PACKAGE Warning: TEXT PackageWarning on input line 37.',
  355. './main.tex',
  356. ],
  357. [
  358. 44,
  359. 'Class PACKAGE Warning: TEXT ClassWarning on input line 44.',
  360. './main.tex',
  361. ],
  362. [52, 'TEXT @latex@warning on input line 52.', './main.tex'],
  363. [58, 'TEXT @font@warning on input line 58.', './main.tex'],
  364. [null, 'Package PACKAGE Warning: TEXT msg_warning package', './main.tex'],
  365. [null, 'Class PACKAGE Warning: TEXT msg_warning class', './main.tex'],
  366. [null, 'TEXT msg_warning latex3', './main.tex'],
  367. [
  368. null,
  369. "File `output-critical' already exists on the system.",
  370. './main.tex',
  371. ],
  372. ])
  373. })
  374. it('should parse errors without blank lines between them', function () {
  375. const { errors, warnings } = parseLatexLog('undefined-control-sequence.log')
  376. expect(warnings).to.be.empty
  377. expect(errors.map(x => [x.line, x.message, x.file])).to.deep.equal([
  378. [3, 'Undefined control sequence.', './main.tex'],
  379. [4, 'Undefined control sequence.', './main.tex'],
  380. [5, 'Undefined control sequence.', './main.tex'],
  381. [5, 'LaTeX Error: Illegal character in array arg.', './main.tex'],
  382. [5, 'LaTeX Error: Illegal character in array arg.', './main.tex'],
  383. [6, 'Undefined control sequence.', './main.tex'],
  384. [7, 'Undefined control sequence.', './main.tex'],
  385. [8, 'Undefined control sequence.', './main.tex'],
  386. [8, 'LaTeX Error: Illegal character in array arg.', './main.tex'],
  387. [8, 'LaTeX Error: Illegal character in array arg.', './main.tex'],
  388. ])
  389. })
  390. it('should not unwrap errors into previous line', function () {
  391. const { errors, warnings } = parseLatexLog(
  392. 'lncs-undefined-control-sequence.log'
  393. )
  394. expect(warnings).to.be.empty
  395. expect(errors.map(x => [x.line, x.message, x.file])).to.deep.equal([
  396. [102, 'Undefined control sequence.', './main.tex'],
  397. ])
  398. })
  399. })
  400. function readLog(filename) {
  401. return fs.readFileSync(path.resolve(__dirname, fixturePath + filename), {
  402. encoding: 'utf8',
  403. flag: 'r',
  404. })
  405. }
  406. function parseLatexLog(filename, opts = {}) {
  407. const log = readLog(filename)
  408. const parser = new LatexLogParser(log, opts)
  409. return parser.parse()
  410. }