Skip to content

Commit b4eff79

Browse files
author
blake2-ppc
committed
extra::test: Use Result instead of Either.
OptRes was combining a successful value with an error message, which fits the Result type perfectly.
1 parent 92c4c07 commit b4eff79

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/libextra/test.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ use treemap::TreeMap;
3131
use std::clone::Clone;
3232
use std::comm::{stream, SharedChan, GenericPort, GenericChan};
3333
use std::libc;
34-
use std::either;
3534
use std::io;
3635
use std::result;
3736
use std::task;
@@ -127,8 +126,8 @@ pub type MetricDiff = TreeMap<~str,MetricChange>;
127126
pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) {
128127
let opts =
129128
match parse_opts(args) {
130-
either::Left(o) => o,
131-
either::Right(m) => fail!(m)
129+
Ok(o) => o,
130+
Err(msg) => fail!(msg)
132131
};
133132
if !run_tests_console(&opts, tests) { fail!("Some tests failed"); }
134133
}
@@ -169,7 +168,7 @@ pub struct TestOpts {
169168
logfile: Option<Path>
170169
}
171170

172-
type OptRes = Either<TestOpts, ~str>;
171+
type OptRes = Result<TestOpts, ~str>;
173172

174173
fn optgroups() -> ~[getopts::groups::OptGroup] {
175174
~[groups::optflag("", "ignored", "Run ignored tests"),
@@ -228,7 +227,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
228227
let matches =
229228
match groups::getopts(args_, optgroups()) {
230229
Ok(m) => m,
231-
Err(f) => return either::Right(getopts::fail_str(f))
230+
Err(f) => return Err(getopts::fail_str(f))
232231
};
233232

234233
if getopts::opt_present(&matches, "h") { usage(args[0], "h"); }
@@ -274,7 +273,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
274273
logfile: logfile
275274
};
276275

277-
either::Left(test_opts)
276+
Ok(test_opts)
278277
}
279278

280279
pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> {
@@ -1155,7 +1154,6 @@ mod tests {
11551154
StaticTestName, DynTestName, DynTestFn};
11561155
use test::{TestOpts, run_test};
11571156

1158-
use std::either;
11591157
use std::comm::{stream, SharedChan};
11601158
use tempfile;
11611159
use std::os;
@@ -1236,8 +1234,8 @@ mod tests {
12361234
fn first_free_arg_should_be_a_filter() {
12371235
let args = ~[~"progname", ~"filter"];
12381236
let opts = match parse_opts(args) {
1239-
either::Left(o) => o,
1240-
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
1237+
Ok(o) => o,
1238+
_ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
12411239
};
12421240
assert!("filter" == opts.filter.clone().unwrap());
12431241
}
@@ -1246,8 +1244,8 @@ mod tests {
12461244
fn parse_ignored_flag() {
12471245
let args = ~[~"progname", ~"filter", ~"--ignored"];
12481246
let opts = match parse_opts(args) {
1249-
either::Left(o) => o,
1250-
_ => fail!("Malformed arg in parse_ignored_flag")
1247+
Ok(o) => o,
1248+
_ => fail!("Malformed arg in parse_ignored_flag")
12511249
};
12521250
assert!((opts.run_ignored));
12531251
}

0 commit comments

Comments
 (0)