OILS / spec / globignore.test.sh View on Github | oilshell.org

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