test_rustdoc.py¶
tests/test_rustdoc.py
Tests for clew/rustdoc.py — the rustdoc-JSON analog of doxygen.py.
test_discover_targets_documents_both_lib_and_same_named_bin
None test_rustdoc.test_discover_targets_documents_both_lib_and_same_named_bin(Path tmp_path)
A package with both a lib and a same-named bin documents both, not just the lib.
Checks
assert kinds == {("dual", "lib"), ("dual", "bin")}, (f"a package with both a lib and a same-named bin must document both; got {kinds}" )
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-006 | measured | test_discover_targets_documents_both_lib_and_same_named_bin → _discover_targets → clean_subprocess_env |
Source · 32 lines
def test_discover_targets_documents_both_lib_and_same_named_bin(tmp_path: Path) -> None:
"""RUSTDOC_INTEGRATION_FEEDBACK.md, finding 1: `knots` and `tools_sqc` both pair a
`[lib]` with a same-named `[[bin]]`, and the old lib-instead-of-bin selection silently
dropped every module reachable only from the bin (`main.rs`, CLI parsing, config
loading, output formatting) with no error — `cargo metadata` succeeds either way, so
nothing in the build log said a target was skipped. This crate reproduces that exact
shape and asserts both targets come back.
@brief A package with both a lib and a same-named bin documents both, not just the lib.
@return None.
@version 1
"""
if shutil.which("cargo") is None:
pytest.skip("needs cargo")
(tmp_path / "Cargo.toml").write_text(
'[package]\nname = "dual"\nversion = "0.1.0"\nedition = "2021"\n\n'
'[lib]\nname = "dual"\n\n[[bin]]\nname = "dual"\npath = "src/main.rs"\n',
encoding="utf-8",
)
src = tmp_path / "src"
src.mkdir()
(src / "lib.rs").write_text("pub fn helper() {}\n", encoding="utf-8")
(src / "main.rs").write_text("fn main() {}\n", encoding="utf-8")
targets = _discover_targets(tmp_path)
kinds = {(t.name, t.kind) for t in targets}
assert kinds == {("dual", "lib"), ("dual", "bin")}, (
f"a package with both a lib and a same-named bin must document both; got {kinds}"
)
Activity · 10 steps
test_run_rustdoc_against_real_crate
None test_rustdoc.test_run_rustdoc_against_real_crate(Path tmp_path)
The end-to-end contract: a real `cargo +nightly rustdoc` run against a real crate lands a doxygen-shaped database with the right path/memberdef rows — the same shape `tests/richdb.py` hand-makes for the C fixture.
Checks
assert result == db_pathassert {"add", "helper", "MAX_RETRIES"} <= namesassert brief == "Adds two numbers together."assert add_static == 0 # pub fnassert helper_static == 1 # private fnassert path_row[0] == "src/main.rs"assert conn.execute("SELECT COUNT(*) FROM compounddef").fetchone()[0] == 0
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-006 | measured | test_run_rustdoc_against_real_crate → run_rustdoc → _require_nightly_rustdoc → clean_subprocess_env |
Source · 37 lines
def test_run_rustdoc_against_real_crate(tmp_path: Path) -> None:
"""The end-to-end contract: a real `cargo +nightly rustdoc` run against a
real crate lands a doxygen-shaped database with the right path/memberdef
rows — the same shape `tests/richdb.py` hand-makes for the C fixture.
"""
db_path = tmp_path / "rustdoc.db"
result = run_rustdoc(RUSTSAMPLE, db_path)
assert result == db_path
conn = sqlite3.connect(str(db_path))
try:
names = {row[0] for row in conn.execute("SELECT name FROM memberdef")}
assert {"add", "helper", "MAX_RETRIES"} <= names
brief = conn.execute(
"SELECT briefdescription FROM memberdef WHERE name = 'add'"
).fetchone()[0]
assert brief == "Adds two numbers together."
add_static, helper_static = (
conn.execute("SELECT static FROM memberdef WHERE name = ?", (name,)).fetchone()[0]
for name in ("add", "helper")
)
assert add_static == 0 # pub fn
assert helper_static == 1 # private fn
path_row = conn.execute(
"SELECT p.name FROM memberdef m JOIN path p ON p.rowid = m.file_id WHERE m.name = 'add'"
).fetchone()
assert path_row[0] == "src/main.rs"
# Every downstream stage that guards with _table_exists (dispatch_edges.py)
# still gets a real, empty compounddef table rather than a missing one.
assert conn.execute("SELECT COUNT(*) FROM compounddef").fetchone()[0] == 0
finally:
conn.close()
Activity · 15 steps
test_run_rustdoc_refuses_a_non_cargo_repo
None test_rustdoc.test_run_rustdoc_refuses_a_non_cargo_repo(Path tmp_path)
Result: passed
Verifies
| requirement | linked | path to the implementer |
|---|---|---|
| REQ-DDB-PIPE-006 | measured | test_run_rustdoc_refuses_a_non_cargo_repo → run_rustdoc → _require_nightly_rustdoc → clean_subprocess_env |
Source · 8 lines
def test_run_rustdoc_refuses_a_non_cargo_repo(tmp_path: Path) -> None:
if not _nightly_rustdoc_available():
pytest.skip("needs cargo + a nightly toolchain")
with pytest.raises(RustdocUnavailableError):
run_rustdoc(tmp_path, tmp_path / "out.db")
@pytestmark_nightly