diff options
Diffstat (limited to 'test')
53 files changed, 639 insertions, 375 deletions
diff --git a/test/command_callback/php-langserver-project/with-composer/composer.json b/test/command_callback/php-langserver-project/with-composer/composer.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/php-langserver-project/with-composer/composer.json diff --git a/test/command_callback/php-langserver-project/with-composer/vendor/bin/php-language-server.php b/test/command_callback/php-langserver-project/with-composer/vendor/bin/php-language-server.php new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/php-langserver-project/with-composer/vendor/bin/php-language-server.php diff --git a/test/command_callback/php-langserver-project/with-git/vendor/bin/php-language-server.php b/test/command_callback/php-langserver-project/with-git/vendor/bin/php-language-server.php new file mode 100755 index 00000000..e69de29b --- /dev/null +++ b/test/command_callback/php-langserver-project/with-git/vendor/bin/php-language-server.php diff --git a/test/command_callback/test_c_clang_command_callbacks.vader b/test/command_callback/test_c_clang_command_callbacks.vader index 7d2ff0bf..b8c02e4d 100644 --- a/test/command_callback/test_c_clang_command_callbacks.vader +++ b/test/command_callback/test_c_clang_command_callbacks.vader @@ -13,8 +13,8 @@ After: call ale#assert#TearDownLinterTest() Execute(The executable should be configurable): - AssertLinter 'clang', ['', ale#Escape('clang') . b:command_tail] + AssertLinter 'clang', [ale#Escape('clang') . b:command_tail] let b:ale_c_clang_executable = 'foobar' - AssertLinter 'foobar', ['', ale#Escape('foobar') . b:command_tail] + AssertLinter 'foobar', [ale#Escape('foobar') . b:command_tail] diff --git a/test/command_callback/test_c_gcc_command_callbacks.vader b/test/command_callback/test_c_gcc_command_callbacks.vader index 1f51c3bc..c5b316c8 100644 --- a/test/command_callback/test_c_gcc_command_callbacks.vader +++ b/test/command_callback/test_c_gcc_command_callbacks.vader @@ -14,8 +14,8 @@ After: unlet! b:command_tail Execute(The executable should be configurable): - AssertLinter 'gcc', ['', ale#Escape('gcc') . b:command_tail] + AssertLinter 'gcc', [ale#Escape('gcc') . b:command_tail] let b:ale_c_gcc_executable = 'foobar' - AssertLinter 'foobar', ['', ale#Escape('foobar') . b:command_tail] + AssertLinter 'foobar', [ale#Escape('foobar') . b:command_tail] diff --git a/test/command_callback/test_cargo_command_callbacks.vader b/test/command_callback/test_cargo_command_callbacks.vader index f0afbc91..438c97db 100644 --- a/test/command_callback/test_cargo_command_callbacks.vader +++ b/test/command_callback/test_cargo_command_callbacks.vader @@ -1,106 +1,113 @@ Before: call ale#assert#SetUpLinterTest('rust', 'cargo') + call ale#test#SetFilename('cargo_paths/test.rs') + let g:cd = 'cd ' . ale#Escape(ale#path#Simplify(g:dir . '/cargo_paths')) . ' && ' let g:suffix = ' --frozen --message-format=json -q' + let g:ale_rust_cargo_avoid_whole_workspace = 0 " Test with version 0.22.0 by default. - WithChainResults ['cargo 0.22.0 (3423351a5 2017-10-06)'] + GivenCommandOutput ['cargo 0.22.0 (3423351a5 2017-10-06)'] After: call ale#assert#TearDownLinterTest() + unlet! g:cd unlet! g:suffix Execute(The linter should not be executed when there's no Cargo.toml file): + call ale#test#SetFilename('../foo.rs') AssertLinterNotExecuted Execute(The linter should be executed when there is a Cargo.toml file): - call ale#test#SetFilename('cargo_paths/test.rs') - - WithChainResults [] - AssertLinter 'cargo', - \ 'cd ' . ale#Escape(ale#path#Simplify(g:dir . '/cargo_paths')) . ' && ' - \ . 'cargo build --frozen --message-format=json -q' - -Execute(The default command should be correct): - WithChainResults [] - AssertLinter '', ['cargo --version', 'cargo build' . g:suffix] + GivenCommandOutput [] + AssertLinter 'cargo', 'cargo build --frozen --message-format=json -q' Execute(`cargo check` should be used when the version is new enough): - WithChainResults ['cargo 0.17.0 (3423351a5 2017-10-06)'] - AssertLinter '', ['cargo --version', 'cargo check' . g:suffix] + GivenCommandOutput ['cargo 0.17.0 (3423351a5 2017-10-06)'] + AssertLinter 'cargo', [ + \ ale#Escape('cargo') . ' --version', + \ 'cargo check' . g:suffix, + \] " We should cache the version check - WithChainResults [] - AssertLinter '', ['', 'cargo check' . g:suffix] + GivenCommandOutput [] + AssertLinter 'cargo', ['cargo check' . g:suffix] Execute(`cargo build` should be used when cargo is too old): - WithChainResults ['cargo 0.16.0 (3423351a5 2017-10-06)'] - AssertLinter '', ['cargo --version', 'cargo build' . g:suffix] + GivenCommandOutput ['cargo 0.16.0 (3423351a5 2017-10-06)'] + AssertLinter 'cargo', [ + \ ale#Escape('cargo') . ' --version', + \ 'cargo build' . g:suffix, + \] - WithChainResults [] - AssertLinter '', ['', 'cargo build' . g:suffix] + GivenCommandOutput [] + AssertLinter 'cargo', ['cargo build' . g:suffix] Execute(`cargo build` should be used when g:ale_rust_cargo_use_check is set to 0): let g:ale_rust_cargo_use_check = 0 - WithChainResults ['cargo 0.24.0 (3423351a5 2017-10-06)'] - AssertLinter '', ['cargo --version', 'cargo build' . g:suffix] + GivenCommandOutput ['cargo 0.24.0 (3423351a5 2017-10-06)'] + AssertLinter 'cargo', [ + \ ale#Escape('cargo') . ' --version', + \ 'cargo build' . g:suffix, + \] " We should cache the version check - WithChainResults [] - AssertLinter '', ['', 'cargo build' . g:suffix] + GivenCommandOutput [] + AssertLinter 'cargo', ['cargo build' . g:suffix] Execute(`cargo check` should be used when the version is new enough): - AssertLinter '', ['cargo --version', 'cargo check' . g:suffix] + AssertLinter 'cargo', [ + \ ale#Escape('cargo') . ' --version', + \ 'cargo check' . g:suffix, + \] " We should cache the version check - WithChainResults [] - AssertLinter '', ['', 'cargo check' . g:suffix] + GivenCommandOutput [] + AssertLinter 'cargo', ['cargo check' . g:suffix] Execute(--all-targets should be used when g:ale_rust_cargo_check_all_targets is set to 1): let g:ale_rust_cargo_check_all_targets = 1 - AssertLinter '', ['cargo --version', 'cargo check --all-targets' . g:suffix] - + AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --all-targets' . g:suffix] " We should cache the version check - WithChainResults [] - AssertLinter '', ['', 'cargo check --all-targets' . g:suffix] + AssertLinter 'cargo', ['cargo check --all-targets' . g:suffix] Execute(--tests should be used when g:ale_rust_cargo_check_tests is set to 1): let g:ale_rust_cargo_check_tests = 1 - AssertLinter '', ['cargo --version', 'cargo check --tests' . g:suffix] + AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --tests' . g:suffix] " We should cache the version check - WithChainResults [] - AssertLinter '', ['', 'cargo check --tests' . g:suffix] + GivenCommandOutput [] + AssertLinter 'cargo', ['cargo check --tests' . g:suffix] Execute(--examples should be used when g:ale_rust_cargo_check_examples is set to 1): let g:ale_rust_cargo_check_examples = 1 - AssertLinter '', ['cargo --version', 'cargo check --examples' . g:suffix] + AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --examples' . g:suffix] " We should cache the version check - WithChainResults [] - AssertLinter '', ['', 'cargo check --examples' . g:suffix] + GivenCommandOutput [] + AssertLinter 'cargo', ['cargo check --examples' . g:suffix] Execute(--no-default-features should be used when g:ale_rust_cargo_default_feature_behavior is none): let b:ale_rust_cargo_default_feature_behavior = 'none' - AssertLinter '', ['cargo --version', 'cargo check --frozen --message-format=json -q --no-default-features'] + AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --no-default-features'] Execute(g:ale_rust_cargo_include_features added when g:ale_rust_cargo_default_feature_behavior is none): let b:ale_rust_cargo_default_feature_behavior = 'none' let b:ale_rust_cargo_include_features = 'foo bar' - AssertLinter '', ['cargo --version', 'cargo check --frozen --message-format=json -q --no-default-features --features ' . ale#Escape('foo bar')] + AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --no-default-features --features ' . ale#Escape('foo bar')] Execute(g:ale_rust_cargo_include_features added and escaped): let b:ale_rust_cargo_default_feature_behavior = 'default' let b:ale_rust_cargo_include_features = "foo bar baz" - AssertLinter '', ['cargo --version', 'cargo check --frozen --message-format=json -q --features ' . ale#Escape('foo bar baz')] + AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --features ' . ale#Escape('foo bar baz')] Execute(--all-features should be used when g:ale_rust_cargo_default_feature_behavior is all): let b:ale_rust_cargo_default_feature_behavior = 'all' @@ -108,14 +115,15 @@ Execute(--all-features should be used when g:ale_rust_cargo_default_feature_beha " since it won't do anything let b:ale_rust_cargo_include_features = 'foo bar' - WithChainResults ['cargo 0.22.0 (3423351a5 2017-10-06)'] - AssertLinter '', ['cargo --version', 'cargo check --frozen --message-format=json -q --all-features'] + GivenCommandOutput ['cargo 0.22.0 (3423351a5 2017-10-06)'] + AssertLinter 'cargo', [ale#Escape('cargo') . ' --version', 'cargo check --frozen --message-format=json -q --all-features'] Execute(When a crate belongs to a workspace we should cd into the crate): + let g:ale_rust_cargo_avoid_whole_workspace = 1 call ale#test#SetFilename('cargo_workspace_paths/subpath/test.rs') AssertLinter 'cargo', [ - \ 'cargo --version', + \ ale#Escape('cargo') . ' --version', \ 'cd ' . ale#Escape(ale#path#Simplify(g:dir . '/cargo_workspace_paths/subpath')) . ' && ' \ . 'cargo check --frozen --message-format=json -q', \] @@ -125,22 +133,22 @@ Execute(When a crate belongs to a workspace we chdir into the crate, unless we d call ale#test#SetFilename('cargo_workspace_paths/subpath/test.rs') AssertLinter 'cargo', [ - \ 'cargo --version', + \ ale#Escape('cargo') . ' --version', \ 'cargo check --frozen --message-format=json -q', \] Execute(When ale_rust_cargo_use_clippy is set, cargo-clippy is used as linter): let b:ale_rust_cargo_use_clippy = 1 - AssertLinter '', [ - \ 'cargo --version', + AssertLinter 'cargo', [ + \ ale#Escape('cargo') . ' --version', \ 'cargo clippy --frozen --message-format=json -q ', \] Execute(When ale_rust_cargo_clippy_options is set, cargo-clippy appends it to commandline): let b:ale_rust_cargo_use_clippy = 1 let b:ale_rust_cargo_clippy_options = '-- -D warnings' - AssertLinter '', [ - \ 'cargo --version', + AssertLinter 'cargo', [ + \ ale#Escape('cargo') . ' --version', \ 'cargo clippy --frozen --message-format=json -q -- -D warnings', \] @@ -148,7 +156,7 @@ Execute(cargo-check does not refer ale_rust_cargo_clippy_options): let b:ale_rust_cargo_use_clippy = 0 let b:ale_rust_cargo_use_check = 1 let b:ale_rust_cargo_clippy_options = '-- -D warnings' - AssertLinter '', [ - \ 'cargo --version', + AssertLinter 'cargo', [ + \ ale#Escape('cargo') . ' --version', \ 'cargo check --frozen --message-format=json -q', \] diff --git a/test/command_callback/test_cookstyle_command_callback.vader b/test/command_callback/test_cookstyle_command_callback.vader new file mode 100644 index 00000000..ad7391cc --- /dev/null +++ b/test/command_callback/test_cookstyle_command_callback.vader @@ -0,0 +1,19 @@ +Before: + call ale#assert#SetUpLinterTest('chef', 'cookstyle') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default command should be correct): + AssertLinter 'cookstyle', ale#Escape('cookstyle') . ' --force-exclusion --format json --stdin %s' + +Execute(The executable path should be configurable): + let b:ale_chef_cookstyle_executable = 'foobar' + + AssertLinter 'foobar', ale#Escape('foobar') . ' --force-exclusion --format json --stdin %s' + +Execute(The linter options should be configurable): + let b:ale_chef_cookstyle_options = '--parallel' + + AssertLinter 'cookstyle', ale#Escape('cookstyle') . ' --parallel --force-exclusion --format json --stdin %s' + diff --git a/test/command_callback/test_elixir_ls_command_callbacks.vader b/test/command_callback/test_elixir_ls_command_callbacks.vader index ca785054..41a5bc34 100644 --- a/test/command_callback/test_elixir_ls_command_callbacks.vader +++ b/test/command_callback/test_elixir_ls_command_callbacks.vader @@ -1,25 +1,24 @@ Before: call ale#assert#SetUpLinterTest('elixir', 'elixir_ls') - let g:ale_has_override['win32'] = 0 - After: - let g:ale_has_override = {} - call ale#assert#TearDownLinterTest() -Execute(should set correct defaults (unix)): - AssertLinter 'elixir-ls/language_server.sh', 'elixir-ls/language_server.sh' - -Execute(should set correct defaults (win32)): - let g:ale_has_override['win32'] = 1 - - AssertLinter 'elixir-ls\language_server.bat', 'elixir-ls\language_server.bat' +Execute(should set correct defaults): + if has('win32') + AssertLinter 'elixir-ls\language_server.bat', 'elixir-ls\language_server.bat' + else + AssertLinter 'elixir-ls/language_server.sh', 'elixir-ls/language_server.sh' + endif Execute(should configure elixir-ls release location): let b:ale_elixir_elixir_ls_release = 'boo' - AssertLinter 'boo/language_server.sh', 'boo/language_server.sh' + if has('win32') + AssertLinter 'boo\language_server.bat', 'boo\language_server.bat' + else + AssertLinter 'boo/language_server.sh', 'boo/language_server.sh' + endif Execute(should set correct LSP values): call ale#test#SetFilename('elixir_paths/umbrella_project/apps/app1/lib/app.ex') diff --git a/test/command_callback/test_elm_lsp_command_callbacks.vader b/test/command_callback/test_elm_lsp_command_callbacks.vader new file mode 100644 index 00000000..d06ef134 --- /dev/null +++ b/test/command_callback/test_elm_lsp_command_callbacks.vader @@ -0,0 +1,29 @@ +Before: + call ale#assert#SetUpLinterTest('elm', 'elm_lsp') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default executable path should be correct): + call ale#test#SetFilename('../elm-test-files/newapp/src/Main.elm') + + AssertLinter 'elm-lsp', ale#Escape('elm-lsp') . ' --stdio' + +Execute(The project root should be detected correctly): + AssertLSPProject '' + + call ale#test#SetFilename('../elm-test-files/newapp/src/Main.elm') + + AssertLSPProject ale#path#Simplify(g:dir . '/../elm-test-files/newapp') + +Execute(Should let users configure a global executable and override local paths): + call ale#test#SetFilename('../elm-test-files/newapp/src/Main.elm') + + let g:ale_elm_lsp_executable = '/path/to/custom/elm-lsp' + let g:ale_elm_lsp_use_global = 1 + + AssertLinter '/path/to/custom/elm-lsp', + \ ale#Escape('/path/to/custom/elm-lsp') . ' --stdio' + +Execute(The language should be correct): + AssertLSPLanguage 'elm' diff --git a/test/command_callback/test_erlang_syntaxerl_command_callback.vader b/test/command_callback/test_erlang_syntaxerl_command_callback.vader index 28cff9b9..e7cc26ea 100644 --- a/test/command_callback/test_erlang_syntaxerl_command_callback.vader +++ b/test/command_callback/test_erlang_syntaxerl_command_callback.vader @@ -19,7 +19,7 @@ Execute (The executable should be configurable): \] Execute (The -b option should be used when available): - WithChainResults [ + GivenCommandOutput [ \ 'Syntax checker for Erlang (0.14.0)', \ 'Usage: syntaxerl [-d | --debug] <FILENAME>', \ ' syntaxerl <-h | --help>', @@ -31,7 +31,7 @@ Execute (The -b option should be used when available): \ ale#Escape('syntaxerl') . ' %t', \] - WithChainResults [ + GivenCommandOutput [ \ 'Syntax checker for Erlang (0.14.0)', \ 'Usage: syntaxerl [-b | --base <FILENAME>] [-d | --debug] <FILENAME>', \ ' syntaxerl <-h | --help>', diff --git a/test/command_callback/test_erubi_command_callback.vader b/test/command_callback/test_erubi_command_callback.vader index 0643efc2..0d88ff93 100644 --- a/test/command_callback/test_erubi_command_callback.vader +++ b/test/command_callback/test_erubi_command_callback.vader @@ -21,7 +21,7 @@ Execute(Executable should filter invalid eRuby when inside a Rails project): \] Execute(Command should be blank if the first command in the chain returns output): - WithChainResults [ + GivenCommandOutput [ \ "/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- erubi/capture_end (LoadError)", \ " from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'", \] diff --git a/test/command_callback/test_flake8_command_callback.vader b/test/command_callback/test_flake8_command_callback.vader index ede511e0..f082a63a 100644 --- a/test/command_callback/test_flake8_command_callback.vader +++ b/test/command_callback/test_flake8_command_callback.vader @@ -3,7 +3,7 @@ Before: let b:bin_dir = has('win32') ? 'Scripts' : 'bin' - WithChainResults ['3.0.0'] + GivenCommandOutput ['3.0.0'] After: unlet! b:executable @@ -18,16 +18,15 @@ Execute(The flake8 callbacks should return the correct default values): \] " The version check should be cached. - WithChainResults [] + GivenCommandOutput [] AssertLinter 'flake8', [ - \ '', \ ale#path#BufferCdString(bufnr('')) \ . ale#Escape('flake8') . ' --format=default --stdin-display-name %s -', \] " Try with older versions. call ale#semver#ResetVersionCache() - WithChainResults ['2.9.9'] + GivenCommandOutput ['2.9.9'] AssertLinter 'flake8', [ \ ale#Escape('flake8') . ' --version', \ ale#path#BufferCdString(bufnr('')) @@ -45,7 +44,7 @@ Execute(The option for disabling changing directories should work): Execute(The flake8 command callback should let you set options): let g:ale_python_flake8_options = '--some-option' - WithChainResults ['3.0.4'] + GivenCommandOutput ['3.0.4'] AssertLinter 'flake8', [ \ ale#Escape('flake8') . ' --version', \ ale#path#BufferCdString(bufnr('')) @@ -54,7 +53,7 @@ Execute(The flake8 command callback should let you set options): \] call ale#semver#ResetVersionCache() - WithChainResults ['2.9.9'] + GivenCommandOutput ['2.9.9'] AssertLinter 'flake8', [ \ ale#Escape('flake8') . ' --version', \ ale#path#BufferCdString(bufnr('')) @@ -129,7 +128,7 @@ Execute(Using `python -m flake8` should be supported for running flake8): let g:ale_python_flake8_executable = 'python' let g:ale_python_flake8_options = '-m flake8 --some-option' - WithChainResults ['2.9.9'] + GivenCommandOutput ['2.9.9'] AssertLinter 'python', [ \ ale#Escape('python') . ' -m flake8 --version', \ ale#path#BufferCdString(bufnr('')) @@ -142,7 +141,7 @@ Execute(Using `python -m flake8` should be supported for running flake8): " Leading spaces shouldn't matter let g:ale_python_flake8_options = ' -m flake8 --some-option' - WithChainResults ['2.9.9'] + GivenCommandOutput ['2.9.9'] AssertLinter 'python', [ \ ale#Escape('python') . ' -m flake8 --version', \ ale#path#BufferCdString(bufnr('')) @@ -154,14 +153,14 @@ Execute(Setting executable to 'pipenv' should append 'run flake8'): let g:ale_python_flake8_executable = 'path/to/pipenv' " FIXME: pipenv should check the version with flake8. - WithChainResults [] + GivenCommandOutput [] AssertLinter 'path/to/pipenv', \ ale#path#BufferCdString(bufnr('')) \ . ale#Escape('path/to/pipenv') . ' run flake8 --format=default -' Execute(Pipenv is detected when python_flake8_auto_pipenv is set): let g:ale_python_flake8_auto_pipenv = 1 - call ale#test#SetFilename('/testplugin/test/python_fixtures/pipenv/whatever.py') + call ale#test#SetFilename('../python_fixtures/pipenv/whatever.py') AssertLinter 'pipenv', \ ale#path#BufferCdString(bufnr('')) diff --git a/test/command_callback/test_gobuild_command_callback.vader b/test/command_callback/test_gobuild_command_callback.vader index c6e324f2..79015b75 100644 --- a/test/command_callback/test_gobuild_command_callback.vader +++ b/test/command_callback/test_gobuild_command_callback.vader @@ -3,7 +3,7 @@ Before: call ale#assert#SetUpLinterTest('go', 'gobuild') - WithChainResults ['/foo/bar', '/foo/baz'] + GivenCommandOutput ['/foo/bar', '/foo/baz'] After: Restore diff --git a/test/command_callback/test_gotype_command_callback.vader b/test/command_callback/test_gotype_command_callback.vader index 1898a0cb..113f4823 100644 --- a/test/command_callback/test_gotype_command_callback.vader +++ b/test/command_callback/test_gotype_command_callback.vader @@ -7,7 +7,7 @@ After: Execute(The default gotype command should be correct): AssertLinter 'gotype', - \ ale#path#CdString(expand('%:p:h')) . ' gotype .' + \ ale#path#CdString(expand('%:p:h')) . ' gotype -e .' Execute(The gotype callback should ignore test files): call ale#test#SetFilename('bla_test.go') diff --git a/test/command_callback/test_javac_command_callback.vader b/test/command_callback/test_javac_command_callback.vader index a7a928e4..42c64e54 100644 --- a/test/command_callback/test_javac_command_callback.vader +++ b/test/command_callback/test_javac_command_callback.vader @@ -48,30 +48,30 @@ Execute(The executable should be configurable): \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t' Execute(The javac callback should include discovered classpaths): - WithChainResults [ + let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [ \ '[DEBUG] Ignore this.', \ '[INFO] Something we should ignore.', \ '/foo/bar.jar', \ '/xyz/abc.jar', - \] + \], {}) - AssertLinter 'javac', + AssertEqual \ g:prefix \ . ' -cp ' \ . ale#Escape(join(['/foo/bar.jar', '/xyz/abc.jar'], g:cp_sep)) - \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t' + \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t', + \ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g') Execute(The javac callback should combine discovered classpaths and manual ones): let g:ale_java_javac_classpath = 'configured.jar' - - WithChainResults [ + let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [ \ '[DEBUG] Ignore this.', \ '[INFO] Something we should ignore.', \ '/foo/bar.jar', \ '/xyz/abc.jar', - \] + \], {}) - AssertLinter 'javac', + AssertEqual \ g:prefix \ . ' -cp ' \ . ale#Escape(join( @@ -82,11 +82,18 @@ Execute(The javac callback should combine discovered classpaths and manual ones) \ ], \ g:cp_sep \ )) - \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t' + \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t', + \ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g') let g:ale_java_javac_classpath = 'configured.jar' . g:cp_sep . 'configured2.jar' + let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [ + \ '[DEBUG] Ignore this.', + \ '[INFO] Something we should ignore.', + \ '/foo/bar.jar', + \ '/xyz/abc.jar', + \], {}) - AssertLinter 'javac', + AssertEqual \ g:prefix \ . ' -cp ' \ . ale#Escape(join( @@ -98,7 +105,8 @@ Execute(The javac callback should combine discovered classpaths and manual ones) \ ], \ g:cp_sep \ )) - \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t' + \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t', + \ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g') Execute(The javac callback should detect source directories): call ale#engine#Cleanup(bufnr('')) @@ -117,25 +125,25 @@ Execute(The javac callback should combine detected source directories and classp call ale#test#SetFilename('java_paths/src/main/java/com/something/dummy.java') call ale#engine#InitBufferInfo(bufnr('')) - WithChainResults [ + let b:command = ale_linters#java#javac#GetCommand(bufnr(''), [ \ '[DEBUG] Ignore this.', \ '[INFO] Something we should ignore.', \ '/foo/bar.jar', \ '/xyz/abc.jar', - \] - AssertLinter 'javac', + \], {}) + + AssertEqual \ ale#path#CdString(expand('%:p:h')) . ale#Escape('javac') . ' -Xlint' \ . ' -cp ' . ale#Escape(join(['/foo/bar.jar', '/xyz/abc.jar'], g:cp_sep)) \ . ' -sourcepath ' . ale#Escape( \ ale#path#Simplify(g:dir . '/java_paths/src/main/java/') \ ) - \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t' + \ . ' -d ' . ale#Escape('TEMP_DIR') . ' %t', + \ substitute(b:command, '%e', '\=ale#Escape(''javac'')', 'g') Execute(The javac callback should use g:ale_java_javac_options correctly): let g:ale_java_javac_options = '--anything --else' - let b:command = ale_linters#java#javac#GetCommand(bufnr(''), []) - AssertLinter 'javac', \ g:prefix . ' -d ' . ale#Escape('TEMP_DIR') . ' --anything --else %t' diff --git a/test/command_callback/test_php_langserver_callbacks.vader b/test/command_callback/test_php_langserver_callbacks.vader index 3b0a427e..59c3fe6c 100644 --- a/test/command_callback/test_php_langserver_callbacks.vader +++ b/test/command_callback/test_php_langserver_callbacks.vader @@ -2,10 +2,6 @@ Before: call ale#assert#SetUpLinterTest('php', 'langserver') After: - if isdirectory(g:dir . '/.git') - call delete(g:dir . '/.git', 'd') - endif - call ale#assert#TearDownLinterTest() Execute(The default executable path should be correct): @@ -23,7 +19,12 @@ Execute(Vendor executables should be detected): \ )) Execute(The project path should be correct for .git directories): - call ale#test#SetFilename('php-langserver-project/test.php') - call mkdir(g:dir . '/.git') + call ale#test#SetFilename('php-langserver-project/with-git/test.php') + silent! call mkdir('php-langserver-project/with-git/.git') + + AssertLSPProject ale#path#Simplify(g:dir . '/php-langserver-project/with-git') + +Execute(The project path should be correct for composer.json file): + call ale#test#SetFilename('php-langserver-project/with-composer/test.php') - AssertLSPProject g:dir + AssertLSPProject ale#path#Simplify(g:dir . '/php-langserver-project/with-composer') diff --git a/test/command_callback/test_phpstan_command_callbacks.vader b/test/command_callback/test_phpstan_command_callbacks.vader index 665661a3..a9df2d7c 100644 --- a/test/command_callback/test_phpstan_command_callbacks.vader +++ b/test/command_callback/test_phpstan_command_callbacks.vader @@ -1,7 +1,7 @@ Before: call ale#assert#SetUpLinterTest('php', 'phpstan') - WithChainResults ['0.10.2'] + GivenCommandOutput ['0.10.2'] After: call ale#assert#TearDownLinterTest() @@ -26,7 +26,7 @@ Execute(Custom phpstan configuration file): \ ale#Escape('phpstan') . ' analyze -l4 --errorFormat raw -c phpstan_config %s' Execute(Choose the right format for error format param): - WithChainResults ['0.10.3'] + GivenCommandOutput ['0.10.3'] AssertLinter 'phpstan', [ \ ale#Escape('phpstan') . ' --version', diff --git a/test/command_callback/test_psalm_command_callbacks.vader b/test/command_callback/test_psalm_command_callbacks.vader index d731054f..33d770c2 100644 --- a/test/command_callback/test_psalm_command_callbacks.vader +++ b/test/command_callback/test_psalm_command_callbacks.vader @@ -24,6 +24,9 @@ Execute(Vendor executables should be detected): Execute(The project path should be correct for .git directories): call ale#test#SetFilename('psalm-project/test.php') - call mkdir(g:dir . '/.git') - AssertLSPProject g:dir
\ No newline at end of file + if !isdirectory(g:dir . '/.git') + call mkdir(g:dir . '/.git') + endif + + AssertLSPProject g:dir diff --git a/test/command_callback/test_reek_command_callback.vader b/test/command_callback/test_reek_command_callback.vader index a7cb7fb9..798c3314 100644 --- a/test/command_callback/test_reek_command_callback.vader +++ b/test/command_callback/test_reek_command_callback.vader @@ -5,7 +5,7 @@ After: call ale#assert#TearDownLinterTest() Execute(The reek callbacks should return the correct default values): - WithChainResults ['reek 5.0.0'] + GivenCommandOutput ['reek 5.0.0'] AssertLinter 'reek', [ \ ale#Escape('reek') . ' --version', \ ale#Escape('reek') . ' -f json --no-progress --no-color --force-exclusion --stdin-filename %s', @@ -14,7 +14,7 @@ Execute(The reek callbacks should return the correct default values): " Try with older versions. call ale#semver#ResetVersionCache() - WithChainResults ['reek 4.8.2'] + GivenCommandOutput ['reek 4.8.2'] AssertLinter 'reek', [ \ ale#Escape('reek') . ' --version', \ ale#Escape('reek') . ' -f json --no-progress --no-color --force-exclusion', @@ -23,7 +23,7 @@ Execute(The reek callbacks should return the correct default values): Execute(Setting bundle appends 'exec reek'): let g:ale_ruby_reek_executable = 'bundle' - WithChainResults ['reek 5.0.0'] + GivenCommandOutput ['reek 5.0.0'] AssertLinter 'bundle', ale#Escape('bundle') \ . ' exec reek' \ . ' -f json --no-progress --no-color --force-exclusion --stdin-filename %s', @@ -31,20 +31,19 @@ Execute(Setting bundle appends 'exec reek'): " Try with older versions. call ale#semver#ResetVersionCache() - WithChainResults ['reek 4.8.2'] + GivenCommandOutput ['reek 4.8.2'] AssertLinter 'bundle', ale#Escape('bundle') \ . ' exec reek' \ . ' -f json --no-progress --no-color --force-exclusion' Execute(The reek version check should be cached): - WithChainResults ['reek 5.0.0'] + GivenCommandOutput ['reek 5.0.0'] AssertLinter 'reek', [ \ ale#Escape('reek') . ' --version', \ ale#Escape('reek') . ' -f json --no-progress --no-color --force-exclusion --stdin-filename %s', \] - WithChainResults [] + GivenCommandOutput [] AssertLinter 'reek', [ - \ '', \ ale#Escape('reek') . ' -f json --no-progress --no-color --force-exclusion --stdin-filename %s', \] diff --git a/test/command_callback/test_shellcheck_command_callback.vader b/test/command_callback/test_shellcheck_command_callback.vader index c5360b7d..fcdb184a 100644 --- a/test/command_callback/test_shellcheck_command_callback.vader +++ b/test/command_callback/test_shellcheck_command_callback.vader @@ -60,7 +60,7 @@ Execute(The -x option should be added when the version is new enough): \ b:prefix . ale#Escape('shellcheck') . b:suffix, \] - WithChainResults [ + GivenCommandOutput [ \ 'ShellCheck - shell script analysis tool', \ 'version: 0.4.4', \ 'license: GNU General Public License, version 3', @@ -72,14 +72,13 @@ Execute(The -x option should be added when the version is new enough): \] " We should cache the version check - WithChainResults [] + GivenCommandOutput [] AssertLinter 'shellcheck', [ - \ '', \ b:prefix . ale#Escape('shellcheck') . ' -x' . b:suffix, \] Execute(The -x option should not be added when the version is too old): - WithChainResults [ + GivenCommandOutput [ \ 'ShellCheck - shell script analysis tool', \ 'version: 0.3.9', \ 'license: GNU General Public License, version 3', @@ -91,7 +90,7 @@ Execute(The -x option should not be added when the version is too old): \] Execute(The version check shouldn't be run again for old versions): - WithChainResults [ + GivenCommandOutput [ \ 'ShellCheck - shell script analysis tool', \ 'version: 0.3.9', \ 'license: GNU General Public License, version 3', @@ -102,6 +101,5 @@ Execute(The version check shouldn't be run again for old versions): \ b:prefix . ale#Escape('shellcheck') . b:suffix, \] AssertLinter 'shellcheck', [ - \ '', \ b:prefix . ale#Escape('shellcheck') . b:suffix, \] diff --git a/test/command_callback/test_swift_sourcekitlsp_command_callbacks.vader b/test/command_callback/test_swift_sourcekitlsp_command_callbacks.vader new file mode 100644 index 00000000..4611c6de --- /dev/null +++ b/test/command_callback/test_swift_sourcekitlsp_command_callbacks.vader @@ -0,0 +1,21 @@ +Before: + call ale#assert#SetUpLinterTest('swift', 'sourcekitlsp') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The default executable path should be correct): + call ale#test#SetFilename('../swift-test-files/swift-package-project/src/folder/dummy.swift') + + AssertLinter 'sourcekit-lsp', ale#Escape('sourcekit-lsp') + +Execute(Should let users configure a global executable and override local paths): + call ale#test#SetFilename('../swift-test-files/swift-package-project/src/folder/dummy.swift') + + let g:ale_sourcekit_lsp_executable = '/path/to/custom/sourcekitlsp' + + AssertLinter '/path/to/custom/sourcekitlsp', + \ ale#Escape('/path/to/custom/sourcekitlsp') + +Execute(The language should be correct): + AssertLSPLanguage 'swift' diff --git a/test/fix/test_ale_fix.vader b/test/fix/test_ale_fix.vader index 52df2a62..9e5ad027 100644 --- a/test/fix/test_ale_fix.vader +++ b/test/fix/test_ale_fix.vader @@ -11,7 +11,6 @@ Before: let g:ale_enabled = 0 let g:ale_echo_cursor = 0 let g:ale_run_synchronously = 1 - unlet! g:ale_run_synchronously_callbacks let g:ale_set_lists_synchronously = 1 let g:ale_fix_buffer_data = {} let g:ale_fixers = { diff --git a/test/fixers/test_eslint_fixer_callback.vader b/test/fixers/test_eslint_fixer_callback.vader index 774595e3..7ea9c2cf 100644 --- a/test/fixers/test_eslint_fixer_callback.vader +++ b/test/fixers/test_eslint_fixer_callback.vader @@ -1,143 +1,129 @@ Before: - call ale#test#SetDirectory('/testplugin/test/fixers') + call ale#assert#SetUpFixerTest('javascript', 'eslint') + runtime autoload/ale/handlers/eslint.vim After: - call ale#test#RestoreDirectory() - call ale#semver#ResetVersionCache() + call ale#assert#TearDownFixerTest() Execute(The executable path should be correct): call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') " eslint_d output with an older eslint version is used here. - AssertEqual + GivenCommandOutput ['v4.4.1 (eslint_d v5.1.0)'] + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) \ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/.eslintrc.js')) \ . ' --fix %t', - \ }, - \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['v4.4.1 (eslint_d v5.1.0)']) + \ } Execute(The lower priority configuration file in a nested directory should be preferred): call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-config/testfile.js') - AssertEqual + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) \ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/subdir-with-config/.eslintrc')) \ . ' --fix %t', - \ }, - \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), []) + \ } Execute(package.json should be used as a last resort): call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-package-json/testfile.js') - AssertEqual + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) \ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/.eslintrc.js')) \ . ' --fix %t', - \ }, - \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), []) + \ } call ale#test#SetFilename('../eslint-test-files/package.json') - AssertEqual + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': \ ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/node_modules/.bin/eslint')) \ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/package.json')) \ . ' --fix %t', - \ }, - \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), []) + \ } Execute(The version check should be correct): - call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') + call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-config/testfile.js') - AssertEqual + " We should run the command to get the version the first time. + GivenCommandOutput ['4.9.0'] + AssertFixer [ + \ (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) + \ . ' --version', \ { - \ 'chain_with': 'ale#fixers#eslint#ApplyFixForVersion', \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) - \ . ' --version' + \ . ' --stdin-filename %s --stdin --fix-dry-run --format=json', + \ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput', \ }, - \ ale#fixers#eslint#Fix(bufnr('')) + \] + + AssertFixer [ + \ { + \ 'command': (has('win32') ? 'node.exe ' : '') + \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) + \ . ' --stdin-filename %s --stdin --fix-dry-run --format=json', + \ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput', + \ }, + \] Execute(--fix-dry-run should be used for 4.9.0 and up): call ale#test#SetFilename('../eslint-test-files/react-app/subdir/testfile.js') - AssertEqual + GivenCommandOutput ['4.9.0'] + AssertFixer \ { \ 'command': (has('win32') ? 'node.exe ' : '') \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) \ . ' --stdin-filename %s --stdin --fix-dry-run --format=json', \ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput', - \ }, - \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['4.9.0']) + \ } Execute(--fix-to-stdout should be used for eslint_d): call ale#test#SetFilename('../eslint-test-files/app-with-eslint-d/testfile.js') - AssertEqual + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': \ ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d')) \ . ' -c ' . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/package.json')) \ . ' --fix %t', - \ }, - \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['']) + \ } " The option should be used when eslint_d is new enough. " We look at the ESLint version instead of the eslint_d version. - AssertEqual + GivenCommandOutput ['v3.19.0 (eslint_d v4.2.0)'] + AssertFixer \ { \ 'command': \ ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d')) \ . ' --stdin-filename %s --stdin --fix-to-stdout', \ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput', - \ }, - \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['v3.19.0 (eslint_d v4.2.0)']) + \ } " The option should be used for new versions too. - AssertEqual + GivenCommandOutput ['4.9.0'] + AssertFixer \ { \ 'command': \ ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/app-with-eslint-d/node_modules/.bin/eslint_d')) \ . ' --stdin-filename %s --stdin --fix-to-stdout', \ 'process_with': 'ale#fixers#eslint#ProcessEslintDOutput', - \ }, - \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['4.9.0']) - -Execute(The version number should be cached): - call ale#test#SetFilename('../eslint-test-files/react-app/subdir-with-config/testfile.js') - - " Call the second callback with the version output. - call ale#fixers#eslint#ApplyFixForVersion(bufnr(''), ['4.9.0']) - - " The version command should be skipped. - AssertEqual - \ { - \ 'chain_with': 'ale#fixers#eslint#ApplyFixForVersion', - \ 'command': '', - \ }, - \ ale#fixers#eslint#Fix(bufnr('')) - - " Call it again without the version output. We should use the newer command. - AssertEqual - \ { - \ 'command': (has('win32') ? 'node.exe ' : '') - \ . ale#Escape(ale#path#Simplify(g:dir . '/../eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) - \ . ' --stdin-filename %s --stdin --fix-dry-run --format=json', - \ 'process_with': 'ale#fixers#eslint#ProcessFixDryRunOutput', - \ }, - \ ale#fixers#eslint#ApplyFixForVersion(bufnr(''), []) + \ } Execute(The --fix-dry-run post-processor should handle JSON output correctly): AssertEqual diff --git a/test/fixers/test_prettier_eslint_fixer.callback.vader b/test/fixers/test_prettier_eslint_fixer.callback.vader index 5c899d86..90e11672 100644 --- a/test/fixers/test_prettier_eslint_fixer.callback.vader +++ b/test/fixers/test_prettier_eslint_fixer.callback.vader @@ -1,54 +1,36 @@ Before: - call ale#test#SetDirectory('/testplugin/test/fixers') - - Save g:ale_javascript_prettier_eslint_executable - Save g:ale_javascript_prettier_eslint_use_global - Save g:ale_javascript_prettier_eslint_options - - unlet! g:ale_javascript_prettier_eslint_executable - unlet! g:ale_javascript_prettier_eslint_use_global - unlet! g:ale_javascript_prettier_eslint_options - - call ale#fixers#prettier_eslint#SetOptionDefaults() + call ale#assert#SetUpFixerTest('javascript', 'prettier_eslint') After: - Restore - - unlet! b:ale_javascript_prettier_eslint_executable - unlet! b:ale_javascript_prettier_eslint_use_global - unlet! b:ale_javascript_prettier_eslint_options - - call ale#test#RestoreDirectory() - call ale#semver#ResetVersionCache() + call ale#assert#TearDownFixerTest() Execute(The default command should be correct): - AssertEqual + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': \ ale#Escape('prettier-eslint') \ . ' %t' \ . ' --write' - \ }, - \ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), []) + \ } Execute(Additional options should be used when set): let b:ale_javascript_prettier_eslint_options = '--foobar' - AssertEqual + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': \ ale#Escape('prettier-eslint') \ . ' %t' \ . ' --foobar --write' - \ }, - \ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), []) + \ } Execute(--eslint-config-path should be set for 4.2.0 and up): call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js') - AssertEqual + GivenCommandOutput ['4.2.0'] + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': @@ -56,58 +38,57 @@ Execute(--eslint-config-path should be set for 4.2.0 and up): \ . ' %t' \ . ' --eslint-config-path ' . ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/.eslintrc.js')) \ . ' --write' - \ }, - \ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), ['4.2.0']) + \ } Execute(--eslint-config-path shouldn't be used for older versions): call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js') - AssertEqual + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': \ ale#Escape('prettier-eslint') \ . ' %t' \ . ' --write' - \ }, - \ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), []) + \ } Execute(The version check should be correct): - AssertEqual + AssertFixer [ + \ ale#Escape('prettier-eslint') . ' --version', \ { - \ 'chain_with': 'ale#fixers#prettier_eslint#ApplyFixForVersion', - \ 'command': ale#Escape('prettier-eslint') . ' --version', - \ }, - \ ale#fixers#prettier_eslint#Fix(bufnr('')) + \ 'read_temporary_file': 1, + \ 'command': + \ ale#Escape('prettier-eslint') + \ . ' %t' + \ . ' --write' + \ } + \] Execute(The new --stdin-filepath option should be used when the version is new enough): call ale#test#SetFilename('eslint-test-files/react-app/foo/bar.js') - AssertEqual + GivenCommandOutput ['4.4.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape('prettier-eslint') \ . ' --eslint-config-path ' . ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/.eslintrc.js')) \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), ['4.4.0']) + \ } Execute(The version number should be cached): - call ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), ['4.4.0']) - - " The version command should be skipped. - AssertEqual + GivenCommandOutput ['4.4.0'] + AssertFixer \ { - \ 'chain_with': 'ale#fixers#prettier_eslint#ApplyFixForVersion', - \ 'command': '', - \ }, - \ ale#fixers#prettier_eslint#Fix(bufnr('')) + \ 'command': ale#path#CdString(expand('%:p:h')) + \ . ale#Escape('prettier-eslint') + \ . ' --stdin-filepath %s --stdin', + \ } - " The newer command should be used. - AssertEqual + GivenCommandOutput [] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape('prettier-eslint') \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier_eslint#ApplyFixForVersion(bufnr(''), []) + \ } diff --git a/test/fixers/test_prettier_fixer_callback.vader b/test/fixers/test_prettier_fixer_callback.vader index 05ed421e..9be161ac 100644 --- a/test/fixers/test_prettier_fixer_callback.vader +++ b/test/fixers/test_prettier_fixer_callback.vader @@ -1,296 +1,284 @@ Before: - call ale#test#SetDirectory('/testplugin/test/fixers') - Save g:ale_javascript_prettier_executable - Save g:ale_javascript_prettier_options + call ale#assert#SetUpFixerTest('javascript', 'prettier') - " Use an invalid global executable, so we don't match it. - let g:ale_javascript_prettier_executable = 'xxxinvalid' - let g:ale_javascript_prettier_options = '' - - call ale#test#SetDirectory('/testplugin/test/fixers') silent cd .. silent cd command_callback let g:dir = getcwd() After: - let g:ale_has_override = {} - - call ale#test#RestoreDirectory() - call ale#semver#ResetVersionCache() + call ale#assert#TearDownFixerTest() Execute(The prettier callback should return the correct default values): call ale#test#SetFilename('../prettier-test-files/testfile.js') - AssertEqual + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': ale#Escape(g:ale_javascript_prettier_executable) \ . ' %t' \ . ' --write', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), []) + \ } Execute(The --config option should not be set automatically): let g:ale_javascript_prettier_use_local_config = 1 call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js') - AssertEqual + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': ale#Escape(g:ale_javascript_prettier_executable) \ . ' %t' \ . ' --write', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), []) + \ } Execute(The prettier callback should include custom prettier options): let g:ale_javascript_prettier_options = '--no-semi' call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js') - AssertEqual + AssertFixer \ { \ 'read_temporary_file': 1, \ 'command': ale#Escape(g:ale_javascript_prettier_executable) \ . ' %t' \ . ' --no-semi' \ . ' --write', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), []) + \ } Execute(The version check should be correct): call ale#test#SetFilename('../prettier-test-files/testfile.js') - AssertEqual - \ { - \ 'chain_with': 'ale#fixers#prettier#ApplyFixForVersion', - \ 'command': ale#Escape(g:ale_javascript_prettier_executable) - \ . ' --version', - \ }, - \ ale#fixers#prettier#Fix(bufnr('')) + AssertFixer [ + \ ale#Escape('prettier') . ' --version', + \ {'read_temporary_file': 1, 'command': ale#Escape('prettier') . ' %t --write'} + \] Execute(--stdin-filepath should be used when prettier is new enough): let g:ale_javascript_prettier_options = '--no-semi' call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js') - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --no-semi' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(The version number should be cached): call ale#test#SetFilename('../prettier-test-files/with_config/testfile.js') - " Call the second callback with the version output. - call ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + GivenCommandOutput ['1.6.0'] + AssertFixer + \ { + \ 'command': ale#path#CdString(expand('%:p:h')) + \ . ale#Escape(g:ale_javascript_prettier_executable) + \ . ' --stdin-filepath %s --stdin', + \ } - " Call it again without the version output. We should use the newer command. - AssertEqual + GivenCommandOutput [] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), []) + \ } Execute(Should set --parser to `babylon` by default, < 1.16.0): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=javascript - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser babylon' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser to `babel` by default, >= 1.16.0): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=javascript - AssertEqual + GivenCommandOutput ['1.16.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser babel' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.16.0']) + \ } Execute(Should set --parser based on filetype, TypeScript): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=typescript - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser typescript' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on filetype, CSS): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=css - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser css' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on filetype, LESS): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=less - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser less' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on filetype, SCSS): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=scss - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser scss' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on filetype, JSON): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=json - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser json' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on filetype, JSON5): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=json5 - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser json5' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on filetype, GraphQL): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=graphql - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser graphql' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on filetype, Markdown): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=markdown - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser markdown' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on filetype, Vue): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=vue - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser vue' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on filetype, YAML): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=yaml - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser yaml' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on filetype, HTML): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=html - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser html' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(Should set --parser based on first filetype of multiple filetypes): call ale#test#SetFilename('../prettier-test-files/testfile') set filetype=css.scss - AssertEqual + GivenCommandOutput ['1.6.0'] + AssertFixer \ { \ 'command': ale#path#CdString(expand('%:p:h')) \ . ale#Escape(g:ale_javascript_prettier_executable) \ . ' --parser css' \ . ' --stdin-filepath %s --stdin', - \ }, - \ ale#fixers#prettier#ApplyFixForVersion(bufnr(''), ['1.6.0']) + \ } Execute(The prettier_d post-processor should permit regular JavaScript content): AssertEqual diff --git a/test/handler/test_cookstyle_handler.vader b/test/handler/test_cookstyle_handler.vader new file mode 100644 index 00000000..7d705a19 --- /dev/null +++ b/test/handler/test_cookstyle_handler.vader @@ -0,0 +1,22 @@ +Before: + runtime ale_linters/chef/cookstyle.vim + +After: + call ale#linter#Reset() + +Execute(Basic warnings should be handled): + AssertEqual + \ [ + \ { + \ 'lnum': 58, + \ 'col': 24, + \ 'code': 'Style/UnneededInterpolation', + \ 'type': 'W', + \ 'end_col': 40, + \ 'text': 'Style/UnneededInterpolation: Prefer `to_s` over string interpolation.', + \ } + \ ], + \ ale_linters#chef#cookstyle#Handle(bufnr(''), [ + \ '{"metadata":{"rubocop_version":"0.62.0","ruby_engine":"ruby","ruby_version":"2.6.0","ruby_patchlevel":"0","ruby_platform":"x86_64-linux"},"files":[{"path":"recipes/default.rb","offenses":[{"severity":"convention","message":"Style/UnneededInterpolation: Prefer `to_s` over string interpolation.","cop_name":"Style/UnneededInterpolation","corrected":false,"location":{"start_line":58,"start_column":24,"last_line":58,"last_column":40,"length":17,"line":58,"column":24}}]}],"summary":{"offense_count":1,"target_file_count":1,"inspected_file_count":1}}' + \ ]) + diff --git a/test/handler/test_psscriptanalyzer_handler.vader b/test/handler/test_psscriptanalyzer_handler.vader new file mode 100644 index 00000000..060d5941 --- /dev/null +++ b/test/handler/test_psscriptanalyzer_handler.vader @@ -0,0 +1,42 @@ +Before: + runtime ale_linters/powershell/psscriptanalyzer.vim + +After: + call ale#linter#Reset() + +Execute(The psscriptanalyzer handler should handle basic information or warnings): + AssertEqual + \ [ + \ { + \ 'lnum': 1, + \ 'type': 'I', + \ 'text': 'The cmdlet ''Get-GithubRepo'' does not have a help comment.', + \ 'code': 'PSProvideCommentHelp', + \ }, + \ { + \ 'lnum': 9, + \ 'type': 'W', + \ 'text': '''%'' is an alias of ''ForEach-Object''. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.', + \ 'code': 'PSAvoidUsingCmdletAliases', + \ }, + \ { + \ 'lnum': 23, + \ 'type': 'E', + \ 'text': 'The ComputerName parameter of a cmdlet should not be hardcoded as this will expose sensitive information about the system.', + \ 'code': 'PSAvoidUsingComputerNameHardcoded', + \ }, + \ ], + \ ale_linters#powershell#psscriptanalyzer#Handle(bufnr(''), [ + \ '1', + \ 'Information', + \ 'The cmdlet ''Get-GithubRepo'' does not have a help comment.', + \ 'PSProvideCommentHelp', + \ '9', + \ 'Warning', + \ '''%'' is an alias of ''ForEach-Object''. Alias can introduce possible problems and make scripts hard to maintain. Please consider changing alias to its full content.', + \ 'PSAvoidUsingCmdletAliases', + \ '23', + \ 'Error', + \ 'The ComputerName parameter of a cmdlet should not be hardcoded as this will expose sensitive information about the system.', + \ 'PSAvoidUsingComputerNameHardcoded', + \ ]) diff --git a/test/handler/test_redpen_handler.vader b/test/handler/test_redpen_handler.vader index 4490bcba..0b030e2d 100644 --- a/test/handler/test_redpen_handler.vader +++ b/test/handler/test_redpen_handler.vader @@ -80,7 +80,7 @@ Execute(redpen handler should handle errors output): \ ']', \ ]) -Execute(redpen handler should no error output): +Execute(The redpen handler should handle an empty error list): AssertEqual \ [], \ ale#handlers#redpen#HandleRedpenOutput(bufnr(''), [ @@ -91,3 +91,8 @@ Execute(redpen handler should no error output): \ ' }', \ ']', \ ]) + +Execute(The redpen handler should handle totally empty output): + AssertEqual + \ [], + \ ale#handlers#redpen#HandleRedpenOutput(bufnr(''), []) diff --git a/test/jsonlint-test-files/app-without-jsonlint/src/app.json b/test/jsonlint-test-files/app-without-jsonlint/src/app.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/jsonlint-test-files/app-without-jsonlint/src/app.json diff --git a/test/jsonlint-test-files/app/node_modules/.bin/jsonlint b/test/jsonlint-test-files/app/node_modules/.bin/jsonlint new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/jsonlint-test-files/app/node_modules/.bin/jsonlint diff --git a/test/jsonlint-test-files/app/src/app.json b/test/jsonlint-test-files/app/src/app.json new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/jsonlint-test-files/app/src/app.json diff --git a/test/jsonlint-test-files/node_modules/jsonlint/lib/cli.js b/test/jsonlint-test-files/node_modules/jsonlint/lib/cli.js new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/jsonlint-test-files/node_modules/jsonlint/lib/cli.js diff --git a/test/lsp/test_lsp_client_messages.vader b/test/lsp/test_lsp_client_messages.vader index e0e2ef20..2abdf6ca 100644 --- a/test/lsp/test_lsp_client_messages.vader +++ b/test/lsp/test_lsp_client_messages.vader @@ -206,7 +206,7 @@ Execute(ale#lsp#message#DidChangeConfiguration() should return correct messages) \ } AssertEqual \ [ - \ 0, + \ 1, \ 'workspace/didChangeConfiguration', \ { \ 'settings': { diff --git a/test/lsp/test_lsp_startup.vader b/test/lsp/test_lsp_startup.vader index 2fbd32de..028ec9b1 100644 --- a/test/lsp/test_lsp_startup.vader +++ b/test/lsp/test_lsp_startup.vader @@ -3,6 +3,7 @@ Before: let g:ale_run_synchronously = 1 unlet! g:ale_run_synchronously_callbacks + unlet! g:ale_run_synchronously_emulate_commands runtime autoload/ale/lsp.vim runtime autoload/ale/lsp_linter.vim @@ -234,6 +235,7 @@ After: call ale#linter#Reset() call ale#lsp#ResetConnections() + unlet! g:ale_run_synchronously_callbacks unlet! g:job_map unlet! g:emulate_job_failure unlet! g:next_job_id diff --git a/test/lsp/test_reset_lsp.vader b/test/lsp/test_reset_lsp.vader index 4a1a155e..310b3d62 100644 --- a/test/lsp/test_reset_lsp.vader +++ b/test/lsp/test_reset_lsp.vader @@ -25,10 +25,10 @@ Before: call ale#linter#Define('testft', { \ 'name': 'lsplinter', \ 'lsp': 'tsserver', - \ 'executable_callback': 'EmptyString', - \ 'command_callback': 'EmptyString', - \ 'project_root_callback': 'EmptyString', - \ 'language_callback': 'EmptyString', + \ 'executable': function('EmptyString'), + \ 'command': function('EmptyString'), + \ 'project_root': function('EmptyString'), + \ 'language': function('EmptyString'), \}) call ale#linter#Define('testft', { diff --git a/test/sign/test_linting_sets_signs.vader b/test/sign/test_linting_sets_signs.vader index c72b0882..a8d5761f 100644 --- a/test/sign/test_linting_sets_signs.vader +++ b/test/sign/test_linting_sets_signs.vader @@ -13,6 +13,7 @@ Before: let g:ale_buffer_info = {} let g:ale_run_synchronously = 1 + unlet! g:ale_run_synchronously_callbacks let g:ale_set_signs = 1 " Disable features we don't need for these tests. let g:ale_set_quickfix = 0 @@ -58,6 +59,7 @@ After: delfunction TestCallback delfunction CollectSigns + unlet! g:ale_run_synchronously_callbacks sign unplace * call ale#linter#Reset() diff --git a/test/sign/test_sign_placement.vader b/test/sign/test_sign_placement.vader index 41bed715..f0b3ba2f 100644 --- a/test/sign/test_sign_placement.vader +++ b/test/sign/test_sign_placement.vader @@ -87,6 +87,7 @@ Before: After: Restore + unlet! g:ale_run_synchronously_callbacks unlet! g:loclist delfunction GenerateResults delfunction ParseSigns diff --git a/test/swift-test-files/non-swift-package-project/src/folder/dummy.swift b/test/swift-test-files/non-swift-package-project/src/folder/dummy.swift new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/swift-test-files/non-swift-package-project/src/folder/dummy.swift diff --git a/test/swift-test-files/swift-package-project/Package.swift b/test/swift-test-files/swift-package-project/Package.swift new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/swift-test-files/swift-package-project/Package.swift diff --git a/test/swift-test-files/swift-package-project/src/folder/dummy.swift b/test/swift-test-files/swift-package-project/src/folder/dummy.swift new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/test/swift-test-files/swift-package-project/src/folder/dummy.swift diff --git a/test/test_ale_has.vader b/test/test_ale_has.vader new file mode 100644 index 00000000..eb1da039 --- /dev/null +++ b/test/test_ale_has.vader @@ -0,0 +1,7 @@ +Execute(Checks for versions below the current version should succeed): + AssertEqual 1, ale#Has('ale-2.4.0') + AssertEqual 1, ale#Has('ALE-2.2.1') + AssertEqual 1, ale#Has('ALE-1.0.0') + +Execute(Checks for newer versions should fail): + AssertEqual 0, ale#Has('ALE-20.0.0') diff --git a/test/test_deferred_command_string.vader b/test/test_deferred_command_string.vader index 4d0c8977..026be6fe 100644 --- a/test/test_deferred_command_string.vader +++ b/test/test_deferred_command_string.vader @@ -17,10 +17,14 @@ Before: \ 'read_buffer': 0, \}) + " Run the test commands in the shell. + let g:ale_run_synchronously_emulate_commands = 0 + After: Restore call ale#assert#TearDownLinterTest() + unlet! g:ale_run_synchronously_callbacks Given foobar (Some imaginary filetype): Execute(It should be possible to compute an executable to check based on the result of commands): diff --git a/test/test_eslint_executable_detection.vader b/test/test_eslint_executable_detection.vader index c1438ed8..5599576e 100644 --- a/test/test_eslint_executable_detection.vader +++ b/test/test_eslint_executable_detection.vader @@ -6,7 +6,6 @@ Before: runtime ale_linters/javascript/eslint.vim After: - let g:ale_has_override = {} let g:ale_javascript_eslint_executable = 'eslint' let g:ale_javascript_eslint_use_global = 0 @@ -54,11 +53,17 @@ Execute(eslint_d should be detected correctly): Execute(eslint.js executables should be run with node on Windows): call ale#test#SetFilename('eslint-test-files/react-app/subdir/testfile.js') - let g:ale_has_override['win32'] = 1 " We have to execute the file with node. - AssertEqual - \ ale#Escape('node.exe') . ' ' - \ . ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) - \ . ' -f unix --stdin --stdin-filename %s', - \ ale#handlers#eslint#GetCommand(bufnr('')) + if has('win32') + AssertEqual + \ ale#Escape('node.exe') . ' ' + \ . ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) + \ . ' -f unix --stdin --stdin-filename %s', + \ ale#handlers#eslint#GetCommand(bufnr('')) + else + AssertEqual + \ ale#Escape(ale#path#Simplify(g:dir . '/eslint-test-files/react-app/node_modules/eslint/bin/eslint.js')) + \ . ' -f unix --stdin --stdin-filename %s', + \ ale#handlers#eslint#GetCommand(bufnr('')) + endif diff --git a/test/test_find_references.vader b/test/test_find_references.vader index eb06e3bc..1a147849 100644 --- a/test/test_find_references.vader +++ b/test/test_find_references.vader @@ -253,14 +253,15 @@ Execute(LSP reference responses should be handled): Execute(Preview windows should not be opened for empty LSP reference responses): call ale#references#SetMap({3: {}}) - call ale#references#HandleLSPResponse( - \ 1, - \ { - \ 'id': 3, - \ 'result': [ - \ ], - \ } - \) + call ale#references#HandleLSPResponse(1, {'id': 3, 'result': []}) + + Assert !g:preview_called + AssertEqual {}, ale#references#GetMap() + AssertEqual ['echom ''No references found.'''], g:expr_list + +Execute(LSP reference responses with a null result should be handled): + call ale#references#SetMap({3: {}}) + call ale#references#HandleLSPResponse(1, {'id': 3, 'result': v:null}) Assert !g:preview_called AssertEqual {}, ale#references#GetMap() diff --git a/test/test_flow_command.vader b/test/test_flow_command.vader index 9fc38930..4805e121 100644 --- a/test/test_flow_command.vader +++ b/test/test_flow_command.vader @@ -1,48 +1,46 @@ Before: runtime ale_linters/javascript/flow.vim - call ale#test#SetDirectory('/testplugin/test') + call ale#assert#SetUpLinterTest('javascript', 'flow') + call ale#test#SetDirectory('/testplugin/test/') After: unlet! b:ale_javascript_flow_use_respect_pragma - - call ale#test#RestoreDirectory() - call ale#linter#Reset() - call ale#semver#ResetVersionCache() + call ale#assert#TearDownLinterTest() Execute(flow should return a command to run if a .flowconfig file exists): call ale#test#SetFilename('flow/a/sub/dummy') - AssertEqual + AssertLinter 'flow', \ ale#Escape('flow') \ . ' check-contents --respect-pragma --json --from ale %s < %t' - \ . (!has('win32') ? '; echo' : ''), - \ ale_linters#javascript#flow#GetCommand(bufnr('%'), []) + \ . (!has('win32') ? '; echo' : '') Execute(flow should not use the respect pragma argument if the option is off): call ale#test#SetFilename('flow/a/sub/dummy') let b:ale_javascript_flow_use_respect_pragma = 0 - AssertEqual + AssertLinter 'flow', \ ale#Escape('flow') \ . ' check-contents --json --from ale %s < %t' - \ . (!has('win32') ? '; echo' : ''), - \ ale_linters#javascript#flow#GetCommand(bufnr('%'), []) + \ . (!has('win32') ? '; echo' : '') Execute(flow should should not use --respect-pragma for old versions): call ale#test#SetFilename('flow/a/sub/dummy') - AssertEqual + GivenCommandOutput [ + \ 'Warning: `flow --version` is deprecated in favor of `flow version`', + \ 'Flow, a static type checker for JavaScript, version 0.27.0', + \] + AssertLinter 'flow', [ + \ ale#Escape('flow') . ' --version', \ ale#Escape('flow') \ . ' check-contents --json --from ale %s < %t' \ . (!has('win32') ? '; echo' : ''), - \ ale_linters#javascript#flow#GetCommand(bufnr('%'), [ - \ 'Warning: `flow --version` is deprecated in favor of `flow version`', - \ 'Flow, a static type checker for JavaScript, version 0.27.0', - \ ]) + \] Execute(flow should not return a command to run if no .flowconfig file exists): call ale#test#SetFilename('flow/b/sub/dummy') - AssertEqual '', ale_linters#javascript#flow#GetCommand(bufnr('%'), []) + AssertLinterNotExecuted diff --git a/test/test_ignoring_linters.vader b/test/test_ignoring_linters.vader index 32eae954..2d9c67de 100644 --- a/test/test_ignoring_linters.vader +++ b/test/test_ignoring_linters.vader @@ -30,6 +30,7 @@ Execute(Exclude should ignore some invalid values): \ {'name': 'linter3', 'aliases': []}, \ ], \ 'foo', + \ 0, \ ) AssertEqual \ [ @@ -45,6 +46,7 @@ Execute(Exclude should ignore some invalid values): \ {'name': 'linter3', 'aliases': []}, \ ], \ 0, + \ 0, \ ) AssertEqual \ [ @@ -60,6 +62,7 @@ Execute(Exclude should ignore some invalid values): \ {'name': 'linter3', 'aliases': []}, \ ], \ v:null, + \ 0, \ ) Execute(Exclude should handle Lists): @@ -75,6 +78,7 @@ Execute(Exclude should handle Lists): \ {'name': 'linter3', 'aliases': []}, \ ], \ ['linter1', 'alias1'], + \ 0, \ ) Execute(Exclude should handle Dictionaries): @@ -90,11 +94,51 @@ Execute(Exclude should handle Dictionaries): \ {'name': 'linter3', 'aliases': []}, \ ], \ {'foo': ['linter1'], 'bar': ['alias1']}, + \ 0, + \ ) + +Execute(Exclude should filter LSP linters when g:ale_disable_lsp is set to 1): + let g:ale_disable_lsp = 1 + AssertEqual + \ [ + \ {'name': 'linter1', 'aliases': [], 'lsp': ''}, + \ {'name': 'linter2', 'aliases': []}, + \ ], + \ ale#engine#ignore#Exclude( + \ 'foo', + \ [ + \ {'name': 'linter1', 'aliases': [], 'lsp': ''}, + \ {'name': 'linter2', 'aliases': []}, + \ {'name': 'linter3', 'aliases': [], 'lsp': 'stdio'}, + \ ], + \ [], + \ 1, + \ ) + +Execute(Exclude should filter LSP linters when b:ale_disable_lsp is set to 1): + let b:ale_disable_lsp = 1 + AssertEqual + \ [ + \ {'name': 'linter1', 'aliases': [], 'lsp': ''}, + \ {'name': 'linter2', 'aliases': []}, + \ ], + \ ale#engine#ignore#Exclude( + \ 'foo', + \ [ + \ {'name': 'linter1', 'aliases': [], 'lsp': ''}, + \ {'name': 'linter2', 'aliases': []}, + \ {'name': 'linter3', 'aliases': [], 'lsp': 'stdio'}, + \ ], + \ [], + \ 1, \ ) Before: Save g:ale_linters_ignore Save g:ale_buffer_info + Save g:ale_disable_lsp + + let g:ale_disable_lsp = 0 let g:linters = [] let g:loclist = [] @@ -127,6 +171,7 @@ After: unlet! b:ale_linters_ignore unlet! b:ale_quitting unlet! b:ale_save_event_fired + unlet! b:ale_disable_lsp unlet! g:linters unlet! g:loclist unlet! g:lsp_message diff --git a/test/test_jsonlint_executable_detection.vader b/test/test_jsonlint_executable_detection.vader new file mode 100644 index 00000000..de52f846 --- /dev/null +++ b/test/test_jsonlint_executable_detection.vader @@ -0,0 +1,45 @@ +Before: + call ale#test#SetDirectory('/testplugin/test') + + runtime ale_linters/json/jsonlint.vim + +After: + let g:ale_json_jsonlint_executable = 'jsonlint' + let g:ale_json_jsonlint_use_global = 0 + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(local executable should be detected correctly): + call ale#test#SetFilename('jsonlint-test-files/app/src/app.json') + + AssertEqual + \ ale#path#Simplify(g:dir . '/jsonlint-test-files/app/node_modules/.bin/jsonlint'), + \ ale_linters#json#jsonlint#GetExecutable(bufnr('')) + +Execute(recursively executable should be detected correctly): + call ale#test#SetFilename('jsonlint-test-files/app-without-jsonlint/src/app.json') + + AssertEqual + \ ale#path#Simplify(g:dir . '/jsonlint-test-files/node_modules/jsonlint/lib/cli.js'), + \ ale_linters#json#jsonlint#GetExecutable(bufnr('')) + +Execute(use_global should override project executable): + let g:ale_json_jsonlint_use_global = 1 + + call ale#test#SetFilename('jsonlint-test-files/app/src/app.json') + + AssertEqual + \ 'jsonlint', + \ ale_linters#json#jsonlint#GetExecutable(bufnr('')) + +Execute(manually defined should override default executable): + let g:ale_json_jsonlint_use_global = 1 + let g:ale_json_jsonlint_executable = 'custom_jsonlint' + + call ale#test#SetFilename('jsonlint-test-files/app/src/app.json') + + AssertEqual + \ 'custom_jsonlint', + \ ale_linters#json#jsonlint#GetExecutable(bufnr('')) + diff --git a/test/test_path_uri.vader b/test/test_path_uri.vader index 504aba77..cc2287cb 100644 --- a/test/test_path_uri.vader +++ b/test/test_path_uri.vader @@ -9,15 +9,46 @@ Execute(ale#path#FromURI should work for Unix paths): AssertEqual '/foo/bar/baz.tst', ale#path#FromURI('FILE:/foo/bar/baz.tst') Execute(ale#path#FromURI should work for Windows paths): - AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:///C:/foo/bar/baz.tst') - AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:/C:/foo/bar/baz.tst') - AssertEqual 'c:\foo\bar\baz.tst', ale#path#FromURI('file:///c:/foo/bar/baz.tst') - AssertEqual 'c:\foo\bar\baz.tst', ale#path#FromURI('file:/c:/foo/bar/baz.tst') - AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('FILE:///C:/foo/bar/baz.tst') - AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('FILE:/C:/foo/bar/baz.tst') - -Execute(ale#path#FromURI should handle encoded paths that look like drive letters): - AssertEqual '/C:/foo/bar/baz.tst', ale#path#FromURI('file:///C%3A/foo/bar/baz.tst') + if has('win32') + AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:///C:/foo/bar/baz.tst') + AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:/C:/foo/bar/baz.tst') + AssertEqual 'c:\foo\bar\baz.tst', ale#path#FromURI('file:///c:/foo/bar/baz.tst') + AssertEqual 'c:\foo\bar\baz.tst', ale#path#FromURI('file:/c:/foo/bar/baz.tst') + AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('FILE:///C:/foo/bar/baz.tst') + AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('FILE:/C:/foo/bar/baz.tst') + else + AssertEqual '/C:/foo/bar/baz.tst', ale#path#FromURI('file:///C:/foo/bar/baz.tst') + AssertEqual '/C:/foo/bar/baz.tst', ale#path#FromURI('file:/C:/foo/bar/baz.tst') + AssertEqual '/c:/foo/bar/baz.tst', ale#path#FromURI('file:///c:/foo/bar/baz.tst') + AssertEqual '/c:/foo/bar/baz.tst', ale#path#FromURI('file:/c:/foo/bar/baz.tst') + AssertEqual '/C:/foo/bar/baz.tst', ale#path#FromURI('FILE:///C:/foo/bar/baz.tst') + AssertEqual '/C:/foo/bar/baz.tst', ale#path#FromURI('FILE:/C:/foo/bar/baz.tst') + endif + +Execute(ale#path#FromURI parse Windows paths with a pipe): + if has('win32') + AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:///C|/foo/bar/baz.tst') + AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:/C|/foo/bar/baz.tst') + AssertEqual 'c:\foo\bar\baz.tst', ale#path#FromURI('file:///c|/foo/bar/baz.tst') + AssertEqual 'c:\foo\bar\baz.tst', ale#path#FromURI('file:/c|/foo/bar/baz.tst') + AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('FILE:///C|/foo/bar/baz.tst') + AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('FILE:/C|/foo/bar/baz.tst') + else + AssertEqual '/C|/foo/bar/baz.tst', ale#path#FromURI('file:///C|/foo/bar/baz.tst') + AssertEqual '/C|/foo/bar/baz.tst', ale#path#FromURI('file:/C|/foo/bar/baz.tst') + AssertEqual '/c|/foo/bar/baz.tst', ale#path#FromURI('file:///c|/foo/bar/baz.tst') + AssertEqual '/c|/foo/bar/baz.tst', ale#path#FromURI('file:/c|/foo/bar/baz.tst') + AssertEqual '/C|/foo/bar/baz.tst', ale#path#FromURI('FILE:///C|/foo/bar/baz.tst') + AssertEqual '/C|/foo/bar/baz.tst', ale#path#FromURI('FILE:/C|/foo/bar/baz.tst') + endif + +Execute(ale#path#FromURI should handle the colon for the drive letter being encoded): + " These URIs shouldn't be created, but we'll handle them anyway. + if has('win32') + AssertEqual 'C:\foo\bar\baz.tst', ale#path#FromURI('file:///C%3A/foo/bar/baz.tst') + else + AssertEqual '/C:/foo/bar/baz.tst', ale#path#FromURI('file:///C%3A/foo/bar/baz.tst') + endif Execute(ale#path#ToURI should work for Unix paths): AssertEqual 'file:///foo/bar/baz.tst', ale#path#ToURI('/foo/bar/baz.tst') diff --git a/test/test_semver_utils.vader b/test/test_semver_utils.vader index 62483505..b38feb06 100644 --- a/test/test_semver_utils.vader +++ b/test/test_semver_utils.vader @@ -1,32 +1,20 @@ After: call ale#semver#ResetVersionCache() -Execute(GetVersion should return the version from the lines of output): +Execute(ParseVersion should return the version from the lines of output): " We should be able to parse the semver string from flake8 - AssertEqual [3, 0, 4], ale#semver#GetVersion('dummy', [ + AssertEqual [3, 0, 4], ale#semver#ParseVersion([ \ '3.0.4 (mccabe: 0.5.2, pyflakes: 1.2.3, pycodestyle: 2.0.0) CPython 2.7.12 on Linux', \ '1.2.3', \]) -Execute(GetVersion should return an empty list when no vesrion can be found): - AssertEqual [], ale#semver#GetVersion('dummy', ['x']) - AssertEqual [], ale#semver#GetVersion('dummy', []) +Execute(ParseVersion should return an empty list when no vesrion can be found): + AssertEqual [], ale#semver#ParseVersion(['x']) + AssertEqual [], ale#semver#ParseVersion([]) -Execute(GetVersion should cache the version): - AssertEqual [], ale#semver#GetVersion('dummy', []) - AssertEqual [3, 4, 7], ale#semver#GetVersion('dummy', ['Version 3.4.7']) - AssertEqual [3, 4, 17], ale#semver#GetVersion('dummy', ['Version 3.4.17']) - AssertEqual [3, 4, 17], ale#semver#GetVersion('dummy', []) - -Execute(GetVersion should tolerate missing patch numbers): +Execute(ParseVersion should tolerate missing patch numbers): " This goes against the semver spec, but we handle it anyway. - AssertEqual [3, 4, 0], ale#semver#GetVersion('dummy', ['Version 3.4']) - -Execute(HasVersion should return 1 when the version has been cached): - call ale#semver#GetVersion('dummy', []) - AssertEqual 0, ale#semver#HasVersion('dummy') - call ale#semver#GetVersion('dummy', ['3.4.7']) - AssertEqual 1, ale#semver#HasVersion('dummy') + AssertEqual [3, 4, 0], ale#semver#ParseVersion(['Version 3.4']) Execute(GTE should compare triples correctly): Assert ale#semver#GTE([3, 0, 4], [3, 0, 0]) diff --git a/test/test_should_do_nothing_conditions.vader b/test/test_should_do_nothing_conditions.vader index de2e2782..6dfed555 100644 --- a/test/test_should_do_nothing_conditions.vader +++ b/test/test_should_do_nothing_conditions.vader @@ -35,6 +35,10 @@ After: unlet! b:funky_command_created unlet! b:fake_mode + if &diff is 1 + let &diff = 0 + endif + runtime autoload/ale/util.vim Given foobar(An empty file): @@ -70,6 +74,11 @@ Execute(DoNothing should return 1 when an operator is pending): AssertEqual 1, ale#ShouldDoNothing(bufnr('')) +Execute(DoNothing should return 1 for diff buffers): + let &diff = 1 + + AssertEqual 1, ale#ShouldDoNothing(bufnr('')) + Execute(The DoNothing check should work if the ALE globals aren't defined): unlet! g:ale_filetype_blacklist unlet! g:ale_maximum_file_size diff --git a/test/test_swift_find_project_root.vader b/test/test_swift_find_project_root.vader new file mode 100644 index 00000000..7cb1cc29 --- /dev/null +++ b/test/test_swift_find_project_root.vader @@ -0,0 +1,18 @@ +Before: + call ale#test#SetDirectory('/testplugin/test') + +After: + call ale#test#RestoreDirectory() + +Execute(Detect root of Swift project with Package.swift correctly): + call ale#test#SetFilename('swift-test-files/swift-package-project/src/folder/dummy.swift') + AssertEqual + \ ale#path#Simplify(g:dir . '/swift-test-files/swift-package-project'), + \ ale#swift#FindProjectRoot(bufnr('')) + +Execute(Detect no root in case of non-Package.swift project): + call ale#test#SetFilename('swift-test-files/non-swift-package-project/src/folder/dummy.swift') + AssertEqual + \ '', + \ ale#swift#FindProjectRoot(bufnr('')) + diff --git a/test/test_swiftlint_executable_detection.vader b/test/test_swiftlint_executable_detection.vader index a8e14c84..dfd4930b 100644 --- a/test/test_swiftlint_executable_detection.vader +++ b/test/test_swiftlint_executable_detection.vader @@ -6,7 +6,6 @@ Before: runtime ale_linters/swift/swiftlint.vim After: - let g:ale_has_override = {} let g:ale_swift_swiftlint_executable = 'swiftlint' let g:ale_swift_swiftlint_use_global = 0 @@ -35,3 +35,5 @@ set ttimeoutlen=0 execute 'set encoding=utf-8' let g:mapleader=',' + +let g:ale_ignore_2_4_warnings = 1 |