Skip to content

Commit 51dbbf3

Browse files
committed
Refactor test utils
1 parent e66ecf6 commit 51dbbf3

File tree

4 files changed

+27
-23
lines changed

4 files changed

+27
-23
lines changed

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 & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,21 @@
77
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
88
#![warn(rust_2018_idioms, unused_lifetimes)]
99

10-
use std::lazy::SyncLazy;
1110
use std::path::PathBuf;
1211
use std::process::Command;
12+
use test_utils::{CARGO_CLIPPY_PATH, IS_RUSTC_TEST_SUITE};
1313

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

2316
#[test]
2417
fn dogfood_clippy() {
2518
// run clippy on itself and fail the test if lint warnings are reported
26-
if cargo::is_rustc_test_suite() {
19+
if IS_RUSTC_TEST_SUITE {
2720
return;
2821
}
2922
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
3023

31-
let mut command = Command::new(&*CLIPPY_PATH);
24+
let mut command = Command::new(&*CARGO_CLIPPY_PATH);
3225
command
3326
.current_dir(root_dir)
3427
.env("CARGO_INCREMENTAL", "0")
@@ -55,7 +48,7 @@ fn dogfood_clippy() {
5548
}
5649

5750
fn test_no_deps_ignores_path_deps_in_workspaces() {
58-
if cargo::is_rustc_test_suite() {
51+
if IS_RUSTC_TEST_SUITE {
5952
return;
6053
}
6154
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
@@ -74,7 +67,7 @@ fn test_no_deps_ignores_path_deps_in_workspaces() {
7467

7568
// `path_dep` is a path dependency of `subcrate` that would trigger a denied lint.
7669
// Make sure that with the `--no-deps` argument Clippy does not run on `path_dep`.
77-
let output = Command::new(&*CLIPPY_PATH)
70+
let output = Command::new(&*CARGO_CLIPPY_PATH)
7871
.current_dir(&cwd)
7972
.env("CARGO_INCREMENTAL", "0")
8073
.arg("clippy")
@@ -93,7 +86,7 @@ fn test_no_deps_ignores_path_deps_in_workspaces() {
9386

9487
let lint_path_dep = || {
9588
// Test that without the `--no-deps` argument, `path_dep` is linted.
96-
let output = Command::new(&*CLIPPY_PATH)
89+
let output = Command::new(&*CARGO_CLIPPY_PATH)
9790
.current_dir(&cwd)
9891
.env("CARGO_INCREMENTAL", "0")
9992
.arg("clippy")
@@ -119,7 +112,7 @@ fn test_no_deps_ignores_path_deps_in_workspaces() {
119112
lint_path_dep();
120113

121114
let successful_build = || {
122-
let output = Command::new(&*CLIPPY_PATH)
115+
let output = Command::new(&*CARGO_CLIPPY_PATH)
123116
.current_dir(&cwd)
124117
.env("CARGO_INCREMENTAL", "0")
125118
.arg("clippy")
@@ -153,7 +146,7 @@ fn test_no_deps_ignores_path_deps_in_workspaces() {
153146
#[test]
154147
fn dogfood_subprojects() {
155148
// run clippy on remaining subprojects and fail the test if lint warnings are reported
156-
if cargo::is_rustc_test_suite() {
149+
if IS_RUSTC_TEST_SUITE {
157150
return;
158151
}
159152

@@ -218,7 +211,7 @@ fn run_metadata_collection_lint() {
218211
fn run_clippy_for_project(project: &str) {
219212
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
220213

221-
let mut command = Command::new(&*CLIPPY_PATH);
214+
let mut command = Command::new(&*test_utils::CARGO_CLIPPY_PATH);
222215

223216
command
224217
.current_dir(root_dir.join(project))

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)