Skip to content

Issue #23: allow comments and blank lines in rule files#44

Open
HoldenHrabak wants to merge 3 commits intoagroce:masterfrom
HoldenHrabak:fix/issue-23-rule-comments
Open

Issue #23: allow comments and blank lines in rule files#44
HoldenHrabak wants to merge 3 commits intoagroce:masterfrom
HoldenHrabak:fix/issue-23-rule-comments

Conversation

@HoldenHrabak
Copy link
Copy Markdown

Summary

Fixes #23.

parseRules() in mutator.py already silently ignored lines starting with #, but only under three conditions: no leading whitespace, the line was not exactly "\n", and the line did not contain ==>. Indented comments ( # note) and whitespace-only blank lines both triggered a spurious DOES NOT MATCH EXPECTED FORMAT warning. This PR fixes that and documents the feature so users can confidently use comments to organise their rule sets.

Changes

  • universalmutator/mutator.py — rewrote the comment/blank-line branch of parseRules so the # / empty check runs on the stripped line. The ==> check still runs first, which preserves two existing rules whose LHS legitimately starts with #:
    • #include ==> DO_NOT_MUTATE in static/c_like.rules
    • # ==> SKIP_MUTATING_REST in static/python.rules
  • tests/test_rule_comments.py — new file, 9 unit tests covering:
    • plain #, indented #, tab-indented #
    • empty and whitespace-only blank lines
    • both legacy #-prefixed rules (regression tests)
    • a realistic mixed-content header
    • malformed-line warning still fires
  • universalmutator/static/universal.rules — added an 8-line header that documents the rules-file format and serves as a live demo that the parser accepts it.
  • README.md — new "Rule Files" section covering the syntax and the comment behaviour.

Scope

Deliberately full-line comments only. Inline comments (foo ==> bar # note) would be nice but are ambiguous — # is a legal regex character, and stripping anything after # in the RHS would silently change the behaviour of any rule a user has written that depends on a literal #. Happy to follow up with a separate PR if that trade-off is acceptable; this one is scoped to the unambiguous case.

Testing

All tests pass locally on Python 3.12:

$ pytest tests/
========================= 10 passed in 55s =========================

The existing test_foo_example.py exercises parseRules end-to-end through the mutate / analyze_mutants / prioritize_mutants CLI pipeline and continues to pass with the header comments now present in universal.rules, confirming no behavioural change in the generated-mutant count.

Diff stats

 README.md                               |  24 ++++++
 tests/test_rule_comments.py             | 144 ++++++++++++++++++++++++++++++++
 universalmutator/mutator.py             |  36 ++++----
 universalmutator/static/universal.rules |  10 +++
 4 files changed, 199 insertions(+), 15 deletions(-)

cc @ClassProg (submitting as a class project)

HoldenHrabak and others added 3 commits April 17, 2026 14:12
parseRules() already silently ignored lines starting with '#' but only when they contained no leading whitespace and the line wasn't exactly '\n'. Indented comments ('    # note') and whitespace-only blank lines produced spurious 'DOES NOT MATCH EXPECTED FORMAT' warnings. Rewrite the branch so that comment/blank detection runs on the stripped line, and verify rule-precedence is preserved: '#include ==> DO_NOT_MUTATE' (c_like.rules) and '# ==> SKIP_MUTATING_REST' (python.rules) still parse as rules because the ' ==> ' check still runs first.
Added tests for comby mode to ensure new comment style is also recognized properly
Fixed an issue where the new comby test would not pass due to the improper parsing of sys.argv arguments. This fix may need to be altered again in conjunction with the update to argparse, but restores test functionality for current version. Also adjusted cmd to use the path to the current Python interpreter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow comments in rules

2 participants