help_spec.lua 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. -- Tests for gen_help_html.lua. Validates :help tags/links and HTML doc generation.
  2. --
  3. -- TODO: extract parts of gen_help_html.lua into Nvim stdlib?
  4. local helpers = require('test.functional.helpers')(after_each)
  5. local clear = helpers.clear
  6. local exec_lua = helpers.exec_lua
  7. local eq = helpers.eq
  8. local ok = helpers.ok
  9. if helpers.skip(helpers.is_ci('cirrus'), 'No need to run this on Cirrus') then return end
  10. describe(':help docs', function()
  11. before_each(clear)
  12. it('validate', function()
  13. -- If this test fails, try these steps (in order):
  14. -- 1. Fix/cleanup the :help docs.
  15. -- 2. Fix the parser: https://github.com/neovim/tree-sitter-vimdoc
  16. -- 3. File a parser bug, and adjust the tolerance of this test in the meantime.
  17. local rv = exec_lua([[return require('scripts.gen_help_html').validate('./build/runtime/doc')]])
  18. -- Check that we actually found helpfiles.
  19. ok(rv.helpfiles > 100, '>100 :help files', rv.helpfiles)
  20. eq({}, rv.invalid_links, 'invalid tags in :help docs')
  21. eq({}, rv.invalid_urls, 'invalid URLs in :help docs')
  22. -- Check that parse errors did not increase.
  23. ok(rv.err_count == 0, 'no parse errors', rv.err_count)
  24. end)
  25. it('gen_help_html.lua generates HTML', function()
  26. -- 1. Test that gen_help_html.lua actually works.
  27. -- 2. Test that parse errors did not increase wildly. Because we explicitly test only a few
  28. -- :help files, we can be precise about the tolerances here.
  29. local tmpdir = exec_lua('return vim.fs.dirname(vim.fn.tempname())')
  30. -- Because gen() is slow (~30s), this test is limited to a few files.
  31. local rv = exec_lua([[
  32. local to_dir = ...
  33. return require('scripts.gen_help_html').gen(
  34. './build/runtime/doc',
  35. to_dir,
  36. { 'pi_health.txt', 'help.txt', 'index.txt', 'nvim.txt', }
  37. )
  38. ]],
  39. tmpdir
  40. )
  41. eq(4, #rv.helpfiles)
  42. eq(0, rv.err_count, 'parse errors in :help docs')
  43. eq({}, rv.invalid_links, 'invalid tags in :help docs')
  44. end)
  45. end)