@@ -10,11 +10,17 @@ extern crate rustc_middle;
1010extern crate rustc_smir;
1111
1212use rustc_middle:: ty:: TyCtxt ;
13- use rustc_smir:: { rustc_internal, stable_mir} ;
13+ use rustc_smir:: rustc_internal;
14+ use rustc_smir:: stable_mir:: CompilerError ;
15+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
16+ use std:: ops:: ControlFlow ;
1417use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
1518use std:: process:: ExitCode ;
1619
1720const CHECK_ARG : & str = "--check-smir" ;
21+ const VERBOSE_ARG : & str = "--verbose" ;
22+ // Use a static variable for simplicity.
23+ static VERBOSE : AtomicBool = AtomicBool :: new ( false ) ;
1824
1925type TestResult = Result < ( ) , String > ;
2026
@@ -32,12 +38,15 @@ fn main() -> ExitCode {
3238 !is_check_arg
3339 } )
3440 . collect ( ) ;
35-
36-
37- let callback = if check_smir { test_stable_mir } else { |_: TyCtxt | ExitCode :: SUCCESS } ;
38- let result = rustc_internal:: StableMir :: new ( args, callback) . continue_compilation ( ) . run ( ) ;
39- if let Ok ( test_result) = result {
40- test_result
41+ VERBOSE . store ( args. iter ( ) . any ( |arg| & * arg == VERBOSE_ARG ) , Ordering :: Relaxed ) ;
42+ let callback = if check_smir {
43+ test_stable_mir
44+ } else {
45+ |_: TyCtxt | ControlFlow :: < ( ) > :: Continue ( ( ) )
46+ } ;
47+ let result = rustc_internal:: StableMir :: new ( args, callback) . run ( ) ;
48+ if result. is_ok ( ) || matches ! ( result, Err ( CompilerError :: Skipped ) ) {
49+ ExitCode :: SUCCESS
4150 } else {
4251 ExitCode :: FAILURE
4352 }
@@ -51,26 +60,32 @@ macro_rules! run_tests {
5160 } ;
5261}
5362
63+ fn info ( msg : String ) {
64+ if VERBOSE . load ( Ordering :: Relaxed ) {
65+ println ! ( "{}" , msg) ;
66+ }
67+ }
68+
5469/// This function invoke other tests and process their results.
5570/// Tests should avoid panic,
56- fn test_stable_mir ( tcx : TyCtxt < ' _ > ) -> ExitCode {
71+ fn test_stable_mir ( _tcx : TyCtxt < ' _ > ) -> ControlFlow < ( ) > {
5772 let results = run_tests ! [
5873 sanity_checks:: test_entry_fn,
5974 sanity_checks:: test_all_fns,
6075 sanity_checks:: test_traits,
6176 sanity_checks:: test_crates
6277 ] ;
6378 let ( success, failure) : ( Vec < _ > , Vec < _ > ) = results. iter ( ) . partition ( |r| r. is_ok ( ) ) ;
64- println ! (
79+ info ( format ! (
6580 "Ran {} tests. {} succeeded. {} failed" ,
6681 results. len( ) ,
6782 success. len( ) ,
6883 failure. len( )
69- ) ;
84+ ) ) ;
7085 if failure. is_empty ( ) {
71- ExitCode :: SUCCESS
86+ ControlFlow :: < ( ) > :: Continue ( ( ) )
7287 } else {
73- ExitCode :: FAILURE
88+ ControlFlow :: < ( ) > :: Break ( ( ) )
7489 }
7590}
7691
@@ -79,10 +94,10 @@ fn run_test<F: FnOnce() -> TestResult>(name: &str, f: F) -> TestResult {
7994 Err ( _) => Err ( "Panic: {}" . to_string ( ) ) ,
8095 Ok ( result) => result,
8196 } ;
82- println ! (
97+ info ( format ! (
8398 "Test {}: {}" ,
8499 name,
85100 result. as_ref( ) . err( ) . unwrap_or( & "Ok" . to_string( ) )
86- ) ;
101+ ) ) ;
87102 result
88103}
0 commit comments