@@ -16,6 +16,7 @@ use test_utils::IS_RUSTC_TEST_SUITE;
1616use ui_test:: custom_flags:: Flag ;
1717use ui_test:: custom_flags:: edition:: Edition ;
1818use ui_test:: custom_flags:: rustfix:: RustfixMode ;
19+ use ui_test:: dependencies:: DependencyBuilder ;
1920use ui_test:: spanned:: Spanned ;
2021use ui_test:: { Args , CommandBuilder , Config , Match , error_on_output_conflict} ;
2122
@@ -27,46 +28,23 @@ use std::path::{Path, PathBuf};
2728use std:: sync:: mpsc:: { Sender , channel} ;
2829use 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-
4031mod 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
12099struct 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