Skip to content

Commit 80524d3

Browse files
committed
std: Demode test
1 parent c946f65 commit 80524d3

File tree

2 files changed

+28
-25
lines changed

2 files changed

+28
-25
lines changed

src/compiletest/compiletest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ fn mode_str(mode: mode) -> ~str {
114114
fn run_tests(config: config) {
115115
let opts = test_opts(config);
116116
let tests = make_tests(config);
117-
let res = test::run_tests_console(opts, tests);
117+
let res = test::run_tests_console(&opts, tests);
118118
if !res { fail ~"Some tests failed"; }
119119
}
120120

src/libstd/test.rs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
// simplest interface possible for representing and running tests
66
// while providing a base that other test frameworks may build off of.
77

8+
#[forbid(deprecated_mode)];
9+
#[forbid(deprecated_pattern)];
10+
811
use core::cmp::Eq;
912
use either::Either;
1013
use result::{Ok, Err};
@@ -52,13 +55,13 @@ type TestDesc = {
5255

5356
// The default console test runner. It accepts the command line
5457
// arguments and a vector of test_descs (generated at compile time).
55-
fn test_main(args: ~[~str], tests: ~[TestDesc]) {
58+
fn test_main(args: &[~str], tests: &[TestDesc]) {
5659
let opts =
5760
match parse_opts(args) {
5861
either::Left(o) => o,
5962
either::Right(m) => fail m
6063
};
61-
if !run_tests_console(opts, tests) { fail ~"Some tests failed"; }
64+
if !run_tests_console(&opts, tests) { fail ~"Some tests failed"; }
6265
}
6366

6467
type TestOpts = {filter: Option<~str>, run_ignored: bool,
@@ -67,7 +70,7 @@ type TestOpts = {filter: Option<~str>, run_ignored: bool,
6770
type OptRes = Either<TestOpts, ~str>;
6871

6972
// Parses command line arguments into test options
70-
fn parse_opts(args: ~[~str]) -> OptRes {
73+
fn parse_opts(args: &[~str]) -> OptRes {
7174
let args_ = vec::tail(args);
7275
let opts = ~[getopts::optflag(~"ignored"), getopts::optopt(~"logfile")];
7376
let matches =
@@ -110,12 +113,12 @@ type ConsoleTestState =
110113
mut failures: ~[TestDesc]};
111114

112115
// A simple console test runner
113-
fn run_tests_console(opts: TestOpts,
114-
tests: ~[TestDesc]) -> bool {
116+
fn run_tests_console(opts: &TestOpts,
117+
tests: &[TestDesc]) -> bool {
115118

116-
fn callback(event: TestEvent, st: ConsoleTestState) {
119+
fn callback(event: &TestEvent, st: ConsoleTestState) {
117120
debug!("callback(event=%?)", event);
118-
match event {
121+
match *event {
119122
TeFiltered(filtered_tests) => {
120123
st.total = vec::len(filtered_tests);
121124
let noun = if st.total != 1u { ~"tests" } else { ~"test" };
@@ -124,7 +127,7 @@ fn run_tests_console(opts: TestOpts,
124127
TeWait(test) => st.out.write_str(fmt!("test %s ... ", test.name)),
125128
TeResult(test, result) => {
126129
match st.log_out {
127-
Some(f) => write_log(f, result, test),
130+
Some(f) => write_log(f, result, &test),
128131
None => ()
129132
}
130133
match result {
@@ -170,7 +173,7 @@ fn run_tests_console(opts: TestOpts,
170173
mut ignored: 0u,
171174
mut failures: ~[]};
172175

173-
run_tests(opts, tests, |x| callback(x, st));
176+
run_tests(opts, tests, |x| callback(&x, st));
174177

175178
assert (st.passed + st.failed + st.ignored == st.total);
176179
let success = st.failed == 0u;
@@ -189,7 +192,7 @@ fn run_tests_console(opts: TestOpts,
189192

190193
return success;
191194

192-
fn write_log(out: io::Writer, result: TestResult, test: TestDesc) {
195+
fn write_log(out: io::Writer, result: TestResult, test: &TestDesc) {
193196
out.write_line(fmt!("%s %s",
194197
match result {
195198
TrOk => ~"ok",
@@ -210,7 +213,7 @@ fn run_tests_console(opts: TestOpts,
210213
write_pretty(out, ~"ignored", term::color_yellow, use_color);
211214
}
212215
213-
fn write_pretty(out: io::Writer, word: ~str, color: u8, use_color: bool) {
216+
fn write_pretty(out: io::Writer, word: &str, color: u8, use_color: bool) {
214217
if use_color && term::color_supported() {
215218
term::fg(out, color);
216219
}
@@ -276,7 +279,7 @@ enum TestEvent {
276279
277280
type MonitorMsg = (TestDesc, TestResult);
278281
279-
fn run_tests(opts: TestOpts, tests: ~[TestDesc],
282+
fn run_tests(opts: &TestOpts, tests: &[TestDesc],
280283
callback: fn@(TestEvent)) {
281284
282285
let mut filtered_tests = filter_tests(opts, tests);
@@ -333,9 +336,9 @@ fn get_concurrency() -> uint {
333336
}
334337
335338
#[allow(non_implicitly_copyable_typarams)]
336-
fn filter_tests(opts: TestOpts,
337-
tests: ~[TestDesc]) -> ~[TestDesc] {
338-
let mut filtered = copy tests;
339+
fn filter_tests(opts: &TestOpts,
340+
tests: &[TestDesc]) -> ~[TestDesc] {
341+
let mut filtered = vec::slice(tests, 0, tests.len());
339342
340343
// Remove tests that don't match the test filter
341344
filtered = if option::is_none(opts.filter) {
@@ -347,21 +350,21 @@ fn filter_tests(opts: TestOpts,
347350
option::None => ~""
348351
};
349352
350-
fn filter_fn(test: TestDesc, filter_str: ~str) ->
353+
fn filter_fn(test: &TestDesc, filter_str: &str) ->
351354
Option<TestDesc> {
352355
if str::contains(test.name, filter_str) {
353-
return option::Some(copy test);
356+
return option::Some(copy *test);
354357
} else { return option::None; }
355358
}
356359
357-
vec::filter_map(filtered, |x| filter_fn(x, filter_str))
360+
vec::filter_map(filtered, |x| filter_fn(&x, filter_str))
358361
};
359362
360363
// Maybe pull out the ignored test and unignore them
361364
filtered = if !opts.run_ignored {
362365
move filtered
363366
} else {
364-
fn filter(test: TestDesc) -> Option<TestDesc> {
367+
fn filter(test: &TestDesc) -> Option<TestDesc> {
365368
if test.ignore {
366369
return option::Some({name: test.name,
367370
testfn: copy test.testfn,
@@ -370,7 +373,7 @@ fn filter_tests(opts: TestOpts,
370373
} else { return option::None; }
371374
};
372375
373-
vec::filter_map(filtered, |x| filter(x))
376+
vec::filter_map(filtered, |x| filter(&x))
374377
};
375378
376379
// Sort the tests alphabetically
@@ -399,12 +402,12 @@ fn run_test(+test: TestDesc, monitor_ch: comm::Chan<MonitorMsg>) {
399402
result_future = Some(move r);
400403
}).spawn(move testfn);
401404
let task_result = future::get(&option::unwrap(move result_future));
402-
let test_result = calc_result(test, task_result == task::Success);
405+
let test_result = calc_result(&test, task_result == task::Success);
403406
comm::send(monitor_ch, (copy test, test_result));
404407
};
405408
}
406409
407-
fn calc_result(test: TestDesc, task_succeeded: bool) -> TestResult {
410+
fn calc_result(test: &TestDesc, task_succeeded: bool) -> TestResult {
408411
if task_succeeded {
409412
if test.should_fail { TrFailed }
410413
else { TrOk }
@@ -514,7 +517,7 @@ mod tests {
514517
ignore: true, should_fail: false},
515518
{name: ~"2", testfn: fn~() { },
516519
ignore: false, should_fail: false}];
517-
let filtered = filter_tests(opts, tests);
520+
let filtered = filter_tests(&opts, tests);
518521
519522
assert (vec::len(filtered) == 1u);
520523
assert (filtered[0].name == ~"1");
@@ -544,7 +547,7 @@ mod tests {
544547
}
545548
tests
546549
};
547-
let filtered = filter_tests(opts, tests);
550+
let filtered = filter_tests(&opts, tests);
548551
549552
let expected =
550553
~[~"int::test_pow", ~"int::test_to_str", ~"sha1::test",

0 commit comments

Comments
 (0)