| 1 |
exec shfmt -h |
| 2 |
! stderr 'flag provided but not defined' |
| 3 |
stderr 'usage: shfmt' |
| 4 |
stderr 'Utilities' # definitely includes our help text |
| 5 |
! stderr 'help requested' # don't duplicate usage output |
| 6 |
! stderr '-test\.' # don't show the test binary's usage func |
| 7 |
|
| 8 |
exec shfmt --help |
| 9 |
stderr 'usage: shfmt' |
| 10 |
|
| 11 |
! exec shfmt -ln=bash -p |
| 12 |
stderr 'cannot coexist' |
| 13 |
|
| 14 |
! exec shfmt --language-dialect=bash --posix |
| 15 |
stderr 'cannot coexist' |
| 16 |
|
| 17 |
! exec shfmt -ln=bad |
| 18 |
stderr 'unknown shell language' |
| 19 |
|
| 20 |
! exec shfmt --to-json file |
| 21 |
stderr '--to-json can only be used with stdin' |
| 22 |
|
| 23 |
! exec shfmt --from-json . |
| 24 |
stderr '--from-json can only be used with stdin' |
| 25 |
|
| 26 |
! exec shfmt -filename=foo file |
| 27 |
stderr '-filename can only be used with stdin' |
| 28 |
|
| 29 |
# Check all the -ln variations. |
| 30 |
|
| 31 |
stdin input-posix |
| 32 |
! exec shfmt |
| 33 |
|
| 34 |
stdin input-posix |
| 35 |
exec shfmt -ln=posix |
| 36 |
stdout 'let' |
| 37 |
|
| 38 |
stdin input-posix |
| 39 |
exec shfmt -p |
| 40 |
stdout 'let' |
| 41 |
|
| 42 |
stdin input-posix |
| 43 |
! exec shfmt -ln=mksh |
| 44 |
|
| 45 |
stdin input-posix |
| 46 |
! exec shfmt -ln=bash |
| 47 |
|
| 48 |
stdin input-mksh |
| 49 |
exec shfmt -ln=mksh |
| 50 |
stdout 'coprocess' |
| 51 |
|
| 52 |
stdin input-mksh |
| 53 |
! exec shfmt |
| 54 |
|
| 55 |
# Ensure that the default "bash" language works with and without flags. |
| 56 |
stdin input-bash |
| 57 |
exec shfmt |
| 58 |
stdout loop |
| 59 |
|
| 60 |
# Ensure that -ln=auto works on stdin via filename. |
| 61 |
stdin input-mksh |
| 62 |
exec shfmt -filename=input.mksh |
| 63 |
stdout 'coprocess' |
| 64 |
|
| 65 |
# Ensure that -ln=auto works on stdin via shebang. |
| 66 |
stdin input-mksh-shebang |
| 67 |
exec shfmt |
| 68 |
stdout 'coprocess' |
| 69 |
|
| 70 |
# Ensure that -ln=auto works on stdin using the fallback. |
| 71 |
stdin input-bash |
| 72 |
exec shfmt |
| 73 |
stdout 'loop' |
| 74 |
|
| 75 |
# The default -ln=auto shouldn't require an extension or shebang, |
| 76 |
# as long as we're explicitly formatting a file. |
| 77 |
exec shfmt input-tiny |
| 78 |
stdout foo |
| 79 |
|
| 80 |
# -ln=auto should prefer a shebang if the extension is only ".sh". |
| 81 |
stdin input-mksh-shebang |
| 82 |
exec shfmt -filename=input.sh |
| 83 |
stdout 'coprocess' |
| 84 |
|
| 85 |
# An explicit -ln=auto should still work. |
| 86 |
stdin input-mksh |
| 87 |
exec shfmt -ln=auto -filename=input.mksh |
| 88 |
stdout 'coprocess' |
| 89 |
|
| 90 |
# Certain filenames are recognised like an extension. |
| 91 |
stdin input-zsh |
| 92 |
exec shfmt -filename=/etc/zprofile |
| 93 |
stdout '\${}' |
| 94 |
cp input-zsh .zshrc |
| 95 |
exec shfmt .zshrc |
| 96 |
stdout '\${}' |
| 97 |
|
| 98 |
# Explicitly state language on parse errors |
| 99 |
stdin input-bash-arrays |
| 100 |
! exec shfmt -ln=auto -filename=input.sh |
| 101 |
stderr 'parsed as posix via -ln=auto' |
| 102 |
|
| 103 |
stdin input-bash-extglobs |
| 104 |
! exec shfmt -filename=input.sh |
| 105 |
stderr 'parsed as posix via -ln=auto' |
| 106 |
|
| 107 |
stdin flags-input |
| 108 |
exec shfmt -i 2 |
| 109 |
cmp stdout flags-output.indent-golden |
| 110 |
|
| 111 |
stdin flags-input |
| 112 |
exec shfmt --indent 2 |
| 113 |
cmp stdout flags-output.indent-golden |
| 114 |
|
| 115 |
stdin flags-input |
| 116 |
exec shfmt -bn |
| 117 |
cmp stdout flags-output.binary-next-line-golden |
| 118 |
|
| 119 |
stdin flags-input |
| 120 |
exec shfmt --binary-next-line |
| 121 |
cmp stdout flags-output.binary-next-line-golden |
| 122 |
|
| 123 |
stdin flags-input |
| 124 |
exec shfmt -ci |
| 125 |
cmp stdout flags-output.case-indent-golden |
| 126 |
|
| 127 |
stdin flags-input |
| 128 |
exec shfmt --case-indent |
| 129 |
cmp stdout flags-output.case-indent-golden |
| 130 |
|
| 131 |
stdin flags-input |
| 132 |
exec shfmt -sr |
| 133 |
cmp stdout flags-output.space-redirects-golden |
| 134 |
|
| 135 |
stdin flags-input |
| 136 |
exec shfmt --space-redirects |
| 137 |
cmp stdout flags-output.space-redirects-golden |
| 138 |
|
| 139 |
stdin flags-input |
| 140 |
exec shfmt -kp |
| 141 |
cmp stdout flags-output.keep-padding-golden |
| 142 |
|
| 143 |
stdin flags-input |
| 144 |
exec shfmt --keep-padding |
| 145 |
cmp stdout flags-output.keep-padding-golden |
| 146 |
|
| 147 |
stdin flags-input |
| 148 |
exec shfmt -fn |
| 149 |
cmp stdout flags-output.func-next-line-golden |
| 150 |
|
| 151 |
stdin flags-input |
| 152 |
exec shfmt --func-next-line |
| 153 |
cmp stdout flags-output.func-next-line-golden |
| 154 |
|
| 155 |
-- input-posix -- |
| 156 |
let a+ |
| 157 |
-- input-bash -- |
| 158 |
for ((;;)); do loop; done |
| 159 |
-- input-tiny -- |
| 160 |
foo |
| 161 |
-- input-mksh -- |
| 162 |
coprocess |& |
| 163 |
-- input-zsh -- |
| 164 |
${} =(bar) |
| 165 |
-- input-mksh-shebang -- |
| 166 |
#!/bin/mksh |
| 167 |
coprocess |& |
| 168 |
-- input-bash-extglobs -- |
| 169 |
#!/bin/sh |
| 170 |
echo !(a) |
| 171 |
-- input-bash-arrays -- |
| 172 |
#!/bin/sh |
| 173 |
foo=(bar) |
| 174 |
|
| 175 |
-- flags-input -- |
| 176 |
foo() { |
| 177 |
bar && |
| 178 |
baz |
| 179 |
|
| 180 |
case $i in |
| 181 |
j) |
| 182 |
z |
| 183 |
;; |
| 184 |
esac |
| 185 |
|
| 186 |
space >redirs |
| 187 |
|
| 188 |
keep padding |
| 189 |
} |
| 190 |
-- flags-output.indent-golden -- |
| 191 |
foo() { |
| 192 |
bar && |
| 193 |
baz |
| 194 |
|
| 195 |
case $i in |
| 196 |
j) |
| 197 |
z |
| 198 |
;; |
| 199 |
esac |
| 200 |
|
| 201 |
space >redirs |
| 202 |
|
| 203 |
keep padding |
| 204 |
} |
| 205 |
-- flags-output.binary-next-line-golden -- |
| 206 |
foo() { |
| 207 |
bar \ |
| 208 |
&& baz |
| 209 |
|
| 210 |
case $i in |
| 211 |
j) |
| 212 |
z |
| 213 |
;; |
| 214 |
esac |
| 215 |
|
| 216 |
space >redirs |
| 217 |
|
| 218 |
keep padding |
| 219 |
} |
| 220 |
-- flags-output.case-indent-golden -- |
| 221 |
foo() { |
| 222 |
bar && |
| 223 |
baz |
| 224 |
|
| 225 |
case $i in |
| 226 |
j) |
| 227 |
z |
| 228 |
;; |
| 229 |
esac |
| 230 |
|
| 231 |
space >redirs |
| 232 |
|
| 233 |
keep padding |
| 234 |
} |
| 235 |
-- flags-output.space-redirects-golden -- |
| 236 |
foo() { |
| 237 |
bar && |
| 238 |
baz |
| 239 |
|
| 240 |
case $i in |
| 241 |
j) |
| 242 |
z |
| 243 |
;; |
| 244 |
esac |
| 245 |
|
| 246 |
space > redirs |
| 247 |
|
| 248 |
keep padding |
| 249 |
} |
| 250 |
-- flags-output.keep-padding-golden -- |
| 251 |
foo() { |
| 252 |
bar && |
| 253 |
baz |
| 254 |
|
| 255 |
case $i in |
| 256 |
j) |
| 257 |
z |
| 258 |
;; |
| 259 |
esac |
| 260 |
|
| 261 |
space >redirs |
| 262 |
|
| 263 |
keep padding |
| 264 |
} |
| 265 |
-- flags-output.func-next-line-golden -- |
| 266 |
foo() |
| 267 |
{ |
| 268 |
bar && |
| 269 |
baz |
| 270 |
|
| 271 |
case $i in |
| 272 |
j) |
| 273 |
z |
| 274 |
;; |
| 275 |
esac |
| 276 |
|
| 277 |
space >redirs |
| 278 |
|
| 279 |
keep padding |
| 280 |
} |