From a42999a639b2916b769a85f37d037be314d9d61b Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 15 Jul 2018 18:24:53 +0100 Subject: Massively reduce the amount of code needed for linter tests --- .../test_shellcheck_command_callback.vader | 126 ++++++++------------- 1 file changed, 46 insertions(+), 80 deletions(-) (limited to 'test/command_callback/test_shellcheck_command_callback.vader') diff --git a/test/command_callback/test_shellcheck_command_callback.vader b/test/command_callback/test_shellcheck_command_callback.vader index 68694b67..23684026 100644 --- a/test/command_callback/test_shellcheck_command_callback.vader +++ b/test/command_callback/test_shellcheck_command_callback.vader @@ -1,129 +1,95 @@ Before: - Save g:ale_sh_shellcheck_exclusions - Save g:ale_sh_shellcheck_executable - Save g:ale_sh_shellcheck_options - - unlet! g:ale_sh_shellcheck_exclusions - unlet! g:ale_sh_shellcheck_executable - unlet! g:ale_sh_shellcheck_options - - runtime ale_linters/sh/shellcheck.vim - - call ale#test#SetDirectory('/testplugin/test/command_callback') + call ale#assert#SetUpLinterTest('sh', 'shellcheck') call ale#test#SetFilename('test.sh') let b:prefix = 'cd ' . ale#Escape(ale#path#Simplify(g:dir)) . ' && ' let b:suffix = ' -f gcc -' After: - Restore - - unlet! b:ale_sh_shellcheck_exclusions - unlet! b:ale_sh_shellcheck_executable - unlet! b:ale_sh_shellcheck_options unlet! b:is_bash unlet! b:prefix - - call ale#test#RestoreDirectory() - - call ale#linter#Reset() + unlet! b:suffix + call ale#assert#TearDownLinterTest() Execute(The default shellcheck command should be correct): - AssertEqual - \ b:prefix . ale#Escape('shellcheck') . b:suffix, - \ ale_linters#sh#shellcheck#GetCommand(bufnr(''), []) + AssertLinter 'shellcheck', b:prefix . ale#Escape('shellcheck') . b:suffix Execute(The shellcheck command should accept options): let b:ale_sh_shellcheck_options = '--foobar' - AssertEqual - \ b:prefix . ale#Escape('shellcheck') . ' --foobar' . b:suffix, - \ ale_linters#sh#shellcheck#GetCommand(bufnr(''), []) + AssertLinter 'shellcheck', + \ b:prefix . ale#Escape('shellcheck') . ' --foobar' . b:suffix Execute(The shellcheck command should accept options and exclusions): let b:ale_sh_shellcheck_options = '--foobar' let b:ale_sh_shellcheck_exclusions = 'foo,bar' - AssertEqual - \ b:prefix . ale#Escape('shellcheck') . ' --foobar -e foo,bar' . b:suffix, - \ ale_linters#sh#shellcheck#GetCommand(bufnr(''), []) + AssertLinter 'shellcheck', + \ b:prefix . ale#Escape('shellcheck') . ' --foobar -e foo,bar' . b:suffix Execute(The shellcheck command should include the dialect): let b:is_bash = 1 - AssertEqual - \ b:prefix . ale#Escape('shellcheck') . ' -s bash' . b:suffix, - \ ale_linters#sh#shellcheck#GetCommand(bufnr(''), []) + AssertLinter 'shellcheck', + \ b:prefix . ale#Escape('shellcheck') . ' -s bash' . b:suffix Execute(The shellcheck command should include the dialect before options and exclusions): let b:is_bash = 1 let b:ale_sh_shellcheck_options = '--foobar' let b:ale_sh_shellcheck_exclusions = 'foo,bar' - AssertEqual - \ b:prefix - \ . ale#Escape('shellcheck') + AssertLinter 'shellcheck', b:prefix . ale#Escape('shellcheck') \ . ' -s bash --foobar -e foo,bar' - \ . b:suffix, - \ ale_linters#sh#shellcheck#GetCommand(bufnr(''), []) + \ . b:suffix -Execute(The VersionCheck function should return the --version command): - AssertEqual +Execute(The -x option should be added when the version is new enough): + AssertLinter 'shellcheck', [ \ ale#Escape('shellcheck') . ' --version', - \ ale_linters#sh#shellcheck#VersionCheck(bufnr('')) - - let g:ale_sh_shellcheck_executable = 'foobar' - - AssertEqual - \ ale#Escape('foobar') . ' --version', - \ ale_linters#sh#shellcheck#VersionCheck(bufnr('')) + \ b:prefix . ale#Escape('shellcheck') . b:suffix, + \] -Execute(The -x option should be added when the version is new enough): - AssertEqual + WithChainResults [ + \ 'ShellCheck - shell script analysis tool', + \ 'version: 0.4.4', + \ 'license: GNU General Public License, version 3', + \ 'website: http://www.shellcheck.net', + \] + AssertLinter 'shellcheck', [ + \ ale#Escape('shellcheck') . ' --version', \ b:prefix . ale#Escape('shellcheck') . ' -x' . b:suffix, - \ ale_linters#sh#shellcheck#GetCommand(bufnr(''), [ - \ 'ShellCheck - shell script analysis tool', - \ 'version: 0.4.4', - \ 'license: GNU General Public License, version 3', - \ 'website: http://www.shellcheck.net', - \ ]) + \] " We should cache the version check - AssertEqual + WithChainResults [] + AssertLinter 'shellcheck', [ + \ '', \ b:prefix . ale#Escape('shellcheck') . ' -x' . b:suffix, - \ ale_linters#sh#shellcheck#GetCommand(bufnr(''), []) - - AssertEqual '', ale_linters#sh#shellcheck#VersionCheck(bufnr('')) + \] -Execute(The version check shouldn't be run again for new versions): - call ale_linters#sh#shellcheck#GetCommand(bufnr(''), [ +Execute(The -x option should not be added when the version is too old): + WithChainResults [ \ 'ShellCheck - shell script analysis tool', - \ 'version: 0.4.4', + \ 'version: 0.3.9', \ 'license: GNU General Public License, version 3', \ 'website: http://www.shellcheck.net', - \]) - -Execute(The -x option should not be added when the version is too old): - AssertEqual - \ b:prefix . ale#Escape('shellcheck') . b:suffix, - \ ale_linters#sh#shellcheck#GetCommand(bufnr(''), [ - \ 'ShellCheck - shell script analysis tool', - \ 'version: 0.3.9', - \ 'license: GNU General Public License, version 3', - \ 'website: http://www.shellcheck.net', - \ ]) - - " We should cache the version check - AssertEqual + \] + AssertLinter 'shellcheck', [ + \ ale#Escape('shellcheck') . ' --version', \ b:prefix . ale#Escape('shellcheck') . b:suffix, - \ ale_linters#sh#shellcheck#GetCommand(bufnr(''), []) + \] Execute(The version check shouldn't be run again for old versions): - call ale_linters#sh#shellcheck#GetCommand(bufnr(''), [ + WithChainResults [ \ 'ShellCheck - shell script analysis tool', \ 'version: 0.3.9', \ 'license: GNU General Public License, version 3', \ 'website: http://www.shellcheck.net', - \]) - - AssertEqual '', ale_linters#sh#shellcheck#VersionCheck(bufnr('')) + \] + AssertLinter 'shellcheck', [ + \ ale#Escape('shellcheck') . ' --version', + \ b:prefix . ale#Escape('shellcheck') . b:suffix, + \] + AssertLinter 'shellcheck', [ + \ '', + \ b:prefix . ale#Escape('shellcheck') . b:suffix, + \] -- cgit v1.2.3