@@ -92,6 +92,7 @@ use time::TestExecTime;
92
92
const ERROR_EXIT_CODE : i32 = 101 ;
93
93
94
94
const SECONDARY_TEST_INVOKER_VAR : & str = "__RUST_TEST_INVOKE" ;
95
+ const SECONDARY_TEST_BENCH_BENCHMARKS_VAR : & str = "__RUST_TEST_BENCH_BENCHMARKS" ;
95
96
96
97
// The default console test runner. It accepts the command line
97
98
// arguments and a vector of test_descs.
@@ -171,10 +172,18 @@ pub fn test_main_static_abort(tests: &[&TestDescAndFn]) {
171
172
// will then exit the process.
172
173
if let Ok ( name) = env:: var ( SECONDARY_TEST_INVOKER_VAR ) {
173
174
env:: remove_var ( SECONDARY_TEST_INVOKER_VAR ) ;
175
+
176
+ // Convert benchmarks to tests if we're not benchmarking.
177
+ let mut tests = tests. iter ( ) . map ( make_owned_test) . collect :: < Vec < _ > > ( ) ;
178
+ if env:: var ( SECONDARY_TEST_BENCH_BENCHMARKS_VAR ) . is_ok ( ) {
179
+ env:: remove_var ( SECONDARY_TEST_BENCH_BENCHMARKS_VAR ) ;
180
+ } else {
181
+ tests = convert_benchmarks_to_tests ( tests) ;
182
+ } ;
183
+
174
184
let test = tests
175
- . iter ( )
185
+ . into_iter ( )
176
186
. filter ( |test| test. desc . name . as_slice ( ) == name)
177
- . map ( make_owned_test)
178
187
. next ( )
179
188
. unwrap_or_else ( || panic ! ( "couldn't find a test with the provided name '{name}'" ) ) ;
180
189
let TestDescAndFn { desc, testfn } = test;
@@ -557,6 +566,7 @@ pub fn run_test(
557
566
let name = desc. name . clone ( ) ;
558
567
let nocapture = opts. nocapture ;
559
568
let time_options = opts. time_options ;
569
+ let bench_benchmarks = opts. bench_benchmarks ;
560
570
561
571
let runtest = move || match strategy {
562
572
RunStrategy :: InProcess => run_test_in_process (
@@ -575,6 +585,7 @@ pub fn run_test(
575
585
time_options. is_some ( ) ,
576
586
monitor_ch,
577
587
time_options,
588
+ bench_benchmarks,
578
589
) ,
579
590
} ;
580
591
@@ -672,13 +683,17 @@ fn spawn_test_subprocess(
672
683
report_time : bool ,
673
684
monitor_ch : Sender < CompletedTest > ,
674
685
time_opts : Option < time:: TestTimeOptions > ,
686
+ bench_benchmarks : bool ,
675
687
) {
676
688
let ( result, test_output, exec_time) = ( || {
677
689
let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
678
690
let current_exe = & args[ 0 ] ;
679
691
680
692
let mut command = Command :: new ( current_exe) ;
681
693
command. env ( SECONDARY_TEST_INVOKER_VAR , desc. name . as_slice ( ) ) ;
694
+ if bench_benchmarks {
695
+ command. env ( SECONDARY_TEST_BENCH_BENCHMARKS_VAR , "1" ) ;
696
+ }
682
697
if nocapture {
683
698
command. stdout ( process:: Stdio :: inherit ( ) ) ;
684
699
command. stderr ( process:: Stdio :: inherit ( ) ) ;
0 commit comments