@@ -10,11 +10,17 @@ extern crate rustc_middle;
10
10
extern crate rustc_smir;
11
11
12
12
use 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 ;
14
17
use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
15
18
use std:: process:: ExitCode ;
16
19
17
20
const 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 ) ;
18
24
19
25
type TestResult = Result < ( ) , String > ;
20
26
@@ -32,12 +38,15 @@ fn main() -> ExitCode {
32
38
!is_check_arg
33
39
} )
34
40
. 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
41
50
} else {
42
51
ExitCode :: FAILURE
43
52
}
@@ -51,26 +60,32 @@ macro_rules! run_tests {
51
60
} ;
52
61
}
53
62
63
+ fn info ( msg : String ) {
64
+ if VERBOSE . load ( Ordering :: Relaxed ) {
65
+ println ! ( "{}" , msg) ;
66
+ }
67
+ }
68
+
54
69
/// This function invoke other tests and process their results.
55
70
/// Tests should avoid panic,
56
- fn test_stable_mir ( tcx : TyCtxt < ' _ > ) -> ExitCode {
71
+ fn test_stable_mir ( _tcx : TyCtxt < ' _ > ) -> ControlFlow < ( ) > {
57
72
let results = run_tests ! [
58
73
sanity_checks:: test_entry_fn,
59
74
sanity_checks:: test_all_fns,
60
75
sanity_checks:: test_traits,
61
76
sanity_checks:: test_crates
62
77
] ;
63
78
let ( success, failure) : ( Vec < _ > , Vec < _ > ) = results. iter ( ) . partition ( |r| r. is_ok ( ) ) ;
64
- println ! (
79
+ info ( format ! (
65
80
"Ran {} tests. {} succeeded. {} failed" ,
66
81
results. len( ) ,
67
82
success. len( ) ,
68
83
failure. len( )
69
- ) ;
84
+ ) ) ;
70
85
if failure. is_empty ( ) {
71
- ExitCode :: SUCCESS
86
+ ControlFlow :: < ( ) > :: Continue ( ( ) )
72
87
} else {
73
- ExitCode :: FAILURE
88
+ ControlFlow :: < ( ) > :: Break ( ( ) )
74
89
}
75
90
}
76
91
@@ -79,10 +94,10 @@ fn run_test<F: FnOnce() -> TestResult>(name: &str, f: F) -> TestResult {
79
94
Err ( _) => Err ( "Panic: {}" . to_string ( ) ) ,
80
95
Ok ( result) => result,
81
96
} ;
82
- println ! (
97
+ info ( format ! (
83
98
"Test {}: {}" ,
84
99
name,
85
100
result. as_ref( ) . err( ) . unwrap_or( & "Ok" . to_string( ) )
86
- ) ;
101
+ ) ) ;
87
102
result
88
103
}
0 commit comments