2016-06-16 14:01:47 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2017-10-15 02:56:02 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2016-06-16 14:01:47 -07:00
|
|
|
local plugin_helpers = require('test.functional.plugin.helpers')
|
|
|
|
|
2017-10-15 09:29:53 -07:00
|
|
|
local clear = helpers.clear
|
2017-10-16 15:10:52 -07:00
|
|
|
local curbuf_contents = helpers.curbuf_contents
|
2017-04-08 14:12:26 -07:00
|
|
|
local command = helpers.command
|
2017-10-15 09:29:53 -07:00
|
|
|
local eq = helpers.eq
|
2018-01-18 07:54:25 -07:00
|
|
|
local getcompletion = helpers.funcs.getcompletion
|
2017-10-15 09:29:53 -07:00
|
|
|
|
|
|
|
describe(':checkhealth', function()
|
|
|
|
it("detects invalid $VIMRUNTIME", function()
|
|
|
|
clear({
|
|
|
|
env={ VIMRUNTIME='bogus', },
|
|
|
|
})
|
|
|
|
local status, err = pcall(command, 'checkhealth')
|
|
|
|
eq(false, status)
|
|
|
|
eq('Invalid $VIMRUNTIME: bogus', string.match(err, 'Invalid.*'))
|
|
|
|
end)
|
2017-11-10 14:37:54 -07:00
|
|
|
it("detects invalid 'runtimepath'", function()
|
|
|
|
clear()
|
|
|
|
command('set runtimepath=bogus')
|
|
|
|
local status, err = pcall(command, 'checkhealth')
|
|
|
|
eq(false, status)
|
|
|
|
eq("Invalid 'runtimepath'", string.match(err, 'Invalid.*'))
|
|
|
|
end)
|
2017-10-15 09:29:53 -07:00
|
|
|
it("detects invalid $VIM", function()
|
2017-10-16 15:10:52 -07:00
|
|
|
clear()
|
|
|
|
-- Do this after startup, otherwise it just breaks $VIMRUNTIME.
|
|
|
|
command("let $VIM='zub'")
|
|
|
|
command("checkhealth nvim")
|
|
|
|
eq("ERROR: $VIM is invalid: zub",
|
|
|
|
string.match(curbuf_contents(), "ERROR: $VIM .* zub"))
|
2017-10-15 09:29:53 -07:00
|
|
|
end)
|
2018-01-18 07:54:25 -07:00
|
|
|
it('completions can be listed via getcompletion()', function()
|
|
|
|
clear()
|
|
|
|
eq('nvim', getcompletion('nvim', 'checkhealth')[1])
|
|
|
|
eq('provider', getcompletion('prov', 'checkhealth')[1])
|
|
|
|
end)
|
2017-10-15 09:29:53 -07:00
|
|
|
end)
|
2017-04-08 14:12:26 -07:00
|
|
|
|
2016-06-16 14:01:47 -07:00
|
|
|
describe('health.vim', function()
|
|
|
|
before_each(function()
|
|
|
|
plugin_helpers.reset()
|
2016-08-20 16:37:18 -07:00
|
|
|
-- Provides functions:
|
|
|
|
-- health#broken#check()
|
|
|
|
-- health#success1#check()
|
|
|
|
-- health#success2#check()
|
2017-04-08 14:12:26 -07:00
|
|
|
command("set runtimepath+=test/functional/fixtures")
|
2016-06-16 14:01:47 -07:00
|
|
|
end)
|
|
|
|
|
2017-10-15 09:29:53 -07:00
|
|
|
it("health#report_*()", function()
|
2016-08-20 16:37:18 -07:00
|
|
|
helpers.source([[
|
|
|
|
let g:health_report = execute([
|
|
|
|
\ "call health#report_start('Check Bar')",
|
|
|
|
\ "call health#report_ok('Bar status')",
|
|
|
|
\ "call health#report_ok('Other Bar status')",
|
|
|
|
\ "call health#report_warn('Zub')",
|
|
|
|
\ "call health#report_start('Baz')",
|
|
|
|
\ "call health#report_warn('Zim', ['suggestion 1', 'suggestion 2'])"
|
|
|
|
\ ])
|
|
|
|
]])
|
|
|
|
local result = helpers.eval("g:health_report")
|
|
|
|
|
|
|
|
helpers.eq(helpers.dedent([[
|
|
|
|
|
|
|
|
|
|
|
|
## Check Bar
|
2017-10-15 02:56:02 -07:00
|
|
|
- OK: Bar status
|
|
|
|
- OK: Other Bar status
|
2016-08-20 16:37:18 -07:00
|
|
|
- WARNING: Zub
|
|
|
|
|
|
|
|
## Baz
|
|
|
|
- WARNING: Zim
|
2017-10-15 02:56:02 -07:00
|
|
|
- ADVICE:
|
2016-09-04 19:57:19 -07:00
|
|
|
- suggestion 1
|
|
|
|
- suggestion 2]]),
|
2016-08-20 16:37:18 -07:00
|
|
|
result)
|
2016-06-16 14:01:47 -07:00
|
|
|
end)
|
|
|
|
|
|
|
|
|
2017-10-15 09:29:53 -07:00
|
|
|
describe(":checkhealth", function()
|
2016-08-20 16:37:18 -07:00
|
|
|
it("concatenates multiple reports", function()
|
2017-10-15 11:31:12 -07:00
|
|
|
command("checkhealth success1 success2")
|
2016-08-20 16:37:18 -07:00
|
|
|
helpers.expect([[
|
2016-09-04 19:57:19 -07:00
|
|
|
|
2016-08-20 16:37:18 -07:00
|
|
|
health#success1#check
|
2016-10-25 06:28:34 -07:00
|
|
|
========================================================================
|
2016-08-20 16:37:18 -07:00
|
|
|
## report 1
|
2017-10-15 02:56:02 -07:00
|
|
|
- OK: everything is fine
|
2016-06-16 14:01:47 -07:00
|
|
|
|
2016-08-20 16:37:18 -07:00
|
|
|
## report 2
|
2017-10-15 02:56:02 -07:00
|
|
|
- OK: nothing to see here
|
2016-08-20 16:37:18 -07:00
|
|
|
|
|
|
|
health#success2#check
|
2016-10-25 06:28:34 -07:00
|
|
|
========================================================================
|
2016-08-20 16:37:18 -07:00
|
|
|
## another 1
|
2017-10-15 02:56:02 -07:00
|
|
|
- OK: ok
|
2016-09-04 19:57:19 -07:00
|
|
|
]])
|
2016-06-16 14:01:47 -07:00
|
|
|
end)
|
|
|
|
|
2016-08-20 16:37:18 -07:00
|
|
|
it("gracefully handles broken healthcheck", function()
|
2017-10-15 11:31:12 -07:00
|
|
|
command("checkhealth broken")
|
2016-08-20 16:37:18 -07:00
|
|
|
helpers.expect([[
|
2016-09-04 19:57:19 -07:00
|
|
|
|
2016-08-20 16:37:18 -07:00
|
|
|
health#broken#check
|
2016-10-25 06:28:34 -07:00
|
|
|
========================================================================
|
2016-08-20 16:37:18 -07:00
|
|
|
- ERROR: Failed to run healthcheck for "broken" plugin. Exception:
|
2017-07-15 07:15:47 -07:00
|
|
|
function health#check[21]..health#broken#check, line 1
|
2016-09-04 19:57:19 -07:00
|
|
|
caused an error
|
|
|
|
]])
|
2016-08-20 16:37:18 -07:00
|
|
|
end)
|
2016-06-16 14:01:47 -07:00
|
|
|
|
2017-10-15 02:56:02 -07:00
|
|
|
it("highlights OK, ERROR", function()
|
|
|
|
local screen = Screen.new(72, 10)
|
|
|
|
screen:attach()
|
|
|
|
screen:set_default_attr_ids({
|
|
|
|
Ok = { foreground = Screen.colors.Grey3, background = 6291200 },
|
|
|
|
Error = { foreground = Screen.colors.Grey100, background = Screen.colors.Red },
|
|
|
|
})
|
|
|
|
screen:set_default_attr_ignore({
|
|
|
|
Heading = { bold=true, foreground=Screen.colors.Magenta },
|
|
|
|
Heading2 = { foreground = Screen.colors.SlateBlue },
|
|
|
|
Bar = { foreground=Screen.colors.Purple },
|
|
|
|
Bullet = { bold=true, foreground=Screen.colors.Brown },
|
|
|
|
})
|
2017-10-15 11:31:12 -07:00
|
|
|
command("checkhealth foo success1")
|
2017-10-15 02:56:02 -07:00
|
|
|
command("1tabclose")
|
|
|
|
command("set laststatus=0")
|
|
|
|
screen:expect([[
|
|
|
|
^ |
|
|
|
|
health#foo#check |
|
|
|
|
========================================================================|
|
|
|
|
- {Error:ERROR:} No healthcheck found for "foo" plugin. |
|
|
|
|
|
|
|
|
|
health#success1#check |
|
|
|
|
========================================================================|
|
|
|
|
## report 1 |
|
|
|
|
- {Ok:OK:} everything is fine |
|
|
|
|
|
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2016-08-20 16:37:18 -07:00
|
|
|
it("gracefully handles invalid healthcheck", function()
|
2017-10-15 11:31:12 -07:00
|
|
|
command("checkhealth non_existent_healthcheck")
|
2016-08-20 16:37:18 -07:00
|
|
|
helpers.expect([[
|
2016-09-04 19:57:19 -07:00
|
|
|
|
2016-08-20 16:37:18 -07:00
|
|
|
health#non_existent_healthcheck#check
|
2016-10-25 06:28:34 -07:00
|
|
|
========================================================================
|
2016-09-04 19:57:19 -07:00
|
|
|
- ERROR: No healthcheck found for "non_existent_healthcheck" plugin.
|
|
|
|
]])
|
2016-08-20 16:37:18 -07:00
|
|
|
end)
|
2016-06-16 14:01:47 -07:00
|
|
|
end)
|
|
|
|
end)
|