Test for broken regex in bamignore
This commit is contained in:
@@ -163,13 +163,18 @@ class bam_config:
|
|||||||
if os.path.isfile(bamignore):
|
if os.path.isfile(bamignore):
|
||||||
with open(bamignore, 'r') as f:
|
with open(bamignore, 'r') as f:
|
||||||
patterns = f.read().split("\n")
|
patterns = f.read().split("\n")
|
||||||
|
import re
|
||||||
|
try:
|
||||||
|
compiled_patterns = [re.compile(p) for p in patterns]
|
||||||
|
except re.error:
|
||||||
|
fatal("Your .bamignore file contains invalid regular expressions")
|
||||||
|
|
||||||
def filter_ignore(f):
|
def filter_ignore(f):
|
||||||
import re
|
for pattern in filter_ignore.compiled_patterns:
|
||||||
for pattern in filter_ignore.patterns:
|
|
||||||
if re.match(pattern, f):
|
if re.match(pattern, f):
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
filter_ignore.patterns = patterns
|
filter_ignore.compiled_patterns = compiled_patterns
|
||||||
|
|
||||||
return filter_ignore
|
return filter_ignore
|
||||||
else:
|
else:
|
||||||
|
@@ -1045,6 +1045,26 @@ class BamIgnoreTest(BamSessionTestCase):
|
|||||||
self.assertEqual("Nothing to commit!\n", stdout)
|
self.assertEqual("Nothing to commit!\n", stdout)
|
||||||
|
|
||||||
|
|
||||||
|
def test_invalid_ignore(self):
|
||||||
|
session_name = "mysession"
|
||||||
|
file_name = "testfile.txt"
|
||||||
|
file_data = b"hello world!\n"
|
||||||
|
|
||||||
|
# A failing regex that breaks syntax highlight as nice side effect
|
||||||
|
file_data_bamignore = r"""("""
|
||||||
|
|
||||||
|
proj_path, session_path = self.init_session(session_name)
|
||||||
|
|
||||||
|
# write the .bamignore in the session root
|
||||||
|
file_quick_write(proj_path, ".bamignore", file_data_bamignore)
|
||||||
|
|
||||||
|
# create some files
|
||||||
|
file_quick_write(session_path, file_name, file_data)
|
||||||
|
|
||||||
|
# now check for status
|
||||||
|
self.assertRaises(RuntimeError, bam_run, ["status",], session_path)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
data = global_setup()
|
data = global_setup()
|
||||||
unittest.main(exit=False)
|
unittest.main(exit=False)
|
||||||
|
Reference in New Issue
Block a user