2016-06-16 14:01:47 -07:00
|
|
|
local helpers = require('test.functional.helpers')(after_each)
|
2021-08-03 14:09:26 -07:00
|
|
|
local global_helpers = require('test.helpers')
|
2017-10-15 02:56:02 -07:00
|
|
|
local Screen = require('test.functional.ui.screen')
|
2016-06-16 14:01:47 -07:00
|
|
|
|
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])
|
2021-09-23 18:33:43 -07:00
|
|
|
eq('vim.lsp', getcompletion('vim.ls', 'checkhealth')[1])
|
2018-01-18 07:54:25 -07:00
|
|
|
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()
|
2019-08-05 01:25:49 -07:00
|
|
|
clear{args={'-u', 'NORC'}}
|
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)
|
|
|
|
|
2021-08-03 14:09:26 -07:00
|
|
|
describe(":checkhealth", function()
|
|
|
|
it("functions health#report_*() render correctly", function()
|
|
|
|
command("checkhealth full_render")
|
|
|
|
helpers.expect([[
|
|
|
|
|
|
|
|
full_render: health#full_render#check
|
|
|
|
========================================================================
|
|
|
|
## report 1
|
|
|
|
- OK: life is fine
|
|
|
|
- WARNING: no what installed
|
2017-10-15 02:56:02 -07:00
|
|
|
- ADVICE:
|
2021-08-03 14:09:26 -07:00
|
|
|
- pip what
|
|
|
|
- make what
|
2016-06-16 14:01:47 -07:00
|
|
|
|
2021-08-03 14:09:26 -07:00
|
|
|
## report 2
|
|
|
|
- INFO: stuff is stable
|
|
|
|
- ERROR: why no hardcopy
|
|
|
|
- ADVICE:
|
|
|
|
- :help |:hardcopy|
|
|
|
|
- :help |:TOhtml|
|
|
|
|
]])
|
|
|
|
end)
|
2016-06-16 14:01:47 -07:00
|
|
|
|
2016-08-20 16:37:18 -07:00
|
|
|
it("concatenates multiple reports", function()
|
2021-08-03 14:09:26 -07:00
|
|
|
command("checkhealth success1 success2 test_plug")
|
2016-08-20 16:37:18 -07:00
|
|
|
helpers.expect([[
|
2016-09-04 19:57:19 -07:00
|
|
|
|
2021-08-03 14:09:26 -07:00
|
|
|
success1: 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
|
|
|
|
2021-08-03 14:09:26 -07:00
|
|
|
success2: 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
|
2021-08-03 14:09:26 -07:00
|
|
|
|
|
|
|
test_plug: require("test_plug.health").check()
|
|
|
|
========================================================================
|
|
|
|
## report 1
|
|
|
|
- OK: everything is fine
|
|
|
|
|
|
|
|
## report 2
|
|
|
|
- OK: nothing to see here
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2021-10-05 15:37:39 -07:00
|
|
|
it("lua plugins, skips vimscript healthchecks with the same name", function()
|
2021-08-03 14:09:26 -07:00
|
|
|
command("checkhealth test_plug")
|
2021-10-05 15:37:39 -07:00
|
|
|
-- Existing file in test/functional/fixtures/lua/test_plug/autoload/health/test_plug.vim
|
|
|
|
-- and the Lua healthcheck is used instead.
|
2021-08-03 14:09:26 -07:00
|
|
|
helpers.expect([[
|
|
|
|
|
|
|
|
test_plug: require("test_plug.health").check()
|
|
|
|
========================================================================
|
|
|
|
## report 1
|
|
|
|
- OK: everything is fine
|
|
|
|
|
|
|
|
## report 2
|
|
|
|
- OK: nothing to see here
|
2016-09-04 19:57:19 -07:00
|
|
|
]])
|
2016-06-16 14:01:47 -07:00
|
|
|
end)
|
|
|
|
|
2021-08-03 14:09:26 -07:00
|
|
|
it("lua plugins submodules", function()
|
|
|
|
command("checkhealth test_plug.submodule")
|
|
|
|
helpers.expect([[
|
|
|
|
|
|
|
|
test_plug.submodule: require("test_plug.submodule.health").check()
|
|
|
|
========================================================================
|
|
|
|
## report 1
|
|
|
|
- OK: everything is fine
|
|
|
|
|
|
|
|
## report 2
|
|
|
|
- OK: nothing to see here
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
|
|
|
it("lua plugins submodules with expression '*'", function()
|
|
|
|
command("checkhealth test_plug*")
|
|
|
|
local buf_lines = helpers.curbuf('get_lines', 0, -1, true)
|
|
|
|
-- avoid dealing with path separators
|
2021-11-06 07:26:10 -07:00
|
|
|
local received = table.concat(buf_lines, '\n', 1, #buf_lines - 5)
|
2021-08-03 14:09:26 -07:00
|
|
|
local expected = helpers.dedent([[
|
|
|
|
|
|
|
|
test_plug: require("test_plug.health").check()
|
|
|
|
========================================================================
|
|
|
|
## report 1
|
|
|
|
- OK: everything is fine
|
|
|
|
|
|
|
|
## report 2
|
|
|
|
- OK: nothing to see here
|
|
|
|
|
|
|
|
test_plug.submodule: require("test_plug.submodule.health").check()
|
|
|
|
========================================================================
|
|
|
|
## report 1
|
|
|
|
- OK: everything is fine
|
|
|
|
|
|
|
|
## report 2
|
|
|
|
- OK: nothing to see here
|
|
|
|
|
2022-01-19 11:30:20 -07:00
|
|
|
test_plug.submodule_empty: require("test_plug.submodule_empty.health").check()
|
|
|
|
========================================================================
|
|
|
|
- ERROR: The healthcheck report for "test_plug.submodule_empty" plugin is empty.
|
|
|
|
|
2021-08-03 14:09:26 -07:00
|
|
|
test_plug.submodule_failed: require("test_plug.submodule_failed.health").check()
|
|
|
|
========================================================================
|
|
|
|
- ERROR: Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception:
|
2021-12-18 09:14:42 -07:00
|
|
|
function health#check, line 20]])
|
2021-08-03 14:09:26 -07:00
|
|
|
eq(expected, received)
|
|
|
|
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
|
|
|
|
2021-08-03 14:09:26 -07:00
|
|
|
broken: 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:
|
2021-12-18 09:14:42 -07:00
|
|
|
function health#check[20]..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
|
|
|
|
2022-01-19 11:30:20 -07:00
|
|
|
it("... including empty reports", function()
|
|
|
|
command("checkhealth test_plug.submodule_empty")
|
|
|
|
helpers.expect([[
|
|
|
|
|
|
|
|
test_plug.submodule_empty: require("test_plug.submodule_empty.health").check()
|
|
|
|
========================================================================
|
|
|
|
- ERROR: The healthcheck report for "test_plug.submodule_empty" plugin is empty.
|
|
|
|
]])
|
|
|
|
end)
|
|
|
|
|
2021-08-03 14:09:26 -07:00
|
|
|
it("gracefully handles broken lua healthcheck", function()
|
|
|
|
command("checkhealth test_plug.submodule_failed")
|
|
|
|
local buf_lines = helpers.curbuf('get_lines', 0, -1, true)
|
2021-11-06 07:26:10 -07:00
|
|
|
local received = table.concat(buf_lines, '\n', 1, #buf_lines - 5)
|
2021-08-03 14:09:26 -07:00
|
|
|
-- avoid dealing with path separators
|
|
|
|
local lua_err = "attempt to perform arithmetic on a nil value"
|
2021-11-06 07:26:10 -07:00
|
|
|
local last_line = buf_lines[#buf_lines - 4]
|
2021-08-03 14:09:26 -07:00
|
|
|
assert(string.find(last_line, lua_err) ~= nil, "Lua error not present")
|
|
|
|
|
|
|
|
local expected = global_helpers.dedent([[
|
|
|
|
|
|
|
|
test_plug.submodule_failed: require("test_plug.submodule_failed.health").check()
|
|
|
|
========================================================================
|
|
|
|
- ERROR: Failed to run healthcheck for "test_plug.submodule_failed" plugin. Exception:
|
2021-12-18 09:14:42 -07:00
|
|
|
function health#check, line 20]])
|
2021-08-03 14:09:26 -07:00
|
|
|
eq(expected, received)
|
|
|
|
end)
|
|
|
|
|
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 },
|
|
|
|
Heading = { bold=true, foreground=Screen.colors.Magenta },
|
|
|
|
Heading2 = { foreground = Screen.colors.SlateBlue },
|
2021-04-26 18:38:12 -07:00
|
|
|
Bar = { foreground = 0x6a0dad },
|
2017-10-15 02:56:02 -07:00
|
|
|
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")
|
2019-10-12 04:29:51 -07:00
|
|
|
screen:expect{grid=[[
|
2017-10-15 02:56:02 -07:00
|
|
|
^ |
|
2021-08-03 14:09:26 -07:00
|
|
|
{Heading:foo: } |
|
2019-10-12 04:29:51 -07:00
|
|
|
{Bar:========================================================================}|
|
2021-10-16 08:45:59 -07:00
|
|
|
{Bullet: -} {Error:ERROR}: No healthcheck found for "foo" plugin. |
|
2017-10-15 02:56:02 -07:00
|
|
|
|
|
2021-08-03 14:09:26 -07:00
|
|
|
{Heading:success1: health#success1#check} |
|
2019-10-12 04:29:51 -07:00
|
|
|
{Bar:========================================================================}|
|
|
|
|
{Heading2:##}{Heading: report 1} |
|
2021-10-16 08:45:59 -07:00
|
|
|
{Bullet: -} {Ok:OK}: everything is fine |
|
2017-10-15 02:56:02 -07:00
|
|
|
|
|
2019-10-12 04:29:51 -07:00
|
|
|
]]}
|
2017-10-15 02:56:02 -07:00
|
|
|
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")
|
2021-08-03 14:09:26 -07:00
|
|
|
-- luacheck: ignore 613
|
2016-08-20 16:37:18 -07:00
|
|
|
helpers.expect([[
|
2016-09-04 19:57:19 -07:00
|
|
|
|
2021-08-03 14:09:26 -07:00
|
|
|
non_existent_healthcheck:
|
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)
|
2022-02-03 02:19:51 -07:00
|
|
|
|
|
|
|
describe(':checkhealth provider', function()
|
|
|
|
it("works correctly with a wrongly configured 'shell'", function()
|
|
|
|
clear()
|
|
|
|
command([[set shell=echo\ WRONG!!!]])
|
|
|
|
command('let g:loaded_perl_provider = 0')
|
|
|
|
command('let g:loaded_python3_provider = 0')
|
|
|
|
command('checkhealth provider')
|
|
|
|
eq(nil, string.match(curbuf_contents(), 'WRONG!!!'))
|
|
|
|
end)
|
|
|
|
end)
|