@@ -13,6 +13,7 @@ use std::{env, fs, iter};
1313
1414use clap_complete:: shells;
1515
16+ use self :: test_helpers:: { prepare_cargo_test, run_cargo_test} ;
1617use crate :: core:: build_steps:: compile:: run_cargo;
1718use crate :: core:: build_steps:: doc:: DocumentationFormat ;
1819use crate :: core:: build_steps:: llvm:: get_llvm_version;
@@ -35,6 +36,7 @@ use crate::utils::render_tests::{add_flags_and_try_run_tests, try_run_tests};
3536use crate :: { CLang , DocTests , GitRepo , Mode , PathSet , envify} ;
3637
3738mod book_tests;
39+ mod test_helpers;
3840mod tidy;
3941
4042pub ( crate ) use book_tests:: {
@@ -2128,120 +2130,6 @@ impl Step for CrateLibrustc {
21282130 }
21292131}
21302132
2131- /// Given a `cargo test` subcommand, add the appropriate flags and run it.
2132- ///
2133- /// Returns whether the test succeeded.
2134- fn run_cargo_test < ' a > (
2135- cargo : builder:: Cargo ,
2136- libtest_args : & [ & str ] ,
2137- crates : & [ String ] ,
2138- primary_crate : & str ,
2139- description : impl Into < Option < & ' a str > > ,
2140- target : TargetSelection ,
2141- builder : & Builder < ' _ > ,
2142- ) -> bool {
2143- let compiler = cargo. compiler ( ) ;
2144- let mut cargo = prepare_cargo_test ( cargo, libtest_args, crates, primary_crate, target, builder) ;
2145- let _time = helpers:: timeit ( builder) ;
2146- let _group = description. into ( ) . and_then ( |what| {
2147- builder. msg_sysroot_tool ( Kind :: Test , compiler. stage , what, compiler. host , target)
2148- } ) ;
2149-
2150- #[ cfg( feature = "build-metrics" ) ]
2151- builder. metrics . begin_test_suite (
2152- build_helper:: metrics:: TestSuiteMetadata :: CargoPackage {
2153- crates : crates. iter ( ) . map ( |c| c. to_string ( ) ) . collect ( ) ,
2154- target : target. triple . to_string ( ) ,
2155- host : compiler. host . triple . to_string ( ) ,
2156- stage : compiler. stage ,
2157- } ,
2158- builder,
2159- ) ;
2160- add_flags_and_try_run_tests ( builder, & mut cargo)
2161- }
2162-
2163- /// Given a `cargo test` subcommand, pass it the appropriate test flags given a `builder`.
2164- fn prepare_cargo_test (
2165- cargo : builder:: Cargo ,
2166- libtest_args : & [ & str ] ,
2167- crates : & [ String ] ,
2168- primary_crate : & str ,
2169- target : TargetSelection ,
2170- builder : & Builder < ' _ > ,
2171- ) -> BootstrapCommand {
2172- let compiler = cargo. compiler ( ) ;
2173- let mut cargo: BootstrapCommand = cargo. into ( ) ;
2174-
2175- // Propagate `--bless` if it has not already been set/unset
2176- // Any tools that want to use this should bless if `RUSTC_BLESS` is set to
2177- // anything other than `0`.
2178- if builder. config . cmd . bless ( ) && !cargo. get_envs ( ) . any ( |v| v. 0 == "RUSTC_BLESS" ) {
2179- cargo. env ( "RUSTC_BLESS" , "Gesundheit" ) ;
2180- }
2181-
2182- // Pass in some standard flags then iterate over the graph we've discovered
2183- // in `cargo metadata` with the maps above and figure out what `-p`
2184- // arguments need to get passed.
2185- if builder. kind == Kind :: Test && !builder. fail_fast {
2186- cargo. arg ( "--no-fail-fast" ) ;
2187- }
2188-
2189- if builder. config . json_output {
2190- cargo. arg ( "--message-format=json" ) ;
2191- }
2192-
2193- match builder. doc_tests {
2194- DocTests :: Only => {
2195- cargo. arg ( "--doc" ) ;
2196- }
2197- DocTests :: No => {
2198- let krate = & builder
2199- . crates
2200- . get ( primary_crate)
2201- . unwrap_or_else ( || panic ! ( "missing crate {primary_crate}" ) ) ;
2202- if krate. has_lib {
2203- cargo. arg ( "--lib" ) ;
2204- }
2205- cargo. args ( [ "--bins" , "--examples" , "--tests" , "--benches" ] ) ;
2206- }
2207- DocTests :: Yes => { }
2208- }
2209-
2210- for krate in crates {
2211- cargo. arg ( "-p" ) . arg ( krate) ;
2212- }
2213-
2214- cargo. arg ( "--" ) . args ( builder. config . test_args ( ) ) . args ( libtest_args) ;
2215- if !builder. config . verbose_tests {
2216- cargo. arg ( "--quiet" ) ;
2217- }
2218-
2219- // The tests are going to run with the *target* libraries, so we need to
2220- // ensure that those libraries show up in the LD_LIBRARY_PATH equivalent.
2221- //
2222- // Note that to run the compiler we need to run with the *host* libraries,
2223- // but our wrapper scripts arrange for that to be the case anyway.
2224- //
2225- // We skip everything on Miri as then this overwrites the libdir set up
2226- // by `Cargo::new` and that actually makes things go wrong.
2227- if builder. kind != Kind :: Miri {
2228- let mut dylib_path = dylib_path ( ) ;
2229- dylib_path. insert ( 0 , PathBuf :: from ( & * builder. sysroot_target_libdir ( compiler, target) ) ) ;
2230- cargo. env ( dylib_path_var ( ) , env:: join_paths ( & dylib_path) . unwrap ( ) ) ;
2231- }
2232-
2233- if builder. remote_tested ( target) {
2234- cargo. env (
2235- format ! ( "CARGO_TARGET_{}_RUNNER" , envify( & target. triple) ) ,
2236- format ! ( "{} run 0" , builder. tool_exe( Tool :: RemoteTestClient ) . display( ) ) ,
2237- ) ;
2238- } else if let Some ( tool) = builder. runner ( target) {
2239- cargo. env ( format ! ( "CARGO_TARGET_{}_RUNNER" , envify( & target. triple) ) , tool) ;
2240- }
2241-
2242- cargo
2243- }
2244-
22452133/// Runs `cargo test` for standard library crates.
22462134///
22472135/// (Also used internally to run `cargo test` for compiler crates.)
0 commit comments