diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 017b578..8592b11 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -426,6 +426,91 @@ jobs: assert d["findings"] == [], d["findings"] PY + # logbook#89 and logbook#81, which were one defect: both questions + # `_branch_polarity` asks of a branch are about one command, and a + # branch body was handed to them whole. On `main` this fixture produces + # *two false findings* rather than two wrong labels -- the polarity it + # invents at line 6 is live, so the line goes on to be reported + # `unwitnessed`, and line 15 is reported `decorative`, which says a + # working assertion is dead. + # + # `printf` for the reason the steps above use it: a heredoc's lines are + # physical lines of *this* script, and a fixture about dead assertions + # would arrive as findings against the file that built it. + - name: the shapes logbook#89 and logbook#81 were filed for + run: | + set -euo pipefail + mkdir -p either/.github/workflows + printf '%s\n' \ + "'on': push" \ + "jobs:" \ + " j:" \ + " steps:" \ + " - run: |" \ + " if grep -q 'either way' out.txt; then" \ + " grep -q 'or this way' out.txt" \ + " fi" \ + " - run: |" \ + " if grep -q 'the bad line' out.txt; then" \ + " grep -q 'and its detail' out.txt" \ + " exit 1" \ + " fi" \ + " - run: |" \ + " if grep -q 'one line either way' out.txt; then grep -q 'or that' out.txt; fi" \ + " - run: |" \ + " if grep -q 'first row' rows.txt; then echo noted; else grep -q 'second row' rows.txt; exit 1; fi" \ + " - run: |" \ + " if grep -q 'present' out.txt; then echo noted; else grep -q 'absent' out.txt || { echo neither; exit 1; }; fi" \ + > either/.github/workflows/ci.yml + cat either/.github/workflows/ci.yml + + # Status captured rather than inherited: line 10 is a real finding + # on purpose -- it is the control for the shape that must stay live + # -- so this run exits 1 by design and `set -e` would end the step + # before a single assertion below ran. + set +e + deadassert either | tee either.txt; status=$? + deadassert either --json > either.json + set -e + test "$status" -eq 1 + + python - <<'PY' + import json + d = json.load(open("either.json")) + + # Lines 6 and 15 are logbook#89: the `then` branch asserts, so the + # step fails only when the condition matches and the branch matcher + # misses, and the condition is not the verdict. Line 19 is + # logbook#78's `else` shape, unchanged, and its own control: the + # `exit` there is behind `|| { ... }` on a matcher, which is one + # command, so splitting must not reach the `;` inside the braces. + why = {x["where"]: x["why"] for x in d["undecided"]} + assert sorted(why) == ["ci.yml:15", "ci.yml:19", "ci.yml:6"], sorted(why) + assert "`then` branch" in why["ci.yml:6"], why["ci.yml:6"] + assert "`then` branch" in why["ci.yml:15"], why["ci.yml:15"] + assert "`else` branch" in why["ci.yml:19"], why["ci.yml:19"] + + # Line 17 is logbook#81, and it is read rather than declined: its + # `else` holds a matcher and then an unconditional `exit`, so the + # condition is the whole verdict. Not in `undecided` above, and + # counted here. + assert d["assertions"] == 4, d["assertions"] + + # Line 10 is the control the whole step rests on: a `then` branch + # that asserts *and* exits is still `needs-no-match`, which is the + # shape of every real guard in this organisation. It is the one + # negated assertion in the file and the one finding. + assert d["negated"] == 1, d["negated"] + found = {(f["kind"], f["line"]) for f in d["findings"]} + assert found == {("unwitnessed", 10)}, d["findings"] + + # And the two findings `main` invents, named so a regression says + # which one came back: the `unwitnessed` is downstream of a false + # live polarity, the `decorative` calls a working assertion dead. + assert ("unwitnessed", 6) not in found, d["findings"] + assert ("decorative", 15) not in found, d["findings"] + PY + # The assertion above is only worth anything if it can go red. Break # one assertion in a copy of this file and check that it does. - name: a broken assertion in this file is caught diff --git a/README.md b/README.md index 4c82865..5f1c211 100644 --- a/README.md +++ b/README.md @@ -178,17 +178,30 @@ stops being reported. under `not read:`. - **Control flow that is not a verdict is declined, not guessed.** A matcher in a `while`/`until` condition is a poll, not an assertion — the loop ends, - the step carries on. A condition whose `else` branch *also* asserts is one - side of an either-or: `if grep -q A f; then :; else grep -q B f; fi` fails - only when neither pattern matches, so neither decides the step alone. The - same holds when the second matcher is an `elif` rather than an `else`: - `if grep -q A f; then :; elif grep -q B f; then exit 1; fi` fails only when - `A` misses *and* `B` matches, so `A` is declined — while `B`, read where it - is actually reached, is the verdict there and comes out `needs-no-match`. An - `if` with no `fi` cannot be read at all. All of those go in `not decided:`, - out of the counts, and — this is the part with teeth — cannot stand as the - witness that a string is ever produced. A condition whose `else` exits on - its own *is* the whole verdict, and is still read as `needs-match`. + the step carries on. A condition whose branch *also* asserts is one side of + an either-or and is declined, whichever branch it is: + `if grep -q A f; then :; else grep -q B f; fi` fails only when neither + pattern matches, and `if grep -q A f; then grep -q B f; fi` fails only when + `A` matches and `B` misses, so in neither one does `A` decide the step + alone. The same holds when the second matcher is an `elif` rather than an + `else`: `if grep -q A f; then :; elif grep -q B f; then exit 1; fi` fails + only when `A` misses *and* `B` matches, so `A` is declined — while `B`, read + where it is actually reached, is the verdict there and comes out + `needs-no-match`. An `if` with no `fi` cannot be read at all. All of those + go in `not decided:`, out of the counts, and — this is the part with teeth — + cannot stand as the witness that a string is ever produced. + + What is *not* declined is a branch that fails on its own. The branch is read + as the command list it is, so `else grep -q B f; exit 1` is the whole + verdict — the `exit` runs whatever `B` does — and stays `needs-match`, while + `else grep -q B f || { exit 1; }` is `B`'s own verdict and is declined. One + `;` apart, opposite answers. +- **A matcher inside a nested `if` in the branch is not seen.** `if grep -q A + f; then if grep -q B f; then exit 1; fi; fi` fails only when both match, and + it is read as though `A` decided it alone. This is the one place the reading + above is still too generous, and it is known rather than fixed: the branch is + split into commands, and a nested `if` is one command whose condition is not + read. It is the next thing to do here. - **`unwitnessed` is a smell, not a proof.** It says nothing in *these workflows* establishes the string can appear. The proof may well live in a unit test, where it is arguably better placed. What the finding is really diff --git a/src/deadassert/shell.py b/src/deadassert/shell.py index 96c1b21..c470f33 100644 --- a/src/deadassert/shell.py +++ b/src/deadassert/shell.py @@ -190,6 +190,131 @@ def group_delta(text: str) -> int: return delta +#: Keywords that open a compound command, and the words that close one. A `;` +#: inside one of these separates commands *inside the nested block*, not the +#: commands of the list being read, so it must not split one. +_BLOCK_OPEN = ("if", "while", "until", "for", "case", "select") +_BLOCK_CLOSE = ("fi", "done", "esac") + +#: What may stand immediately before a word for that word to be a command +#: rather than an argument. Without this `echo fi` closes a block. +_COMMAND_AFTER = ";&|({" +_COMMAND_KEYWORD = re.compile(r"(?:^|[;\s&|(){])(?:then|else|elif|do|in)$") + +#: A command list keeps going after `then`, `else`, `do` and `in` exactly as +#: it does after a `;` -- the reason `_FAILING` lists them too. Stripped off +#: the front of a part so the command behind one is visible to both. +LEADING_KEYWORD = re.compile(r"^(?:then|else|elif|do|in)\s+") + + +def _is_command(text: str, index: int) -> bool: + """Whether the word at `index` stands where a command can start.""" + before = text[:index].rstrip() + if not before: + return True + return before[-1] in _COMMAND_AFTER or bool(_COMMAND_KEYWORD.search(before)) + + +def command_parts(text: str) -> list[str]: + """`text` split on the `;` that separate one command from the next. + + The scanning rules are `group_delta`'s, for the same reason: a `;` only + separates commands at the top level, and not one inside quotes, + `$(...)`, `${...}`, backticks, a `{ ... }` group, a `(...)` subshell or a + nested `if`/`while`/`case`. Each part comes back stripped, with any + leading `then`/`else`/`do` dropped, because a part is handed to + `_bare_assertion` and `command_head` starts its match at the program + name -- `then grep -q X f` reads as a command called `then`. + + Why this is a splitter and not a regex: the two shapes it has to keep + apart are one `;` deep each. + + grep -q 'B' f; exit 1 two commands -- the exit is nobody's verdict + grep -q 'B' f || { echo; exit 1; } one command -- the exit is grep's verdict + + `&&` and `||` are left alone on purpose: they make what follows + conditional on a verdict, which is the distinction `_branch_polarity` + exists to read. A lone `&` separates commands too and is also left + alone -- not splitting declines rather than over-claims, and nothing in + 37 workflow files backgrounds a command in a branch. + """ + parts: list[str] = [] + start = 0 + quote: str | None = None + #: Closers owed to `$(`, `${` and backticks, as in `group_delta`. + stack: list[str] = [] + braces = 0 + parens = 0 + block = 0 + index = 0 + while index < len(text): + ch = text[index] + if quote: + if ch == quote: + quote = None + index += 1 + continue + if ch in "'\"": + quote = ch + index += 1 + continue + if ch == "`": + if stack and stack[-1] == "`": + stack.pop() + else: + stack.append("`") + index += 1 + continue + if ch == "$" and index + 1 < len(text) and text[index + 1] in "({": + stack.append(")" if text[index + 1] == "(" else "}") + index += 2 + continue + if ch == "(" and stack: + stack.append(")") + index += 1 + continue + if ch in ")}" and stack and stack[-1] == ch: + stack.pop() + index += 1 + continue + if stack: + index += 1 + continue + if ch == "{" and (index == 0 or text[index - 1] in _GROUP_OPEN_AFTER): + if text[index + 1 : index + 2] in ("", " ", "\t"): + braces += 1 + index += 1 + continue + if ch == "}" and (index == 0 or text[index - 1] in " \t;&("): + braces -= 1 + index += 1 + continue + if ch == "(": + parens += 1 + index += 1 + continue + if ch == ")": + parens = max(parens - 1, 0) + index += 1 + continue + if ch.isalpha() or ch == "_": + word = re.match(r"\w+", text[index:]).group(0) + if _is_command(text, index): + if word in _BLOCK_OPEN: + block += 1 + elif word in _BLOCK_CLOSE: + block -= 1 + index += len(word) + continue + if ch == ";" and braces <= 0 and parens <= 0 and block <= 0: + parts.append(text[start:index]) + start = index + 1 + index += 1 + parts.append(text[start:]) + stripped = (LEADING_KEYWORD.sub("", part.strip()) for part in parts) + return [part for part in stripped if part] + + def function_spans(script: str) -> list[tuple[int, int, str]]: """`(first line, last line, name)` for each function definition. @@ -562,16 +687,22 @@ def _branch_polarity(lines: list[tuple[int, str]], index: int) -> tuple[str, str gated = False def note(which: str, part: str) -> None: - asserts = _bare_assertion(part) - if _FAILING.search(part): - fails[which] = True - # An `exit` reached through `|| { ... }` on a matcher is that - # matcher's verdict, not an unconditional failure. Neither is one - # reached past an `elif` condition that holds a matcher. - unconditional = not asserts and not (which == "else" and gated) - alone[which] = alone[which] or unconditional - if asserts: - fails[which] = True + # Asked per command, not per part. A branch body is a command list, + # and both questions below are about one command: `grep -q B f` + # followed by `exit 1` fails whatever `B` does, while + # `grep -q B f || { exit 1; }` fails only when `B` misses, and read + # as one blob those two are indistinguishable -- logbook#81. + for piece in command_parts(part): + asserts = _bare_assertion(piece) + if asserts: + fails[which] = True + if _FAILING.search(piece): + fails[which] = True + # An `exit` reached through `|| { ... }` on a matcher is that + # matcher's verdict, not an unconditional failure. Neither is + # one reached past an `elif` condition that holds a matcher. + unconditional = not asserts and not (which == "else" and gated) + alone[which] = alone[which] or unconditional for offset, (_, text) in enumerate(lines[index:]): for token in re.findall(r"(?:^|[;\s])(if|fi)(?=[;\s]|$)", text): @@ -608,6 +739,11 @@ def note(which: str, part: str) -> None: if depth > 0: return "undecided", "the `if` has no matching `fi` in this script" if fails["then"] and not fails["else"]: + if not alone["then"]: + return "undecided", ( + "the matcher is one side of an either-or: the `then` branch asserts too, " + "so a match here is not on its own what fails the step" + ) return "needs-no-match", None if fails["else"] and not fails["then"]: if not alone["else"]: diff --git a/tests/test_shell.py b/tests/test_shell.py index 925c586..5d304df 100644 --- a/tests/test_shell.py +++ b/tests/test_shell.py @@ -266,6 +266,67 @@ def test_if_then_at_the_top_level_is_still_its_own_line(self): ] +class TestCommandParts: + r"""The splitter behind logbook#81, and the one `;` it must not split on. + + `command_parts` is only interesting because of what it refuses to do. + Every case below is a `;` that looks like a command separator and is + not, and each one has a wrong answer attached to it: a `;` inside + `|| { ... }` yields a bare `exit 1`, which would read as a failure no + matcher gets a say in and put logbook#78's shape back on a live + polarity. + """ + + def test_a_list_splits_on_its_separators(self): + assert shell.command_parts("grep -q 'B' f; exit 1") == ["grep -q 'B' f", "exit 1"] + + def test_a_brace_group_is_one_command(self): + # The case with teeth: `exit 1` here is the matcher's verdict. + text = "grep -q 'B' f || { echo no; exit 1; }" + assert shell.command_parts(text) == [text] + + def test_a_nested_compound_is_one_command(self): + text = "if grep -q 'B' f; then exit 1; fi" + assert shell.command_parts(text) == [text] + assert shell.command_parts("while grep -q x f; do sleep 1; done") == [ + "while grep -q x f; do sleep 1; done" + ] + assert shell.command_parts("case $x in a) echo a;; esac; exit 1") == [ + "case $x in a) echo a;; esac", + "exit 1", + ] + + def test_a_keyword_in_argument_position_opens_and_closes_nothing(self): + # The direction with teeth is the *opening* one: a stray `fi` only + # pushes the depth negative, which a `<= 0` test forgives, but a + # stray `if` hides the separator after it and the part goes back to + # being read as one blob. + assert shell.command_parts("echo if; exit 1") == ["echo if", "exit 1"] + assert shell.command_parts("echo fi; exit 1") == ["echo fi", "exit 1"] + + def test_a_separator_in_quotes_or_an_expansion_is_not_one(self): + assert shell.command_parts("grep -q 'a;b' f; exit 1") == ["grep -q 'a;b' f", "exit 1"] + assert shell.command_parts("echo $(date; true); exit 1") == ["echo $(date; true)", "exit 1"] + assert shell.command_parts("echo ${x:-a;b}; exit 1") == ["echo ${x:-a;b}", "exit 1"] + assert shell.command_parts("echo `date; true`; exit 1") == ["echo `date; true`", "exit 1"] + assert shell.command_parts("( grep -q B f; exit 1 )") == ["( grep -q B f; exit 1 )"] + + def test_a_leading_keyword_comes_off(self): + # Without this the branch body of a one-line `if` is a command called + # `then`, which is no matcher and no `exit` -- the shape that read + # `decorative`. + assert shell.command_parts("; then grep -q 'C' f; fi") == ["grep -q 'C' f", "fi"] + assert shell._bare_assertion(shell.command_parts("; then grep -q 'C' f")[0]) + + def test_the_separators_the_shell_uses_that_this_does_not(self): + # `&&`, `||` and `&` all separate commands. The first two make what + # follows conditional on a verdict, which is the distinction being + # read; a lone `&` is left with them because not splitting declines + # rather than over-claims. + assert shell.command_parts("grep -q B f && exit 1") == ["grep -q B f && exit 1"] + assert shell.command_parts("grep -q B f & exit 1") == ["grep -q B f & exit 1"] + + class TestOneLineIf: """An `if` must read the same whether it is written on one line or four. @@ -367,12 +428,29 @@ def test_spans_cover_both_definition_forms(self): class TestEitherOr: - """`if grep A; then :; else grep B; fi` -- logbook#78. - - The step fails only when *neither* pattern matches, so neither pattern - decides it alone. Confirmed against `bash -e` with a file holding only - `B`: the script exits 0, which is what makes `needs-match` on `A` a - false label rather than a pessimistic one. + r"""A branch that asserts, so the condition above it is not the verdict. + + logbook#78 for the `else` branch, logbook#89 for the `then` branch, and + logbook#81 for the spelling that put both on one line. The condition + decides the step only when nothing in the branch it chooses gets a say, + and a branch body is a command list: `grep -q B f` followed by `exit 1` + fails whatever `B` does, while `grep -q B f || { exit 1; }` fails only + when `B` misses. + + Every expectation here was taken from running the shape under `bash -e` + for each combination of which patterns `f` holds, never from reading the + code: + + none A B C AB AC BC ABC + then, bare matcher 0 1 0 0 1 0 0 0 + then, matcher then exit 0 1 0 . 1 1 . 1 + else, bare matcher 1 0 1 0 0 0 0 0 + else, matcher then exit 1 0 1 1 0 0 1 0 + + Row 1 is why `needs-no-match` on a `then`-branch either-or is a false + label: `A` present with `C` present exits 0. Row 2 is the control one + `;` away from it, where the `exit` is nobody's verdict and the condition + really is `needs-no-match`. """ script = "if grep -q 'A' out.txt; then\n echo 'a note'\nelse\n grep -q 'B' out.txt\nfi" @@ -407,34 +485,107 @@ def test_an_exit_reached_through_the_else_matcher_is_still_either_or(self): ) assert shell.scan(script)[0].polarity == "undecided" - def test_a_matcher_and_an_exit_on_one_line_is_over_declined(self): - """Known over-decline, pinned so it is visible rather than folklore. - - `else grep -q B f; exit 1` fails whatever `B` does -- verified - against `bash -e`, exit 1 with `B` present -- so `needs-match` on the - condition is right and this declines it anyway. The multi-line - spelling of the same branch gets it right, because `note` is called - once per logical line and the `exit` arrives on its own; here both - commands reach it as one part. Declining is the safe direction and - no repository in the organisation writes it this way (0 of 37 - workflow files), so this is filed rather than fixed: splitting a part - on a top-level `;` has to stay out of `|| { ... }`, which is a - splitter with its own edge cases and not an end-of-shift change. + def test_a_matcher_and_an_exit_on_one_line_is_the_verdict(self): + """logbook#81: the two spellings of one `else` branch now agree. + + `else grep -q B f; exit 1` fails whatever `B` does -- exit 1 with + `B` present as well as absent -- so the condition is the whole + verdict and `needs-match` is right. The multi-line spelling always + got this, because `note` is called once per logical line and the + `exit` arrived on its own; written on one line both commands reached + it as a single part, no part was free of a matcher, and the condition + was declined. """ script = "if grep -q 'A' f; then echo note; else grep -q 'B' f; exit 1; fi" - assert shell.scan(script)[0].polarity == "undecided" + assert shell.scan(script)[0].polarity == "needs-match" + + def test_the_multi_line_spelling_of_that_branch_agrees(self): + """The control for the test above: the spelling must not matter.""" + script = "if grep -q 'A' f; then\n echo note\nelse\n grep -q 'B' f\n exit 1\nfi" + assert shell.scan(script)[0].polarity == "needs-match" + + def test_a_then_branch_that_asserts_declines_the_condition(self): + """logbook#89, the mirror of logbook#78 and the dangerous direction. + + `alone` was tracked for both branches and read only for the `else`, + so this reported `needs-no-match` -- a *live* polarity, counted, + able to stand as a witness, and feeding "every assertion here fails + when the thing it names stops being true". Under `bash -e` the step + exits 1 only when `A` matches and `B` misses: `A` present with `B` + present exits 0, so `B` gets a say and the condition is not the + verdict. + """ + script = "if grep -q 'A' out.txt; then\n grep -q 'B' out.txt\nfi" + condition = shell.scan(script)[0] + assert condition.polarity == "undecided" + assert "either-or" in (condition.undecided or "") + assert "`then` branch" in (condition.undecided or "") - def test_a_then_branch_that_asserts_is_left_alone(self): - """`if grep A; then grep B; fi` is an implication, not a disjunction. + def test_a_then_branch_matcher_is_still_read(self): + """The mirror of `test_the_else_branch_matcher_is_still_read`. - Deliberately not changed: the step fails when `A` appears and `B` - does not, so `needs-no-match` on `A` is the generous-but-defensible - reading every branch body already gets. Pinned so that changing it - is a decision rather than an accident. + Only the condition's label was wrong. The matcher in the branch body + is as load bearing as it ever was. """ - script = "if grep -q 'A' out.txt; then\n grep -q 'B' out.txt\nfi" + found = shell.scan("if grep -q 'A' out.txt; then\n grep -q 'B' out.txt\nfi") + assert [a.pattern for a in found] == ["A", "B"] + assert found[1].polarity == "needs-match" + + def test_a_then_branch_that_also_exits_is_the_verdict(self): + """The control one `;` away, and the reason this needs a splitter. + + Row 2 of the class docstring: the `exit` is nobody's verdict, so the + step fails exactly when `A` matches. Declining this as well would be + the easy over-correction -- it is the shape of every `if grep -q bad + out.txt; then echo ...; exit 1; fi` guard in the organisation. + """ + script = "if grep -q 'A' f; then\n grep -q 'B' f\n exit 1\nfi" assert shell.scan(script)[0].polarity == "needs-no-match" + def test_a_one_line_then_branch_that_asserts_is_not_decorative(self): + """The same shape on one line read `decorative` -- a finding. + + Worse than logbook#89's wrong label, and the same root: the body + arrived as `; then grep -q 'C' f; fi`, where `command_head` sees a + command called `then` and no matcher at all. So the branch looked + empty, neither branch could fail, and the tool reported a live + assertion as dead config. + """ + found = shell.scan("if grep -q 'A' f; then grep -q 'C' f; fi")[0] + assert found.polarity == "undecided" + assert found.polarity != "decorative" + + def test_a_one_line_then_branch_that_exits_is_still_the_verdict(self): + """And its control: the splitter must not decline this one.""" + found = shell.scan("if grep -q 'A' f; then grep -q 'B' f; exit 1; fi")[0] + assert found.polarity == "needs-no-match" + + def test_a_matcher_in_a_nested_condition_is_still_over_decided(self): + """Pinned, not fixed: the gap this change leaves, filed as logbook#90. + + `if grep -q 'B' f; then exit 1; fi` is one command, so the splitter + correctly keeps it whole -- and `_bare_assertion` asks + `command_head` about it, which answers "a command called `if`". The + matcher in the nested condition is invisible, the `exit` looks + unconditional, and the outer condition reads `needs-no-match`. Under + `bash -e` the step exits 1 only when both patterns match, so that is + logbook#89's claim one level deeper. Both spellings agree on it now, + which they did not before. + """ + nested = "if grep -q 'B' f; then exit 1; fi" + for script in ( + f"if grep -q 'A' f; then\n {nested}\nfi", + f"if grep -q 'A' f; then {nested}; fi", + ): + assert shell.scan(script)[0].polarity == "needs-no-match", script + # The `else` mirror, wrong the same way: the step exits 1 only when + # `A` misses and `B` matches, and `needs-match` is just as live. + for script in ( + f"if grep -q 'A' f; then\n echo x\nelse\n {nested}\nfi", + f"if grep -q 'A' f; then echo x; else {nested}; fi", + ): + assert shell.scan(script)[0].polarity == "needs-match", script + class TestElifConditions: r"""A matcher in an `elif` condition, and what the chain does to the one above it. @@ -571,19 +722,6 @@ def test_a_three_way_chain_declines_the_middle_condition(self): assert found["B"].undecided == "either branch of the `if` can fail the step" assert found["C"].polarity == "needs-no-match" - def test_a_then_branch_whose_only_failure_is_a_matcher_is_over_decided(self): - """Pinned, not fixed: logbook#89, and not an `elif` problem at all. - - `alone` is tracked for both branches and read only for the `else`, so - the mirror of logbook#78 in the `then` branch still reports a live - polarity. Under `bash -e` this exits 1 only when `A` matches and `C` - misses -- `A` present with `C` present exits 0 -- so `needs-no-match` - is not true of `A`. Pinned here so the behaviour is written down - rather than folklore, and so fixing logbook#89 has to come past it. - """ - found = {a.pattern: a for a in shell.scan("if grep -q 'A' f; then\n grep -q 'C' f\nfi")} - assert found["A"].polarity == "needs-no-match" - class TestAVerdictOverNoBranches: r"""`decorative` must not be reachable from a walk that read nothing.