Debian Codegraph @

cmd/shfmt/testdata/script/detect.txtar

raw
1 # Test the --detect flag and its modes.
2
3 ! exec shfmt --detect=bad .
4 stderr '--detect only allows'
5
6 # The default only uses shell extensions and extensionless shebangs.
7 exec shfmt -f .
8 ! stderr .
9 stdout 'ext\.sh'
10 stdout 'noext-shebang'
11 ! stdout '\.other'
12
13 exec shfmt -f --detect=default .
14 ! stderr .
15 stdout 'ext\.sh'
16 stdout 'noext-shebang'
17 ! stdout '\.other'
18
19 # detect=all reads shebangs regardless of any non-shell extension.
20 exec shfmt -f --detect=all .
21 ! stderr .
22 stdout 'plain\.other'
23 stdout 'exec\.other'
24 ! stdout 'noshebang\.other'
25 ! stdout 'hidden'
26
27 # detect=exec only considers files with an executable bit set.
28 [!windows] chmod 755 exec.other
29 [!windows] chmod 755 execnoshebang.other
30 [!windows] exec shfmt -f --detect=exec .
31 [!windows] ! stderr .
32 [!windows] stdout 'exec\.other'
33 [!windows] ! stdout 'plain\.other'
34 [!windows] ! stdout 'execnoshebang\.other'
35
36 # --find on explicit file arguments applies the detect mode too.
37 exec shfmt -f --detect=all plain.other noshebang.other
38 stdout 'plain\.other'
39 ! stdout 'noshebang\.other'
40
41 # Formatting a directory follows the same detection.
42 ! exec shfmt -l --detect=all .
43 stdout 'plain\.other'
44
45 exec shfmt -l -w --detect=all .
46 stdout 'plain\.other'
47 grep '^foo' plain.other
48
49 -- ext.sh --
50 foo
51 -- noext-shebang --
52 #!/bin/sh
53 foo
54 -- plain.other --
55 #!/bin/sh
56 foo
57 -- exec.other --
58 #!/bin/sh
59 foo
60 -- execnoshebang.other --
61 foo long enough
62 -- noshebang.other --
63 foo long enough
64 -- .hidden.other --
65 #!/bin/sh
66 foo