1- use crate :: core:: compiler:: { Compilation , CompileKind , Doctest , UnitOutput } ;
1+ use crate :: core:: compiler:: { Compilation , CompileKind , Doctest , Metadata , Unit , UnitOutput } ;
22use crate :: core:: shell:: Verbosity ;
33use crate :: core:: { TargetKind , Workspace } ;
44use crate :: ops;
55use crate :: util:: errors:: CargoResult ;
66use crate :: util:: { add_path_args, CargoTestError , Config , Test } ;
7- use cargo_util:: ProcessError ;
7+ use cargo_util:: { ProcessBuilder , ProcessError } ;
88use std:: ffi:: OsString ;
9+ use std:: path:: { Path , PathBuf } ;
910
1011pub struct TestOptions {
1112 pub compile_opts : ops:: CompileOptions ,
@@ -21,6 +22,30 @@ pub fn run_tests(
2122 let compilation = compile_tests ( ws, options) ?;
2223
2324 if options. no_run {
25+ let config = ws. config ( ) ;
26+ let cwd = config. cwd ( ) ;
27+ for UnitOutput {
28+ unit,
29+ path,
30+ script_meta,
31+ } in compilation. tests . iter ( )
32+ {
33+ let ( exe_display, cmd) = cmd_builds (
34+ config,
35+ cwd,
36+ unit,
37+ path,
38+ script_meta,
39+ test_args,
40+ & compilation,
41+ ) ?;
42+ config
43+ . shell ( )
44+ . concise ( |shell| shell. status ( "Executable" , & exe_display) ) ?;
45+ config
46+ . shell ( )
47+ . verbose ( |shell| shell. status ( "Executable" , & cmd) ) ?;
48+ }
2449 return Ok ( None ) ;
2550 }
2651 let ( test, mut errors) = run_unit_tests ( ws. config ( ) , options, test_args, & compilation) ?;
@@ -48,6 +73,23 @@ pub fn run_benches(
4873 let compilation = compile_tests ( ws, options) ?;
4974
5075 if options. no_run {
76+ let config = ws. config ( ) ;
77+ let cwd = config. cwd ( ) ;
78+ for UnitOutput {
79+ unit,
80+ path,
81+ script_meta,
82+ } in compilation. tests . iter ( )
83+ {
84+ let ( exe_display, cmd) =
85+ cmd_builds ( config, cwd, unit, path, script_meta, args, & compilation) ?;
86+ config
87+ . shell ( )
88+ . concise ( |shell| shell. status ( "Executable" , & exe_display) ) ?;
89+ config
90+ . shell ( )
91+ . verbose ( |shell| shell. status ( "Executable" , & cmd) ) ?;
92+ }
5193 return Ok ( None ) ;
5294 }
5395
@@ -86,28 +128,8 @@ fn run_unit_tests(
86128 {
87129 let test = unit. target . name ( ) . to_string ( ) ;
88130
89- let test_path = unit. target . src_path ( ) . path ( ) . unwrap ( ) ;
90- let exe_display = if let TargetKind :: Test = unit. target . kind ( ) {
91- format ! (
92- "{} ({})" ,
93- test_path
94- . strip_prefix( unit. pkg. root( ) )
95- . unwrap_or( test_path)
96- . display( ) ,
97- path. strip_prefix( cwd) . unwrap_or( path) . display( )
98- )
99- } else {
100- format ! (
101- "unittests ({})" ,
102- path. strip_prefix( cwd) . unwrap_or( path) . display( )
103- )
104- } ;
105-
106- let mut cmd = compilation. target_process ( path, unit. kind , & unit. pkg , * script_meta) ?;
107- cmd. args ( test_args) ;
108- if unit. target . harness ( ) && config. shell ( ) . verbosity ( ) == Verbosity :: Quiet {
109- cmd. arg ( "--quiet" ) ;
110- }
131+ let ( exe_display, cmd) =
132+ cmd_builds ( config, cwd, unit, path, script_meta, test_args, compilation) ?;
111133 config
112134 . shell ( )
113135 . concise ( |shell| shell. status ( "Running" , & exe_display) ) ?;
@@ -152,6 +174,41 @@ fn run_unit_tests(
152174 }
153175}
154176
177+ fn cmd_builds (
178+ config : & Config ,
179+ cwd : & Path ,
180+ unit : & Unit ,
181+ path : & PathBuf ,
182+ script_meta : & Option < Metadata > ,
183+ test_args : & [ & str ] ,
184+ compilation : & Compilation < ' _ > ,
185+ ) -> CargoResult < ( String , ProcessBuilder ) > {
186+ let test_path = unit. target . src_path ( ) . path ( ) . unwrap ( ) ;
187+ let exe_display = if let TargetKind :: Test = unit. target . kind ( ) {
188+ format ! (
189+ "{} ({})" ,
190+ test_path
191+ . strip_prefix( unit. pkg. root( ) )
192+ . unwrap_or( test_path)
193+ . display( ) ,
194+ path. strip_prefix( cwd) . unwrap_or( path) . display( )
195+ )
196+ } else {
197+ format ! (
198+ "unittests ({})" ,
199+ path. strip_prefix( cwd) . unwrap_or( path) . display( )
200+ )
201+ } ;
202+
203+ let mut cmd = compilation. target_process ( path, unit. kind , & unit. pkg , * script_meta) ?;
204+ cmd. args ( test_args) ;
205+ if unit. target . harness ( ) && config. shell ( ) . verbosity ( ) == Verbosity :: Quiet {
206+ cmd. arg ( "--quiet" ) ;
207+ }
208+
209+ Ok ( ( exe_display, cmd) )
210+ }
211+
155212fn run_doc_tests (
156213 ws : & Workspace < ' _ > ,
157214 options : & TestOptions ,
0 commit comments