Skip to content

Commit

Permalink
Test against clippy warnings in stubs (#1830)
Browse files Browse the repository at this point in the history
  • Loading branch information
senekor authored Dec 19, 2023
1 parent 585c8b3 commit 1234952
Show file tree
Hide file tree
Showing 12 changed files with 173 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
tmp
/bin/configlet
exercises/*/*/Cargo.lock
exercises/*/*/clippy.log
clippy.log
.vscode
.prob-spec
3 changes: 3 additions & 0 deletions exercises/concept/csv-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
name = "csv_builder"
version = "0.1.0"
edition = "2021"

[lints.clippy]
new_without_default = "allow"
3 changes: 3 additions & 0 deletions exercises/practice/bowling/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
edition = "2021"
name = "bowling"
version = "1.2.0"

[lints.clippy]
new_without_default = "allow"
3 changes: 2 additions & 1 deletion exercises/practice/fizzy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ name = "fizzy"
version = "0.0.0"
edition = "2021"

[dependencies]
[lints.clippy]
new_without_default = "allow"
3 changes: 3 additions & 0 deletions exercises/practice/forth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
edition = "2021"
name = "forth"
version = "1.7.0"

[lints.clippy]
new_without_default = "allow"
3 changes: 3 additions & 0 deletions exercises/practice/grade-school/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
edition = "2021"
name = "grade-school"
version = "0.0.0"

[lints.clippy]
new_without_default = "allow"
3 changes: 3 additions & 0 deletions exercises/practice/react/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
edition = "2021"
name = "react"
version = "2.0.0"

[lints.clippy]
new_without_default = "allow"
3 changes: 2 additions & 1 deletion exercises/practice/robot-name/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ edition = "2021"
name = "robot-name"
version = "0.0.0"

[dependencies]
[lints.clippy]
new_without_default = "allow"
3 changes: 2 additions & 1 deletion exercises/practice/simple-linked-list/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ edition = "2021"
name = "simple_linked_list"
version = "0.1.0"

[dependencies]
[lints.clippy]
new_without_default = "allow"
71 changes: 67 additions & 4 deletions rust-tooling/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust-tooling/ci-tests/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ glob = "0.3.1"
ignore = "0.4.20"
models = { version = "0.1.0", path = "../models" }
serde_json = "1.0.108"
tempdir = "0.3.7"
utils = { version = "0.1.0", path = "../utils" }
83 changes: 83 additions & 0 deletions rust-tooling/ci-tests/tests/stubs_are_warning_free.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use std::process::{Command, Stdio};

use glob::glob;

#[test]
fn stubs_are_warning_free() {
utils::fs::cd_into_repo_root();

let temp_dir = tempdir::TempDir::new("exercism-rust").unwrap();

let mut handles = vec![];

for manifest in glob("exercises/*/*/Cargo.toml")
.unwrap()
.map(Result::unwrap)
{
if std::fs::read_to_string(&manifest.parent().unwrap().join(".meta").join("config.json"))
.unwrap()
.contains("allowed-to-not-compile")
{
continue;
}
let slug = manifest
.parent()
.unwrap()
.file_name()
.unwrap()
.to_str()
.unwrap();
let handle = Command::new("cargo")
.args([
"clippy",
"--quiet",
"--manifest-path",
&manifest.display().to_string(),
"--target-dir",
&temp_dir.path().join(slug).display().to_string(),
"--",
// necessary for clippy to return a non-zero exit code
// if it finds warnings
"--deny",
"warnings",
])
.stderr(Stdio::piped())
.spawn()
.unwrap();

handles.push((slug.to_string(), handle));
}

let mut log = String::new();

for (slug, handle) in handles {
let output = handle.wait_with_output().unwrap();

if output.status.success() {
continue;
}
let stderr = String::from_utf8(output.stderr).unwrap();
log.push_str(&format!(
"\
################################################################
################
################ {slug}
{stderr}
"
));
}

if !log.is_empty() {
std::fs::write("clippy.log", &log).expect("should write clippy.log");
}
assert!(
log.is_empty(),
"
╔═════════════════════════════════════════╗
║ clippy found warnings, check clippy.log ║
╚═════════════════════════════════════════╝
"
);
}

0 comments on commit 1234952

Please sign in to comment.