summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorw0rp <devw0rp@gmail.com>2017-08-28 19:16:23 +0100
committerw0rp <devw0rp@gmail.com>2017-08-28 19:16:23 +0100
commitb031531e79d409af3b143a1f40431cd868cd78fb (patch)
tree43109aa362992890041ec486fdc2f64bdb14325d /test
parent73ec83d055a62019c41e699981e841e395219cca (diff)
downloadale-b031531e79d409af3b143a1f40431cd868cd78fb.zip
#869 - Detect the shell dialect from the hashbang for shellcheck
Diffstat (limited to 'test')
-rw-r--r--test/command_callback/test_shellcheck_command_callback.vader47
-rw-r--r--test/test_shell_detection.vader83
2 files changed, 130 insertions, 0 deletions
diff --git a/test/command_callback/test_shellcheck_command_callback.vader b/test/command_callback/test_shellcheck_command_callback.vader
new file mode 100644
index 00000000..0d8fef66
--- /dev/null
+++ b/test/command_callback/test_shellcheck_command_callback.vader
@@ -0,0 +1,47 @@
+Before:
+ Save g:ale_sh_shellcheck_exclusions
+ Save g:ale_sh_shellcheck_executable
+ Save g:ale_sh_shellcheck_options
+
+ unlet! g:ale_sh_shellcheck_exclusions
+ unlet! g:ale_sh_shellcheck_executable
+ unlet! g:ale_sh_shellcheck_options
+
+ runtime ale_linters/sh/shellcheck.vim
+
+After:
+ Restore
+
+ unlet! b:ale_sh_shellcheck_exclusions
+ unlet! b:ale_sh_shellcheck_executable
+ unlet! b:ale_sh_shellcheck_options
+ unlet! b:is_bash
+
+ call ale#linter#Reset()
+
+Execute(The default shellcheck command should be correct):
+ AssertEqual
+ \ 'shellcheck -f gcc -',
+ \ ale_linters#sh#shellcheck#GetCommand(bufnr(''))
+
+Execute(The shellcheck command should accept options):
+ let b:ale_sh_shellcheck_options = '--foobar'
+
+ AssertEqual
+ \ 'shellcheck --foobar -f gcc -',
+ \ ale_linters#sh#shellcheck#GetCommand(bufnr(''))
+
+Execute(The shellcheck command should accept options and exclusions):
+ let b:ale_sh_shellcheck_options = '--foobar'
+ let b:ale_sh_shellcheck_exclusions = 'foo,bar'
+
+ AssertEqual
+ \ 'shellcheck --foobar -e foo,bar -f gcc -',
+ \ ale_linters#sh#shellcheck#GetCommand(bufnr(''))
+
+Execute(The shellcheck command should include the dialect):
+ let b:is_bash = 1
+
+ AssertEqual
+ \ 'shellcheck -s bash -f gcc -',
+ \ ale_linters#sh#shellcheck#GetCommand(bufnr(''))
diff --git a/test/test_shell_detection.vader b/test/test_shell_detection.vader
new file mode 100644
index 00000000..37cf43ce
--- /dev/null
+++ b/test/test_shell_detection.vader
@@ -0,0 +1,83 @@
+Before:
+ runtime ale_linters/sh/shell.vim
+ runtime ale_linters/sh/shellcheck.vim
+
+After:
+ call ale#linter#Reset()
+
+ unlet! b:is_bash
+ unlet! b:is_sh
+ unlet! b:is_kornshell
+
+Given(A file with a Bash hashbang):
+ #!/bin/bash
+
+Execute(/bin/bash should be detected appropriately):
+ AssertEqual 'bash', ale#handlers#sh#GetShellType(bufnr(''))
+ AssertEqual 'bash', ale_linters#sh#shell#GetExecutable(bufnr(''))
+ AssertEqual 'bash', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))
+
+Given(A file with /bin/sh):
+ #!/usr/bin/env sh -eu --foobar
+
+Execute(/bin/sh should be detected appropriately):
+ AssertEqual 'sh', ale#handlers#sh#GetShellType(bufnr(''))
+ AssertEqual 'sh', ale_linters#sh#shell#GetExecutable(bufnr(''))
+ AssertEqual 'sh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))
+
+Given(A file with bash as an argument to env):
+ #!/usr/bin/env bash
+
+Execute(/usr/bin/env bash should be detected appropriately):
+ AssertEqual 'bash', ale#handlers#sh#GetShellType(bufnr(''))
+ AssertEqual 'bash', ale_linters#sh#shell#GetExecutable(bufnr(''))
+ AssertEqual 'bash', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))
+
+Given(A file with a tcsh hash bang and arguments):
+ #!/usr/bin/env tcsh -eu --foobar
+
+Execute(tcsh should be detected appropriately):
+ AssertEqual 'tcsh', ale#handlers#sh#GetShellType(bufnr(''))
+ AssertEqual 'tcsh', ale_linters#sh#shell#GetExecutable(bufnr(''))
+ AssertEqual 'tcsh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))
+
+Given(A file with a zsh hash bang and arguments):
+ #!/usr/bin/env zsh -eu --foobar
+
+Execute(zsh should be detected appropriately):
+ AssertEqual 'zsh', ale#handlers#sh#GetShellType(bufnr(''))
+ AssertEqual 'zsh', ale_linters#sh#shell#GetExecutable(bufnr(''))
+ AssertEqual 'zsh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))
+
+Given(A file with a csh hash bang and arguments):
+ #!/usr/bin/env csh -eu --foobar
+
+Execute(zsh should be detected appropriately):
+ AssertEqual 'csh', ale#handlers#sh#GetShellType(bufnr(''))
+ AssertEqual 'csh', ale_linters#sh#shell#GetExecutable(bufnr(''))
+ AssertEqual 'csh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))
+
+Given(A file with a sh hash bang and arguments):
+ #!/usr/bin/env sh -eu --foobar
+
+Execute(sh should be detected appropriately):
+ AssertEqual 'sh', ale#handlers#sh#GetShellType(bufnr(''))
+ AssertEqual 'sh', ale_linters#sh#shell#GetExecutable(bufnr(''))
+ AssertEqual 'sh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))
+
+Given(A file without a hashbang):
+
+Execute(The bash dialect should be used for shellcheck if b:is_bash is 1):
+ let b:is_bash = 1
+
+ AssertEqual 'bash', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))
+
+Execute(The sh dialect should be used for shellcheck if b:is_sh is 1):
+ let b:is_sh = 1
+
+ AssertEqual 'sh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))
+
+Execute(The ksh dialect should be used for shellcheck if b:is_kornshell is 1):
+ let b:is_kornshell = 1
+
+ AssertEqual 'ksh', ale_linters#sh#shellcheck#GetDialectArgument(bufnr(''))