health_spec.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. local helpers = require('test.functional.helpers')(after_each)
  2. local Screen = require('test.functional.ui.screen')
  3. local plugin_helpers = require('test.functional.plugin.helpers')
  4. local clear = helpers.clear
  5. local curbuf_contents = helpers.curbuf_contents
  6. local command = helpers.command
  7. local eq = helpers.eq
  8. local getcompletion = helpers.funcs.getcompletion
  9. describe(':checkhealth', function()
  10. it("detects invalid $VIMRUNTIME", function()
  11. clear({
  12. env={ VIMRUNTIME='bogus', },
  13. })
  14. local status, err = pcall(command, 'checkhealth')
  15. eq(false, status)
  16. eq('Invalid $VIMRUNTIME: bogus', string.match(err, 'Invalid.*'))
  17. end)
  18. it("detects invalid 'runtimepath'", function()
  19. clear()
  20. command('set runtimepath=bogus')
  21. local status, err = pcall(command, 'checkhealth')
  22. eq(false, status)
  23. eq("Invalid 'runtimepath'", string.match(err, 'Invalid.*'))
  24. end)
  25. it("detects invalid $VIM", function()
  26. clear()
  27. -- Do this after startup, otherwise it just breaks $VIMRUNTIME.
  28. command("let $VIM='zub'")
  29. command("checkhealth nvim")
  30. eq("ERROR: $VIM is invalid: zub",
  31. string.match(curbuf_contents(), "ERROR: $VIM .* zub"))
  32. end)
  33. it('completions can be listed via getcompletion()', function()
  34. clear()
  35. eq('nvim', getcompletion('nvim', 'checkhealth')[1])
  36. eq('provider', getcompletion('prov', 'checkhealth')[1])
  37. end)
  38. end)
  39. describe('health.vim', function()
  40. before_each(function()
  41. plugin_helpers.reset()
  42. -- Provides functions:
  43. -- health#broken#check()
  44. -- health#success1#check()
  45. -- health#success2#check()
  46. command("set runtimepath+=test/functional/fixtures")
  47. end)
  48. it("health#report_*()", function()
  49. helpers.source([[
  50. let g:health_report = execute([
  51. \ "call health#report_start('Check Bar')",
  52. \ "call health#report_ok('Bar status')",
  53. \ "call health#report_ok('Other Bar status')",
  54. \ "call health#report_warn('Zub')",
  55. \ "call health#report_start('Baz')",
  56. \ "call health#report_warn('Zim', ['suggestion 1', 'suggestion 2'])"
  57. \ ])
  58. ]])
  59. local result = helpers.eval("g:health_report")
  60. helpers.eq(helpers.dedent([[
  61. ## Check Bar
  62. - OK: Bar status
  63. - OK: Other Bar status
  64. - WARNING: Zub
  65. ## Baz
  66. - WARNING: Zim
  67. - ADVICE:
  68. - suggestion 1
  69. - suggestion 2]]),
  70. result)
  71. end)
  72. describe(":checkhealth", function()
  73. it("concatenates multiple reports", function()
  74. command("checkhealth success1 success2")
  75. helpers.expect([[
  76. health#success1#check
  77. ========================================================================
  78. ## report 1
  79. - OK: everything is fine
  80. ## report 2
  81. - OK: nothing to see here
  82. health#success2#check
  83. ========================================================================
  84. ## another 1
  85. - OK: ok
  86. ]])
  87. end)
  88. it("gracefully handles broken healthcheck", function()
  89. command("checkhealth broken")
  90. helpers.expect([[
  91. health#broken#check
  92. ========================================================================
  93. - ERROR: Failed to run healthcheck for "broken" plugin. Exception:
  94. function health#check[21]..health#broken#check, line 1
  95. caused an error
  96. ]])
  97. end)
  98. it("highlights OK, ERROR", function()
  99. local screen = Screen.new(72, 10)
  100. screen:attach()
  101. screen:set_default_attr_ids({
  102. Ok = { foreground = Screen.colors.Grey3, background = 6291200 },
  103. Error = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
  104. })
  105. screen:set_default_attr_ignore({
  106. Heading = { bold=true, foreground=Screen.colors.Magenta },
  107. Heading2 = { foreground = Screen.colors.SlateBlue },
  108. Bar = { foreground=Screen.colors.Purple },
  109. Bullet = { bold=true, foreground=Screen.colors.Brown },
  110. })
  111. command("checkhealth foo success1")
  112. command("1tabclose")
  113. command("set laststatus=0")
  114. screen:expect([[
  115. ^ |
  116. health#foo#check |
  117. ========================================================================|
  118. - {Error:ERROR:} No healthcheck found for "foo" plugin. |
  119. |
  120. health#success1#check |
  121. ========================================================================|
  122. ## report 1 |
  123. - {Ok:OK:} everything is fine |
  124. |
  125. ]])
  126. end)
  127. it("gracefully handles invalid healthcheck", function()
  128. command("checkhealth non_existent_healthcheck")
  129. helpers.expect([[
  130. health#non_existent_healthcheck#check
  131. ========================================================================
  132. - ERROR: No healthcheck found for "non_existent_healthcheck" plugin.
  133. ]])
  134. end)
  135. end)
  136. end)