@@ -16,110 +16,25 @@ 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
22- use std:: collections:: { BTreeMap , HashMap } ;
23+ use std:: collections:: HashMap ;
2324use std:: env:: { self , set_var, var_os} ;
2425use std:: ffi:: { OsStr , OsString } ;
2526use std:: fmt:: Write ;
2627use 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.
61- ///
62- /// The dependency files are located by parsing the depinfo file for this test
63- /// module. This assumes the `-Z binary-dep-depinfo` flag is enabled. All test
64- /// dependencies must be added to Cargo.toml at the project root. Test
65- /// dependencies that are not *directly* used by this test module require an
66- /// `extern crate` declaration.
67- fn extern_flags ( ) -> Vec < String > {
68- let current_exe_depinfo = {
69- let mut path = env:: current_exe ( ) . unwrap ( ) ;
70- path. set_extension ( "d" ) ;
71- fs:: read_to_string ( path) . unwrap ( )
72- } ;
73- let mut crates = BTreeMap :: < & str , & str > :: new ( ) ;
74- for line in current_exe_depinfo. lines ( ) {
75- // each dependency is expected to have a Makefile rule like `/path/to/crate-hash.rlib:`
76- let parse_name_path = || {
77- if line. starts_with ( char:: is_whitespace) {
78- return None ;
79- }
80- let path_str = line. strip_suffix ( ':' ) ?;
81- let path = Path :: new ( path_str) ;
82- if !matches ! ( path. extension( ) ?. to_str( ) ?, "rlib" | "so" | "dylib" | "dll" ) {
83- return None ;
84- }
85- let ( name, _hash) = path. file_stem ( ) ?. to_str ( ) ?. rsplit_once ( '-' ) ?;
86- // the "lib" prefix is not present for dll files
87- let name = name. strip_prefix ( "lib" ) . unwrap_or ( name) ;
88- Some ( ( name, path_str) )
89- } ;
90- if let Some ( ( name, path) ) = parse_name_path ( )
91- && TEST_DEPENDENCIES . contains ( & name)
92- {
93- // A dependency may be listed twice if it is available in sysroot,
94- // and the sysroot dependencies are listed first. As of the writing,
95- // this only seems to apply to if_chain.
96- crates. insert ( name, path) ;
97- }
98- }
99- let not_found: Vec < & str > = TEST_DEPENDENCIES
100- . iter ( )
101- . copied ( )
102- . filter ( |n| !crates. contains_key ( n) )
103- . collect ( ) ;
104- assert ! (
105- not_found. is_empty( ) ,
106- "dependencies not found in depinfo: {not_found:?}\n \
107- help: Make sure the `-Z binary-dep-depinfo` rust flag is enabled\n \
108- help: Try adding to dev-dependencies in Cargo.toml\n \
109- help: Be sure to also add `extern crate ...;` to tests/compile-test.rs",
110- ) ;
111- crates
112- . into_iter ( )
113- . map ( |( name, path) | format ! ( "--extern={name}={path}" ) )
114- . collect ( )
115- }
116-
11733// whether to run internal tests or not
11834const RUN_INTERNAL_TESTS : bool = cfg ! ( feature = "internal" ) ;
11935
12036struct TestContext {
12137 args : Args ,
122- extern_flags : Vec < String > ,
12338 diagnostic_collector : Option < DiagnosticCollector > ,
12439 collector_thread : Option < thread:: JoinHandle < ( ) > > ,
12540}
@@ -134,7 +49,6 @@ impl TestContext {
13449 . unzip ( ) ;
13550 Self {
13651 args,
137- extern_flags : extern_flags ( ) ,
13852 diagnostic_collector,
13953 collector_thread,
14054 }
@@ -158,6 +72,17 @@ impl TestContext {
15872 } ;
15973 let defaults = config. comment_defaults . base ( ) ;
16074 defaults. set_custom ( "edition" , Edition ( "2024" . into ( ) ) ) ;
75+ defaults. set_custom (
76+ "dependencies" ,
77+ DependencyBuilder {
78+ program : CommandBuilder {
79+ ..CommandBuilder :: cargo ( )
80+ } ,
81+ crate_manifest_path : Path :: new ( "clippy_test_deps" ) . join ( "Cargo.toml" ) ,
82+ build_std : None ,
83+ bless_lockfile : self . args . bless ,
84+ } ,
85+ ) ;
16186 defaults. exit_status = None . into ( ) ;
16287 if mandatory_annotations {
16388 defaults. require_annotations = Some ( Spanned :: dummy ( true ) ) . into ( ) ;
@@ -182,12 +107,10 @@ impl TestContext {
182107 "-Zui-testing" ,
183108 "-Zdeduplicate-diagnostics=no" ,
184109 "-Dwarnings" ,
185- & format ! ( "-Ldependency={}" , deps_path. display( ) ) ,
186110 ]
187111 . map ( OsString :: from) ,
188112 ) ;
189113
190- config. program . args . extend ( self . extern_flags . iter ( ) . map ( OsString :: from) ) ;
191114 // Prevent rustc from creating `rustc-ice-*` files the console output is enough.
192115 config. program . envs . push ( ( "RUSTC_ICE" . into ( ) , Some ( "0" . into ( ) ) ) ) ;
193116
0 commit comments