Skip to content

Commit 1316505

Browse files
committed
---
yaml --- r: 3942 b: refs/heads/master c: 4a34776 h: refs/heads/master v: v3
1 parent 328e76b commit 1316505

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 7d475530a0aecbe243813b7cc23136058d114f2d
2+
refs/heads/master: 4a347760edb8d8c36b9468a5db7185ac0c922ab7

trunk/src/lib/test.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,32 @@ fn filter_tests(&test_opts opts, &test_desc[] tests) -> test_desc[] {
212212

213213
fn run_test(&test_desc test) -> test_result {
214214
if (!test.ignore) {
215-
test.fn();
216-
ret tr_ok;
215+
if (run_test_fn_in_task(test.fn)) {
216+
ret tr_ok;
217+
} else {
218+
ret tr_failed;
219+
}
217220
} else {
218221
ret tr_ignored;
219222
}
220223
}
221224

225+
// We need to run our tests in another task in order to trap test failures.
226+
// But, at least currently, functions can't be used as spawn arguments so
227+
// we've got to treat our test functions as unsafe pointers.
228+
fn run_test_fn_in_task(&fn() f) -> bool {
229+
fn run_task(*mutable fn() fptr) {
230+
task::unsupervise();
231+
(*fptr)()
232+
}
233+
auto fptr = ptr::addr_of(f);
234+
auto test_task = spawn run_task(fptr);
235+
ret alt (task::join(test_task)) {
236+
task::tr_success { true }
237+
task::tr_failure { false }
238+
}
239+
}
240+
222241

223242
// Local Variables:
224243
// mode: rust;

0 commit comments

Comments
 (0)