summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorBen Blum <bblum@andrew.cmu.edu>2013-07-11 19:42:40 -0400
committerBen Blum <bblum@andrew.cmu.edu>2013-07-20 05:08:57 -0400
commita093b5434a7110967d8597fb602588b299f9859e (patch)
tree764c0a4b0a36dc2629566e24a62283cb64f48206 /src/libstd
parent9ad199754923e6d0ce8a004087036bf5bd347fbf (diff)
downloadrust-a093b5434a7110967d8597fb602588b299f9859e.tar.gz
rust-a093b5434a7110967d8597fb602588b299f9859e.zip
Add test::with_test_task() convenience function.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/rt/test.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs
index 1562160550a..11a02dfbeeb 100644
--- a/src/libstd/rt/test.rs
+++ b/src/libstd/rt/test.rs
@@ -293,7 +293,7 @@ pub fn spawntask_try(f: ~fn()) -> Result<(), ()> {
     if exit_status { Ok(()) } else { Err(()) }
 }
 
-// Spawn a new task in a new scheduler and return a thread handle.
+/// Spawn a new task in a new scheduler and return a thread handle.
 pub fn spawntask_thread(f: ~fn()) -> Thread {
     use rt::sched::*;
 
@@ -317,6 +317,16 @@ pub fn spawntask_thread(f: ~fn()) -> Thread {
     return thread;
 }
 
+/// Get a ~Task for testing purposes other than actually scheduling it.
+pub fn with_test_task(blk: ~fn(~Task) -> ~Task) {
+    do run_in_bare_thread {
+        let mut sched = ~new_test_uv_sched();
+        let task = blk(~Task::new_root(&mut sched.stack_pool, ||{}));
+        sched.enqueue_task(task);
+        sched.run();
+    }
+}
+
 
 /// Get a port number, starting at 9600, for use in tests
 pub fn next_test_port() -> u16 {