@@ -16,6 +16,7 @@ use test_utils::IS_RUSTC_TEST_SUITE;
16
16
use ui_test:: custom_flags:: Flag ;
17
17
use ui_test:: custom_flags:: edition:: Edition ;
18
18
use ui_test:: custom_flags:: rustfix:: RustfixMode ;
19
+ use ui_test:: dependencies:: DependencyBuilder ;
19
20
use ui_test:: spanned:: Spanned ;
20
21
use ui_test:: { Args , CommandBuilder , Config , Match , error_on_output_conflict} ;
21
22
@@ -27,46 +28,23 @@ use std::path::{Path, PathBuf};
27
28
use std:: sync:: mpsc:: { Sender , channel} ;
28
29
use std:: { fs, iter, thread} ;
29
30
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
-
40
31
mod test_utils;
41
32
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`.
61
37
///
62
38
/// The dependency files are located by parsing the depinfo file for this test
63
39
/// module. This assumes the `-Z binary-dep-depinfo` flag is enabled. All test
64
40
/// dependencies must be added to Cargo.toml at the project root. Test
65
41
/// dependencies that are not *directly* used by this test module require an
66
42
/// `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 ( ) ;
68
46
let current_exe_depinfo = {
69
- let mut path = env :: current_exe ( ) . unwrap ( ) ;
47
+ let mut path = current_exe_path . clone ( ) ;
70
48
path. set_extension ( "d" ) ;
71
49
fs:: read_to_string ( path) . unwrap ( )
72
50
} ;
@@ -88,15 +66,15 @@ fn extern_flags() -> Vec<String> {
88
66
Some ( ( name, path_str) )
89
67
} ;
90
68
if let Some ( ( name, path) ) = parse_name_path ( )
91
- && TEST_DEPENDENCIES . contains ( & name)
69
+ && INTERNAL_TEST_DEPENDENCIES . contains ( & name)
92
70
{
93
71
// A dependency may be listed twice if it is available in sysroot,
94
72
// and the sysroot dependencies are listed first. As of the writing,
95
73
// this only seems to apply to if_chain.
96
74
crates. insert ( name, path) ;
97
75
}
98
76
}
99
- let not_found: Vec < & str > = TEST_DEPENDENCIES
77
+ let not_found: Vec < & str > = INTERNAL_TEST_DEPENDENCIES
100
78
. iter ( )
101
79
. copied ( )
102
80
. filter ( |n| !crates. contains_key ( n) )
@@ -111,6 +89,7 @@ fn extern_flags() -> Vec<String> {
111
89
crates
112
90
. into_iter ( )
113
91
. map ( |( name, path) | format ! ( "--extern={name}={path}" ) )
92
+ . chain ( [ format ! ( "-Ldependency={}" , deps_path. display( ) ) ] )
114
93
. collect ( )
115
94
}
116
95
@@ -119,7 +98,6 @@ const RUN_INTERNAL_TESTS: bool = cfg!(feature = "internal");
119
98
120
99
struct TestContext {
121
100
args : Args ,
122
- extern_flags : Vec < String > ,
123
101
diagnostic_collector : Option < DiagnosticCollector > ,
124
102
collector_thread : Option < thread:: JoinHandle < ( ) > > ,
125
103
}
@@ -134,7 +112,6 @@ impl TestContext {
134
112
. unzip ( ) ;
135
113
Self {
136
114
args,
137
- extern_flags : extern_flags ( ) ,
138
115
diagnostic_collector,
139
116
collector_thread,
140
117
}
@@ -158,6 +135,15 @@ impl TestContext {
158
135
} ;
159
136
let defaults = config. comment_defaults . base ( ) ;
160
137
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
+ ) ;
161
147
defaults. exit_status = None . into ( ) ;
162
148
if mandatory_annotations {
163
149
defaults. require_annotations = Some ( Spanned :: dummy ( true ) ) . into ( ) ;
@@ -182,12 +168,10 @@ impl TestContext {
182
168
"-Zui-testing" ,
183
169
"-Zdeduplicate-diagnostics=no" ,
184
170
"-Dwarnings" ,
185
- & format ! ( "-Ldependency={}" , deps_path. display( ) ) ,
186
171
]
187
172
. map ( OsString :: from) ,
188
173
) ;
189
174
190
- config. program . args . extend ( self . extern_flags . iter ( ) . map ( OsString :: from) ) ;
191
175
// Prevent rustc from creating `rustc-ice-*` files the console output is enough.
192
176
config. program . envs . push ( ( "RUSTC_ICE" . into ( ) , Some ( "0" . into ( ) ) ) ) ;
193
177
@@ -227,6 +211,10 @@ fn run_internal_tests(cx: &TestContext) {
227
211
return ;
228
212
}
229
213
let mut config = cx. base_config ( "ui-internal" , true ) ;
214
+ config
215
+ . program
216
+ . args
217
+ . extend ( internal_extern_flags ( ) . iter ( ) . map ( OsString :: from) ) ;
230
218
config. bless_command = Some ( "cargo uitest --features internal -- -- --bless" . into ( ) ) ;
231
219
232
220
ui_test:: run_tests_generic (
0 commit comments