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

164 lines, 98 significant
1## oils_failures_allowed: 14
2## compare_shells: bash
3## legacy_tmp_dir: true
4
5#### Don't glob flags on file system with GLOBIGNORE
6# This is a bash-specific extension.
7expr $0 : '.*/osh$' >/dev/null && exit 99 # disabled until cd implemented
8touch _tmp/-n _tmp/zzzzz
9cd _tmp # this fail in osh
10GLOBIGNORE=-*:zzzzz # colon-separated pattern list
11echo -* hello zzzz?
12## STDOUT:
13-* hello zzzz?
14## END
15## N-I dash/mksh/ash stdout-json: "hello zzzzz"
16## status: 0
17
18#### basic star case -> ignore files with txt extension
19touch {basic.md,basic.txt}
20GLOBIGNORE=*.txt
21echo *.*
22## STDOUT:
23basic.md
24## END
25
26#### basic question mark case -> ignore txt files with one char filename
27touch {1.txt,10.txt}
28GLOBIGNORE=?.txt
29echo *.*
30## STDOUT:
3110.txt
32## END
33
34#### multiple patterns -> ignore files with o or h extensions
35touch {hello.c,hello.h,hello.o,hello}
36GLOBIGNORE=*.o:*.h
37echo hello*
38## STDOUT:
39hello hello.c
40## END
41
42#### ignore specific file
43mkdir src
44touch src/{__init__.py,__main__.py}
45GLOBIGNORE='src/__init__.py'
46echo src/*
47## STDOUT:
48src/__main__.py
49## END
50
51#### ignore contents of specific directories
52mkdir {src,compose,dist,node_modules}
53touch src/{a.js,b.js}
54touch compose/{base.compose.yaml,dev.compose.yaml}
55touch dist/index.js
56touch node_modules/package.js
57GLOBIGNORE=dist/*:node_modules/*
58echo */*
59## STDOUT:
60compose/base.compose.yaml compose/dev.compose.yaml src/a.js src/b.js
61## END
62
63#### find files in subdirectory but not the ignored pattern
64mkdir {dir1,dir2}
65touch dir1/{a.txt,ignore.txt}
66touch dir2/{a.txt,ignore.txt}
67GLOBIGNORE=*/ignore*
68echo */*
69## STDOUT:
70dir1/a.txt dir2/a.txt
71## END
72
73#### basic range cases
74rm -rf _tmp
75touch {a,b,c,d,A,B,C,D}
76GLOBIGNORE=*[ab]*
77echo *
78GLOBIGNORE=*[ABC]*
79echo *
80GLOBIGNORE=*[!ab]*
81echo *
82## STDOUT:
83A B C D c d
84D a b c d
85a b
86## END
87
88#### range cases using character classes
89touch {_testing.py,pyproject.toml,20231114.log,.env}
90touch 'has space.docx'
91GLOBIGNORE=[[:alnum:]]*
92echo *.*
93GLOBIGNORE=[![:alnum:]]*
94echo *.*
95GLOBIGNORE=*[[:space:]]*
96echo *.*
97GLOBIGNORE=[[:digit:]_.]*
98echo *.*
99## STDOUT:
100.env _testing.py
10120231114.log has space.docx pyproject.toml
102.env 20231114.log _testing.py pyproject.toml
103has space.docx pyproject.toml
104## END
105
106#### ignore everything
107# This pattern appears in public repositories
108touch {1.txt,2.log,3.md}
109GLOBIGNORE=*
110echo *
111## STDOUT:
112*
113## END
114
115#### treat escaped patterns literally
116touch {escape-10.txt,escape*.txt}
117GLOBIGNORE="escape\*.txt"
118echo *.*
119## STDOUT:
120escape-10.txt
121## END
122
123#### resetting globignore reverts to default behaviour
124touch reset.txt
125GLOBIGNORE=*.txt
126echo *.*
127GLOBIGNORE=
128echo *.*
129## STDOUT:
130*.*
131reset.txt
132## END
133
134#### find dotfiles while ignoring . or ..
135# globskipdots is enabled by default in bash >=5.2
136# for bash <5.2 this pattern is a common way to match dotfiles but not . or ..
137shopt -u globskipdots
138touch .env
139GLOBIGNORE=.:..
140echo .*
141GLOBIGNORE=
142echo .* | sort
143## STDOUT:
144.env
145. .. .env
146## END
147
148#### different styles
149# each style of "ignore everything" spotted in a public repo
150touch image.jpeg
151GLOBIGNORE=*
152echo *
153GLOBIGNORE='*'
154echo *
155GLOBIGNORE="*"
156echo *
157GLOBIGNORE=\*
158echo *
159## STDOUT:
160*
161*
162*
163*
164## END