tests.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562
  1. define([
  2. '../src/js/latex-log-parser',
  3. '../src/js/bib-log-parser',
  4. 'text!logs/errors.log',
  5. 'text!logs/warnings.log',
  6. 'text!logs/bad-boxes.log',
  7. 'text!logs/biber-warnings.log',
  8. 'text!logs/natbib-warnings.log',
  9. 'text!logs/geometry-warnings.log',
  10. 'text!logs/caption-warnings.log',
  11. 'text!logs/runaway-arguments.log',
  12. 'text!logs/filenames.log',
  13. 'text!logs/file-line-error.log',
  14. 'text!logs/biber.blg',
  15. 'text!logs/bibtex.blg',
  16. ], function (
  17. LatexParser,
  18. BibLogParser,
  19. errorLog,
  20. warningLog,
  21. badBoxesLog,
  22. biberWarningsLog,
  23. natbibWarningsLog,
  24. geometryWarningsLog,
  25. captionWarningsLog,
  26. runawayArgumentsLog,
  27. filenamesLog,
  28. fileLineErrorLog,
  29. biberBlg,
  30. bibtexBlg
  31. ) {
  32. function prettyFileList(files, depth) {
  33. depth = depth || ' '
  34. for (var i = 0; i < files.length; i++) {
  35. console.log(depth + files[i].path)
  36. prettyFileList(files[i].files, depth + ' ')
  37. }
  38. }
  39. module('Errors')
  40. test('Error parsing', function () {
  41. var errors = LatexParser.parse(errorLog, {
  42. ignoreDuplicates: true,
  43. }).errors
  44. var expectedErrors = [
  45. [29, 'Undefined control sequence.'] + '',
  46. [
  47. 30,
  48. 'LaTeX Error: \\begin{equation} on input line 28 ended by \\end{equaion}.',
  49. ] + '',
  50. [30, 'Missing $ inserted.'] + '',
  51. [30, 'Display math should end with $$.'] + '',
  52. [46, 'Extra }, or forgotten \\right.'] + '',
  53. [46, 'Missing \\right. inserted.'] + '',
  54. [46, 'Missing } inserted.'] + '',
  55. ]
  56. expect(expectedErrors.length)
  57. for (var i = 0; i < errors.length; i++) {
  58. if (
  59. expectedErrors.indexOf([errors[i].line, errors[i].message] + '') > -1
  60. ) {
  61. ok(true, 'Found error: ' + errors[i].message)
  62. }
  63. }
  64. })
  65. module('Bad boxes')
  66. test('Badbox parsing', function () {
  67. var errors = LatexParser.parse(badBoxesLog).typesetting
  68. var expectedErrors = [
  69. [9, 'Overfull \\hbox (29.11179pt too wide) in paragraph at lines 9--10'] +
  70. '',
  71. [11, 'Underfull \\hbox (badness 10000) in paragraph at lines 11--13'] +
  72. '',
  73. [27, 'Overfull \\vbox (12.00034pt too high) detected at line 27'] + '',
  74. [46, 'Underfull \\vbox (badness 10000) detected at line 46'] + '',
  75. [54, 'Underfull \\hbox (badness 10000) in paragraph at lines 54--55'] +
  76. '',
  77. [58, 'Underfull \\hbox (badness 10000) in paragraph at lines 58--60'] +
  78. '',
  79. ]
  80. expect(expectedErrors.length)
  81. for (var i = 0; i < errors.length; i++) {
  82. if (
  83. expectedErrors.indexOf([errors[i].line, errors[i].message] + '') > -1
  84. ) {
  85. ok(true, 'Found error: ' + errors[i].message)
  86. }
  87. }
  88. })
  89. module('Warnings')
  90. test('Warning parsing', function () {
  91. var errors = LatexParser.parse(warningLog).warnings
  92. var expectedErrors = [
  93. [
  94. 7,
  95. "Citation `Lambert:2010iw' on page 1 undefined on input line 7.",
  96. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/introduction.tex',
  97. ] + '',
  98. [
  99. 7,
  100. "Citation `Lambert:2010iw' on page 1 undefined on input line 7.",
  101. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/introduction.tex',
  102. ] + '',
  103. [
  104. 72,
  105. "Citation `Manton:2004tk' on page 3 undefined on input line 72.",
  106. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/instantons.tex',
  107. ] + '',
  108. [
  109. 108,
  110. "Citation `Atiyah1978' on page 4 undefined on input line 108.",
  111. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/instantons.tex',
  112. ] + '',
  113. [
  114. 176,
  115. "Citation `Dorey:1996hu' on page 5 undefined on input line 176.",
  116. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/instantons.tex',
  117. ] + '',
  118. [
  119. 3,
  120. "Citation `Manton1982' on page 8 undefined on input line 3.",
  121. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/moduli_space_approximation.tex',
  122. ] + '',
  123. [
  124. 21,
  125. "Citation `Weinberg:2006rq' on page 9 undefined on input line 21.",
  126. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/moduli_space_approximation.tex',
  127. ] + '',
  128. [
  129. 192,
  130. "Citation `Bak:1999sv' on page 12 undefined on input line 192.",
  131. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/moduli_space_approximation.tex',
  132. ] + '',
  133. [
  134. 9,
  135. "Citation `Peeters:2001np' on page 13 undefined on input line 9.",
  136. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/dynamics_of_single_instanton.tex',
  137. ] + '',
  138. [
  139. 27,
  140. "Citation `Osborn:1981yf' on page 15 undefined on input line 27.",
  141. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/dynamics_of_two_instantons.tex',
  142. ] + '',
  143. [
  144. 27,
  145. "Citation `Peeters:2001np' on page 15 undefined on input line 27.",
  146. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/dynamics_of_two_instantons.tex',
  147. ] + '',
  148. [
  149. 20,
  150. "Citation `Osborn:1981yf' on page 22 undefined on input line 20.",
  151. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/appendices.tex',
  152. ] + '',
  153. [
  154. 103,
  155. "Citation `Osborn:1981yf' on page 23 undefined on input line 103.",
  156. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/appendices.tex',
  157. ] + '',
  158. [
  159. 103,
  160. "Citation `Peeters:2001np' on page 23 undefined on input line 103.",
  161. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/appendices.tex',
  162. ] + '',
  163. [
  164. 352,
  165. "Citation `Peeters:2001np' on page 27 undefined on input line 352.",
  166. 'compiles/d1585ce575dea4cab55f784a22a88652/sections/appendices.tex',
  167. ] + '',
  168. ]
  169. expect(expectedErrors.length)
  170. for (var i = 0; i < errors.length; i++) {
  171. if (
  172. expectedErrors.indexOf(
  173. [errors[i].line, errors[i].message, errors[i].file] + ''
  174. ) > -1
  175. ) {
  176. ok(true, 'Found error: ' + errors[i].message)
  177. }
  178. }
  179. })
  180. module('Biber Warnings')
  181. test('Biber Warning parsing', function () {
  182. var errors = LatexParser.parse(biberWarningsLog).warnings
  183. var expectedErrors = [
  184. [
  185. null,
  186. 'Package biblatex Warning: No "backend" specified, using Biber backend. To use BibTeX, load biblatex with the "backend=bibtex" option.',
  187. '/usr/local/texlive/2013/texmf-dist/tex/latex/biblatex/biblatex.sty',
  188. ] + '',
  189. [
  190. null,
  191. 'Package biblatex Warning: The following entry could not be found in the database: Missing3 Please verify the spelling and rerun LaTeX afterwards.',
  192. '/compile/output.bbl',
  193. ] + '',
  194. [
  195. null,
  196. 'Package biblatex Warning: The following entry could not be found in the database: Missing2 Please verify the spelling and rerun LaTeX afterwards.',
  197. '/compile/output.bbl',
  198. ] + '',
  199. [
  200. null,
  201. 'Package biblatex Warning: The following entry could not be found in the database: Missing1 Please verify the spelling and rerun LaTeX afterwards.',
  202. '/compile/output.bbl',
  203. ] + '',
  204. ]
  205. expect(expectedErrors.length)
  206. for (var i = 0; i < errors.length; i++) {
  207. if (
  208. expectedErrors.indexOf(
  209. [errors[i].line, errors[i].message, errors[i].file] + ''
  210. ) > -1
  211. ) {
  212. ok(true, 'Found error: ' + errors[i].message)
  213. } else {
  214. ok(false, 'Unexpected error found: ' + errors[i].message)
  215. }
  216. }
  217. })
  218. module('Natbib Warnings')
  219. test('Natbib Warning parsing', function () {
  220. var errors = LatexParser.parse(natbibWarningsLog).warnings
  221. var expectedErrors = [
  222. [
  223. 6,
  224. "Package natbib Warning: Citation `blah' on page 1 undefined on input line 6.",
  225. '/compile/main.tex',
  226. ] + '',
  227. [
  228. null,
  229. 'Package natbib Warning: There were undefined citations.',
  230. '/compile/main.tex',
  231. ] + '',
  232. ]
  233. expect(expectedErrors.length)
  234. for (var i = 0; i < errors.length; i++) {
  235. if (
  236. expectedErrors.indexOf(
  237. [errors[i].line, errors[i].message, errors[i].file] + ''
  238. ) > -1
  239. ) {
  240. ok(true, 'Found error: ' + errors[i].message)
  241. } else {
  242. ok(false, 'Unexpected error found: ' + errors[i].message)
  243. }
  244. }
  245. })
  246. module('Geometry Warnings')
  247. test('Geometry Warning parsing', function () {
  248. var errors = LatexParser.parse(geometryWarningsLog).warnings
  249. var expectedErrors = [
  250. [
  251. null,
  252. "Package geometry Warning: Over-specification in `h'-direction. `width' (597.50787pt) is ignored.",
  253. '/compile/main.tex',
  254. ] + '',
  255. [
  256. null,
  257. "Package geometry Warning: Over-specification in `v'-direction. `height' (845.04684pt) is ignored.",
  258. '/compile/main.tex',
  259. ] + '',
  260. ]
  261. expect(expectedErrors.length)
  262. for (var i = 0; i < errors.length; i++) {
  263. if (
  264. expectedErrors.indexOf(
  265. [errors[i].line, errors[i].message, errors[i].file] + ''
  266. ) > -1
  267. ) {
  268. ok(true, 'Found error: ' + errors[i].message)
  269. } else {
  270. ok(false, 'Unexpected error found: ' + errors[i].message)
  271. }
  272. }
  273. })
  274. module('Caption Warnings')
  275. test('Caption Warning parsing', function () {
  276. var errors = LatexParser.parse(captionWarningsLog).warnings
  277. var expectedErrors = [
  278. [
  279. null,
  280. 'Package caption Warning: Unsupported document class (or package) detected, usage of the caption package is not recommended. See the caption package documentation for explanation.',
  281. '/usr/local/texlive/2014/texmf-dist/tex/latex/caption/caption.sty',
  282. ] + '',
  283. [
  284. 46,
  285. "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.",
  286. '/compile/main.tex',
  287. ] + '',
  288. ]
  289. expect(expectedErrors.length)
  290. for (var i = 0; i < errors.length; i++) {
  291. if (
  292. expectedErrors.indexOf(
  293. [errors[i].line, errors[i].message, errors[i].file] + ''
  294. ) > -1
  295. ) {
  296. ok(true, 'Found error: ' + errors[i].message)
  297. } else {
  298. ok(false, 'Unexpected error found: ' + errors[i].message)
  299. }
  300. }
  301. })
  302. module('Runaway Arguments')
  303. test('Runaway Arguments parsing', function () {
  304. var errors = LatexParser.parse(runawayArgumentsLog).errors
  305. var expectedErrors = [
  306. [null, 'Runaway argument?', '/compile/runaway_argument.tex'] + '',
  307. [null, 'Emergency stop.', '/compile/runaway_argument.tex'] + '',
  308. ]
  309. expect(expectedErrors.length)
  310. for (var i = 0; i < errors.length; i++) {
  311. if (
  312. expectedErrors.indexOf(
  313. [errors[i].line, errors[i].message, errors[i].file] + ''
  314. ) > -1
  315. ) {
  316. ok(true, 'Found error: ' + errors[i].message)
  317. } else {
  318. ok(false, 'Unexpected error found: ' + errors[i].message)
  319. }
  320. }
  321. })
  322. module('Filename Errors')
  323. test('Filename parsing', function () {
  324. var { errors, warnings, typesetting } = LatexParser.parse(filenamesLog)
  325. var expectedErrors = [
  326. [
  327. 1,
  328. 'Undefined control sequence.',
  329. '/compile/a folder with spaces/a subfolder with spaces/a subsubfolder with spaces/another file with spaces.tex',
  330. ] + '',
  331. ]
  332. var expectedWarnings = [
  333. [
  334. 9,
  335. "Citation `Peeters:2001np' on page 13 undefined on input line 9.",
  336. '/compile/main',
  337. ] + '',
  338. ]
  339. var expectedTypesetting = [
  340. [
  341. 123,
  342. 'Overfull \\hbox (4.56pt too wide) in paragraph at lines 123--456',
  343. '/compile/otherfile',
  344. ] + '',
  345. ]
  346. expect(
  347. expectedErrors.length +
  348. expectedWarnings.length +
  349. expectedTypesetting.length
  350. )
  351. for (var i = 0; i < errors.length; i++) {
  352. if (
  353. expectedErrors.indexOf(
  354. [errors[i].line, errors[i].message, errors[i].file] + ''
  355. ) > -1
  356. ) {
  357. ok(true, 'Found error: ' + errors[i].message)
  358. } else {
  359. ok(false, 'Unexpected error found: ' + errors[i].message)
  360. }
  361. }
  362. for (var i = 0; i < warnings.length; i++) {
  363. if (
  364. expectedWarnings.indexOf(
  365. [warnings[i].line, warnings[i].message, warnings[i].file] + ''
  366. ) > -1
  367. ) {
  368. ok(true, 'Found error: ' + warnings[i].message)
  369. } else {
  370. ok(false, 'Unexpected error found: ' + warnings[i].message)
  371. }
  372. }
  373. for (var i = 0; i < typesetting.length; i++) {
  374. if (
  375. expectedTypesetting.indexOf(
  376. [typesetting[i].line, typesetting[i].message, typesetting[i].file] +
  377. ''
  378. ) > -1
  379. ) {
  380. ok(true, 'Found error: ' + typesetting[i].message)
  381. } else {
  382. ok(false, 'Unexpected error found: ' + typesetting[i].message)
  383. }
  384. }
  385. })
  386. module('File Line Errors')
  387. test('File line error parsing', function () {
  388. var errors = LatexParser.parse(fileLineErrorLog).errors
  389. var expectedErrors = [
  390. [
  391. 1,
  392. 'Undefined control sequence.',
  393. '/compile/a folder with spaces/a subfolder with spaces/a subsubfolder with spaces/another file with spaces.tex',
  394. ] + '',
  395. ]
  396. expect(expectedErrors.length)
  397. for (var i = 0; i < errors.length; i++) {
  398. if (
  399. expectedErrors.indexOf(
  400. [errors[i].line, errors[i].message, errors[i].file] + ''
  401. ) > -1
  402. ) {
  403. ok(true, 'Found error: ' + errors[i].message)
  404. } else {
  405. ok(false, 'Unexpected error found: ' + errors[i].message)
  406. }
  407. }
  408. })
  409. module('General')
  410. test('Ignore Duplicates', function () {
  411. var errors = LatexParser.parse(errorLog).errors
  412. equal(errors.length, 10, 'Duplicates included')
  413. errors = LatexParser.parse(errorLog, { ignoreDuplicates: true }).errors
  414. equal(errors.length, 7, 'Duplicates ignored')
  415. })
  416. test('File paths', function () {
  417. var errors = LatexParser.parse(errorLog).errors
  418. for (var i = 0; i < errors.length; i++) {
  419. equal(
  420. errors[i].file,
  421. 'compiles/dff0c37d892f346e58fc14975a16bf69/sections/appendices.tex',
  422. 'File path correct'
  423. )
  424. }
  425. errors = LatexParser.parse(badBoxesLog).all
  426. for (var i = 0; i < errors.length; i++) {
  427. equal(
  428. errors[i].file,
  429. 'compiles/b6cf470376785e64ad84c57e3296c912/logs/bad-boxes.tex',
  430. 'File path correct'
  431. )
  432. }
  433. })
  434. // biber-log-parser
  435. module('BibLogParser')
  436. test('Typical biber .blg file', function () {
  437. var result = BibLogParser.parse(biberBlg, {})
  438. equal(typeof result, 'object')
  439. equal(result.all.length, 14)
  440. equal(result.errors.length, 1)
  441. equal(result.warnings.length, 2)
  442. var error = result.errors[0]
  443. equal(error.level, 'error')
  444. equal(error.line, '8')
  445. equal(error.file, 'bibliography.bib')
  446. equal(
  447. error.message,
  448. 'syntax error: at end of input, expected end of entry ("}" or ")") (skipping to next "@")'
  449. )
  450. })
  451. test('Not a .blg file', function () {
  452. try {
  453. var result = BibLogParser.parse(captionWarningsLog)
  454. } catch (e) {
  455. ok(true, 'Should throw an error')
  456. }
  457. })
  458. test('Empty string', function () {
  459. try {
  460. var result = BibLogParser.parse('')
  461. } catch (e) {
  462. ok(true, 'Should throw an error')
  463. }
  464. })
  465. test('Not a string', function () {
  466. try {
  467. var result = BibLogParser.parse({ a: 1 })
  468. } catch (e) {
  469. ok(true, 'Should throw an error')
  470. }
  471. })
  472. test('typical bibtex .blg file', function () {
  473. var result = BibLogParser.parse(bibtexBlg, {})
  474. equal(typeof result, 'object')
  475. equal(result.all.length, 13)
  476. equal(result.warnings.length, 6)
  477. var firstWarning = result.warnings[0]
  478. equal(firstWarning.file, 'references.bib')
  479. equal(firstWarning.line, '152')
  480. equal(firstWarning.level, 'warning')
  481. equal(firstWarning.message, 'string name "something" is undefined')
  482. var thirdWarning = result.warnings[2]
  483. equal(
  484. thirdWarning.message,
  485. "can't use both author and editor fields in Binney87"
  486. )
  487. equal(result.errors.length, 7)
  488. var firstError = result.errors[0]
  489. equal(firstError.file, 'references.bib')
  490. equal(firstError.line, '196')
  491. equal(firstError.level, 'error')
  492. equal(firstError.message.indexOf("I was expecting a `,' or a `}'"), 0)
  493. equal(
  494. firstError.message.indexOf('(Error may have been on previous line)') > 0,
  495. true
  496. )
  497. var crossReferenceError = result.errors[5]
  498. equal(crossReferenceError.level, 'error')
  499. equal(crossReferenceError.message.indexOf('A bad cross reference'), 0)
  500. var styleError = result.errors[6]
  501. equal(styleError.level, 'error')
  502. equal(styleError.message.indexOf("I couldn't open style file aa.bst"), 0)
  503. })
  504. })