diff options
Diffstat (limited to 'test')
29 files changed, 855 insertions, 59 deletions
diff --git a/test/command_callback/test_bingo_command_callback.vader b/test/command_callback/test_bingo_command_callback.vader index f4cb3231..5544effa 100644 --- a/test/command_callback/test_bingo_command_callback.vader +++ b/test/command_callback/test_bingo_command_callback.vader @@ -1,4 +1,6 @@ Before: + Save g:ale_go_go111module + call ale#assert#SetUpLinterTest('go', 'bingo') After: @@ -9,6 +11,7 @@ After: endif unlet! b:ale_completion_enabled + unlet! b:ale_go_go111module call ale#assert#TearDownLinterTest() @@ -34,6 +37,14 @@ Execute(should set bingo options): AssertLinter 'bingo', \ ale#Escape('bingo') . ' --mode stdio --trace' +Execute(should support Go environment variables): + call ale#test#SetFilename('go_paths/go1/prj1/file.go') + let b:ale_go_go111module = 'on' + + AssertLinter 'bingo', + \ ale#Env('GO111MODULE', 'on') . ale#Escape('bingo') . ' --mode stdio' + + Execute(Should return directory for 'go.mod' if found in parent directory): call ale#test#SetFilename('../go_files/test.go') @@ -44,3 +55,20 @@ Execute(Should return nearest directory with '.git' if found in parent directory call mkdir(g:dir . '/.git') AssertLSPProject g:dir + +Execute(Should ignore 'go.mod' and return '.git' dir if modules off): + call ale#test#SetFilename('../go_files/test.go') + + let b:ale_go_go111module = 'off' + let b:parent_dir = ale#path#Simplify(g:dir . '/..') + let b:git_dir = b:parent_dir . '/.git' + + if !isdirectory(b:git_dir) + call mkdir(b:git_dir) + endif + + AssertLSPProject b:parent_dir + + call delete(b:git_dir, 'd') + unlet! b:parent_dir + unlet! b:git_dir diff --git a/test/command_callback/test_cargo_command_callbacks.vader b/test/command_callback/test_cargo_command_callbacks.vader index 438c97db..e56551ae 100644 --- a/test/command_callback/test_cargo_command_callbacks.vader +++ b/test/command_callback/test_cargo_command_callbacks.vader @@ -139,23 +139,60 @@ Execute(When a crate belongs to a workspace we chdir into the crate, unless we d 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', [ \ ale#Escape('cargo') . ' --version', - \ 'cargo clippy --frozen --message-format=json -q ', + \ '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', [ \ ale#Escape('cargo') . ' --version', \ 'cargo clippy --frozen --message-format=json -q -- -D warnings', \] +Execute(Clippy options work without prepending --): + let b:ale_rust_cargo_use_clippy = 1 + let b:ale_rust_cargo_clippy_options = '-D warnings' + + AssertLinter 'cargo', [ + \ ale#Escape('cargo') . ' --version', + \ 'cargo clippy --frozen --message-format=json -q -- -D warnings', + \] + +Execute(Build supports all cargo flags): + let g:ale_rust_cargo_use_check = 0 + let g:ale_rust_cargo_check_all_targets = 1 + let g:ale_rust_cargo_check_tests = 1 + let g:ale_rust_cargo_check_examples = 1 + let b:ale_rust_cargo_default_feature_behavior = 'all' + + AssertLinter 'cargo', [ + \ ale#Escape('cargo') . ' --version', + \ 'cargo build --all-targets --examples --tests --frozen --message-format=json -q --all-features', + \] + +Execute(Clippy supports all cargo flags): + let b:ale_rust_cargo_use_clippy = 1 + let g:ale_rust_cargo_check_all_targets = 1 + let g:ale_rust_cargo_check_tests = 1 + let g:ale_rust_cargo_check_examples = 1 + let b:ale_rust_cargo_default_feature_behavior = 'all' + let b:ale_rust_cargo_clippy_options = '-D warnings' + + AssertLinter 'cargo', [ + \ ale#Escape('cargo') . ' --version', + \ 'cargo clippy --all-targets --examples --tests --frozen --message-format=json -q --all-features -- -D warnings', + \] + 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', [ \ ale#Escape('cargo') . ' --version', \ 'cargo check --frozen --message-format=json -q', diff --git a/test/command_callback/test_cs_csc_command_callbacks.vader b/test/command_callback/test_cs_csc_command_callbacks.vader new file mode 100644 index 00000000..c21ce209 --- /dev/null +++ b/test/command_callback/test_cs_csc_command_callbacks.vader @@ -0,0 +1,47 @@ +Before: + call ale#assert#SetUpLinterTest('cs', 'csc') + +After: + call ale#assert#TearDownLinterTest() + +Execute(The csc linter should return the correct default command): + AssertLinter 'csc', ale#path#CdString(g:dir) + \ . 'csc /unsafe /out:TEMP /t:module /recurse:' . ale#Escape('*.cs') + +Execute(The options should be be used in the command): + let g:ale_cs_csc_options = '' + + AssertLinter 'csc', ale#path#CdString(g:dir) + \ . 'csc /unsafe /out:TEMP /t:module /recurse:' . ale#Escape('*.cs') + +Execute(The souce path should be be used in the command): + let g:ale_cs_csc_source = '../foo/bar' + + AssertLinter 'csc', ale#path#CdString('../foo/bar') + \ . 'csc /unsafe /out:TEMP /t:module /recurse:' . ale#Escape('*.cs') + +Execute(The list of search pathes for assemblies should be be used in the command if not empty): + let g:ale_cs_csc_assembly_path = ['/usr/lib/mono', '../foo/bar'] + + AssertLinter 'csc', ale#path#CdString(g:dir) + \ . 'csc /unsafe' + \ . ' /lib:' . ale#Escape('/usr/lib/mono') . ',' . ale#Escape('../foo/bar') + \ . ' /out:TEMP /t:module /recurse:' . ale#Escape('*.cs') + + let g:ale_cs_csc_assembly_path = [] + + AssertLinter 'csc', ale#path#CdString(g:dir) + \ . 'csc /unsafe /out:TEMP /t:module /recurse:' . ale#Escape('*.cs') + +Execute(The list of assemblies should be be used in the command if not empty): + let g:ale_cs_csc_assemblies = ['foo.dll', 'bar.dll'] + + AssertLinter 'csc', ale#path#CdString(g:dir) + \ . 'csc /unsafe' + \ . ' /r:' . ale#Escape('foo.dll') . ',' . ale#Escape('bar.dll') + \ . ' /out:TEMP /t:module /recurse:' . ale#Escape('*.cs') + + let g:ale_cs_csc_assemblies = [] + + AssertLinter 'csc', ale#path#CdString(g:dir) + \ . 'csc /unsafe /out:TEMP /t:module /recurse:' . ale#Escape('*.cs') diff --git a/test/command_callback/test_elm_lsp_command_callbacks.vader b/test/command_callback/test_elm_ls_command_callbacks.vader index d06ef134..3e1d5fbf 100644 --- a/test/command_callback/test_elm_lsp_command_callbacks.vader +++ b/test/command_callback/test_elm_ls_command_callbacks.vader @@ -1,5 +1,5 @@ Before: - call ale#assert#SetUpLinterTest('elm', 'elm_lsp') + call ale#assert#SetUpLinterTest('elm', 'elm_ls') After: call ale#assert#TearDownLinterTest() @@ -7,7 +7,7 @@ After: 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' + AssertLinter 'elm-language-server', ale#Escape('elm-language-server') . ' --stdio' Execute(The project root should be detected correctly): AssertLSPProject '' @@ -19,11 +19,11 @@ Execute(The project root should be detected correctly): 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 + let g:ale_elm_ls_executable = '/path/to/custom/elm-language-server' + let g:ale_elm_ls_use_global = 1 - AssertLinter '/path/to/custom/elm-lsp', - \ ale#Escape('/path/to/custom/elm-lsp') . ' --stdio' + AssertLinter '/path/to/custom/elm-language-server', + \ ale#Escape('/path/to/custom/elm-language-server') . ' --stdio' Execute(The language should be correct): AssertLSPLanguage 'elm' diff --git a/test/command_callback/test_gobuild_command_callback.vader b/test/command_callback/test_gobuild_command_callback.vader index 79015b75..fdf23866 100644 --- a/test/command_callback/test_gobuild_command_callback.vader +++ b/test/command_callback/test_gobuild_command_callback.vader @@ -14,6 +14,16 @@ Execute(The default commands should be correct): \ ale#path#CdString(expand('%:p:h')) \ . 'go test -c -o /dev/null ./' +Execute(Go environment variables should be supported): + let b:ale_go_go111module = 'on' + + AssertLinter 'go', + \ ale#path#CdString(expand('%:p:h')) + \ . ale#Env('GO111MODULE', 'on') + \ . 'go test -c -o /dev/null ./' + + unlet! b:ale_go_go111module + Execute(Extra options should be supported): let g:ale_go_gobuild_options = '--foo-bar' diff --git a/test/command_callback/test_gofmt_command_callback.vader b/test/command_callback/test_gofmt_command_callback.vader new file mode 100644 index 00000000..4da1f6c8 --- /dev/null +++ b/test/command_callback/test_gofmt_command_callback.vader @@ -0,0 +1,23 @@ +Before: + Save g:ale_go_go111module + + call ale#assert#SetUpLinterTest('go', 'gofmt') + call ale#test#SetFilename('../go_files/testfile2.go') + +After: + Restore + + unlet! b:ale_go_go111module + + call ale#assert#TearDownLinterTest() + +Execute(The default gofmt command should be correct): + AssertLinter 'gofmt', + \ ale#Escape('gofmt') . ' -e %t' + +Execute(The gofmt command should support Go environment variables): + let b:ale_go_go111module = 'on' + + AssertLinter 'gofmt', + \ ale#Env('GO111MODULE', 'on') + \ . ale#Escape('gofmt') . ' -e %t' diff --git a/test/command_callback/test_golangci_lint_command_callback.vader b/test/command_callback/test_golangci_lint_command_callback.vader index 345f58b1..7f1e2ac4 100644 --- a/test/command_callback/test_golangci_lint_command_callback.vader +++ b/test/command_callback/test_golangci_lint_command_callback.vader @@ -1,8 +1,14 @@ Before: + Save g:ale_go_go111module + call ale#assert#SetUpLinterTest('go', 'golangci_lint') call ale#test#SetFilename('test.go') After: + Restore + + unlet! b:ale_go_go111module + call ale#assert#TearDownLinterTest() Execute(The golangci-lint defaults should be correct): @@ -30,6 +36,16 @@ Execute(The golangci-lint callback should use configured options): \ . ' run ' . ale#Escape(expand('%' . ':t')) \ . ' --foobar' +Execute(The golangci-lint callback should support environment variables): + let b:ale_go_go111module = 'on' + + AssertLinter 'golangci-lint', + \ ale#path#CdString(expand('%:p:h')) + \ . ale#Env('GO111MODULE', 'on') + \ . ale#Escape('golangci-lint') + \ . ' run ' . ale#Escape(expand('%' . ':t')) + \ . ' --enable-all' + Execute(The golangci-lint `lint_package` option should use the correct command): let b:ale_go_golangci_lint_package = 1 diff --git a/test/command_callback/test_golangserver_command_callback.vader b/test/command_callback/test_golangserver_command_callback.vader index 90fdc26f..325adf63 100644 --- a/test/command_callback/test_golangserver_command_callback.vader +++ b/test/command_callback/test_golangserver_command_callback.vader @@ -1,6 +1,7 @@ Before: Save $GOPATH Save g:ale_completion_enabled + Save g:ale_go_go111module let g:ale_completion_enabled = 0 let g:sep = has('win32') ? ';' : ':' @@ -14,6 +15,7 @@ After: Restore unlet! b:ale_completion_enabled + unlet! b:ale_go_go111module unlet! g:sep call ale#assert#TearDownLinterTest() @@ -52,6 +54,12 @@ Execute(should ignore go-langserver -gocodecompletion option): AssertLinter 'go-langserver', ale#Escape('go-langserver') . ' -trace' +Execute(should support Go environment variables): + let b:ale_go_go111module = 'on' + + AssertLinter 'go-langserver', + \ ale#Env('GO111MODULE', 'on') . ale#Escape('go-langserver') + Execute(should set go-langserver for go app1): call ale#test#SetFilename('go_paths/go1/prj1/file.go') diff --git a/test/command_callback/test_golint_command_callbacks.vader b/test/command_callback/test_golint_command_callbacks.vader index 7c300309..64916707 100644 --- a/test/command_callback/test_golint_command_callbacks.vader +++ b/test/command_callback/test_golint_command_callbacks.vader @@ -1,7 +1,13 @@ Before: + Save g:ale_go_go111module + call ale#assert#SetUpLinterTest('go', 'golint') After: + Restore + + unlet! b:ale_go_go111module + call ale#assert#TearDownLinterTest() Execute(The default golint command should be correct): @@ -16,3 +22,9 @@ Execute(The golint options should be configurable): let b:ale_go_golint_options = '--foo' AssertLinter 'golint', ale#Escape('golint') . ' --foo %t' + +Execute(The golint command should support Go environment variables): + let b:ale_go_go111module = 'on' + + AssertLinter 'golint', + \ ale#Env('GO111MODULE', 'on') . ale#Escape('golint') . ' %t' diff --git a/test/command_callback/test_gometalinter_command_callback.vader b/test/command_callback/test_gometalinter_command_callback.vader index 88e86801..d922efc6 100644 --- a/test/command_callback/test_gometalinter_command_callback.vader +++ b/test/command_callback/test_gometalinter_command_callback.vader @@ -1,8 +1,14 @@ Before: + Save g:ale_go_go111module + call ale#assert#SetUpLinterTest('go', 'gometalinter') call ale#test#SetFilename('test.go') After: + Restore + + unlet! b:ale_go_go111module + call ale#assert#TearDownLinterTest() Execute(The gometalinter defaults should be correct): @@ -30,6 +36,16 @@ Execute(The gometalinter callback should use configured options): \ . ' --include=' . ale#Escape(ale#util#EscapePCRE(expand('%' . ':t'))) \ . ' --foobar' . ' .' +Execute(The gometalinter should use configured environment variables): + let b:ale_go_go111module = 'off' + + AssertLinter 'gometalinter', + \ ale#path#CdString(expand('%:p:h')) + \ . ale#Env('GO111MODULE', 'off') + \ . ale#Escape('gometalinter') + \ . ' --include=' . ale#Escape(ale#util#EscapePCRE(expand('%' . ':t'))) + \ . ' .' + Execute(The gometalinter `lint_package` option should use the correct command): let b:ale_go_gometalinter_lint_package = 1 diff --git a/test/command_callback/test_gopls_command_callback.vader b/test/command_callback/test_gopls_command_callback.vader index 0e079a73..92b20b18 100644 --- a/test/command_callback/test_gopls_command_callback.vader +++ b/test/command_callback/test_gopls_command_callback.vader @@ -1,13 +1,15 @@ Before: + Save g:ale_go_go111module + call ale#assert#SetUpLinterTest('go', 'gopls') After: - Restore - if isdirectory(g:dir . '/.git') call delete(g:dir . '/.git', 'd') endif + unlet! b:ale_go_go111module + unlet! b:ale_go_go111module unlet! b:ale_completion_enabled call ale#assert#TearDownLinterTest() @@ -34,6 +36,12 @@ Execute(should set gopls options): AssertLinter 'gopls', \ ale#Escape('gopls') . ' --mode stdio --trace' +Execute(should support go environment variables): + let b:ale_go_go111module = 'off' + + AssertLinter 'gopls', + \ ale#Env('GO111MODULE', 'off') . ale#Escape('gopls') . ' --mode stdio' + Execute(Should return directory for 'go.mod' if found in parent directory): call ale#test#SetFilename('../go_files/test.go') @@ -44,3 +52,20 @@ Execute(Should return nearest directory with '.git' if found in parent directory call mkdir(g:dir . '/.git') AssertLSPProject g:dir + +Execute(Should ignore 'go.mod' and return '.git' dir if modules off): + call ale#test#SetFilename('../go_files/test.go') + + let b:ale_go_go111module = 'off' + let b:parent_dir = ale#path#Simplify(g:dir . '/..') + let b:git_dir = b:parent_dir . '/.git' + + if !isdirectory(b:git_dir) + call mkdir(b:git_dir) + endif + + AssertLSPProject b:parent_dir + + call delete(b:git_dir, 'd') + unlet! b:parent_dir + unlet! b:git_dir diff --git a/test/command_callback/test_gosimple_command_callback.vader b/test/command_callback/test_gosimple_command_callback.vader index 59013df0..ee89eed8 100644 --- a/test/command_callback/test_gosimple_command_callback.vader +++ b/test/command_callback/test_gosimple_command_callback.vader @@ -1,10 +1,21 @@ Before: + Save g:ale_go_go111module + call ale#assert#SetUpLinterTest('go', 'gosimple') call ale#test#SetFilename('../go_files/testfile2.go') After: + unlet! b:ale_go_go111module + call ale#assert#TearDownLinterTest() Execute(The default gosimple command should be correct): AssertLinter 'gosimple', \ ale#path#CdString(expand('%:p:h')) . ' gosimple .' + +Execute(The gosimple command should support Go environment variables): + let b:ale_go_go111module = 'on' + + AssertLinter 'gosimple', + \ ale#path#CdString(expand('%:p:h')) . ' ' + \ . ale#Env('GO111MODULE', 'on') . 'gosimple .' diff --git a/test/command_callback/test_gotype_command_callback.vader b/test/command_callback/test_gotype_command_callback.vader index 113f4823..1334fcff 100644 --- a/test/command_callback/test_gotype_command_callback.vader +++ b/test/command_callback/test_gotype_command_callback.vader @@ -1,8 +1,12 @@ Before: + Save g:ale_go_go111module + call ale#assert#SetUpLinterTest('go', 'gotype') call ale#test#SetFilename('../go_files/testfile2.go') After: + unlet! b:ale_go_go111module + call ale#assert#TearDownLinterTest() Execute(The default gotype command should be correct): @@ -13,3 +17,11 @@ Execute(The gotype callback should ignore test files): call ale#test#SetFilename('bla_test.go') AssertLinter 'gotype', '' + +Execute(The gotype callback should support Go environment variables): + let b:ale_go_go111module = 'on' + + AssertLinter 'gotype', + \ ale#path#CdString(expand('%:p:h')) . ' ' + \ . ale#Env('GO111MODULE', 'on') + \ . 'gotype -e .' diff --git a/test/command_callback/test_govet_command_callback.vader b/test/command_callback/test_govet_command_callback.vader index a55c0812..59022180 100644 --- a/test/command_callback/test_govet_command_callback.vader +++ b/test/command_callback/test_govet_command_callback.vader @@ -1,10 +1,15 @@ Before: Save g:ale_go_go_executable Save g:ale_go_govet_options + Save g:ale_go_go111module + call ale#assert#SetUpLinterTest('go', 'govet') After: Restore + + unlet! b:ale_go_go111module + call ale#assert#TearDownLinterTest() Execute(The default command should be correct): @@ -12,8 +17,18 @@ Execute(The default command should be correct): Execute(Extra options should be supported): let g:ale_go_govet_options = '--foo-bar' + AssertLinter 'go', ale#path#CdString(expand('%:p:h')) . ' go vet --foo-bar .' Execute(The executable should be configurable): let g:ale_go_go_executable = 'foobar' + AssertLinter 'foobar', ale#path#CdString(expand('%:p:h')) . ' foobar vet .' + +Execute(Go environment variables should be supported): + let b:ale_go_go111module = 'on' + + AssertLinter 'go', + \ ale#path#CdString(expand('%:p:h')) . ' ' + \ . ale#Env('GO111MODULE', 'on') + \ . 'go vet .' diff --git a/test/command_callback/test_sorbet_command_callback.vader b/test/command_callback/test_sorbet_command_callback.vader new file mode 100644 index 00000000..b46e90a4 --- /dev/null +++ b/test/command_callback/test_sorbet_command_callback.vader @@ -0,0 +1,27 @@ + +Before: + call ale#assert#SetUpLinterTest('ruby', 'sorbet') + call ale#test#SetFilename('dummy.rb') + + let g:ale_ruby_sorbet_executable = 'srb' + let g:ale_ruby_sorbet_options = '' + +After: + call ale#assert#TearDownLinterTest() + +Execute(Executable should default to srb): + AssertLinter 'srb', ale#Escape('srb') + \ . ' tc --lsp --disable-watchman' + +Execute(Should be able to set a custom executable): + let g:ale_ruby_sorbet_executable = 'bin/srb' + + AssertLinter 'bin/srb' , ale#Escape('bin/srb') + \ . ' tc --lsp --disable-watchman' + +Execute(Setting bundle appends 'exec srb tc'): + let g:ale_ruby_sorbet_executable = 'path to/bundle' + + AssertLinter 'path to/bundle', ale#Escape('path to/bundle') + \ . ' exec srb' + \ . ' tc --lsp --disable-watchman' diff --git a/test/command_callback/test_staticcheck_command_callback.vader b/test/command_callback/test_staticcheck_command_callback.vader index 7f17b146..ae0d3584 100644 --- a/test/command_callback/test_staticcheck_command_callback.vader +++ b/test/command_callback/test_staticcheck_command_callback.vader @@ -1,8 +1,12 @@ Before: + Save g:ale_go_go111module + call ale#assert#SetUpLinterTest('go', 'staticcheck') call ale#test#SetFilename('test.go') After: + unlet! b:ale_go_go111module + call ale#assert#TearDownLinterTest() Execute(The staticcheck callback should return the right defaults): @@ -24,3 +28,20 @@ Execute(The staticcheck `lint_package` option should use the correct command): AssertLinter 'staticcheck', \ ale#path#CdString(expand('%:p:h')) . 'staticcheck .', + +Execute(The staticcheck callback should use the `GO111MODULE` option if set): + let b:ale_go_go111module = 'off' + + AssertLinter 'staticcheck', + \ ale#path#CdString(expand('%:p:h')) + \ . ale#Env('GO111MODULE', 'off') + \ . 'staticcheck ' + \ . ale#Escape(expand('%' . ':t')) + + " Test with lint_package option set + let b:ale_go_staticcheck_lint_package = 1 + + AssertLinter 'staticcheck', + \ ale#path#CdString(expand('%:p:h')) + \ . ale#Env('GO111MODULE', 'off') + \ . 'staticcheck .' diff --git a/test/completion/test_completion_events.vader b/test/completion/test_completion_events.vader index 6bc0035e..5672f8e5 100644 --- a/test/completion/test_completion_events.vader +++ b/test/completion/test_completion_events.vader @@ -62,6 +62,10 @@ After: delfunction CheckCompletionCalled + if exists('*CompleteCallback') + delfunction CompleteCallback + endif + " Stop any timers we left behind. " This stops the tests from failing randomly. call ale#completion#StopTimer() @@ -333,6 +337,30 @@ Execute(b:ale_completion_info should be set up correctly for other sources): \ b:ale_completion_info Assert !exists('b:ale_completion_result') +Execute(b:ale_completion_info should be set up correctly when requesting completions via callback): + let b:ale_completion_result = [] + call setpos('.', [bufnr(''), 3, 14, 0]) + + function! CompleteCallback() abort + echo 'Called' + endfunction + + + call ale#completion#GetCompletions('ale-callback', {'callback': funcref('CompleteCallback')}) + + AssertEqual + \ { + \ 'request_id': 0, + \ 'conn_id': 0, + \ 'column': 14, + \ 'line_length': 14, + \ 'line': 3, + \ 'prefix': 'ab', + \ 'source': 'ale-callback', + \ }, + \ b:ale_completion_info + Assert !exists('b:ale_completion_result') + Execute(The correct keybinds should be configured): redir => g:output silent map <Plug>(ale_show_completion_menu) diff --git a/test/completion/test_public_completion_api.vader b/test/completion/test_public_completion_api.vader index befbb436..c3cd42b8 100644 --- a/test/completion/test_public_completion_api.vader +++ b/test/completion/test_public_completion_api.vader @@ -32,6 +32,10 @@ Execute(ale#completion#GetCompletionPosition() should return the position in the " This is the first character of 'bar' AssertEqual 4, ale#completion#GetCompletionPosition() +Execute(ale#completion#GetCompletionPositionForDeoplete() should return the position on the given input string): + " This is the first character of 'bar' + AssertEqual 4, ale#completion#GetCompletionPositionForDeoplete('foo bar') + Execute(ale#completion#CanProvideCompletions should return 0 when no completion sources are available): AssertEqual 0, ale#completion#CanProvideCompletions() diff --git a/test/fixers/test_clangformat_fixer_callback.vader b/test/fixers/test_clangformat_fixer_callback.vader index a55576bf..ae7db4cf 100644 --- a/test/fixers/test_clangformat_fixer_callback.vader +++ b/test/fixers/test_clangformat_fixer_callback.vader @@ -20,7 +20,7 @@ Execute(The clang-format callback should return the correct default values): AssertEqual \ { \ 'command': ale#Escape(g:ale_c_clangformat_executable) - \ . ' ' + \ . ' --assume-filename=' . ale#Escape(bufname(bufnr(''))) \ }, \ ale#fixers#clangformat#Fix(bufnr('')) @@ -31,6 +31,7 @@ Execute(The clangformat callback should include any additional options): AssertEqual \ { \ 'command': ale#Escape(g:ale_c_clangformat_executable) + \ . ' --assume-filename=' . ale#Escape(bufname(bufnr(''))) \ . ' --some-option', \ }, \ ale#fixers#clangformat#Fix(bufnr('')) diff --git a/test/fixers/test_clangtidy_fixer_callback.vader b/test/fixers/test_clangtidy_fixer_callback.vader new file mode 100644 index 00000000..68416b36 --- /dev/null +++ b/test/fixers/test_clangtidy_fixer_callback.vader @@ -0,0 +1,51 @@ +Before: + Save g:ale_c_clangtidy_executable + + " Use an invalid global executable, so we don't match it. + let g:ale_c_clangtidy_executable = 'xxxinvalid' + let g:ale_c_build_dir = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + silent cd ../command_callback + let g:dir = getcwd() + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The clangtidy callback should return the correct default values): + call ale#test#SetFilename('c_paths/dummy.c') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_c_clangtidy_executable) + \ . ' -fix -fix-errors %t' + \ }, + \ ale#fixers#clangtidy#Fix(bufnr('')) + +Execute(The clangtidy callback should include any additional options): + call ale#test#SetFilename('c_paths/dummy.c') + let g:ale_c_clangtidy_extra_options = '--some-option' + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_c_clangtidy_executable) + \ . ' -fix -fix-errors --some-option %t', + \ }, + \ ale#fixers#clangtidy#Fix(bufnr('')) + +Execute(The clangtidy callback should support cpp files): + call ale#test#SetFilename('c_paths/dummy.cpp') + let g:ale_cpp_clangtidy_executable = 'invalidpp' + set filetype=cpp " The test fails without this + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_cpp_clangtidy_executable) + \ . ' -fix -fix-errors %t', + \ }, + \ ale#fixers#clangtidy#Fix(bufnr('')) diff --git a/test/fixers/test_gofmt_fixer_callback.vader b/test/fixers/test_gofmt_fixer_callback.vader index 14e6e063..16659655 100644 --- a/test/fixers/test_gofmt_fixer_callback.vader +++ b/test/fixers/test_gofmt_fixer_callback.vader @@ -1,6 +1,7 @@ Before: Save g:ale_go_gofmt_executable Save g:ale_go_gofmt_options + Save g:ale_go_go111module " Use an invalid global executable, so we don't match it. let g:ale_go_gofmt_executable = 'xxxinvalid' @@ -11,6 +12,8 @@ Before: After: Restore + unlet! b:ale_go_go111module + call ale#test#RestoreDirectory() Execute(The gofmt callback should return the correct default values): @@ -27,6 +30,7 @@ Execute(The gofmt callback should return the correct default values): Execute(The gofmt callback should include custom gofmt options): let g:ale_go_gofmt_options = "-r '(a) -> a'" + call ale#test#SetFilename('../go_files/testfile.go') AssertEqual @@ -38,3 +42,17 @@ Execute(The gofmt callback should include custom gofmt options): \ . ' %t', \ }, \ ale#fixers#gofmt#Fix(bufnr('')) + +Execute(The gofmt callback should support Go environment variables): + let g:ale_go_go111module = 'off' + + call ale#test#SetFilename('../go_files/testfile.go') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Env('GO111MODULE', 'off') + \ . ale#Escape('xxxinvalid') . ' -l -w' + \ . ' %t', + \ }, + \ ale#fixers#gofmt#Fix(bufnr('')) diff --git a/test/fixers/test_goimports_fixer_callback.vader b/test/fixers/test_goimports_fixer_callback.vader index cec06354..3ea022ff 100644 --- a/test/fixers/test_goimports_fixer_callback.vader +++ b/test/fixers/test_goimports_fixer_callback.vader @@ -1,6 +1,7 @@ Before: Save g:ale_go_goimports_executable Save g:ale_go_goimports_options + Save g:ale_go_go111module " Use an invalid global executable, so we don't match it. let g:ale_go_goimports_executable = 'xxxinvalid' @@ -12,6 +13,8 @@ Before: After: Restore + unlet! b:ale_go_go111module + call ale#test#RestoreDirectory() Execute(The goimports callback should return 0 when the executable isn't executable): @@ -39,3 +42,16 @@ Execute(The goimports callback should include extra options): \ 'command': ale#Escape(g:ale_go_goimports_executable) . ' -l -w -srcdir %s --xxx %t' \ }, \ ale#fixers#goimports#Fix(bufnr('')) + +Execute(The goimports callback should support Go environment variables): + let g:ale_go_goimports_executable = has('win32') ? 'cmd' : 'echo' + let g:ale_go_go111module = 'on' + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Env('GO111MODULE', 'on') + \ . ale#Escape(g:ale_go_goimports_executable) + \ . ' -l -w -srcdir %s %t' + \ }, + \ ale#fixers#goimports#Fix(bufnr('')) diff --git a/test/fixers/test_gomod_fixer_callback.vader b/test/fixers/test_gomod_fixer_callback.vader index a378e961..422caf63 100644 --- a/test/fixers/test_gomod_fixer_callback.vader +++ b/test/fixers/test_gomod_fixer_callback.vader @@ -1,18 +1,22 @@ Before: Save g:ale_go_go_executable + Save g:ale_go_go111module " Use an invalid global executable, so we don't match it. let g:ale_go_go_executable = 'xxxinvalid' + let g:ale_go_go111module = '' call ale#test#SetDirectory('/testplugin/test/fixers') After: Restore + unlet! b:ale_go_go111module + call ale#test#RestoreDirectory() Execute(The gomod callback should return the correct default values): call ale#test#SetFilename('../go_files/go.mod') - setl ft=gomod + setl filetype=gomod AssertEqual \ { @@ -22,3 +26,16 @@ Execute(The gomod callback should return the correct default values): \ . ' %t', \ }, \ ale#fixers#gomod#Fix(bufnr('')) + +Execute(The gomod callback should support Go environment variables): + call ale#test#SetFilename('../go_files/go.mod') + setl filetype=gomod + let g:ale_go_go111module = 'on' + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Env('GO111MODULE', 'on') + \ . ale#Escape('xxxinvalid') . ' mod edit -fmt %t' + \ }, + \ ale#fixers#gomod#Fix(bufnr('')) diff --git a/test/fixers/test_sorbet_fixer_callback.vader b/test/fixers/test_sorbet_fixer_callback.vader new file mode 100644 index 00000000..71870e4c --- /dev/null +++ b/test/fixers/test_sorbet_fixer_callback.vader @@ -0,0 +1,42 @@ + +Before: + Save g:ale_ruby_sorbet_executable + Save g:ale_ruby_sorbet_options + + " Use an invalid global executable, so we don't match it. + let g:ale_ruby_sorbet_executable = 'xxxinvalid' + let g:ale_ruby_sorbet_options = '' + + call ale#test#SetDirectory('/testplugin/test/fixers') + silent cd .. + silent cd command_callback + let g:dir = getcwd() + +After: + Restore + + call ale#test#RestoreDirectory() + +Execute(The sorbet callback should return the correct default values): + call ale#test#SetFilename('ruby_paths/dummy.rb') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_ruby_sorbet_executable) + \ . ' tc --autocorrect --file %t', + \ }, + \ ale#fixers#sorbet#Fix(bufnr('')) + +Execute(The sorbet callback should include custom sorbet options): + let g:ale_ruby_sorbet_options = '--enable-experimental-lsp-hover' + call ale#test#SetFilename('ruby_paths/with_config/dummy.rb') + + AssertEqual + \ { + \ 'read_temporary_file': 1, + \ 'command': ale#Escape(g:ale_ruby_sorbet_executable) + \ . ' tc --enable-experimental-lsp-hover' + \ . ' --autocorrect --file %t', + \ }, + \ ale#fixers#sorbet#Fix(bufnr('')) diff --git a/test/handler/test_csc_handler.vader b/test/handler/test_csc_handler.vader new file mode 100644 index 00000000..3db5b6fd --- /dev/null +++ b/test/handler/test_csc_handler.vader @@ -0,0 +1,98 @@ +Before: + Save g:ale_cs_csc_source + + unlet! g:ale_cs_csc_source + + call ale#test#SetDirectory('/testplugin/test/handler') + call ale#test#SetFilename('Test.cs') + + runtime ale_linters/cs/csc.vim + +After: + unlet! g:ale_cs_csc_source + + call ale#test#RestoreDirectory() + call ale#linter#Reset() + +Execute(The csc handler should work with the default of the buffer's directory): + AssertEqual + \ [ + \ { + \ 'lnum': 12, + \ 'col' : 29, + \ 'text': '; expected', + \ 'code': 'CS1001', + \ 'type': 'E', + \ 'filename': ale#path#Simplify(g:dir . '/Test.cs'), + \ }, + \ ], + \ ale_linters#cs#csc#Handle(bufnr(''), [ + \ 'Test.cs(12,29): error CS1001: ; expected', + \ 'Compilation failed: 2 error(s), 1 warnings', + \ ]) + +Execute(The csc handler should handle cannot find symbol errors): + let g:ale_cs_csc_source = '/home/foo/project/bar' + + AssertEqual + \ [ + \ { + \ 'lnum': 12, + \ 'col' : 29, + \ 'text': '; expected', + \ 'code': 'CS1001', + \ 'type': 'E', + \ 'filename': ale#path#Simplify('/home/foo/project/bar/Test.cs'), + \ }, + \ { + \ 'lnum': 101, + \ 'col': 0, + \ 'text': 'Unexpected processor directive (no #if for this #endif)', + \ 'code': 'CS1028', + \ 'type': 'E', + \ 'filename': ale#path#Simplify('/home/foo/project/bar/Test.cs'), + \ }, + \ { + \ 'lnum': 10, + \ 'col': 12, + \ 'text': 'some warning', + \ 'code': 'CS0123', + \ 'type': 'W', + \ 'filename': ale#path#Simplify('/home/foo/project/bar/Test.cs'), + \ }, + \ ], + \ ale_linters#cs#csc#Handle(bufnr(''), [ + \ 'Test.cs(12,29): error CS1001: ; expected', + \ 'Test.cs(101,0): error CS1028: Unexpected processor directive (no #if for this #endif)', + \ 'Test.cs(10,12): warning CS0123: some warning', + \ 'Compilation failed: 2 error(s), 1 warnings', + \ ]) + +Execute(The csc handler should handle non file specific compiler errors without reporting overal status report as error): + let g:ale_cs_csc_source = '/home/foo/project/bar' + + AssertEqual + \ [ + \ { + \ 'lnum': -1, + \ 'col' : -1, + \ 'text': 'No source files specified.', + \ 'code': 'CS2008', + \ 'type': 'W', + \ 'filename': '<csc>', + \ }, + \ { + \ 'lnum': -1, + \ 'col': -1, + \ 'text': 'Outputs without source must have the /out option specified', + \ 'code': 'CS1562', + \ 'type': 'E', + \ 'filename': '<csc>', + \ }, + \ ], + \ ale_linters#cs#csc#Handle(bufnr(''), [ + \ 'Microsoft (R) Visual C# Compiler version 2.8.2.62916 (2ad4aabc)', + \ 'Copyright (C) Microsoft Corporation. All rights reserved.', + \ 'warning CS2008: No source files specified.', + \ 'error CS1562: Outputs without source must have the /out option specified', + \ ]) diff --git a/test/handler/test_mcsc_handler.vader b/test/handler/test_mcsc_handler.vader index 8ae47357..c04f7d27 100644 --- a/test/handler/test_mcsc_handler.vader +++ b/test/handler/test_mcsc_handler.vader @@ -67,3 +67,22 @@ Execute(The mcs handler should handle cannot find symbol errors): \ 'Test.cs(10,12): warning CS0123: some warning', \ 'Compilation failed: 2 error(s), 1 warnings', \ ]) + +Execute(The mcsc handler should handle non file specific compiler errors without reporting overal status report as error): + let g:ale_cs_mcsc_source = '/home/foo/project/bar' + + AssertEqual + \ [ + \ { + \ 'lnum': -1, + \ 'col' : -1, + \ 'text': 'No files to compile were specified', + \ 'code': 'CS2008', + \ 'type': 'E', + \ 'filename': '<mcs>', + \ }, + \ ], + \ ale_linters#cs#mcsc#Handle(bufnr(''), [ + \ 'error CS2008: No files to compile were specified', + \ 'Compilation failed: 1 error(s), 0 warnings', + \ ]) diff --git a/test/python/test_deoplete_source.py b/test/python/test_deoplete_source.py index 1462f77d..9e56a10d 100644 --- a/test/python/test_deoplete_source.py +++ b/test/python/test_deoplete_source.py @@ -41,6 +41,12 @@ class DeopleteSourceTest(unittest.TestCase): ) self.assertEqual(attributes, { + 'input_patterns': { + '_': r'\.\w*$', + 'rust': r'(\.|::)\w*$', + 'typescript': r'(\.|\'|")\w*$', + 'cpp': r'(\.|::|->)\w*$', + }, 'is_bytepos': True, 'mark': '[L]', 'min_pattern_length': 1, @@ -48,12 +54,13 @@ class DeopleteSourceTest(unittest.TestCase): 'rank': 1000, }) - def test_completion_position(self): - self.call_results['ale#completion#GetCompletionPosition'] = 2 + def test_complete_position(self): + self.call_results['ale#completion#GetCompletionPositionForDeoplete'] = 2 + context = {'input': 'foo'} - self.assertEqual(self.source.get_completion_position(), 2) + self.assertEqual(self.source.get_complete_position(context), 2) self.assertEqual(self.call_list, [ - ('ale#completion#GetCompletionPosition', ()), + ('ale#completion#GetCompletionPositionForDeoplete', ('foo',)), ]) def test_request_completion_results(self): diff --git a/test/test_ale_info.vader b/test/test_ale_info.vader index decd49e9..e1208679 100644 --- a/test/test_ale_info.vader +++ b/test/test_ale_info.vader @@ -1,50 +1,112 @@ Before: Save g:ale_buffer_info Save g:ale_cache_executable_check_failures + Save g:ale_change_sign_column_color + Save g:ale_command_wrapper Save g:ale_completion_delay Save g:ale_completion_enabled Save g:ale_completion_max_suggestions + Save g:ale_echo_cursor + Save g:ale_echo_msg_error_str + Save g:ale_echo_msg_format + Save g:ale_echo_msg_info_str + Save g:ale_echo_msg_warning_str + Save g:ale_fix_on_save Save g:ale_fixers + Save g:ale_history_enabled Save g:ale_history_log_output + Save g:ale_keep_list_window_open + Save g:ale_lint_delay + Save g:ale_lint_on_enter + Save g:ale_lint_on_filetype_changed Save g:ale_lint_on_insert_leave + Save g:ale_lint_on_save Save g:ale_lint_on_text_changed Save g:ale_linters + Save g:ale_linters_explicit + Save g:ale_list_vertical + Save g:ale_list_window_size + Save g:ale_loclist_msg_format Save g:ale_lsp_error_messages + Save g:ale_lsp_root + Save g:ale_max_buffer_history_size + Save g:ale_max_signs Save g:ale_maximum_file_size + Save g:ale_open_list Save g:ale_pattern_options Save g:ale_pattern_options_enabled Save g:ale_set_balloons + Save g:ale_set_highlights + Save g:ale_set_loclist + Save g:ale_set_quickfix + Save g:ale_set_signs + Save g:ale_sign_column_always Save g:ale_sign_error Save g:ale_sign_info + Save g:ale_sign_offset Save g:ale_sign_style_error Save g:ale_sign_style_warning Save g:ale_sign_warning Save g:ale_statusline_format Save g:ale_type_map + Save g:ale_use_global_executables + Save g:ale_virtualtext_cursor + Save g:ale_warn_about_trailing_blank_lines Save g:ale_warn_about_trailing_whitespace unlet! b:ale_history let g:ale_buffer_info = {} let g:ale_cache_executable_check_failures = 0 + let g:ale_change_sign_column_color = 0 + let g:ale_command_wrapper = '' let g:ale_completion_delay = 100 let g:ale_completion_enabled = 0 let g:ale_completion_max_suggestions = 50 + let g:ale_echo_cursor = 1 + let g:ale_echo_msg_error_str = 'Error' + let g:ale_echo_msg_format = '%code: %%s' + let g:ale_echo_msg_info_str = 'Info' + let g:ale_echo_msg_warning_str = 'Warning' + let g:ale_fix_on_save = 0 + let g:ale_history_enabled = 1 let g:ale_history_log_output = 1 + let g:ale_keep_list_window_open = 0 + let g:ale_lint_delay = 200 + let g:ale_lint_on_enter = 1 + let g:ale_lint_on_filetype_changed = 1 let g:ale_lint_on_insert_leave = 1 + let g:ale_lint_on_save = 1 let g:ale_lint_on_text_changed = 'normal' + let g:ale_linters_explicit = 0 + let g:ale_list_vertical = 0 + let g:ale_list_window_size = 10 + let g:ale_loclist_msg_format = '%code: %%s' let g:ale_lsp_error_messages = {} + let g:ale_lsp_root = {} + let g:ale_max_buffer_history_size = 20 + let g:ale_max_signs = -1 let g:ale_maximum_file_size = 0 + let g:ale_open_list = 0 let g:ale_pattern_options = {} let g:ale_pattern_options_enabled = 0 let g:ale_set_balloons = 0 + let g:ale_set_highlights = 1 + let g:ale_set_loclist = 1 + let g:ale_set_quickfix = 0 + let g:ale_set_signs = 1 + let g:ale_sign_column_always = 0 let g:ale_sign_error = '>>' let g:ale_sign_info = '--' + let g:ale_sign_offset = 1000000 let g:ale_sign_style_error = '>>' let g:ale_sign_style_warning = '--' let g:ale_sign_warning = '--' let g:ale_statusline_format = ['%d error(s)', '%d warning(s)', 'OK'] let g:ale_type_map = {} + let g:ale_use_global_executables = v:null + let g:ale_virtualtext_cursor = 0 + let g:ale_warn_about_trailing_blank_lines = 1 let g:ale_warn_about_trailing_whitespace = 1 let g:testlinter1 = {'name': 'testlinter1', 'executable': 'testlinter1', 'command': 'testlinter1', 'callback': 'testCB1', 'output_stream': 'stdout'} @@ -164,6 +226,8 @@ After: unlet! b:ale_testft2_testlinter2_foo unlet! g:ale_testft2_testlinter2_bar unlet! g:info_test_file + unlet! g:ale_testft_build_dir_names + unlet! g:ale_testft_testlinter2_option delfunction CheckInfo call ale#test#RestoreDirectory() @@ -632,3 +696,52 @@ Execute (LSP errors for other linters shouldn't appear): \ + g:globals_lines \ + g:command_header \) + +Given testft.testft2 (Empty buffer with two filetypes): +Execute (ALEInfo should include linter global options): + call ale#linter#Define('testft', g:testlinter1) + call ale#linter#Define('testft2', g:testlinter2) + + " eg: like g:c_build_dir_names + let g:ale_testft_build_dir_names = ['build', 'bin'] + + call add(g:variables_lines, 'let g:ale_testft_build_dir_names = [''build'', ''bin'']') + + call CheckInfo( + \ [ + \ ' Current Filetype: testft.testft2', + \ 'Available Linters: [''testlinter1'', ''testlinter2'']', + \ ' Enabled Linters: [''testlinter1'', ''testlinter2'']', + \ ] + \ + g:fixer_lines + \ + g:variables_lines + \ + g:globals_lines + \ + g:command_header + \) + +Given testft (Empty buffer with two filetypes): +Execute (ALEInfo should include linter global options for enabled linters): + call ale#linter#Define('testft', g:testlinter1) + call ale#linter#Define('testft', g:testlinter2) + + let g:ale_linters = {'testft': ['testlinter1']} + + " should not appear, since not enabled + let g:ale_testft_testlinter2_option = 'test' + + let g:globals_lines[index(g:globals_lines, 'let g:ale_linters = {}')] + \ = 'let g:ale_linters = {''testft'': [''testlinter1'']}' + + call CheckInfo( + \ [ + \ ' Current Filetype: testft', + \ 'Available Linters: [''testlinter1'', ''testlinter2'']', + \ ' Enabled Linters: [''testlinter1'']', + \ ] + \ + g:fixer_lines + \ + g:variables_lines + \ + g:globals_lines + \ + g:command_header + \) + + diff --git a/test/test_c_flag_parsing.vader b/test/test_c_flag_parsing.vader index 045554a3..8ae6f9dc 100644 --- a/test/test_c_flag_parsing.vader +++ b/test/test_c_flag_parsing.vader @@ -14,7 +14,7 @@ Execute(The CFlags parser should be able to parse include directives): call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') AssertEqual - \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'), + \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')), \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c']) AssertEqual @@ -25,14 +25,14 @@ Execute(ParseCFlags should ignore -c and -o): call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') AssertEqual - \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir'), + \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')), \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -c file.c -o a.out']) Execute(The CFlags parser should be able to parse macro directives): call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') AssertEqual - \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') + \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) \ . ' -DTEST=1', \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=1 -c file.c']) @@ -40,7 +40,7 @@ Execute(The CFlags parser should be able to parse macro directives with spaces): call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') AssertEqual - \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') + \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) \ . ' -DTEST=$(( 2 * 4 ))', \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=$(( 2 * 4 )) -c file.c']) @@ -48,14 +48,14 @@ Execute(The CFlags parser should be able to parse shell directives with spaces): call ale#test#SetFilename('test_c_projects/makefile_project/subdir/file.c') AssertEqual - \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') + \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlagsFromMakeOutput(bufnr(''), ['gcc -Isubdir -DTEST=`date +%s` -c file.c']) Execute(ParseCFlags should be able to parse flags with relative paths): AssertEqual - \ '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') + \ '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), @@ -67,8 +67,8 @@ Execute(ParseCFlags should be able to parse flags with relative paths): Execute(ParseCFlags should be able to parse -Dgoal): AssertEqual \ '-Dgoal=9' - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), @@ -77,16 +77,30 @@ Execute(ParseCFlags should be able to parse -Dgoal): \ . ' -DTEST=`date +%s` -c file.c' \ ) +Execute(ParseCFlags should ignore -T and other arguments): + AssertEqual + \ '-Dgoal=9' + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ . ' ' . '--sysroot=subdir' + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) + \ . ' -DTEST=`date +%s`', + \ ale#c#ParseCFlags( + \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), + \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir --sysroot=subdir ' + \ . '-I'. ale#path#Simplify('kernel/include') + \ . ' -DTEST=`date +%s` -c file.c' + \ ) + Execute(ParseCFlags should handle paths with spaces in double quotes): AssertEqual \ '-Dgoal=9' - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/"dir with spaces"') - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Isubdir ' + \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' \ . '-I"dir with spaces"' . ' -I'. ale#path#Simplify('kernel/include') \ . ' -DTEST=`date +%s` -c file.c' \ ) @@ -94,28 +108,29 @@ Execute(ParseCFlags should handle paths with spaces in double quotes): Execute(ParseCFlags should handle paths with spaces in single quotes): AssertEqual \ '-Dgoal=9' - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') - \ . ' ' . '-I' . ale#path#Simplify(g:dir. "/test_c_projects/makefile_project/'dir with spaces'") - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Isubdir ' - \ . "-I'dir with spaces'" . ' -I'. ale#path#Simplify('kernel/include') + \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' + \ . '-I''dir with spaces''' . ' -I'. ale#path#Simplify('kernel/include') \ . ' -DTEST=`date +%s` -c file.c' \ ) Execute(ParseCFlags should handle paths with minuses): AssertEqual \ '-Dgoal=9' - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash') - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Isubdir ' - \ . ' -Idir-with-dash' + \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' + \ . '-I''dir with spaces''' . ' -Idir-with-dash' \ . ' -I'. ale#path#Simplify('kernel/include') \ . ' -DTEST=`date +%s` -c file.c' \ ) @@ -123,14 +138,17 @@ Execute(ParseCFlags should handle paths with minuses): Execute(ParseCFlags should handle -D with minuses): AssertEqual \ '-Dgoal=9' - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) \ . ' -Dmacro-with-dash' - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include') + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')) \ . ' -DTEST=`date +%s`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Isubdir ' + \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' \ . '-Dmacro-with-dash ' + \ . '-I''dir with spaces''' . ' -Idir-with-dash' \ . ' -I'. ale#path#Simplify('kernel/include') \ . ' -DTEST=`date +%s` -c file.c' \ ) @@ -138,11 +156,16 @@ Execute(ParseCFlags should handle -D with minuses): Execute(ParseCFlags should handle flags at the end of the line): AssertEqual \ '-Dgoal=9' - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir') - \ . ' ' . '-I' . ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include'), + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ . ' -Dmacro-with-dash' + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')), \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 -Isubdir ' + \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' + \ . '-Dmacro-with-dash ' + \ . '-I''dir with spaces''' . ' -Idir-with-dash' \ . ' -I'. ale#path#Simplify('kernel/include') \ ) @@ -156,14 +179,14 @@ Execute(ParseCompileCommandsFlags should parse some basic flags): silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c')) AssertEqual - \ '-I/usr/include/xmms2', + \ '-I ' . ale#path#Simplify('/usr/include/xmms2'), \ ale#c#ParseCompileCommandsFlags(bufnr(''), { "xmms2-mpris.c": [ \ { - \ 'directory': '/foo/bar/xmms2-mpris', - \ 'command': '/usr/bin/cc -I' . '/usr/include/xmms2' + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2') \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' - \ . ' -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c', - \ 'file': '/foo/bar/xmms2-mpris/src/xmms2-mpris.c', + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), \ }, \ ] }, {}) @@ -183,14 +206,14 @@ Execute(ParseCompileCommandsFlags should fall back to files in the same director silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c')) AssertEqual - \ '-I/usr/include/xmms2', + \ '-I ' . ale#path#Simplify('/usr/include/xmms2'), \ ale#c#ParseCompileCommandsFlags(bufnr(''), {}, { "src": [ \ { - \ 'directory': '/foo/bar/xmms2-mpris', - \ 'command': '/usr/bin/cc -I' . '/usr/include/xmms2' + \ 'directory': ale#path#Simplify('/foo/bar/xmms2-mpris'), + \ 'command': '/usr/bin/cc -I' . ale#path#Simplify('/usr/include/xmms2') \ . ' -o CMakeFiles/xmms2-mpris.dir/src/xmms2-mpris.c.o' - \ . ' -c ' . '/foo/bar/xmms2-mpris/src/xmms2-mpris.c', - \ 'file': (has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c', + \ . ' -c ' . ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.c'), + \ 'file': ale#path#Simplify((has('win32') ? 'C:' : '') . '/foo/bar/xmms2-mpris/src/xmms2-other.c'), \ }, \ ] }) @@ -198,7 +221,7 @@ Execute(ParseCompileCommandsFlags should take commands from matching .c files fo silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.h')) AssertEqual - \ '-I/usr/include/xmms2', + \ '-I /usr/include/xmms2', \ ale#c#ParseCompileCommandsFlags( \ bufnr(''), \ { @@ -220,7 +243,7 @@ Execute(ParseCompileCommandsFlags should take commands from matching .cpp files silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.hpp')) AssertEqual - \ '-I/usr/include/xmms2', + \ '-I /usr/include/xmms2', \ ale#c#ParseCompileCommandsFlags( \ bufnr(''), \ { @@ -242,7 +265,7 @@ Execute(ParseCompileCommandsFlags should take commands from matching .cpp files silent noautocmd execute 'file! ' . fnameescape(ale#path#Simplify('/foo/bar/xmms2-mpris/src/xmms2-mpris.h')) AssertEqual - \ '-I/usr/include/xmms2', + \ '-I /usr/include/xmms2', \ ale#c#ParseCompileCommandsFlags( \ bufnr(''), \ { @@ -282,13 +305,64 @@ Execute(ParseCompileCommandsFlags should not take commands from .c files for .h \ }, \ ) +Execute(ParseCFlags should not merge flags): + AssertEqual + \ '-Dgoal=9' + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/subdir')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir with spaces')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/dir-with-dash')) + \ . ' ' . '-I' . ' ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/kernel/include')), + \ ale#c#ParseCFlags( + \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), + \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla -Isubdir ' + \ . 'subdir/somedep1.o ' . 'subdir/somedep2.o ' + \ . '-I''dir with spaces''' . ' -Idir-with-dash ' + \ . 'subdir/somedep3.o ' . 'subdir/somedep4.o ' + \ . ' -I'. ale#path#Simplify('kernel/include') . ' ' + \ . 'subdir/somedep5.o ' . 'subdir/somedep6.o ' + \ ) + Execute(ParseCFlags should handle parenthesis and quotes): AssertEqual - \ '-Dgoal=9 -Dtest1="('' '')" file1.o -Dtest2=''(` `)'' file2.o -Dtest3=`(" ")` file3.o', + \ '-Dgoal=9 -Dtest1="('' '')" -Dtest2=''(` `)'' -Dtest3=`(" ")`', \ ale#c#ParseCFlags( \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), - \ 'gcc -Dgoal=9 ' + \ 'gcc -Dgoal=9 -Tlinkerfile.ld blabla ' \ . '-Dtest1="('' '')" file1.o ' \ . '-Dtest2=''(` `)'' file2.o ' \ . '-Dtest3=`(" ")` file3.o ' \ ) + +Execute(CFlags we want to pass): + AssertEqual + \ '-I ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/inc')) + \ . ' -I ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/include')) + \ . ' -iquote ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/incquote')) + \ . ' -isystem ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/incsystem')) + \ . ' -idirafter ' . ale#Escape(ale#path#Simplify(g:dir. '/test_c_projects/makefile_project/incafter')) + \ . ' -Dmacro=value -D macro2 -Bbdir -B bdir2' + \ . ' -iprefix prefix -iwithprefix prefix2 -iwithprefixbefore prefix3' + \ . ' -isysroot sysroot --sysroot=test --no-sysroot-suffix -imultilib multidir' + \ . ' -Wsome-warning -std=c89 -pedantic -pedantic-errors -ansi' + \ . ' -foption -O2 -C -CC -trigraphs -nostdinc -nostdinc++' + \ . ' -iplugindir=dir -march=native -w', + \ ale#c#ParseCFlags( + \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), + \ 'gcc' + \ . ' -Iinc -I include -iquote incquote -isystem incsystem -idirafter incafter' + \ . ' -Dmacro=value -D macro2 -Bbdir -B bdir2' + \ . ' -iprefix prefix -iwithprefix prefix2 -iwithprefixbefore prefix3' + \ . ' -isysroot sysroot --sysroot=test --no-sysroot-suffix -imultilib multidir' + \ . ' -Wsome-warning -std=c89 -pedantic -pedantic-errors -ansi' + \ . ' -foption -O2 -C -CC -trigraphs -nostdinc -nostdinc++' + \ . ' -iplugindir=dir -march=native -w' + \ ) + +Execute(CFlags we dont want to pass): + AssertEqual + \ '', + \ ale#c#ParseCFlags( + \ ale#path#Simplify(g:dir. '/test_c_projects/makefile_project'), + \ 'gcc -Wl,option -Wa,option -Wp,option filename.c somelib.a ' + \ . '-fdump-file=name -fdiagnostics-arg -fno-show-column' + \ ) |