diff --git a/codespell_lib/_codespell.py b/codespell_lib/_codespell.py index 7065e0b4d39..5bf34f4cd8d 100644 --- a/codespell_lib/_codespell.py +++ b/codespell_lib/_codespell.py @@ -863,7 +863,14 @@ def main(*args): file_opener = FileOpener(options.hard_encoding_detection, options.quiet_level) + glob_match = GlobMatch(options.skip) + try: + glob_match.match("/random/path") # does not need a real path + except re.error: + print("ERROR: --skip/-S has been fed an invalid glob", + file=sys.stderr) + return EX_USAGE bad_count = 0 for filename in options.files: diff --git a/codespell_lib/tests/test_basic.py b/codespell_lib/tests/test_basic.py index bbf2ea47ddb..6165e63a85e 100644 --- a/codespell_lib/tests/test_basic.py +++ b/codespell_lib/tests/test_basic.py @@ -120,9 +120,23 @@ def test_basic(tmpdir, capsys): assert cs.main(d) == 0 # empty directory - os.mkdir(op.join(d, 'test')) + os.mkdir(op.join(d, 'empty')) assert cs.main(d) == 0 + g = op.join(d, 'glob') + os.mkdir(g) + fname = op.join(g, '[b-a].txt') + with open(fname, 'a') as f: + f.write('errror\n') + code, _, stderr = cs.main('--skip', '[b-a].txt', + fname, std=True) + assert code == EX_USAGE, 'invalid glob' + assert 'invalid glob' in stderr + assert cs.main(g) == 1 + assert cs.main('--skip', '[[]b-a[]].txt', g) == 0 + os.remove(fname) + os.rmdir(g) + def test_interactivity(tmpdir, capsys): """Test interaction"""