@@ -107,23 +107,33 @@ fn spawn_test_thread(
107107 return None ;
108108 }
109109
110- let runnable_test = RunnableTest :: new ( test) ;
110+ let args = TestThreadArgs {
111+ config : Arc :: clone ( & test. config ) ,
112+ testpaths : test. testpaths . clone ( ) ,
113+ revision : test. revision . clone ( ) ,
114+ } ;
111115 let should_panic = test. desc . should_panic ;
112- let run_test = move || run_test_inner ( id, should_panic, runnable_test , completion_tx) ;
116+ let run_test = move || test_thread_main ( id, should_panic, args , completion_tx) ;
113117
114118 let thread_builder = thread:: Builder :: new ( ) . name ( test. desc . name . clone ( ) ) ;
115119 let join_handle = thread_builder. spawn ( run_test) . unwrap ( ) ;
116120 Some ( join_handle)
117121}
118122
123+ struct TestThreadArgs {
124+ config : Arc < Config > ,
125+ testpaths : TestPaths ,
126+ revision : Option < String > ,
127+ }
128+
119129/// Runs a single test, within the dedicated thread spawned by the caller.
120- fn run_test_inner (
130+ fn test_thread_main (
121131 id : TestId ,
122132 should_panic : ShouldPanic ,
123- runnable_test : RunnableTest ,
133+ args : TestThreadArgs ,
124134 completion_sender : mpsc:: Sender < TestCompletion > ,
125135) {
126- let capture = CaptureKind :: for_config ( & runnable_test . config ) ;
136+ let capture = CaptureKind :: for_config ( & args . config ) ;
127137
128138 // Install a panic-capture buffer for use by the custom panic hook.
129139 if capture. should_set_panic_hook ( ) {
@@ -133,7 +143,24 @@ fn run_test_inner(
133143 let stdout = capture. stdout ( ) ;
134144 let stderr = capture. stderr ( ) ;
135145
136- let panic_payload = panic:: catch_unwind ( move || runnable_test. run ( stdout, stderr) ) . err ( ) ;
146+ // Run the test, catching any panics so that we can gracefully report
147+ // failure (or success).
148+ //
149+ // FIXME(Zalathar): Ideally we would report test failures with `Result`,
150+ // and use panics only for bugs within compiletest itself, but that would
151+ // require a major overhaul of error handling in the test runners.
152+ let panic_payload = panic:: catch_unwind ( || {
153+ __rust_begin_short_backtrace ( || {
154+ crate :: runtest:: run (
155+ & args. config ,
156+ stdout,
157+ stderr,
158+ & args. testpaths ,
159+ args. revision . as_deref ( ) ,
160+ ) ;
161+ } ) ;
162+ } )
163+ . err ( ) ;
137164
138165 if let Some ( panic_buf) = panic_hook:: take_capture_buf ( ) {
139166 let panic_buf = panic_buf. lock ( ) . unwrap_or_else ( |e| e. into_inner ( ) ) ;
@@ -207,33 +234,6 @@ impl CaptureKind {
207234#[ derive( Clone , Copy , Debug , PartialEq , Eq , Hash ) ]
208235struct TestId ( usize ) ;
209236
210- struct RunnableTest {
211- config : Arc < Config > ,
212- testpaths : TestPaths ,
213- revision : Option < String > ,
214- }
215-
216- impl RunnableTest {
217- fn new ( test : & CollectedTest ) -> Self {
218- let config = Arc :: clone ( & test. config ) ;
219- let testpaths = test. testpaths . clone ( ) ;
220- let revision = test. revision . clone ( ) ;
221- Self { config, testpaths, revision }
222- }
223-
224- fn run ( & self , stdout : & dyn ConsoleOut , stderr : & dyn ConsoleOut ) {
225- __rust_begin_short_backtrace ( || {
226- crate :: runtest:: run (
227- & self . config ,
228- stdout,
229- stderr,
230- & self . testpaths ,
231- self . revision . as_deref ( ) ,
232- ) ;
233- } ) ;
234- }
235- }
236-
237237/// Fixed frame used to clean the backtrace with `RUST_BACKTRACE=1`.
238238#[ inline( never) ]
239239fn __rust_begin_short_backtrace < T , F : FnOnce ( ) -> T > ( f : F ) -> T {
0 commit comments