diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2017-10-15 18:29:53 +0200 |
---|---|---|
committer | Justin M. Keyes <justinkz@gmail.com> | 2017-10-17 01:51:20 +0200 |
commit | 5baeb4a49c061472a125f98af798c522d8504fbe (patch) | |
tree | 237e3c69fda8f4b95074823a6663443c7bcce368 | |
parent | 2f4647e77b7e8271aad1b45eb07fbabed78d9fe6 (diff) | |
download | rneovim-5baeb4a49c061472a125f98af798c522d8504fbe.tar.gz rneovim-5baeb4a49c061472a125f98af798c522d8504fbe.tar.bz2 rneovim-5baeb4a49c061472a125f98af798c522d8504fbe.zip |
ex-cmds: :checkhealth
Built-in `:checkhealth` checks for valid $VIMRUNTIME by attempting to
autoload `health#check()`.
closes #2977
closes #3159
-rw-r--r-- | src/nvim/eval.c | 29 | ||||
-rw-r--r-- | src/nvim/ex_cmds.lua | 6 | ||||
-rw-r--r-- | test/functional/plugin/health_spec.lua | 26 |
3 files changed, 59 insertions, 2 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index b2a0d9a767..986c4a9a17 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -22850,3 +22850,32 @@ void eval_format_source_name_line(char *buf, size_t bufsize) (sourcing_name ? sourcing_name : (char_u *)"?"), (sourcing_name ? sourcing_lnum : 0)); } + +/// ":checkhealth [plugins]" +void ex_checkhealth(exarg_T *eap) +{ + bool found = !!find_func((char_u *)"health#check"); + if (!found + && script_autoload("health#check", sizeof("health#check") - 1, false)) { + found = !!find_func((char_u *)"health#check"); + } + if (!found) { + const char *vimruntime_env = os_getenv("VIMRUNTIME"); + if (vimruntime_env == NULL) { + EMSG(_("E5009: $VIMRUNTIME is empty or unset")); + return; + } else { + EMSG2(_("E5009: Invalid $VIMRUNTIME: %s"), os_getenv("VIMRUNTIME")); + return; + } + } + + size_t bufsize = STRLEN(eap->arg) + strlen("CheckHealth ") + 1; + char *buf = xmalloc(bufsize); + snprintf(buf, bufsize, "CheckHealth %s", eap->arg); + + do_cmdline_cmd(buf); + + xfree(buf); +} + diff --git a/src/nvim/ex_cmds.lua b/src/nvim/ex_cmds.lua index 5a578cd088..f99954db7a 100644 --- a/src/nvim/ex_cmds.lua +++ b/src/nvim/ex_cmds.lua @@ -451,6 +451,12 @@ return { func='ex_changes', }, { + command='checkhealth', + flags=bit.bor(EXTRA, TRLBAR), + addr_type=ADDR_LINES, + func='ex_checkhealth', + }, + { command='checkpath', flags=bit.bor(TRLBAR, BANG, CMDWIN), addr_type=ADDR_LINES, diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 8646ec98bf..a85a3ce495 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -2,7 +2,29 @@ local helpers = require('test.functional.helpers')(after_each) local Screen = require('test.functional.ui.screen') local plugin_helpers = require('test.functional.plugin.helpers') +local clear = helpers.clear local command = helpers.command +local eq = helpers.eq + +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) + it("detects invalid $VIM", function() + clear({ + env={ VIM='bogus', }, + }) + local status, err = pcall(command, 'checkhealth') + eq(false, status) + -- Invalid $VIM causes $VIMRUNTIME to be broken. + eq('Invalid $VIMRUNTIME: bogus', string.match(err, 'Invalid.*')) + end) +end) describe('health.vim', function() before_each(function() @@ -14,7 +36,7 @@ describe('health.vim', function() command("set runtimepath+=test/functional/fixtures") end) - it("reports", function() + it("health#report_*()", function() helpers.source([[ let g:health_report = execute([ \ "call health#report_start('Check Bar')", @@ -44,7 +66,7 @@ describe('health.vim', function() end) - describe(":CheckHealth", function() + describe(":checkhealth", function() it("concatenates multiple reports", function() command("CheckHealth success1 success2") helpers.expect([[ |