test_generated_file_subject.py

tests/test_generated_file_subject.py

`error.c` IS GENERATED, AND A READER HAD NO WAY TO LEARN THAT FROM THE INDEX.

test_a_generated_file_says_so

None test_generated_file_subject.test_a_generated_file_says_so(sqlite3.Connection generated)

The generated file's subject says it is generated, and by what.

tests/test_generated_file_subject.py:89

Checks

  • assert built is not None
  • assert built.generated_by is not None, "the file the rubric calls generated must say so"
  • assert gen.kind == "custom_command"
  • assert gen.source_file == "library/CMakeLists.txt" and gen.source_line == 134, gen
  • assert "generate_errors.pl" in [c.name for c in gen.command], gen.command

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003measuredtest_a_generated_file_says_so → file_subject → has_columns
REQ-DDB-QUERY-004measuredtest_a_generated_file_says_so → file_subject
Source · 19 lines
def test_a_generated_file_says_so(generated: sqlite3.Connection) -> None:
    """RED BEFORE THE FIX: `FileSubject` has no `generated_by`, so the one fact the rubric says an
    answer will get wrong is absent from the reply about that very file.

    Matched on BASENAME, because the build file names `${CMAKE_CURRENT_BINARY_DIR}/error.c` and
    the index holds `library/error.c`. Neither string contains the other, and resolving the
    variable is not available — so the basename is the only honest join, and it is stated as such
    rather than presented as a resolved path.
    """
    built = file_subject(generated, "library/error.c")

    assert built is not None
    assert built.generated_by is not None, "the file the rubric calls generated must say so"
    gen = built.generated_by
    assert gen.kind == "custom_command"
    assert gen.source_file == "library/CMakeLists.txt" and gen.source_line == 134, gen
    assert "generate_errors.pl" in [c.name for c in gen.command], gen.command

Activity · 7 steps
lines 98–98built = file_subject(generated, "library/error.c")lines 100–100assert built is not Nonelines 101–101assert built.generated_by is not None, "the file the rubric calls generated must say so"lines 102–102gen = built.generated_bylines 103–103assert gen.kind == "custom_command"lines 104–104assert gen.source_file == "library/CMakeLists.txt" and gen.source_line == 134, genlines 105–105assert "generate_errors.pl" in [c.name for c in gen.command], gen.command

test_a_hand_written_file_has_no_generated_by

None test_generated_file_subject.test_a_hand_written_file_has_no_generated_by(sqlite3.Connection generated)

A hand-written file carries no generation claim at all.

tests/test_generated_file_subject.py:129

Checks

  • assert file_subject(generated, "library/CMakeLists.txt").generated_by is None

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003measuredtest_a_hand_written_file_has_no_generated_by → file_subject → has_columns
REQ-DDB-QUERY-004measuredtest_a_hand_written_file_has_no_generated_by → file_subject
Source · 9 lines
def test_a_hand_written_file_has_no_generated_by(generated: sqlite3.Connection) -> None:
    """ABSENCE, NOT A FALSE NEGATIVE FIELD. `CMakeLists.txt` is not generated, and the field is
    None rather than an empty record — the rule `SubjectDossier` follows for every section it
    does not populate. A `generated_by` present-but-empty would read as "we checked and it is
    generated by nothing".
    """
    assert file_subject(generated, "library/CMakeLists.txt").generated_by is None

Activity · 1 steps
lines 135–135assert file_subject(generated, "library/CMakeLists.txt").generated_by is None

test_the_generator_lists_what_it_produces

None test_generated_file_subject.test_the_generator_lists_what_it_produces(sqlite3.Connection generated)

The producing script says what it produces.

tests/test_generated_file_subject.py:140

Checks

  • assert built is not None
  • assert "error.c" in built.generates, (f"the script's own subject must name what it produces: {built.generates}" )
  • assert file_subject(generated, "library/error.c").generates == ()

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003measuredtest_the_generator_lists_what_it_produces → file_subject → has_columns
REQ-DDB-QUERY-004measuredtest_the_generator_lists_what_it_produces → file_subject
Source · 15 lines
def test_the_generator_lists_what_it_produces(generated: sqlite3.Connection) -> None:
    """THE OTHER DIRECTION, and it is a different question with a different asker: a contributor
    editing `generate_errors.pl` wants to know what regenerates, which is how they check they
    changed the right input. mbedtls Q4 asks exactly that — "what a contributor has to do to add
    a new one".
    """
    built = file_subject(generated, "scripts/generate_errors.pl")

    assert built is not None
    assert "error.c" in built.generates, (
        f"the script's own subject must name what it produces: {built.generates}"
    )
    ## And a file that produces nothing says so by an empty tuple, which is a measurement: this
    ## index was read and that file generates nothing.
    assert file_subject(generated, "library/error.c").generates == ()

1 more lines, not shown

Activity · 4 steps
lines 146–146built = file_subject(generated, "scripts/generate_errors.pl")lines 148–148assert built is not Nonelines 149–151assert "error.c" in built.generates, ( f"the script's own subject must name what it produces: {built.generates}" )lines 154–154assert file_subject(generated, "library/error.c").generates == ()

test_the_inputs_are_listed_and_a_variable_stays_unresolved

None test_generated_file_subject.test_the_inputs_are_listed_and_a_variable_stays_unresolved(sqlite3.Connection generated)

The inputs are listed, and an unresolved one says it is unresolved.

tests/test_generated_file_subject.py:110

Checks

  • assert "generate_errors.pl" in named and "error.fmt" in named, gen.depends
  • assert glob.unresolved is True and "error_headers" in glob.literal, glob

Result: passed

Verifies

requirementlinkedpath to the implementer
REQ-DDB-QUERY-003measuredtest_the_inputs_are_listed_and_a_variable_stays_unresolved → file_subject → has_columns
REQ-DDB-QUERY-004measuredtest_the_inputs_are_listed_and_a_variable_stays_unresolved → file_subject
Source · 17 lines
def test_the_inputs_are_listed_and_a_variable_stays_unresolved(
    generated: sqlite3.Connection,
) -> None:
    """THE THREE `set` MEMBERS mbedtls Q4 wants are inputs: the generator, the headers directory
    and `error.fmt`. `${error_headers}` is a glob CMake expands at configure time — it must be
    reported as unresolved rather than dropped, because a reader counting the inputs needs to
    know one of them is a pattern, and must not be given `error_headers` as a filename.
    """
    gen = file_subject(generated, "library/error.c").generated_by

    named = [d.name for d in gen.depends if d.name]
    assert "generate_errors.pl" in named and "error.fmt" in named, gen.depends

    glob = next(d for d in gen.depends if not d.name)
    assert glob.unresolved is True and "error_headers" in glob.literal, glob

Activity · 5 steps
lines 118–118gen = file_subject(generated, "library/error.c").generated_bylines 120–120named = [d.name for d in gen.depends if d.name]lines 121–121assert "generate_errors.pl" in named and "error.fmt" in named, gen.dependslines 123–123glob = next(d for d in gen.depends if not d.name)lines 124–124assert glob.unresolved is True and "error_headers" in glob.literal, glob