From 2cc523c3afd3c98e80499409182ca96708d996f4 Mon Sep 17 00:00:00 2001 From: TJ DeVries Date: Thu, 16 Jun 2016 17:01:47 -0400 Subject: CheckHealth - Use execute() instead of redir - Fixed logic on suboptimal pyenv/virtualenv checks. - Move system calls from strings to lists. Fixes #5218 - Add highlighting - Automatically discover health checkers - Add tests Helped-by: Shougo Matsushita Helped-by: Tommy Allen Closes #4932 --- test/functional/plugin/health_spec.lua | 58 ++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 test/functional/plugin/health_spec.lua (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua new file mode 100644 index 0000000000..972cabd662 --- /dev/null +++ b/test/functional/plugin/health_spec.lua @@ -0,0 +1,58 @@ +local helpers = require('test.functional.helpers')(after_each) +local plugin_helpers = require('test.functional.plugin.helpers') + +describe('health.vim', function() + before_each(function() + plugin_helpers.reset() + end) + + it('should echo the results when using the basic functions', function() + helpers.execute("call health#report_start('Foo')") + local report = helpers.redir_exec([[call health#report_start('Check Bar')]]) + .. helpers.redir_exec([[call health#report_ok('Bar status')]]) + .. helpers.redir_exec([[call health#report_ok('Other Bar status')]]) + .. helpers.redir_exec([[call health#report_warn('Zub')]]) + .. helpers.redir_exec([[call health#report_start('Baz')]]) + .. helpers.redir_exec([[call health#report_warn('Zim', ['suggestion 1', 'suggestion 2'])]]) + + local expected_contents = { + 'Checking: Check Bar', + 'SUCCESS: Bar status', + 'WARNING: Zub', + 'SUGGESTIONS:', + '- suggestion 1', + '- suggestion 2' + } + + for _, content in ipairs(expected_contents) do + assert(string.find(report, content)) + end + end) + + + describe('CheckHealth', function() + -- Run the health check and store important results + -- Run it here because it may take awhile to complete, depending on the system + helpers.execute([[CheckHealth!]]) + local report = helpers.curbuf_contents() + local health_checkers = helpers.redir_exec("echo g:health_checkers") + + it('should find the default checker upon execution', function() + assert(string.find(health_checkers, "'health#nvim#check': v:true")) + end) + + it('should alert the user that health#nvim#check is running', function() + assert(string.find(report, '# Checking health')) + assert(string.find(report, 'Checker health#nvim#check says:')) + assert(string.find(report, 'Checking:')) + end) + end) + + it('should allow users to disable checkers', function() + helpers.execute("call health#disable_checker('health#nvim#check')") + helpers.execute("CheckHealth!") + local health_checkers = helpers.redir_exec("echo g:health_checkers") + + assert(string.find(health_checkers, "'health#nvim#check': v:false")) + end) +end) -- cgit From 545e7a416310c9ff700b2afed9eef834c8948c8b Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sun, 7 Aug 2016 14:16:30 -0400 Subject: CheckHealth - Overlay markdown syntax/filetype, don't invent new filetypes/syntaxes. - migrate s:check_ruby() - s:indent_after_line1 - Less-verbose output --- test/functional/plugin/health_spec.lua | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 972cabd662..50fbfd58ee 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -6,7 +6,7 @@ describe('health.vim', function() plugin_helpers.reset() end) - it('should echo the results when using the basic functions', function() + it('reports results', function() helpers.execute("call health#report_start('Foo')") local report = helpers.redir_exec([[call health#report_start('Check Bar')]]) .. helpers.redir_exec([[call health#report_ok('Bar status')]]) @@ -30,25 +30,22 @@ describe('health.vim', function() end) - describe('CheckHealth', function() - -- Run the health check and store important results - -- Run it here because it may take awhile to complete, depending on the system + describe(':CheckHealth', function() + -- Run it here because it may be slow, depending on the system. helpers.execute([[CheckHealth!]]) local report = helpers.curbuf_contents() local health_checkers = helpers.redir_exec("echo g:health_checkers") - it('should find the default checker upon execution', function() + it('finds the default checker', function() assert(string.find(health_checkers, "'health#nvim#check': v:true")) end) - it('should alert the user that health#nvim#check is running', function() - assert(string.find(report, '# Checking health')) - assert(string.find(report, 'Checker health#nvim#check says:')) - assert(string.find(report, 'Checking:')) + it('prints a header with the name of the checker', function() + assert(string.find(report, 'health#nvim#check')) end) end) - it('should allow users to disable checkers', function() + it('allows users to disable checkers', function() helpers.execute("call health#disable_checker('health#nvim#check')") helpers.execute("CheckHealth!") local health_checkers = helpers.redir_exec("echo g:health_checkers") -- cgit From ed49d9d866f8260842ea177fa9ce31dbc398701d Mon Sep 17 00:00:00 2001 From: "Justin M. Keyes" Date: Sat, 20 Aug 2016 19:37:18 -0400 Subject: CheckHealth: Accept [plugin1 [, plugin2 [, ...]]] args. To healthcheck the "foo" plugin: :CheckHealth foo To healthcheck the "foo" and "bar" plugins: :CheckHealth foo bar To run all auto-discovered healthchecks: :CheckHealth --- test/functional/plugin/health_spec.lua | 100 +++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 37 deletions(-) (limited to 'test/functional/plugin') diff --git a/test/functional/plugin/health_spec.lua b/test/functional/plugin/health_spec.lua index 50fbfd58ee..a9665cd751 100644 --- a/test/functional/plugin/health_spec.lua +++ b/test/functional/plugin/health_spec.lua @@ -4,52 +4,78 @@ local plugin_helpers = require('test.functional.plugin.helpers') describe('health.vim', function() before_each(function() plugin_helpers.reset() + -- Provides functions: + -- health#broken#check() + -- health#success1#check() + -- health#success2#check() + helpers.execute("set runtimepath+=test/functional/fixtures") end) - it('reports results', function() - helpers.execute("call health#report_start('Foo')") - local report = helpers.redir_exec([[call health#report_start('Check Bar')]]) - .. helpers.redir_exec([[call health#report_ok('Bar status')]]) - .. helpers.redir_exec([[call health#report_ok('Other Bar status')]]) - .. helpers.redir_exec([[call health#report_warn('Zub')]]) - .. helpers.redir_exec([[call health#report_start('Baz')]]) - .. helpers.redir_exec([[call health#report_warn('Zim', ['suggestion 1', 'suggestion 2'])]]) - - local expected_contents = { - 'Checking: Check Bar', - 'SUCCESS: Bar status', - 'WARNING: Zub', - 'SUGGESTIONS:', - '- suggestion 1', - '- suggestion 2' - } - - for _, content in ipairs(expected_contents) do - assert(string.find(report, content)) - end + it("reports", function() + 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 + - SUCCESS: Bar status + - SUCCESS: Other Bar status + - WARNING: Zub + + ## Baz + - WARNING: Zim + - SUGGESTIONS: + - suggestion 1 + - suggestion 2]]), + result) end) - describe(':CheckHealth', function() - -- Run it here because it may be slow, depending on the system. - helpers.execute([[CheckHealth!]]) - local report = helpers.curbuf_contents() - local health_checkers = helpers.redir_exec("echo g:health_checkers") + describe(":CheckHealth", function() + it("concatenates multiple reports", function() + helpers.execute("CheckHealth success1 success2") + helpers.expect([[ + health#success1#check + ================================================================================ - it('finds the default checker', function() - assert(string.find(health_checkers, "'health#nvim#check': v:true")) - end) + ## report 1 + - SUCCESS: everything is fine - it('prints a header with the name of the checker', function() - assert(string.find(report, 'health#nvim#check')) + ## report 2 + - SUCCESS: nothing to see here + + health#success2#check + ================================================================================ + + ## another 1 + - SUCCESS: ok]]) end) - end) - it('allows users to disable checkers', function() - helpers.execute("call health#disable_checker('health#nvim#check')") - helpers.execute("CheckHealth!") - local health_checkers = helpers.redir_exec("echo g:health_checkers") + it("gracefully handles broken healthcheck", function() + helpers.execute("CheckHealth broken") + helpers.expect([[ + health#broken#check + ================================================================================ + - ERROR: Failed to run healthcheck for "broken" plugin. Exception: + caused an error]]) + end) - assert(string.find(health_checkers, "'health#nvim#check': v:false")) + it("gracefully handles invalid healthcheck", function() + helpers.execute("CheckHealth non_existent_healthcheck") + helpers.expect([[ + health#non_existent_healthcheck#check + ================================================================================ + - ERROR: No healthcheck found for "non_existent_healthcheck" plugin.]]) + end) end) end) -- cgit