Answer stability round 2: 0 🔴, 1 🟡 (0 misread); compare each test declaration's whole text, so an attribute a fix adds to it counts as a change

This commit is contained in:
2026-11-27 17:43:33 +01:00
parent f5940f265d
commit 814779c9a1
4 changed files with 26 additions and 14 deletions
+10 -8
View File
@@ -56,18 +56,19 @@ def modules(source: bytes) -> dict[bytes, tuple[int, int]] | None:
return found if depth == 0 and inside is None else None
def declared(source: bytes) -> list[str] | None:
"""The name of each `#[cfg(test)] mod name;` of source, in the order they stand. The module's code is in a file of its own. None where
def declared(source: bytes) -> list[tuple[str, str]] | None:
"""Each `#[cfg(test)] mod name;` of source, in the order they stand, as the module's name and the declaration's text from the
`#[cfg(test)]` to the `;` with its spaces and newlines squeezed to one space. The module's code is in a file of its own. None where
a string or comment is never closed."""
names = []
found = []
position = 0
while match := SCAN.search(source, position):
if (after := after_token(source, match)) is None:
return None
position = after
if match.group() == b"#[cfg(test)]" and (declaration := DECLARATION.match(source, position)):
names.append(declaration.group("name").decode())
return names
found.append((declaration.group("name").decode(), " ".join(source[match.start():declaration.end()].decode().split())))
return found
def homes(path: str, name: str) -> list[str]:
@@ -115,11 +116,12 @@ def with_tests_of(planted: bytes, copy: bytes) -> bytes:
"""copy with each of its test modules replaced by the one of that name in planted, and each that planted lacks left out. So a test a
fix changed, removed or added doesn't count.
Where copy lacks a `mod name;` declaration of planted's, or cannot have its declarations told apart, planted is returned: the file
of that module stands as planted, and a fix that drops the declaration would leave its tests uncompiled. Otherwise, where planted's
Where copy lacks a `mod name;` declaration of planted's, as written, or cannot have its declarations told apart, planted is
returned: the file of that module stands as planted, and a fix that drops the declaration or adds an attribute such as `#[path]`
to it would leave its tests uncompiled or unrun. Otherwise, where planted's
modules cannot be told apart, or planted has none and copy's cannot be told apart, copy is returned as it is. Where planted has some
and copy's cannot be told apart, or copy lacks one of planted's, planted is returned: Haiku's file has no module to put them in."""
if not set(declared(planted) or []) <= set(declared(copy) or []):
if not {text for _, text in declared(planted) or []} <= {text for _, text in declared(copy) or []}:
return planted
before, after = modules(planted), modules(copy)
# Haiku's file stands where planted's modules can't be told apart. The bench never plants a bug in such a file, and a guess at