Repository navigation
ci: enforce Clippy in the test build #5536
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
3 commits
Select commit
Hold shift + click to select a range
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 was deleted.
Oops, something went wrong.
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
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,48 @@ | ||
| """A test build must reject Clippy findings without a separate lint compile.""" | ||
|
|
||
| import os | ||
| from pathlib import Path | ||
| import shutil | ||
| import subprocess | ||
| import tempfile | ||
| import unittest | ||
|
|
||
|
|
||
| ROOT = Path(__file__).resolve().parents[2] | ||
|
|
||
|
|
||
| class TestLints(unittest.TestCase): | ||
| def test_clippy_warning_fails_test_build(self): | ||
| with tempfile.TemporaryDirectory() as directory: | ||
| root = Path(directory) | ||
| (root / "rs").mkdir() | ||
| (root / "sh" / "rs").mkdir(parents=True) | ||
| (root / "src").mkdir() | ||
| (root / "justfile").write_text("mod rs\n") | ||
| shutil.copy(ROOT / "rs" / "justfile", root / "rs" / "justfile") | ||
| shutil.copy(ROOT / "sh" / "rs" / "nextest.sh", root / "sh" / "rs" / "nextest.sh") | ||
| (root / "Cargo.toml").write_text( | ||
| '[package]\nname = "test-lint-gate"\nversion = "0.0.0"\nedition = "2024"\n' | ||
| ) | ||
| (root / "src" / "lib.rs").write_text( | ||
| 'pub fn empty(values: &[u8]) -> bool { values.len() == 0 }\n' | ||
| '#[test]\nfn runs() { assert!(empty(&[])); }\n' | ||
| ) | ||
| toolchain = Path(shutil.which("clippy-driver")).parent | ||
| env = dict(os.environ, CARGO_TARGET_DIR=str(root / "target"), | ||
| PATH=f"{toolchain}:{os.environ['PATH']}") | ||
| subprocess.run(["cargo", "generate-lockfile", "--offline"], cwd=root, | ||
| env=env, check=True, capture_output=True) | ||
| result = subprocess.run(["just", "rs", "test"], cwd=root, env=env, | ||
| text=True, capture_output=True) | ||
| self.assertNotEqual(result.returncode, 0, result.stdout + result.stderr) | ||
| self.assertIn("clippy::len_zero", result.stderr) | ||
| source = root / "src" / "lib.rs" | ||
| source.write_text(source.read_text().replace("values.len() == 0", "values.is_empty()")) | ||
| result = subprocess.run(["just", "rs", "test"], cwd=root, env=env, | ||
| text=True, capture_output=True) | ||
| self.assertEqual(result.returncode, 0, result.stdout + result.stderr) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cargo nextestbuilds tests usingcargo test --no-run --message-format json-render-diagnostics, but Cargo 1.98 does not honorbuild.warnings="deny"when processing JSON diagnostics, so Clippy warnings leave Cargo with exit code 0 and nextest proceeds. Becauseci-checknow omits the separate default-featurecargo clippy ... -D warningspass, such warnings can merge despite the intended gate. Keep an explicit denial mechanism that Clippy itself enforces until Cargo's JSON warning-accounting bug is fixed. See nextest's documented Cargo invocation and Cargo's openbuild.warningsJSON bug.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Declining: the gate does fire through nextest's JSON build on Cargo 1.98. The X11 capture job on the previous head failed exactly this way:
cargo test --no-run --message-format json-render-diagnostics --package moq-video ...reported "moq-video(lib test) generated 2 warnings" then "warnings are denied bybuild.warningsconfiguration" and exited 101 (log).sh/rs/test-lints.test.pyalso pins it: it runsjust rs test(nextest) on a crate with aclippy::len_zerofinding and asserts a nonzero exit, then a clean build passes. It passes locally and runs in CI via.github/justfile, so a Cargo regression here would fail loudly.(Written by Claude Opus 5.5)