diff --git a/reframe/frontend/check_filters.py b/reframe/frontend/check_filters.py index a16bce3f9b..9bb57534ae 100644 --- a/reframe/frontend/check_filters.py +++ b/reframe/frontend/check_filters.py @@ -2,10 +2,18 @@ import reframe.core.runtime as rt import reframe.utility.sanity as util +from reframe.core.exceptions import ReframeError + + +def re_compile(patt): + try: + return re.compile(patt) + except re.error: + raise ReframeError("invalid regex: '%s'" % patt) def have_name(patt): - regex = re.compile(patt) + regex = re_compile(patt) def _fn(c): return regex.match(c.name) @@ -21,7 +29,7 @@ def _fn(c): def have_tag(patt): - regex = re.compile(patt) + regex = re_compile(patt) def _fn(c): return any(regex.match(p) for p in c.tags) @@ -30,7 +38,7 @@ def _fn(c): def have_prgenv(patt): - regex = re.compile(patt) + regex = re_compile(patt) def _fn(c): if '*' in c.valid_prog_environs: diff --git a/unittests/test_check_filters.py b/unittests/test_check_filters.py index 6cde2560f9..d077f31c41 100644 --- a/unittests/test_check_filters.py +++ b/unittests/test_check_filters.py @@ -5,6 +5,7 @@ import reframe.utility.sanity as sn import unittests.fixtures as fixtures from reframe.core.pipeline import RegressionTest +from reframe.core.exceptions import ReframeError class TestCheckFilters(unittest.TestCase): @@ -90,3 +91,18 @@ def test_have_gpu_only(self): def test_have_cpu_only(self): self.assertEqual(1, self.count_checks(filters.have_cpu_only())) + + def test_invalid_regex(self): + # We need to explicitly call `evaluate` to make sure the exception + # is triggered in all cases + with self.assertRaises(ReframeError): + self.count_checks(filters.have_name('*foo')).evaluate() + + with self.assertRaises(ReframeError): + self.count_checks(filters.have_not_name('*foo')).evaluate() + + with self.assertRaises(ReframeError): + self.count_checks(filters.have_tag('*foo')).evaluate() + + with self.assertRaises(ReframeError): + self.count_checks(filters.have_prgenv('*foo')).evaluate()