diff options
Diffstat (limited to 'test')
22 files changed, 296 insertions, 327 deletions
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_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_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_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_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/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..02bae9c1 100644 --- a/test/fixers/test_prettier_fixer_callback.vader +++ b/test/fixers/test_prettier_fixer_callback.vader @@ -1,296 +1,286 @@ 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#assert#TearDownFixerTest() - call ale#test#RestoreDirectory() - call ale#semver#ResetVersionCache() + let g:ale_has_override = {} 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/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/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/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..0d12e665 100644 --- a/test/test_eslint_executable_detection.vader +++ b/test/test_eslint_executable_detection.vader @@ -54,11 +54,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_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_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]) |