tests.js 15 KB

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