@@ -118,10 +118,30 @@ def test_basic(tmpdir, capsys):
118118 assert cs .main (d ) == 0
119119
120120 # empty directory
121- os .mkdir (op .join (d , 'test ' ))
121+ os .mkdir (op .join (d , 'empty ' ))
122122 assert cs .main (d ) == 0
123123
124124
125+ def test_bad_glob (tmpdir , capsys ):
126+ # disregard invalid globs, properly handle escaped globs
127+ g = op .join (tmpdir , 'glob' )
128+ os .mkdir (g )
129+ fname = op .join (g , '[b-a].txt' )
130+ with open (fname , 'a' ) as f :
131+ f .write ('abandonned\n ' )
132+ assert cs .main (g ) == 1
133+ # bad glob is invalid
134+ code , _ , stderr = cs .main ('--skip' , '[b-a].txt' ,
135+ g , std = True )
136+ if sys .hexversion < 0x030A05F0 : # Python < 3.10.5 raises re.error
137+ assert code == EX_USAGE , 'invalid glob'
138+ assert 'invalid glob' in stderr
139+ else : # Python >= 3.10.5 does not match
140+ assert code == 1
141+ # properly escaped glob is valid, and matches glob-like file name
142+ assert cs .main ('--skip' , '[[]b-a[]].txt' , g ) == 0
143+
144+
125145@pytest .mark .skipif (
126146 not sys .platform == 'linux' , reason = 'Only supported on Linux' )
127147def test_permission_error (tmp_path , capsys ):
0 commit comments