Skip to content

Commit ae01756

Browse files
committed
Auto merge of #8266 - camsteffen:test-tweaks, r=<try>
Some test code cleanup changelog: none Mainly moves /clippy_workspace_tests into /tests and combines the two dogfood tests which can't run concurrently.
2 parents b66dbe8 + 01ef7c7 commit ae01756

File tree

17 files changed

+136
-195
lines changed

17 files changed

+136
-195
lines changed

.github/workflows/clippy.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ jobs:
7070
run: cargo test --features deny-warnings
7171
working-directory: clippy_dev
7272

73-
- name: Test cargo-clippy
74-
run: ../target/debug/cargo-clippy
75-
working-directory: clippy_workspace_tests
76-
77-
- name: Test cargo-clippy --fix
78-
run: ../target/debug/cargo-clippy clippy --fix
79-
working-directory: clippy_workspace_tests
80-
8173
- name: Test clippy-driver
8274
run: bash .github/driver.sh
8375
env:

.github/workflows/clippy_bors.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,6 @@ jobs:
133133
run: cargo test --features deny-warnings
134134
working-directory: clippy_dev
135135

136-
- name: Test cargo-clippy
137-
run: ../target/debug/cargo-clippy
138-
working-directory: clippy_workspace_tests
139-
140-
- name: Test cargo-clippy --fix
141-
run: ../target/debug/cargo-clippy clippy --fix
142-
working-directory: clippy_workspace_tests
143-
144136
- name: Test clippy-driver
145137
run: bash .github/driver.sh
146138
env:

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ out
1919
/target
2020
/clippy_lints/target
2121
/clippy_utils/target
22-
/clippy_workspace_tests/target
2322
/clippy_dev/target
2423
/lintcheck/target
2524
/rustc_tools_util/target

clippy_utils/src/paths.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ pub const PARKING_LOT_RWLOCK_WRITE_GUARD: [&str; 2] = ["parking_lot", "RwLockWri
117117
pub const PATH_BUF_AS_PATH: [&str; 4] = ["std", "path", "PathBuf", "as_path"];
118118
pub const PATH_TO_PATH_BUF: [&str; 4] = ["std", "path", "Path", "to_path_buf"];
119119
pub const PERMISSIONS: [&str; 3] = ["std", "fs", "Permissions"];
120+
#[cfg_attr(not(unix), allow(clippy::invalid_paths))]
120121
pub const PERMISSIONS_FROM_MODE: [&str; 6] = ["std", "os", "unix", "fs", "PermissionsExt", "from_mode"];
121122
pub const POLL: [&str; 4] = ["core", "task", "poll", "Poll"];
122123
pub const POLL_PENDING: [&str; 5] = ["core", "task", "poll", "Poll", "Pending"];

tests/cargo/mod.rs

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/compile-test.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![feature(test)] // compiletest_rs requires this attribute
2+
#![feature(once_cell)]
23
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
34
#![warn(rust_2018_idioms, unused_lifetimes)]
45

@@ -11,8 +12,9 @@ use std::ffi::{OsStr, OsString};
1112
use std::fs;
1213
use std::io;
1314
use std::path::{Path, PathBuf};
15+
use test_utils::IS_RUSTC_TEST_SUITE;
1416

15-
mod cargo;
17+
mod test_utils;
1618

1719
// whether to run internal tests or not
1820
const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal");
@@ -304,7 +306,7 @@ fn run_ui_cargo(config: &mut compiletest::Config) {
304306
Ok(result)
305307
}
306308

307-
if cargo::is_rustc_test_suite() {
309+
if IS_RUSTC_TEST_SUITE {
308310
return;
309311
}
310312

tests/dogfood.rs

Lines changed: 10 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -3,179 +3,26 @@
33
//!
44
//! See [Eating your own dog food](https://en.wikipedia.org/wiki/Eating_your_own_dog_food) for context
55
6-
// Dogfood cannot run on Windows
7-
#![cfg(not(windows))]
86
#![feature(once_cell)]
97
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
108
#![warn(rust_2018_idioms, unused_lifetimes)]
119

12-
use std::lazy::SyncLazy;
1310
use std::path::PathBuf;
1411
use std::process::Command;
12+
use test_utils::IS_RUSTC_TEST_SUITE;
1513

16-
mod cargo;
17-
18-
static CLIPPY_PATH: SyncLazy<PathBuf> = SyncLazy::new(|| {
19-
let mut path = std::env::current_exe().unwrap();
20-
assert!(path.pop()); // deps
21-
path.set_file_name("cargo-clippy");
22-
path
23-
});
14+
mod test_utils;
2415

2516
#[test]
2617
fn dogfood_clippy() {
27-
// run clippy on itself and fail the test if lint warnings are reported
28-
if cargo::is_rustc_test_suite() {
29-
return;
30-
}
31-
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
32-
33-
let mut command = Command::new(&*CLIPPY_PATH);
34-
command
35-
.current_dir(root_dir)
36-
.env("CARGO_INCREMENTAL", "0")
37-
.arg("clippy")
38-
.arg("--all-targets")
39-
.arg("--all-features")
40-
.arg("--")
41-
.args(&["-D", "clippy::all"])
42-
.args(&["-D", "clippy::pedantic"])
43-
.arg("-Cdebuginfo=0"); // disable debuginfo to generate less data in the target dir
44-
45-
// internal lints only exist if we build with the internal feature
46-
if cfg!(feature = "internal") {
47-
command.args(&["-D", "clippy::internal"]);
48-
}
49-
50-
let output = command.output().unwrap();
51-
52-
println!("status: {}", output.status);
53-
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
54-
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
55-
56-
assert!(output.status.success());
57-
}
58-
59-
fn test_no_deps_ignores_path_deps_in_workspaces() {
60-
if cargo::is_rustc_test_suite() {
61-
return;
62-
}
63-
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
64-
let target_dir = root.join("target").join("dogfood");
65-
let cwd = root.join("clippy_workspace_tests");
66-
67-
// Make sure we start with a clean state
68-
Command::new("cargo")
69-
.current_dir(&cwd)
70-
.env("CARGO_TARGET_DIR", &target_dir)
71-
.arg("clean")
72-
.args(&["-p", "subcrate"])
73-
.args(&["-p", "path_dep"])
74-
.output()
75-
.unwrap();
76-
77-
// `path_dep` is a path dependency of `subcrate` that would trigger a denied lint.
78-
// Make sure that with the `--no-deps` argument Clippy does not run on `path_dep`.
79-
let output = Command::new(&*CLIPPY_PATH)
80-
.current_dir(&cwd)
81-
.env("CARGO_INCREMENTAL", "0")
82-
.arg("clippy")
83-
.args(&["-p", "subcrate"])
84-
.arg("--no-deps")
85-
.arg("--")
86-
.arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
87-
.args(&["--cfg", r#"feature="primary_package_test""#])
88-
.output()
89-
.unwrap();
90-
println!("status: {}", output.status);
91-
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
92-
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
93-
94-
assert!(output.status.success());
95-
96-
let lint_path_dep = || {
97-
// Test that without the `--no-deps` argument, `path_dep` is linted.
98-
let output = Command::new(&*CLIPPY_PATH)
99-
.current_dir(&cwd)
100-
.env("CARGO_INCREMENTAL", "0")
101-
.arg("clippy")
102-
.args(&["-p", "subcrate"])
103-
.arg("--")
104-
.arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
105-
.args(&["--cfg", r#"feature="primary_package_test""#])
106-
.output()
107-
.unwrap();
108-
println!("status: {}", output.status);
109-
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
110-
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
111-
112-
assert!(!output.status.success());
113-
assert!(
114-
String::from_utf8(output.stderr)
115-
.unwrap()
116-
.contains("error: empty `loop {}` wastes CPU cycles")
117-
);
118-
};
119-
120-
// Make sure Cargo is aware of the removal of `--no-deps`.
121-
lint_path_dep();
122-
123-
let successful_build = || {
124-
let output = Command::new(&*CLIPPY_PATH)
125-
.current_dir(&cwd)
126-
.env("CARGO_INCREMENTAL", "0")
127-
.arg("clippy")
128-
.args(&["-p", "subcrate"])
129-
.arg("--")
130-
.arg("-Cdebuginfo=0") // disable debuginfo to generate less data in the target dir
131-
.output()
132-
.unwrap();
133-
println!("status: {}", output.status);
134-
println!("stdout: {}", String::from_utf8_lossy(&output.stdout));
135-
println!("stderr: {}", String::from_utf8_lossy(&output.stderr));
136-
137-
assert!(output.status.success());
138-
139-
output
140-
};
141-
142-
// Trigger a sucessful build, so Cargo would like to cache the build result.
143-
successful_build();
144-
145-
// Make sure there's no spurious rebuild when nothing changes.
146-
let stderr = String::from_utf8(successful_build().stderr).unwrap();
147-
assert!(!stderr.contains("Compiling"));
148-
assert!(!stderr.contains("Checking"));
149-
assert!(stderr.contains("Finished"));
150-
151-
// Make sure Cargo is aware of the new `--cfg` flag.
152-
lint_path_dep();
153-
}
154-
155-
#[test]
156-
fn dogfood_subprojects() {
157-
// run clippy on remaining subprojects and fail the test if lint warnings are reported
158-
if cargo::is_rustc_test_suite() {
18+
if IS_RUSTC_TEST_SUITE {
15919
return;
16020
}
16121

162-
// NOTE: `path_dep` crate is omitted on purpose here
163-
for project in &[
164-
"clippy_workspace_tests",
165-
"clippy_workspace_tests/src",
166-
"clippy_workspace_tests/subcrate",
167-
"clippy_workspace_tests/subcrate/src",
168-
"clippy_dev",
169-
"clippy_lints",
170-
"clippy_utils",
171-
"rustc_tools_util",
172-
] {
173-
run_clippy_for_project(project);
22+
// "" is the root package
23+
for package in &["", "clippy_dev", "clippy_lints", "clippy_utils", "rustc_tools_util"] {
24+
run_clippy_for_package(package);
17425
}
175-
176-
// NOTE: Since tests run in parallel we can't run cargo commands on the same workspace at the
177-
// same time, so we test this immediately after the dogfood for workspaces.
178-
test_no_deps_ignores_path_deps_in_workspaces();
17926
}
18027

18128
#[test]
@@ -191,7 +38,7 @@ fn run_metadata_collection_lint() {
19138

19239
// Run collection as is
19340
std::env::set_var("ENABLE_METADATA_COLLECTION", "1");
194-
run_clippy_for_project("clippy_lints");
41+
run_clippy_for_package("clippy_lints");
19542

19643
// Check if cargo caching got in the way
19744
if let Ok(file) = File::open(metadata_output_path) {
@@ -214,13 +61,13 @@ fn run_metadata_collection_lint() {
21461
.unwrap();
21562

21663
// Running the collection again
217-
run_clippy_for_project("clippy_lints");
64+
run_clippy_for_package("clippy_lints");
21865
}
21966

220-
fn run_clippy_for_project(project: &str) {
67+
fn run_clippy_for_package(project: &str) {
22168
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
22269

223-
let mut command = Command::new(&*CLIPPY_PATH);
70+
let mut command = Command::new(&*test_utils::CARGO_CLIPPY_PATH);
22471

22572
command
22673
.current_dir(root_dir.join(project))

tests/fmt.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,6 @@ fn fmt() {
1010
return;
1111
}
1212

13-
// Skip this test if nightly rustfmt is unavailable
14-
let rustup_output = Command::new("rustup").args(&["component", "list"]).output().unwrap();
15-
assert!(rustup_output.status.success());
16-
let component_output = String::from_utf8_lossy(&rustup_output.stdout);
17-
if !component_output.contains("rustfmt") {
18-
return;
19-
}
20-
2113
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
2214
let output = Command::new("cargo")
2315
.current_dir(root_dir)

tests/test_utils/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#![allow(dead_code)] // see https://github.com/rust-lang/rust/issues/46379
2+
3+
use std::lazy::SyncLazy;
4+
use std::path::PathBuf;
5+
6+
pub static CARGO_CLIPPY_PATH: SyncLazy<PathBuf> = SyncLazy::new(|| {
7+
let mut path = std::env::current_exe().unwrap();
8+
assert!(path.pop()); // deps
9+
path.set_file_name("cargo-clippy");
10+
path
11+
});
12+
13+
pub const IS_RUSTC_TEST_SUITE: bool = option_env!("RUSTC_TEST_SUITE").is_some();

0 commit comments

Comments
 (0)