tests: comment filters keep a trailing comment, so a check can read text that is only in a comment (42 sites)

Open
#2,904 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
55/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
testing

Research direction

Start with the 42 matching filters under tools/tests, beginning at the examples in test_builtin_defaults_contract.py, test_runtime_lifecycle_invariants.py, and test_vcpkg_pin.py. For each hit, inspect the assertion and determine whether trailing comment text can affect it; add a failing mutant test for each affected check. Record each hit’s outcome, then use a shared comment-cut helper where needed and verify the mutants fail when the asserted text appears only in a trailing comment.

Written by the indexing model from the issue text.

Description

backlog

Evidence at e062cb52e

Many tests drop a source's comments with a whole-line filter: a line is kept only if it does not start with # after stripping.
Such a filter keeps any # that follows code on the same line, so a trailing comment stays in the text the test checks.

git grep -n -E 'startswith\("#"\)|split\("#", 1\)' -- tools/tests (at e062cb52e) prints 42 hits. Most are whole-line filters, for
example tools/tests/test_builtin_defaults_contract.py:137:

code = "\n".join(line for line in module.splitlines() if not line.lstrip().startswith("#"))

A few cut at the first # instead (for example tools/tests/test_runtime_lifecycle_invariants.py:126 and
tools/tests/test_vcpkg_pin.py:109), so they handle trailing comments.

Found while fixing #2901: the test test_the_generated_header_is_group_readable checked for a grant, and a grant inside a trailing
comment passed the whole-line filter. That test now cuts each line at its first #; its mutant M2 fails with the grant in a
trailing comment.

Not shown

  • Per-site verdicts. This issue does not classify each of the 42 hits as a defect or not. It only names the shape and the count.
  • Whether any of the 42 checks passes wrongly today because of a trailing comment. Only the one case above was constructed and run.

Falsifier

A test under tools/tests that fails or passes on a trailing comment's text in its own test body, on a file where the whole-line
filter and a first-# cut give different results for the check, would show the shape is not the same across hits. A count of
hits alone is not a falsifier.

Work

  1. Per hit: read the check and say whether a trailing comment can make it pass or fail wrongly. Record each hit as fixed, filed by
    number, or not the same shape with the reason.
  2. For each hit that can pass wrongly, add a mutant test first: a trailing comment that holds the asserted text must not satisfy
    the check. It must fail on the current tree.
  3. Use one shared helper for the comment cut where the repo has no such helper yet, and move the hits to it.
Dominant language
C++
Stars
3
Forks
5
Avg merge
4h 37m
Merged PRs (30d)
524

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from EchoTools/nevr-runtime

All issues in EchoTools/nevr-runtime

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.