OILS / spec / globstar.test.sh View on Github | oils.pub

97 lines, 55 significant
1## oils_failures_allowed: 4
2## compare_shells: bash zsh
3
4#### globstar is off -> ** is treated like *
5case $SH in zsh) exit ;; esac
6
7shopt -u globstar
8
9mkdir -p c/subdir
10touch {leaf.md,c/leaf.md,c/subdir/leaf.md}
11
12echo **/*.* | sort
13## STDOUT:
14c/leaf.md
15## END
16## N-I zsh STDOUT:
17## END
18
19#### each occurrence of ** recurses through all depths
20shopt -s globstar
21
22mkdir -p c/subdir
23touch {leaf.md,c/leaf.md,c/subdir/leaf.md}
24
25echo **/*.* | tr ' ' '\n' | sort
26echo
27echo **/**/*.* | tr ' ' '\n' | sort
28## STDOUT:
29c/leaf.md
30c/subdir/leaf.md
31leaf.md
32
33c/leaf.md
34c/subdir/leaf.md
35leaf.md
36## END
37
38## BUG zsh STDOUT:
39c/leaf.md
40c/subdir/leaf.md
41leaf.md
42
43c/leaf.md
44c/leaf.md
45c/subdir/leaf.md
46c/subdir/leaf.md
47c/subdir/leaf.md
48leaf.md
49## END
50
51#### within braces, globstar works when there is a comma
52shopt -s globstar
53
54mkdir -p c/subdir
55touch c/subdir/leaf.md
56
57echo {**/*.*,} | sort | sed 's/[[:space:]]*$//'
58## STDOUT:
59c/subdir/leaf.md
60## END
61
62#### ** behaves like * if adjacent to anything other than /
63shopt -s globstar
64
65mkdir directory
66touch leaf.md
67touch directory/leaf.md
68
69echo **/*.* | sort
70echo directory/**/*.md | sort
71echo d**/*.md | sort
72echo **y/*.md | sort
73echo d**y/*.md | sort
74## STDOUT:
75directory/leaf.md leaf.md
76directory/leaf.md
77directory/leaf.md
78directory/leaf.md
79directory/leaf.md
80## END
81
82#### in zsh, ***/ follows symlinked directories, while **/ does not
83case $SH in bash) exit ;; esac
84
85mkdir directory-1
86mkdir directory-2
87touch directory-2/leaf-2.md
88ln -s -T ../directory-2 directory-1/symlink
89
90echo **/*.* | sort
91echo ***/*.* | sort
92## STDOUT:
93directory-2/leaf-2.md
94directory-1/symlink/leaf-2.md directory-2/leaf-2.md
95## END
96## N-I bash STDOUT:
97## END