diff options
| author | Marijn Haverbeke <marijnh@gmail.com> | 2012-02-22 13:18:15 +0100 |
|---|---|---|
| committer | Marijn Haverbeke <marijnh@gmail.com> | 2012-02-22 13:18:15 +0100 |
| commit | ffd50b9cdfa38bc80f2444d917eef5a02c38c32f (patch) | |
| tree | 383a83ae49b7690a07d9b546e25b3b43a9adddbe /src/test | |
| parent | 72373438d28eecfa565ad16bd84f800b8c8067c0 (diff) | |
Make the various from_str functions return options
So that they can be used with user input without causing task failures. Closes #1335
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/bench/msgsend.rs | 4 | ||||
| -rw-r--r-- | src/test/bench/shootout-ackermann.rs | 2 | ||||
| -rw-r--r-- | src/test/bench/shootout-binarytrees.rs | 3 | ||||
| -rw-r--r-- | src/test/bench/shootout-fannkuchredux.rs | 2 | ||||
| -rw-r--r-- | src/test/bench/shootout-fibo.rs | 2 | ||||
| -rw-r--r-- | src/test/bench/shootout-mandelbrot.rs | 37 | ||||
| -rw-r--r-- | src/test/bench/shootout-nbody.rs | 2 | ||||
| -rw-r--r-- | src/test/bench/shootout-pfib.rs | 3 | ||||
| -rw-r--r-- | src/test/bench/shootout-spectralnorm.rs | 2 | ||||
| -rw-r--r-- | src/test/bench/shootout-threadring.rs | 7 | ||||
| -rw-r--r-- | src/test/bench/sudoku.rs | 6 | ||||
| -rw-r--r-- | src/test/bench/task-perf-one-million.rs | 2 | ||||
| -rw-r--r-- | src/test/bench/task-perf-spawnalot.rs | 8 | ||||
| -rw-r--r-- | src/test/bench/task-perf-vector-party.rs | 12 |
14 files changed, 30 insertions, 62 deletions
diff --git a/src/test/bench/msgsend.rs b/src/test/bench/msgsend.rs index 73db81c88a0..36a974002a2 100644 --- a/src/test/bench/msgsend.rs +++ b/src/test/bench/msgsend.rs @@ -33,8 +33,8 @@ fn run(args: [str]) { let to_child = task::spawn_listener {|po| server(po, to_parent); }; - let size = uint::from_str(args[1]); - let workers = uint::from_str(args[2]); + let size = option::get(uint::from_str(args[1])); + let workers = option::get(uint::from_str(args[2])); let start = std::time::precise_time_s(); let to_child = to_child; let worker_results = []; diff --git a/src/test/bench/shootout-ackermann.rs b/src/test/bench/shootout-ackermann.rs index ca0555ca49d..92a6a182308 100644 --- a/src/test/bench/shootout-ackermann.rs +++ b/src/test/bench/shootout-ackermann.rs @@ -14,7 +14,7 @@ fn ack(m: int, n: int) -> int { fn main(args: [str]) { let n = if vec::len(args) == 2u { - int::from_str(args[1]) + option::get(int::from_str(args[1])) } else { 8 }; diff --git a/src/test/bench/shootout-binarytrees.rs b/src/test/bench/shootout-binarytrees.rs index 3f1d47d3be2..3054e364dd3 100644 --- a/src/test/bench/shootout-binarytrees.rs +++ b/src/test/bench/shootout-binarytrees.rs @@ -1,5 +1,4 @@ use std; -import int; enum tree { nil, node(~tree, ~tree, int), } @@ -21,7 +20,7 @@ fn bottom_up_tree(item: int, depth: int) -> ~tree { fn main(args: [str]) { let n = if vec::len(args) == 2u { - int::from_str(args[1]) + option::get(int::from_str(args[1])) } else { 8 }; diff --git a/src/test/bench/shootout-fannkuchredux.rs b/src/test/bench/shootout-fannkuchredux.rs index 65c1971af6e..26ed2fcf0a4 100644 --- a/src/test/bench/shootout-fannkuchredux.rs +++ b/src/test/bench/shootout-fannkuchredux.rs @@ -60,7 +60,7 @@ fn fannkuch(n: int) -> int { fn main(args: [str]) { let n = if vec::len(args) == 2u { - int::from_str(args[1]) + option::get(int::from_str(args[1])) } else { 8 }; diff --git a/src/test/bench/shootout-fibo.rs b/src/test/bench/shootout-fibo.rs index ad31289a109..2868cb0f667 100644 --- a/src/test/bench/shootout-fibo.rs +++ b/src/test/bench/shootout-fibo.rs @@ -10,7 +10,7 @@ fn fib(n: int) -> int { fn main(args: [str]) { let n = if vec::len(args) == 2u { - int::from_str(args[1]) + option::get(int::from_str(args[1])) } else { 30 }; diff --git a/src/test/bench/shootout-mandelbrot.rs b/src/test/bench/shootout-mandelbrot.rs index 985b2e82504..984e8d78a18 100644 --- a/src/test/bench/shootout-mandelbrot.rs +++ b/src/test/bench/shootout-mandelbrot.rs @@ -136,36 +136,21 @@ fn writer(path: str, writech: comm::chan<comm::chan<line>>, size: uint) } } -fn main(argv: [str]) -{ - let size = if vec::len(argv) < 2_u { - 80u - } - else { - uint::from_str(argv[1]) - }; - let yieldevery = if vec::len(argv) < 3_u { - 10_u - } - else { - uint::from_str(argv[2]) - }; - let path = if vec::len(argv) < 4_u { - "" - } - else { - argv[3] - }; +fn main(argv: [str]) { + let size = if vec::len(argv) < 2_u { 80u } + else { option::get(uint::from_str(argv[1])) }; + let yieldevery = if vec::len(argv) < 3_u { 10_u } + else { option::get(uint::from_str(argv[2])) }; + let path = if vec::len(argv) < 4_u { "" } + else { argv[3] }; let writep = comm::port(); let writech = comm::chan(writep); - task::spawn { - || writer(path, writech, size); + task::spawn {|| + writer(path, writech, size); }; let ch = comm::recv(writep); - uint::range(0_u, size) { - |j| task::spawn { - || chanmb(j, size, ch); - }; + uint::range(0_u, size) {|j| + task::spawn {|| chanmb(j, size, ch);}; if j % yieldevery == 0_u { #debug("Y %u", j); task::yield(); diff --git a/src/test/bench/shootout-nbody.rs b/src/test/bench/shootout-nbody.rs index c43568c6759..ac0f47f520e 100644 --- a/src/test/bench/shootout-nbody.rs +++ b/src/test/bench/shootout-nbody.rs @@ -15,7 +15,7 @@ native mod libc { fn main(args: [str]) { let n = if vec::len(args) == 2u { - int::from_str(args[1]) + option::get(int::from_str(args[1])) } else { 100000 }; diff --git a/src/test/bench/shootout-pfib.rs b/src/test/bench/shootout-pfib.rs index edf9ed71754..8105b019de4 100644 --- a/src/test/bench/shootout-pfib.rs +++ b/src/test/bench/shootout-pfib.rs @@ -90,7 +90,8 @@ fn main(argv: [str]) { if opts.stress { stress(2); } else { - let max = uint::parse_buf(str::bytes(argv[1]), 10u) as int; + let max = option::get(uint::parse_buf(str::bytes(argv[1]), + 10u)) as int; let num_trials = 10; diff --git a/src/test/bench/shootout-spectralnorm.rs b/src/test/bench/shootout-spectralnorm.rs index 44f550968e1..6c475985d49 100644 --- a/src/test/bench/shootout-spectralnorm.rs +++ b/src/test/bench/shootout-spectralnorm.rs @@ -43,7 +43,7 @@ fn eval_AtA_times_u(u: [const float], AtAu: [mutable float]) { fn main(args: [str]) { let N = if vec::len(args) == 2u { - uint::from_str(args[1]) + option::get(uint::from_str(args[1])) } else { 1000u }; diff --git a/src/test/bench/shootout-threadring.rs b/src/test/bench/shootout-threadring.rs index 3e0150fc45c..539567a28ee 100644 --- a/src/test/bench/shootout-threadring.rs +++ b/src/test/bench/shootout-threadring.rs @@ -38,11 +38,8 @@ fn roundtrip(id: int, p: comm::port<int>, ch: comm::chan<int>) { } fn main(args: [str]) { - let token = if vec::len(args) < 2u { - 1000 - } else { - int::from_str(args[1]) - }; + let token = if vec::len(args) < 2u { 1000 } + else { option::get(int::from_str(args[1])) }; start(token); } \ No newline at end of file diff --git a/src/test/bench/sudoku.rs b/src/test/bench/sudoku.rs index 61a083f1f53..9b02ee0a49f 100644 --- a/src/test/bench/sudoku.rs +++ b/src/test/bench/sudoku.rs @@ -35,9 +35,9 @@ fn read_grid(f: io::reader) -> grid_t { while !f.eof() { let comps = str::split_byte(str::trim(f.read_line()), ',' as u8); if vec::len(comps) >= 3u { - let row = uint::from_str(comps[0]) as u8; - let col = uint::from_str(comps[1]) as u8; - g[row][col] = uint::from_str(comps[2]) as u8; + let row = option::get(uint::from_str(comps[0])) as u8; + let col = option::get(uint::from_str(comps[1])) as u8; + g[row][col] = option::get(uint::from_str(comps[2])) as u8; } } ret grid_ctor(g); diff --git a/src/test/bench/task-perf-one-million.rs b/src/test/bench/task-perf-one-million.rs index 98eefbaf06f..bf74f736a83 100644 --- a/src/test/bench/task-perf-one-million.rs +++ b/src/test/bench/task-perf-one-million.rs @@ -47,7 +47,7 @@ fn calc(children: uint, parent_ch: comm::chan<msg>) { fn main(args: [str]) { let children = if vec::len(args) == 2u { - uint::from_str(args[1]) + option::get(uint::from_str(args[1])) } else { 100u }; diff --git a/src/test/bench/task-perf-spawnalot.rs b/src/test/bench/task-perf-spawnalot.rs index 3e38ff5ea22..de81e0263d5 100644 --- a/src/test/bench/task-perf-spawnalot.rs +++ b/src/test/bench/task-perf-spawnalot.rs @@ -1,9 +1,3 @@ -use std; -import vec; -import task; -import uint; -import str; - fn f(&&n: uint) { let i = 0u; while i < n { @@ -18,7 +12,7 @@ fn main(args: [str]) { let n = if vec::len(args) < 2u { 10u - } else { uint::parse_buf(str::bytes(args[1]), 10u) }; + } else { option::get(uint::parse_buf(str::bytes(args[1]), 10u)) }; let i = 0u; while i < n { task::spawn {|| f(n); }; i += 1u; } } diff --git a/src/test/bench/task-perf-vector-party.rs b/src/test/bench/task-perf-vector-party.rs index 000e3670500..0b24596da64 100644 --- a/src/test/bench/task-perf-vector-party.rs +++ b/src/test/bench/task-perf-vector-party.rs @@ -3,12 +3,6 @@ // that synchronization by spawning a number of tasks and then // allocating and freeing vectors. -use std; -import vec; -import uint; -import str; -import task; - fn f(&&n: uint) { uint::range(0u, n) {|i| let v: [u8] = []; @@ -17,9 +11,7 @@ fn f(&&n: uint) { } fn main(args: [str]) { - let n = - if vec::len(args) < 2u { - 100u - } else { uint::parse_buf(str::bytes(args[1]), 10u) }; + let n = if vec::len(args) < 2u { 100u } + else { option::get(uint::from_str(args[1])) }; uint::range(0u, 100u) {|i| task::spawn {|| f(n); };} } |
