about summary refs log tree commit diff
path: root/src/test/stdtest/task.rs
blob: 021a56a5dff481306d45fdc089b20533bcc454f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import core::*;

use std;
import task;
import comm;

#[test]
fn test_sleep() { task::sleep(1000000u); }

// FIXME: Leaks on windows
#[test]
#[ignore(cfg(target_os = "win32"))]
fn test_unsupervise() {
    fn f() { task::unsupervise(); fail; }
    task::spawn {|| f();};
}

#[test]
fn test_lib_spawn() {
    fn foo() { #error("Hello, World!"); }
    task::spawn {|| foo();};
}

#[test]
fn test_lib_spawn2() {
    fn foo(x: int) { assert (x == 42); }
    task::spawn {|| foo(42);};
}

#[test]
fn test_join_chan() {
    fn winner() { }

    let t = task::spawn_joinable {|| winner();};
    alt task::join(t) {
      task::tr_success. {/* yay! */ }
      _ { fail "invalid task status received" }
    }
}

// FIXME: Leaks on windows
#[test]
#[ignore(cfg(target_os = "win32"))]
fn test_join_chan_fail() {
    fn failer() { task::unsupervise(); fail }

    let t = task::spawn_joinable {|| failer();};
    alt task::join(t) {
      task::tr_failure. {/* yay! */ }
      _ { fail "invalid task status received" }
    }
}

#[test]
fn spawn_polymorphic() {
    fn foo<T:send>(x: T) { log(error, x); }
    task::spawn {|| foo(true);};
    task::spawn {|| foo(42);};
}

#[test]
fn try_success() {
    alt task::try {||
        "Success!"
    } {
        result::ok("Success!") { }
        _ { fail; }
    }
}

#[test]
#[ignore(cfg(target_os = "win32"))]
fn try_fail() {
    alt task::try {||
        fail
    } {
        result::err(()) { }
        _ { fail; }
    }
}