#2132 - Replace command_chain and chain_with with ale#command#Run

This commit is contained in:
w0rp
2019-04-07 14:58:06 +01:00
parent cdf89f8269
commit 3bebcb5d48
48 changed files with 751 additions and 694 deletions

View File

@@ -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]

View File

@@ -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]

View File

@@ -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',
\]

View File

@@ -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>',

View File

@@ -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'",
\]

View File

@@ -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(''))

View File

@@ -3,7 +3,7 @@ Before:
call ale#assert#SetUpLinterTest('go', 'gobuild')
WithChainResults ['/foo/bar', '/foo/baz']
GivenCommandOutput ['/foo/bar', '/foo/baz']
After:
Restore

View File

@@ -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'

View File

@@ -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',

View File

@@ -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',
\]

View File

@@ -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,
\]