Skip to content

Commit 665dbb3

Browse files
committed
Move all other test thread args into TestThreadArgs
1 parent f988679 commit 665dbb3

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/tools/compiletest/src/executor.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -98,41 +98,42 @@ pub(crate) fn run_tests(config: &Config, tests: Vec<CollectedTest>) -> bool {
9898
fn spawn_test_thread(
9999
id: TestId,
100100
test: &CollectedTest,
101-
completion_tx: mpsc::Sender<TestCompletion>,
101+
completion_sender: mpsc::Sender<TestCompletion>,
102102
) -> Option<thread::JoinHandle<()>> {
103103
if test.desc.ignore && !test.config.run_ignored {
104-
completion_tx
104+
completion_sender
105105
.send(TestCompletion { id, outcome: TestOutcome::Ignored, stdout: None })
106106
.unwrap();
107107
return None;
108108
}
109109

110110
let args = TestThreadArgs {
111+
id,
111112
config: Arc::clone(&test.config),
112113
testpaths: test.testpaths.clone(),
113114
revision: test.revision.clone(),
115+
should_panic: test.desc.should_panic,
116+
completion_sender,
114117
};
115-
let should_panic = test.desc.should_panic;
116-
let run_test = move || test_thread_main(id, should_panic, args, completion_tx);
117-
118118
let thread_builder = thread::Builder::new().name(test.desc.name.clone());
119-
let join_handle = thread_builder.spawn(run_test).unwrap();
119+
let join_handle = thread_builder.spawn(move || test_thread_main(args)).unwrap();
120120
Some(join_handle)
121121
}
122122

123+
/// All of the owned data needed by `test_thread_main`.
123124
struct TestThreadArgs {
125+
id: TestId,
126+
124127
config: Arc<Config>,
125128
testpaths: TestPaths,
126129
revision: Option<String>,
130+
should_panic: ShouldPanic,
131+
132+
completion_sender: mpsc::Sender<TestCompletion>,
127133
}
128134

129135
/// Runs a single test, within the dedicated thread spawned by the caller.
130-
fn test_thread_main(
131-
id: TestId,
132-
should_panic: ShouldPanic,
133-
args: TestThreadArgs,
134-
completion_sender: mpsc::Sender<TestCompletion>,
135-
) {
136+
fn test_thread_main(args: TestThreadArgs) {
136137
let capture = CaptureKind::for_config(&args.config);
137138

138139
// Install a panic-capture buffer for use by the custom panic hook.
@@ -168,7 +169,8 @@ fn test_thread_main(
168169
write!(stderr, "{panic_buf}");
169170
}
170171

171-
let outcome = match (should_panic, panic_payload) {
172+
// Interpret the presence/absence of a panic as test failure/success.
173+
let outcome = match (args.should_panic, panic_payload) {
172174
(ShouldPanic::No, None) | (ShouldPanic::Yes, Some(_)) => TestOutcome::Succeeded,
173175
(ShouldPanic::No, Some(_)) => TestOutcome::Failed { message: None },
174176
(ShouldPanic::Yes, None) => {
@@ -177,7 +179,7 @@ fn test_thread_main(
177179
};
178180

179181
let stdout = capture.into_inner();
180-
completion_sender.send(TestCompletion { id, outcome, stdout }).unwrap();
182+
args.completion_sender.send(TestCompletion { id: args.id, outcome, stdout }).unwrap();
181183
}
182184

183185
enum CaptureKind {

0 commit comments

Comments
 (0)