Skip to content

Commit a093b54

Browse files
committed
Add test::with_test_task() convenience function.
1 parent 9ad1997 commit a093b54

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/libstd/rt/test.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(), ()> {
293293
if exit_status { Ok(()) } else { Err(()) }
294294
}
295295

296-
// Spawn a new task in a new scheduler and return a thread handle.
296+
/// Spawn a new task in a new scheduler and return a thread handle.
297297
pub fn spawntask_thread(f: ~fn()) -> Thread {
298298
use rt::sched::*;
299299

@@ -317,6 +317,16 @@ pub fn spawntask_thread(f: ~fn()) -> Thread {
317317
return thread;
318318
}
319319

320+
/// Get a ~Task for testing purposes other than actually scheduling it.
321+
pub fn with_test_task(blk: ~fn(~Task) -> ~Task) {
322+
do run_in_bare_thread {
323+
let mut sched = ~new_test_uv_sched();
324+
let task = blk(~Task::new_root(&mut sched.stack_pool, ||{}));
325+
sched.enqueue_task(task);
326+
sched.run();
327+
}
328+
}
329+
320330

321331
/// Get a port number, starting at 9600, for use in tests
322332
pub fn next_test_port() -> u16 {

0 commit comments

Comments
 (0)