Repository navigation
Enforce the Rust lint baseline #448
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
593d791
Enforce the Rust lint baseline
da65e78
Simplify safe target discovery
4d01e7f
Clarify Cargo target table dispatch
702706a
Normalize boundary contract spelling
5b97a79
Harden doctest and boundary contracts
bf294d4
Type the boundary read-text test double
b9270f3
Decouple the doctest warning regression
849bdfe
Cover inferred Cargo target roots
f8071cc
Exempt Cargo's color flag from spelling
9098fb8
Match Cargo target overrides in boundary checks
1a62a50
Group Cargo override test inputs
73a9e93
Document boundary contract helpers
4773181
Explain boundary contract test failures
69c940f
Align boundary discovery with Cargo
1887e81
Require nested Cargo target roots
86d3783
Simplify nested target discovery
e6bc20d
Match Cargo automatic target discovery
f1ba45d
Preserve boundary workspace symlinks
43805fc
Isolate boundary probe source copies
67abfb8
Simplify boundary workspace link tests
6f6e2c6
Ignore ordinary Cargo support files
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| """Prove the Linux doctest route fails when a doctest emits a warning.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import shutil | ||
| import subprocess # ruff: ignore[suspicious-subprocess-import] - this test executes a fixed pinned Cargo command. | ||
| import sys | ||
| import typing as typ | ||
|
|
||
| import pytest | ||
|
|
||
| if typ.TYPE_CHECKING: | ||
| from pathlib import Path | ||
|
|
||
| DEV_FAST_TOOLCHAIN = "nightly-2026-08-23" | ||
| DOCTEST_RUSTDOC_FLAGS = ( | ||
| "--cfg docsrs -D warnings -Zunstable-options --display-doctest-warnings " | ||
| "--doctest-build-arg=-D --doctest-build-arg=warnings" | ||
| ) | ||
| WARNING_DOCTEST = """//! Warning-bearing doctest fixture. | ||
|
|
||
| /// ``` | ||
| /// #[deprecated(note = "doctest warning contract")] | ||
| /// fn legacy() {} | ||
| /// legacy(); | ||
| /// ``` | ||
| pub struct WarningFixture; | ||
| """ | ||
|
|
||
|
|
||
| def _run_doctests( | ||
| crate: Path, cargo: str, rustdoc_flags: str | None | ||
| ) -> subprocess.CompletedProcess[str]: | ||
| """Run the pinned nightly with the standard backend and stated Rustdoc flags.""" | ||
| environment: dict[str, str] = dict(os.environ) | ||
| environment.update({ | ||
| "CARGO_TARGET_DIR": str(crate / "target"), | ||
| "RUSTFLAGS": "-D warnings", | ||
| "RUSTUP_TOOLCHAIN": DEV_FAST_TOOLCHAIN, | ||
| }) | ||
| if rustdoc_flags is not None: | ||
| environment["RUSTDOCFLAGS"] = rustdoc_flags | ||
| else: | ||
| environment.pop("RUSTDOCFLAGS", None) | ||
| return subprocess.run( # ruff: ignore[subprocess-without-shell-equals-true] - fixed Cargo argv and pinned toolchain. | ||
| [ | ||
| cargo, | ||
| "--color", | ||
| "never", | ||
| "test", | ||
| "--doc", | ||
| "--manifest-path", | ||
| str(crate / "Cargo.toml"), | ||
| ], | ||
| capture_output=True, | ||
| check=False, | ||
| cwd=crate, | ||
| env=environment, | ||
| text=True, | ||
| ) | ||
|
|
||
|
|
||
| def _diagnostics(completed: subprocess.CompletedProcess[str]) -> str: | ||
| """Return every Cargo diagnostic stream for setup and failure assertions.""" | ||
| return completed.stdout + completed.stderr | ||
|
|
||
|
|
||
| @pytest.mark.skipif( | ||
| sys.platform != "linux", reason="the production doctest warning route is Linux-only" | ||
| ) | ||
| def test_pinned_doctest_route_rejects_a_warning(tmp_path: Path) -> None: | ||
| """Only the corrected nightly Rustdoc route rejects a doctest warning.""" | ||
| crate = tmp_path / "warning-doctest" | ||
| source = crate / "src/lib.rs" | ||
| source.parent.mkdir(parents=True) | ||
| (crate / "Cargo.toml").write_text( | ||
| '[package]\nname = "warning-doctest"\nversion = "0.1.0"\nedition = "2024"\n', | ||
| encoding="utf-8", | ||
| ) | ||
| source.write_text(WARNING_DOCTEST, encoding="utf-8") | ||
| cargo = shutil.which("cargo") | ||
| assert cargo is not None, "the doctest contract requires Cargo on PATH" | ||
| former_route = _run_doctests(crate, cargo, rustdoc_flags=None) | ||
| former_diagnostics = _diagnostics(former_route) | ||
| assert former_route.returncode == 0, ( | ||
| "the former RUSTFLAGS-only route must pass the warning-bearing doctest:\n" | ||
| f"{former_diagnostics}" | ||
| ) | ||
| assert "test result: ok" in former_diagnostics, ( | ||
| "the former route must execute the doctest rather than only build setup" | ||
| ) | ||
|
|
||
| corrected_route = _run_doctests(crate, cargo, DOCTEST_RUSTDOC_FLAGS) | ||
| corrected_diagnostics = _diagnostics(corrected_route) | ||
| assert corrected_route.returncode != 0, ( | ||
| "the corrected Rustdoc route must reject a doctest warning:\n" | ||
| f"{corrected_diagnostics}" | ||
| ) | ||
| assert "\x1b" not in corrected_diagnostics, ( | ||
| "the synthetic Cargo route must disable colour for deterministic diagnostics" | ||
| ) | ||
| assert "error: use of deprecated function" in corrected_diagnostics, ( | ||
| "the corrected route must fail on the doctest warning rather than setup" | ||
| ) | ||
| assert "-D deprecated" in corrected_diagnostics, ( | ||
| "rustdoc must deny the displayed doctest warning" | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.