Skip to content

Commit 10fe036

Browse files
committed
WIP: use ui_test dependency builder for non-internal test dependencies
1 parent dff9f9f commit 10fe036

File tree

4 files changed

+42
-46
lines changed

4 files changed

+42
-46
lines changed

Cargo.toml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ anstream = "0.6.18"
3434

3535
[dev-dependencies]
3636
cargo_metadata = "0.18.1"
37-
ui_test = "0.30.1"
37+
ui_test = { git = "https://github.com/RalfJung/ui_test", branch = "dependencies" }
3838
regex = "1.5.5"
3939
serde = { version = "1.0.145", features = ["derive"] }
4040
serde_json = "1.0.122"
@@ -45,14 +45,6 @@ itertools = "0.12"
4545
pulldown-cmark = { version = "0.11", default-features = false, features = ["html"] }
4646
askama = { version = "0.14", default-features = false, features = ["alloc", "config", "derive"] }
4747

48-
# UI test dependencies
49-
if_chain = "1.0"
50-
quote = "1.0.25"
51-
syn = { version = "2.0", features = ["full"] }
52-
futures = "0.3"
53-
parking_lot = "0.12"
54-
tokio = { version = "1", features = ["io-util"] }
55-
5648
[build-dependencies]
5749
rustc_tools_util = { path = "rustc_tools_util", version = "0.4.2" }
5850

clippy_test_deps/Cargo.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[package]
2+
name = "clippy_test_deps"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# Add dependencies here to make them available in ui tests.
7+
8+
[dependencies]
9+
if_chain = "1.0"
10+
quote = "1.0.25"
11+
syn = { version = "2.0", features = ["full"] }
12+
futures = "0.3"
13+
parking_lot = "0.12"
14+
tokio = { version = "1", features = ["io-util"] }
15+
itertools = "0.12"

clippy_test_deps/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}

tests/compile-test.rs

Lines changed: 25 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use test_utils::IS_RUSTC_TEST_SUITE;
1616
use ui_test::custom_flags::Flag;
1717
use ui_test::custom_flags::edition::Edition;
1818
use ui_test::custom_flags::rustfix::RustfixMode;
19+
use ui_test::dependencies::DependencyBuilder;
1920
use ui_test::spanned::Spanned;
2021
use ui_test::{Args, CommandBuilder, Config, Match, error_on_output_conflict};
2122

@@ -27,46 +28,23 @@ use std::path::{Path, PathBuf};
2728
use std::sync::mpsc::{Sender, channel};
2829
use std::{fs, iter, thread};
2930

30-
// Test dependencies may need an `extern crate` here to ensure that they show up
31-
// in the depinfo file (otherwise cargo thinks they are unused)
32-
extern crate futures;
33-
extern crate if_chain;
34-
extern crate itertools;
35-
extern crate parking_lot;
36-
extern crate quote;
37-
extern crate syn;
38-
extern crate tokio;
39-
4031
mod test_utils;
4132

42-
/// All crates used in UI tests are listed here
43-
static TEST_DEPENDENCIES: &[&str] = &[
44-
"clippy_config",
45-
"clippy_lints",
46-
"clippy_utils",
47-
"futures",
48-
"if_chain",
49-
"itertools",
50-
"parking_lot",
51-
"quote",
52-
"regex",
53-
"serde_derive",
54-
"serde",
55-
"syn",
56-
"tokio",
57-
];
58-
59-
/// Produces a string with an `--extern` flag for all UI test crate
60-
/// dependencies.
33+
/// All crates used in internal UI tests are listed here
34+
static INTERNAL_TEST_DEPENDENCIES: &[&str] = &["clippy_config", "clippy_lints", "clippy_utils"];
35+
36+
/// Produces a string with an `--extern` flag for all `INTERNAL_TEST_DEPENDENCIES`.
6137
///
6238
/// The dependency files are located by parsing the depinfo file for this test
6339
/// module. This assumes the `-Z binary-dep-depinfo` flag is enabled. All test
6440
/// dependencies must be added to Cargo.toml at the project root. Test
6541
/// dependencies that are not *directly* used by this test module require an
6642
/// `extern crate` declaration.
67-
fn extern_flags() -> Vec<String> {
43+
fn internal_extern_flags() -> Vec<String> {
44+
let current_exe_path = env::current_exe().unwrap();
45+
let deps_path = current_exe_path.parent().unwrap();
6846
let current_exe_depinfo = {
69-
let mut path = env::current_exe().unwrap();
47+
let mut path = current_exe_path.clone();
7048
path.set_extension("d");
7149
fs::read_to_string(path).unwrap()
7250
};
@@ -88,15 +66,15 @@ fn extern_flags() -> Vec<String> {
8866
Some((name, path_str))
8967
};
9068
if let Some((name, path)) = parse_name_path()
91-
&& TEST_DEPENDENCIES.contains(&name)
69+
&& INTERNAL_TEST_DEPENDENCIES.contains(&name)
9270
{
9371
// A dependency may be listed twice if it is available in sysroot,
9472
// and the sysroot dependencies are listed first. As of the writing,
9573
// this only seems to apply to if_chain.
9674
crates.insert(name, path);
9775
}
9876
}
99-
let not_found: Vec<&str> = TEST_DEPENDENCIES
77+
let not_found: Vec<&str> = INTERNAL_TEST_DEPENDENCIES
10078
.iter()
10179
.copied()
10280
.filter(|n| !crates.contains_key(n))
@@ -111,6 +89,7 @@ fn extern_flags() -> Vec<String> {
11189
crates
11290
.into_iter()
11391
.map(|(name, path)| format!("--extern={name}={path}"))
92+
.chain([format!("-Ldependency={}", deps_path.display())])
11493
.collect()
11594
}
11695

@@ -119,7 +98,6 @@ const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal");
11998

12099
struct TestContext {
121100
args: Args,
122-
extern_flags: Vec<String>,
123101
diagnostic_collector: Option<DiagnosticCollector>,
124102
collector_thread: Option<thread::JoinHandle<()>>,
125103
}
@@ -134,7 +112,6 @@ impl TestContext {
134112
.unzip();
135113
Self {
136114
args,
137-
extern_flags: extern_flags(),
138115
diagnostic_collector,
139116
collector_thread,
140117
}
@@ -158,6 +135,15 @@ impl TestContext {
158135
};
159136
let defaults = config.comment_defaults.base();
160137
defaults.set_custom("edition", Edition("2024".into()));
138+
defaults.set_custom(
139+
"dependencies",
140+
DependencyBuilder {
141+
program: CommandBuilder::cargo(),
142+
crate_manifest_path: Path::new("clippy_test_deps").join("Cargo.toml"),
143+
build_std: None,
144+
bless_lockfile: self.args.bless,
145+
},
146+
);
161147
defaults.exit_status = None.into();
162148
if mandatory_annotations {
163149
defaults.require_annotations = Some(Spanned::dummy(true)).into();
@@ -182,12 +168,10 @@ impl TestContext {
182168
"-Zui-testing",
183169
"-Zdeduplicate-diagnostics=no",
184170
"-Dwarnings",
185-
&format!("-Ldependency={}", deps_path.display()),
186171
]
187172
.map(OsString::from),
188173
);
189174

190-
config.program.args.extend(self.extern_flags.iter().map(OsString::from));
191175
// Prevent rustc from creating `rustc-ice-*` files the console output is enough.
192176
config.program.envs.push(("RUSTC_ICE".into(), Some("0".into())));
193177

@@ -227,6 +211,10 @@ fn run_internal_tests(cx: &TestContext) {
227211
return;
228212
}
229213
let mut config = cx.base_config("ui-internal", true);
214+
config
215+
.program
216+
.args
217+
.extend(internal_extern_flags().iter().map(OsString::from));
230218
config.bless_command = Some("cargo uitest --features internal -- -- --bless".into());
231219

232220
ui_test::run_tests_generic(

0 commit comments

Comments
 (0)