Skip to content

Commit

Permalink
Merge branch 'mr/pmderodat/optfile-sharp' into 'master'
Browse files Browse the repository at this point in the history
e3.testsuite.optfileparser: restrict syntax for discriminants

See merge request it/e3-testsuite!40
  • Loading branch information
pmderodat committed Oct 21, 2024
2 parents 0f6d3d9 + 2abf665 commit 6c5a02a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 11 additions & 1 deletion src/e3/testsuite/optfileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
1 change: 1 addition & 0 deletions tests/tests/optfiles/sharp_in_comment.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALL DEAD # This # can # contain # sharps
1 change: 1 addition & 0 deletions tests/tests/optfiles/syntax_error_3.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is not a comment and should be rejected
16 changes: 16 additions & 0 deletions tests/tests/test_optfileparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 6c5a02a

Please sign in to comment.