Skip to content

Commit

Permalink
Merge pull request #757 from teojgo/bugfix/invalid_regex_filter
Browse files Browse the repository at this point in the history
[bugfix] Do not crash when invalid regular expressions are passed to the test selection options
  • Loading branch information
vkarak committed Apr 15, 2019
2 parents 3753da9 + d56b6be commit f428382
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
14 changes: 11 additions & 3 deletions reframe/frontend/check_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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:
Expand Down
16 changes: 16 additions & 0 deletions unittests/test_check_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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()

0 comments on commit f428382

Please sign in to comment.