| 1 |
cp input.sh input.sh.orig |
| 2 |
|
| 3 |
# Using stdin should use EditorConfig. |
| 4 |
stdin input.sh |
| 5 |
exec shfmt |
| 6 |
cmp stdout input.sh.golden |
| 7 |
! stderr . |
| 8 |
|
| 9 |
# Verify that -filename works well with EditorConfig. |
| 10 |
stdin stdin-filename-bash |
| 11 |
exec shfmt |
| 12 |
|
| 13 |
stdin stdin-filename-bash |
| 14 |
! exec shfmt -filename=foo_posix.sh |
| 15 |
stderr '^foo_posix.sh:.* arrays are a bash.*parsed as posix via EditorConfig' |
| 16 |
|
| 17 |
stdin stdin-filename-bash |
| 18 |
! exec shfmt -filename=${WORK}/foo_posix.sh |
| 19 |
stderr ^${WORK@R}/'foo_posix.sh:.* arrays are a bash.*parsed as posix via EditorConfig' |
| 20 |
|
| 21 |
# Using a file path should use EditorConfig, including with the use of flags |
| 22 |
# like -l. |
| 23 |
exec shfmt input.sh |
| 24 |
cmp stdout input.sh.golden |
| 25 |
! stderr . |
| 26 |
|
| 27 |
! exec shfmt -l input.sh |
| 28 |
stdout 'input\.sh' |
| 29 |
! stderr . |
| 30 |
|
| 31 |
# Using any formatting option should skip all EditorConfig usage. |
| 32 |
exec shfmt -p input.sh |
| 33 |
cmp stdout input.sh.orig |
| 34 |
! stderr . |
| 35 |
|
| 36 |
exec shfmt -l -p input.sh |
| 37 |
! stdout . |
| 38 |
! stderr . |
| 39 |
|
| 40 |
exec shfmt -sr input.sh |
| 41 |
cmp stdout input.sh.orig |
| 42 |
! stderr . |
| 43 |
|
| 44 |
# Check that EditorConfig files merge properly. |
| 45 |
exec shfmt morespaces/input.sh |
| 46 |
cmp stdout morespaces/input.sh.golden |
| 47 |
! stderr . |
| 48 |
|
| 49 |
# Check a folder with all other knobs. |
| 50 |
exec shfmt -l otherknobs |
| 51 |
! stdout . |
| 52 |
! stderr . |
| 53 |
|
| 54 |
# Files found by walking directories are skipped if they match ignore=true properties. |
| 55 |
! exec shfmt -l ignored |
| 56 |
stdout 'regular\.sh' |
| 57 |
! stdout 'ignored\.sh' |
| 58 |
! stderr . |
| 59 |
|
| 60 |
# EditorConfig ignore=true properties are obeyed even when any formatting flags |
| 61 |
# are used, which cause formatting options from EditorConfig files to be skipped. |
| 62 |
! exec shfmt -i=0 -l ignored |
| 63 |
stdout 'regular\.sh' |
| 64 |
! stdout 'ignored\.sh' |
| 65 |
! stderr . |
| 66 |
|
| 67 |
# Formatting files directly does not obey ignore=true properties by default. |
| 68 |
# Test the various modes in which shfmt can run. |
| 69 |
! exec shfmt -l input.sh ignored/1_lone_ignored.sh ignored/third_party/bad_syntax_ignored.sh |
| 70 |
stdout -count=1 'input\.sh$' |
| 71 |
stdout -count=1 'ignored\.sh$' |
| 72 |
stderr -count=1 'ignored\.sh.* must be followed by' |
| 73 |
! exec shfmt -d input.sh ignored/1_lone_ignored.sh ignored/third_party/bad_syntax_ignored.sh |
| 74 |
stdout -count=2 'input\.sh$' |
| 75 |
stdout -count=2 'ignored\.sh$' |
| 76 |
stderr -count=1 'ignored\.sh.* must be followed by' |
| 77 |
! exec shfmt input.sh ignored/1_lone_ignored.sh ignored/third_party/bad_syntax_ignored.sh |
| 78 |
stdout -count=1 'indented' |
| 79 |
stdout -count=1 'echo foo' |
| 80 |
stderr -count=1 'ignored\.sh.* must be followed by' |
| 81 |
stdin ignored/1_lone_ignored.sh |
| 82 |
exec shfmt --filename=ignored/1_lone_ignored.sh |
| 83 |
stdout -count=1 'echo foo' |
| 84 |
! stderr . |
| 85 |
|
| 86 |
# Formatting files directly obeys ignore=true when --apply-ignore is given. |
| 87 |
# Test the same modes that the earlier section does. |
| 88 |
! exec shfmt --apply-ignore -l input.sh ignored/1_lone_ignored.sh ignored/third_party/bad_syntax_ignored.sh |
| 89 |
stdout -count=1 'input\.sh$' |
| 90 |
! stdout 'ignored\.sh' |
| 91 |
! stderr . |
| 92 |
! exec shfmt --apply-ignore -d input.sh ignored/1_lone_ignored.sh ignored/third_party/bad_syntax_ignored.sh |
| 93 |
stdout -count=2 'input\.sh$' |
| 94 |
! stdout 'ignored\.sh' |
| 95 |
! stderr . |
| 96 |
exec shfmt --apply-ignore input.sh ignored/1_lone_ignored.sh ignored/third_party/bad_syntax_ignored.sh |
| 97 |
stdout -count=1 'indented' |
| 98 |
! stdout 'echo foo' |
| 99 |
! stderr . |
| 100 |
stdin ignored/1_lone_ignored.sh |
| 101 |
exec shfmt --apply-ignore --filename=ignored/1_lone_ignored.sh |
| 102 |
! stdout . |
| 103 |
! stderr . |
| 104 |
! exec shfmt --apply-ignore --diff hidden/.script.sh |
| 105 |
stdout -count=1 '^\+ indented' |
| 106 |
|
| 107 |
# Check EditorConfig [[language]] sections, used primarily for extension-less strings with shebangs. |
| 108 |
exec shfmt -d shebang |
| 109 |
! stdout . |
| 110 |
! stderr . |
| 111 |
|
| 112 |
# Verify that sibling EditorConfig files do not get their settings mixed up, |
| 113 |
# which could happen if we incrementally use their flags without care. |
| 114 |
exec shfmt -d multiconfig |
| 115 |
! stdout . |
| 116 |
! stderr . |
| 117 |
|
| 118 |
-- .editorconfig -- |
| 119 |
root = true |
| 120 |
|
| 121 |
[*] |
| 122 |
indent_style = space |
| 123 |
indent_size = 3 |
| 124 |
|
| 125 |
[*_posix.sh] |
| 126 |
shell_variant = posix |
| 127 |
-- input.sh -- |
| 128 |
{ |
| 129 |
indented |
| 130 |
} |
| 131 |
-- input.sh.golden -- |
| 132 |
{ |
| 133 |
indented |
| 134 |
} |
| 135 |
-- stdin-filename-bash -- |
| 136 |
array=( |
| 137 |
element |
| 138 |
) |
| 139 |
-- morespaces/.editorconfig -- |
| 140 |
[*.sh] |
| 141 |
indent_size = 6 |
| 142 |
-- morespaces/input.sh -- |
| 143 |
{ |
| 144 |
indented |
| 145 |
} |
| 146 |
-- morespaces/input.sh.golden -- |
| 147 |
{ |
| 148 |
indented |
| 149 |
} |
| 150 |
-- otherknobs/.editorconfig -- |
| 151 |
root = true |
| 152 |
|
| 153 |
[*_bash.sh] |
| 154 |
shell_variant = bash |
| 155 |
|
| 156 |
[*_mksh.sh] |
| 157 |
shell_variant = mksh |
| 158 |
|
| 159 |
[indent.sh] |
| 160 |
# check its default; we tested "space" above. |
| 161 |
|
| 162 |
[binary_next_line.sh] |
| 163 |
binary_next_line = true |
| 164 |
|
| 165 |
[switch_case_indent.sh] |
| 166 |
switch_case_indent = true |
| 167 |
|
| 168 |
[space_redirects.sh] |
| 169 |
space_redirects = true |
| 170 |
|
| 171 |
[keep_padding.sh] |
| 172 |
keep_padding = true |
| 173 |
|
| 174 |
[function_next_line.sh] |
| 175 |
function_next_line = true |
| 176 |
|
| 177 |
[simplify.sh] |
| 178 |
simplify = true |
| 179 |
|
| 180 |
[minify.sh] |
| 181 |
minify = true |
| 182 |
|
| 183 |
-- otherknobs/shell_variant_bash.sh -- |
| 184 |
array=(elem) |
| 185 |
-- otherknobs/shell_variant_mksh.sh -- |
| 186 |
coprocess |& |
| 187 |
-- otherknobs/indent.sh -- |
| 188 |
{ |
| 189 |
indented |
| 190 |
} |
| 191 |
-- otherknobs/binary_next_line.sh -- |
| 192 |
foo \ |
| 193 |
| bar |
| 194 |
-- otherknobs/switch_case_indent.sh -- |
| 195 |
case "$1" in |
| 196 |
A) echo foo ;; |
| 197 |
esac |
| 198 |
-- otherknobs/space_redirects.sh -- |
| 199 |
echo foo > bar |
| 200 |
-- otherknobs/keep_padding.sh -- |
| 201 |
echo foo bar |
| 202 |
-- otherknobs/function_next_line.sh -- |
| 203 |
foo() |
| 204 |
{ |
| 205 |
echo foo |
| 206 |
} |
| 207 |
-- otherknobs/simplify.sh -- |
| 208 |
foo() { |
| 209 |
((bar)) |
| 210 |
} |
| 211 |
-- otherknobs/minify.sh -- |
| 212 |
foo(){ |
| 213 |
((bar)) |
| 214 |
} |
| 215 |
-- ignored/.editorconfig -- |
| 216 |
root = true |
| 217 |
|
| 218 |
[third_party/**] |
| 219 |
ignore = true |
| 220 |
|
| 221 |
[1_lone_ignored.sh] |
| 222 |
ignore = true |
| 223 |
|
| 224 |
[2_dir_ignored] |
| 225 |
ignore = true |
| 226 |
|
| 227 |
-- ignored/third_party/bad_syntax_ignored.sh -- |
| 228 |
bad (syntax |
| 229 |
-- ignored/1_lone_ignored.sh -- |
| 230 |
echo foo |
| 231 |
-- ignored/2_dir_ignored/ignored.sh -- |
| 232 |
echo foo |
| 233 |
-- ignored/3_regular/regular.sh -- |
| 234 |
echo foo |
| 235 |
-- shebang/.editorconfig -- |
| 236 |
root = true |
| 237 |
|
| 238 |
[*] |
| 239 |
indent_style = space |
| 240 |
indent_size = 1 |
| 241 |
|
| 242 |
[[shell]] |
| 243 |
indent_size = 2 |
| 244 |
|
| 245 |
[[bash]] |
| 246 |
indent_size = 4 |
| 247 |
|
| 248 |
[[zsh]] |
| 249 |
indent_size = 5 |
| 250 |
|
| 251 |
-- shebang/binsh -- |
| 252 |
#!/bin/sh |
| 253 |
|
| 254 |
{ |
| 255 |
indented |
| 256 |
} |
| 257 |
-- shebang/binbash -- |
| 258 |
#!/bin/bash |
| 259 |
|
| 260 |
{ |
| 261 |
indented |
| 262 |
} |
| 263 |
array=(elem) |
| 264 |
-- shebang/binzsh -- |
| 265 |
#!/bin/zsh |
| 266 |
|
| 267 |
{ |
| 268 |
indented |
| 269 |
} |
| 270 |
array=(elem) |
| 271 |
-- hidden/.script.sh -- |
| 272 |
{ |
| 273 |
indented |
| 274 |
} |
| 275 |
-- multiconfig/space_redirects/.editorconfig -- |
| 276 |
[*] |
| 277 |
space_redirects = true |
| 278 |
-- multiconfig/space_redirects/f.sh -- |
| 279 |
foo > bar |
| 280 |
foo && |
| 281 |
bar |
| 282 |
-- multiconfig/binary_next_line/.editorconfig -- |
| 283 |
[*] |
| 284 |
binary_next_line = true |
| 285 |
-- multiconfig/binary_next_line/f.sh -- |
| 286 |
foo >bar |
| 287 |
foo \ |
| 288 |
&& bar |