summaryrefslogtreecommitdiff
path: root/test/test_shell_detection.vader
blob: 11d801c30e04fdd2f768fe050b0519c2f6e329b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
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#handlers#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#handlers#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#handlers#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#handlers#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#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a csh hash bang and arguments):
  #!/usr/bin/env csh -eu --foobar

Execute(csh should be detected appropriately):
  AssertEqual 'csh', ale#handlers#sh#GetShellType(bufnr(''))
  AssertEqual 'csh', ale_linters#sh#shell#GetExecutable(bufnr(''))
  AssertEqual 'csh', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a ksh hashbang):
  #!/bin/ksh

Execute(/bin/ksh should be detected appropriately):
  AssertEqual 'ksh', ale#handlers#sh#GetShellType(bufnr(''))
  AssertEqual 'ksh', ale_linters#sh#shell#GetExecutable(bufnr(''))
  AssertEqual 'ksh', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a ksh as an argument to env):
  #!/usr/bin/env ksh

Execute(ksh should be detected appropriately):
  AssertEqual 'ksh', ale#handlers#sh#GetShellType(bufnr(''))
  AssertEqual 'ksh', ale_linters#sh#shell#GetExecutable(bufnr(''))
  AssertEqual 'ksh', ale#handlers#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#handlers#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#handlers#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#handlers#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#handlers#shellcheck#GetDialectArgument(bufnr(''))

Execute(The filetype should be used as the default shell type when there is no hashbang line):
  set filetype=zsh
  AssertEqual 'zsh', ale#handlers#sh#GetShellType(bufnr(''))

  set filetype=tcsh
  AssertEqual 'tcsh', ale#handlers#sh#GetShellType(bufnr(''))

  set filetype=python
  AssertEqual '', ale#handlers#sh#GetShellType(bufnr(''))

Given(A file with /bin/ash):
  #!/bin/ash

Execute(The ash dialect should be used for the shell and the base function):
  AssertEqual 'ash', ale#handlers#sh#GetShellType(bufnr(''))
  AssertEqual 'ash', ale_linters#sh#shell#GetExecutable(bufnr(''))

Execute(dash should be used for shellcheck, which has no ash dialect):
  AssertEqual 'dash', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with /bin/dash):
  #!/bin/dash

Execute(The dash dialect should be used for the shell and the base function):
  AssertEqual 'dash', ale#handlers#sh#GetShellType(bufnr(''))
  AssertEqual 'dash', ale_linters#sh#shell#GetExecutable(bufnr(''))

Execute(dash should be used for shellcheck):
  AssertEqual 'dash', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a Bash shellcheck shell directive):
  # shellcheck shell=bash

Execute(bash dialect should be detected appropriately):
  AssertEqual 'bash', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a sh shellcheck shell directive):
  #shellcheck   shell=sh

Execute(sh dialect should be detected appropriately):
  AssertEqual 'sh', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a tcsh shellcheck shell directive):
  #   shellcheck   shell=tcsh

Execute(tcsh dialect should be detected appropriately):
  AssertEqual 'tcsh', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a zsh shellcheck shell directive):
  #   shellcheck shell=zsh

Execute(zsh dialect should be detected appropriately):
  AssertEqual 'zsh', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a csh shellcheck shell directive):
  # shellcheck shell=csh

Execute(zsh dialect should be detected appropriately):
  AssertEqual 'csh', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a ksh shellcheck shell directive):
  # shellcheck shell=ksh

Execute(ksh dialect should be detected appropriately):
  AssertEqual 'ksh', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a dash shellcheck shell directive):
  # shellcheck shell=dash

Execute(dash dialect should be detected appropriately):
  AssertEqual 'dash', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))

Given(A file with a ash shellcheck shell directive):
  # shellcheck shell=ash

Execute(dash dialect should be detected for ash that shellcheck does not support):
  AssertEqual 'dash', ale#handlers#shellcheck#GetDialectArgument(bufnr(''))