@@ -55,7 +55,9 @@ fn detect_errors_from_rustc_stderr_file(p: PathBuf) -> HashMap<DiagnosticCode, u
55
55
56
56
impl Tester {
57
57
fn new ( ) -> Result < Self > {
58
- let tmp_file = AbsPathBuf :: assert ( "/tmp/ra-rustc-test.rs" . into ( ) ) ;
58
+ let mut path = std:: env:: temp_dir ( ) ;
59
+ path. push ( "ra-rustc-test.rs" ) ;
60
+ let tmp_file = AbsPathBuf :: try_from ( path) . unwrap ( ) ;
59
61
std:: fs:: write ( & tmp_file, "" ) ?;
60
62
let mut cargo_config = CargoConfig :: default ( ) ;
61
63
cargo_config. sysroot = Some ( RustLibSource :: Discover ) ;
@@ -122,26 +124,43 @@ impl Tester {
122
124
change. change_file ( self . root_file , Some ( Arc :: from ( text) ) ) ;
123
125
self . host . apply_change ( change) ;
124
126
let diagnostic_config = DiagnosticsConfig :: test_sample ( ) ;
125
- let diags = self
126
- . host
127
- . analysis ( )
128
- . diagnostics ( & diagnostic_config, ide:: AssistResolveStrategy :: None , self . root_file )
129
- . unwrap ( ) ;
127
+
130
128
let mut actual = HashMap :: new ( ) ;
131
- for diag in diags {
132
- if !matches ! ( diag. code, DiagnosticCode :: RustcHardError ( _) ) {
133
- continue ;
134
- }
135
- if !should_have_no_error && !SUPPORTED_DIAGNOSTICS . contains ( & diag. code ) {
136
- continue ;
129
+ let panicked = match std:: panic:: catch_unwind ( || {
130
+ self . host
131
+ . analysis ( )
132
+ . diagnostics ( & diagnostic_config, ide:: AssistResolveStrategy :: None , self . root_file )
133
+ . unwrap ( )
134
+ } ) {
135
+ Err ( e) => Some ( e) ,
136
+ Ok ( diags) => {
137
+ for diag in diags {
138
+ if !matches ! ( diag. code, DiagnosticCode :: RustcHardError ( _) ) {
139
+ continue ;
140
+ }
141
+ if !should_have_no_error && !SUPPORTED_DIAGNOSTICS . contains ( & diag. code ) {
142
+ continue ;
143
+ }
144
+ * actual. entry ( diag. code ) . or_insert ( 0 ) += 1 ;
145
+ }
146
+ None
137
147
}
138
- * actual. entry ( diag. code ) . or_insert ( 0 ) += 1 ;
139
- }
148
+ } ;
140
149
// Ignore tests with diagnostics that we don't emit.
141
150
ignore_test |= expected. keys ( ) . any ( |k| !SUPPORTED_DIAGNOSTICS . contains ( k) ) ;
142
151
if ignore_test {
143
152
println ! ( "{p:?} IGNORE" ) ;
144
153
self . ignore_count += 1 ;
154
+ } else if let Some ( panic) = panicked {
155
+ if let Some ( msg) = panic
156
+ . downcast_ref :: < String > ( )
157
+ . map ( String :: as_str)
158
+ . or_else ( || panic. downcast_ref :: < & str > ( ) . copied ( ) )
159
+ {
160
+ println ! ( "{msg:?} " )
161
+ }
162
+ println ! ( "PANIC" ) ;
163
+ self . fail_count += 1 ;
145
164
} else if actual == expected {
146
165
println ! ( "{p:?} PASS" ) ;
147
166
self . pass_count += 1 ;
@@ -225,11 +244,11 @@ impl flags::RustcTests {
225
244
let tester = AssertUnwindSafe ( & mut tester) ;
226
245
let p = p. clone ( ) ;
227
246
move || {
247
+ let _guard = stdx:: panic_context:: enter ( p. display ( ) . to_string ( ) ) ;
228
248
let tester = tester;
229
249
tester. 0 . test ( p) ;
230
250
}
231
251
} ) {
232
- println ! ( "panic detected at test {:?}" , p) ;
233
252
std:: panic:: resume_unwind ( e) ;
234
253
}
235
254
}
0 commit comments