summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-06-21 22:33:34 +0100
committerw0rp <devw0rp@gmail.com>2017-06-21 22:33:34 +0100
commitdab6f39eb0b5d0dd77a8dc3fe58d0648d82696f7 (patch)
tree18faefa99cc56fee65db35c007c0e2e267166cc6
parentab534c2995dabfb8adcdc62d0ac66ed1b1110f4c (diff)
downloadale-dab6f39eb0b5d0dd77a8dc3fe58d0648d82696f7.zip
Fix some escaping and make some tests set filenames consistently
-rw-r--r--ale_linters/ruby/brakeman.vim2
-rw-r--r--autoload/ale/test.vim19
-rw-r--r--test/command_callback/test_brakeman_command_callback.vader46
-rw-r--r--test/command_callback/test_cppcheck_command_callbacks.vader15
-rw-r--r--test/phpcs-test-files/project-with-phpcs/foo/test.php0
-rw-r--r--test/phpcs-test-files/project-without-phpcs/foo/test.php0
-rw-r--r--test/test_phpcs_executable_detection.vader21
7 files changed, 71 insertions, 32 deletions
diff --git a/ale_linters/ruby/brakeman.vim b/ale_linters/ruby/brakeman.vim
index 3cc5b77d..fa5617df 100644
--- a/ale_linters/ruby/brakeman.vim
+++ b/ale_linters/ruby/brakeman.vim
@@ -40,7 +40,7 @@ function! ale_linters#ruby#brakeman#GetCommand(buffer) abort
return 'brakeman -f json -q '
\ . ale#Var(a:buffer, 'ruby_brakeman_options')
- \ . ' -p ' . l:rails_root
+ \ . ' -p ' . ale#Escape(l:rails_root)
endfunction
function! s:FindRailsRoot(buffer) abort
diff --git a/autoload/ale/test.vim b/autoload/ale/test.vim
new file mode 100644
index 00000000..f63fc3ab
--- /dev/null
+++ b/autoload/ale/test.vim
@@ -0,0 +1,19 @@
+" Author: w0rp <devw0rp@gmail.com>
+" Description: Functions for making testing ALE easier.
+"
+" This file should not typically be loaded during the normal execution of ALE.
+
+" Change the filename for the current buffer using a relative path to
+" the script without running autocmd commands.
+"
+" If a g:dir variable is set, it will be used as the path to the directory
+" containing the test file.
+function! ale#test#SetFilename(path) abort
+ let l:dir = get(g:, 'dir', '')
+
+ if empty(l:dir)
+ let l:dir = getcwd()
+ endif
+
+ silent noautocmd execute 'file ' . fnameescape(simplify(l:dir . '/' . a:path))
+endfunction
diff --git a/test/command_callback/test_brakeman_command_callback.vader b/test/command_callback/test_brakeman_command_callback.vader
index 262f865e..607aec64 100644
--- a/test/command_callback/test_brakeman_command_callback.vader
+++ b/test/command_callback/test_brakeman_command_callback.vader
@@ -1,26 +1,42 @@
Before:
- runtime ale_linters/ruby/brakeman.vim
+ Save g:ale_ruby_brakeman_options
+
+ runtime ale_linters/ruby/brakeman.vim
+
+ let g:ale_ruby_brakeman_options = ''
+
+ silent! cd /testplugin/test/command_callback
+ let g:dir = getcwd()
After:
- call ale#linter#Reset()
+ Restore
+
+ silent execute 'cd ' . fnameescape(g:dir)
+ unlet! g:dir
+
+ call ale#linter#Reset()
Execute(The brakeman command callback should detect absence of a valid Rails app):
- cd /testplugin/test/ruby_fixtures/not_a_rails_app/
- AssertEqual
- \ '',
- \ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
+ call ale#test#SetFilename('../ruby_fixtures/not_a_rails_app/test.rb')
+
+ AssertEqual
+ \ '',
+ \ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
Execute(The brakeman command callback should find a valid Rails app root):
- cd /testplugin/test/ruby_fixtures/valid_rails_app/db/
- AssertEqual
- \ 'brakeman -f json -q -p /testplugin/test/ruby_fixtures/valid_rails_app',
- \ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
+ call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/db/test.rb')
+
+ AssertEqual
+ \ 'brakeman -f json -q -p '
+ \ . ale#Escape(simplify(g:dir . '/../ruby_fixtures/valid_rails_app')),
+ \ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
Execute(The brakeman command callback should include configured options):
- cd /testplugin/test/ruby_fixtures/valid_rails_app/db/
- let g:ale_ruby_brakeman_options = '--combobulate'
+ call ale#test#SetFilename('../ruby_fixtures/valid_rails_app/db/test.rb')
+ let g:ale_ruby_brakeman_options = '--combobulate'
- AssertEqual
- \ 'brakeman -f json -q --combobulate -p /testplugin/test/ruby_fixtures/valid_rails_app',
- \ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
+ AssertEqual
+ \ 'brakeman -f json -q --combobulate -p '
+ \ . ale#Escape(simplify(g:dir . '/../ruby_fixtures/valid_rails_app')),
+ \ ale_linters#ruby#brakeman#GetCommand(bufnr(''))
diff --git a/test/command_callback/test_cppcheck_command_callbacks.vader b/test/command_callback/test_cppcheck_command_callbacks.vader
index 63958643..69bb214d 100644
--- a/test/command_callback/test_cppcheck_command_callbacks.vader
+++ b/test/command_callback/test_cppcheck_command_callbacks.vader
@@ -5,36 +5,43 @@ Before:
After:
silent execute 'cd ' . fnameescape(b:dir)
unlet! b:dir
+
call ale#linter#Reset()
Execute(The default C cppcheck command should be correct):
runtime ale_linters/c/cppcheck.vim
+ call ale#test#SetFilename('cppcheck_paths/two/foo.cpp')
+
AssertEqual
\ 'cppcheck -q --language=c --enable=style %t',
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))
Execute(cppcheck for C should detect compile_commands.json files):
runtime ale_linters/c/cppcheck.vim
- cd cppcheck_paths/one
+
+ call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
AssertEqual
- \ 'cd ' . shellescape(b:dir . '/cppcheck_paths/one') . ' && '
+ \ 'cd ' . ale#Escape(b:dir . '/cppcheck_paths/one') . ' && '
\ . 'cppcheck -q --language=c --project=compile_commands.json --enable=style %t',
\ ale_linters#c#cppcheck#GetCommand(bufnr(''))
Execute(The default C++ cppcheck command should be correct):
runtime ale_linters/cpp/cppcheck.vim
+ call ale#test#SetFilename('cppcheck_paths/two/foo.cpp')
+
AssertEqual
\ 'cppcheck -q --language=c++ --enable=style %t',
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))
Execute(cppcheck for C++ should detect compile_commands.json files):
runtime ale_linters/cpp/cppcheck.vim
- cd cppcheck_paths/one
+
+ call ale#test#SetFilename('cppcheck_paths/one/foo.cpp')
AssertEqual
- \ 'cd ' . shellescape(b:dir . '/cppcheck_paths/one') . ' && '
+ \ 'cd ' . ale#Escape(b:dir . '/cppcheck_paths/one') . ' && '
\ . 'cppcheck -q --language=c++ --project=compile_commands.json --enable=style %t',
\ ale_linters#cpp#cppcheck#GetCommand(bufnr(''))
diff --git a/test/phpcs-test-files/project-with-phpcs/foo/test.php b/test/phpcs-test-files/project-with-phpcs/foo/test.php
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/phpcs-test-files/project-with-phpcs/foo/test.php
diff --git a/test/phpcs-test-files/project-without-phpcs/foo/test.php b/test/phpcs-test-files/project-without-phpcs/foo/test.php
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/phpcs-test-files/project-without-phpcs/foo/test.php
diff --git a/test/test_phpcs_executable_detection.vader b/test/test_phpcs_executable_detection.vader
index 678606f8..72b7af0b 100644
--- a/test/test_phpcs_executable_detection.vader
+++ b/test/test_phpcs_executable_detection.vader
@@ -1,5 +1,9 @@
Before:
+ Save g:ale_php_phpcs_executable
+ Save g:ale_php_phpcs_use_global
+
let g:ale_php_phpcs_executable = 'phpcs_test'
+ let g:ale_php_phpcs_use_global = 0
silent! cd /testplugin/test
let g:dir = getcwd()
@@ -7,39 +11,32 @@ Before:
runtime ale_linters/php/phpcs.vim
After:
- let g:ale_php_phpcs_executable = 'phpcs'
- let g:ale_php_phpcs_use_global = 0
+ Restore
- silent execute 'cd ' . g:dir
+ silent execute 'cd ' . fnameescape(g:dir)
unlet! g:dir
call ale#linter#Reset()
Execute(project with phpcs should use local by default):
- silent noautocmd new phpcs-test-files/project-with-phpcs/vendor/bin/phpcs
+ call ale#test#SetFilename('phpcs-test-files/project-with-phpcs/foo/test.php')
AssertEqual
\ g:dir . '/phpcs-test-files/project-with-phpcs/vendor/bin/phpcs',
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
- :q
-
Execute(use-global should override local detection):
let g:ale_php_phpcs_use_global = 1
- silent noautocmd new phpcs-test-files/project-with-phpcs/vendor/bin/phpcs
+ call ale#test#SetFilename('phpcs-test-files/project-with-phpcs/foo/test.php')
AssertEqual
\ 'phpcs_test',
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
- :q
-
Execute(project without phpcs should use global):
- silent noautocmd new phpcs-test-files/project-without-phpcs/vendor/bin/phpcs
+ call ale#test#SetFilename('phpcs-test-files/project-without-phpcs/foo/test.php')
AssertEqual
\ 'phpcs_test',
\ ale_linters#php#phpcs#GetExecutable(bufnr(''))
-
- :q