Issue #23: allow comments and blank lines in rule files#44
Open
HoldenHrabak wants to merge 3 commits intoagroce:masterfrom
Open
Issue #23: allow comments and blank lines in rule files#44HoldenHrabak wants to merge 3 commits intoagroce:masterfrom
HoldenHrabak wants to merge 3 commits intoagroce:masterfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #23.
parseRules()inmutator.pyalready 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 spuriousDOES NOT MATCH EXPECTED FORMATwarning. 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 ofparseRulesso 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_MUTATEinstatic/c_like.rules# ==> SKIP_MUTATING_RESTinstatic/python.rulestests/test_rule_comments.py— new file, 9 unit tests covering:#, indented#, tab-indented##-prefixed rules (regression tests)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:
The existing
test_foo_example.pyexercisesparseRulesend-to-end through themutate/analyze_mutants/prioritize_mutantsCLI pipeline and continues to pass with the header comments now present inuniversal.rules, confirming no behavioural change in the generated-mutant count.Diff stats
cc @ClassProg (submitting as a class project)