diff --git a/NEWS.md b/NEWS.md index 323f5bb..0a82989 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ 27.0 (Not released yet) ======================= +* `e3.testsuite.optfileparser`: restrict syntax for discriminants. * Fix test filtering when not all test finders have dedicated directories. * `PatternSubstitute`: update annotations to accept replacement callbacks. * `e3.testsuite.report.xunit`: add a `XUnitImportApp` class to make it possible diff --git a/src/e3/testsuite/optfileparser.py b/src/e3/testsuite/optfileparser.py index dedad0f..2c14972 100644 --- a/src/e3/testsuite/optfileparser.py +++ b/src/e3/testsuite/optfileparser.py @@ -22,7 +22,17 @@ # Regexp that matches valid lines in test.opt files -OPTLINE_REGEXPS = re.compile(r"^([^\s]+)(\s+([a-zA-Z0-9_-]+)(\s+(.*))?)?$") +OPTLINE_REGEXPS = re.compile( + # Comma-separated list of discriminants + r"^([a-zA-Z0-9!+,._-]+)" + # The rest is optional... + "(" + # Command + r"\s+([a-zA-Z0-9_-]+)" + # Optional command argument + r"(\s+(.*))?" + ")?$" +) class BadFormattingError(Exception): diff --git a/tests/tests/optfiles/sharp_in_comment.opt b/tests/tests/optfiles/sharp_in_comment.opt new file mode 100644 index 0000000..9ae4dad --- /dev/null +++ b/tests/tests/optfiles/sharp_in_comment.opt @@ -0,0 +1 @@ +ALL DEAD # This # can # contain # sharps diff --git a/tests/tests/optfiles/syntax_error_3.opt b/tests/tests/optfiles/syntax_error_3.opt new file mode 100644 index 0000000..6e51e91 --- /dev/null +++ b/tests/tests/optfiles/syntax_error_3.opt @@ -0,0 +1 @@ +# This is not a comment and should be rejected diff --git a/tests/tests/test_optfileparser.py b/tests/tests/test_optfileparser.py index a9b626b..efa168b 100644 --- a/tests/tests/test_optfileparser.py +++ b/tests/tests/test_optfileparser.py @@ -220,3 +220,19 @@ def test_check_syntax_main(): p = Run(["e3-opt-check", "dead.opt", "tags.opt"], cwd=optfiles_dir) assert p.status == 0 assert p.out == "" + + +def test_sharp(): + """Check the handling for lines that contain '#'.""" + of = parse_file("sharp_in_comment.opt") + assert of.get_value("dead") == "# This # can # contain # sharps" + + try: + parse_file("syntax_error_3.opt") + except BadFormattingError as exc: + assert str(exc) == ( + "Can not parse line 1:" + " # This is not a comment and should be rejected" + ) + else: + raise AssertionError()