5
5
// simplest interface possible for representing and running tests
6
6
// while providing a base that other test frameworks may build off of.
7
7
8
+ #[ forbid( deprecated_mode) ] ;
9
+ #[ forbid( deprecated_pattern) ] ;
10
+
8
11
use core:: cmp:: Eq ;
9
12
use either:: Either ;
10
13
use result:: { Ok , Err } ;
@@ -52,13 +55,13 @@ type TestDesc = {
52
55
53
56
// The default console test runner. It accepts the command line
54
57
// 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 ] ) {
56
59
let opts =
57
60
match parse_opts ( args) {
58
61
either:: Left ( o) => o,
59
62
either:: Right ( m) => fail m
60
63
} ;
61
- if !run_tests_console ( opts, tests) { fail ~"Some tests failed"; }
64
+ if !run_tests_console ( & opts, tests) { fail ~"Some tests failed"; }
62
65
}
63
66
64
67
type TestOpts = { filter : Option < ~str > , run_ignored : bool ,
@@ -67,7 +70,7 @@ type TestOpts = {filter: Option<~str>, run_ignored: bool,
67
70
type OptRes = Either < TestOpts , ~str > ;
68
71
69
72
// Parses command line arguments into test options
70
- fn parse_opts ( args : ~ [ ~str ] ) -> OptRes {
73
+ fn parse_opts ( args : & [ ~str ] ) -> OptRes {
71
74
let args_ = vec:: tail ( args) ;
72
75
let opts = ~[ getopts:: optflag ( ~"ignored") , getopts:: optopt ( ~"logfile") ] ;
73
76
let matches =
@@ -110,12 +113,12 @@ type ConsoleTestState =
110
113
mut failures : ~[ TestDesc ] } ;
111
114
112
115
// 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 {
115
118
116
- fn callback ( event : TestEvent , st : ConsoleTestState ) {
119
+ fn callback ( event : & TestEvent , st : ConsoleTestState ) {
117
120
debug ! ( "callback(event=%?)" , event) ;
118
- match event {
121
+ match * event {
119
122
TeFiltered ( filtered_tests) => {
120
123
st. total = vec:: len ( filtered_tests) ;
121
124
let noun = if st. total != 1 u { ~"tests" } else { ~"test" } ;
@@ -124,7 +127,7 @@ fn run_tests_console(opts: TestOpts,
124
127
TeWait ( test) => st. out . write_str ( fmt ! ( "test %s ... " , test. name) ) ,
125
128
TeResult ( test, result) => {
126
129
match st. log_out {
127
- Some ( f) => write_log ( f, result, test) ,
130
+ Some ( f) => write_log ( f, result, & test) ,
128
131
None => ( )
129
132
}
130
133
match result {
@@ -170,7 +173,7 @@ fn run_tests_console(opts: TestOpts,
170
173
mut ignored: 0 u,
171
174
mut failures: ~[ ] } ;
172
175
173
- run_tests ( opts, tests, |x| callback ( x, st) ) ;
176
+ run_tests ( opts, tests, |x| callback ( & x, st) ) ;
174
177
175
178
assert ( st. passed + st. failed + st. ignored == st. total ) ;
176
179
let success = st. failed == 0 u;
@@ -189,7 +192,7 @@ fn run_tests_console(opts: TestOpts,
189
192
190
193
return success;
191
194
192
- fn write_log( out : io:: Writer , result : TestResult , test : TestDesc ) {
195
+ fn write_log( out : io:: Writer , result : TestResult , test : & TestDesc ) {
193
196
out. write_line ( fmt!( "%s %s" ,
194
197
match result {
195
198
TrOk => ~"ok",
@@ -210,7 +213,7 @@ fn run_tests_console(opts: TestOpts,
210
213
write_pretty(out, ~" ignored", term::color_yellow, use_color);
211
214
}
212
215
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) {
214
217
if use_color && term::color_supported() {
215
218
term::fg(out, color);
216
219
}
@@ -276,7 +279,7 @@ enum TestEvent {
276
279
277
280
type MonitorMsg = (TestDesc, TestResult);
278
281
279
- fn run_tests(opts: TestOpts, tests: ~ [TestDesc],
282
+ fn run_tests(opts: & TestOpts, tests: & [TestDesc],
280
283
callback: fn@(TestEvent)) {
281
284
282
285
let mut filtered_tests = filter_tests(opts, tests);
@@ -333,9 +336,9 @@ fn get_concurrency() -> uint {
333
336
}
334
337
335
338
#[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()) ;
339
342
340
343
// Remove tests that don't match the test filter
341
344
filtered = if option::is_none(opts.filter) {
@@ -347,21 +350,21 @@ fn filter_tests(opts: TestOpts,
347
350
option::None => ~" "
348
351
};
349
352
350
- fn filter_fn(test: TestDesc, filter_str: ~ str) ->
353
+ fn filter_fn(test: & TestDesc, filter_str: & str) ->
351
354
Option<TestDesc> {
352
355
if str::contains(test.name, filter_str) {
353
- return option::Some(copy test);
356
+ return option::Some(copy * test);
354
357
} else { return option::None; }
355
358
}
356
359
357
- vec::filter_map(filtered, |x| filter_fn(x, filter_str))
360
+ vec::filter_map(filtered, |x| filter_fn(& x, filter_str))
358
361
};
359
362
360
363
// Maybe pull out the ignored test and unignore them
361
364
filtered = if !opts.run_ignored {
362
365
move filtered
363
366
} else {
364
- fn filter(test: TestDesc) -> Option<TestDesc> {
367
+ fn filter(test: & TestDesc) -> Option<TestDesc> {
365
368
if test.ignore {
366
369
return option::Some({name: test.name,
367
370
testfn: copy test.testfn,
@@ -370,7 +373,7 @@ fn filter_tests(opts: TestOpts,
370
373
} else { return option::None; }
371
374
};
372
375
373
- vec::filter_map(filtered, |x| filter(x))
376
+ vec::filter_map(filtered, |x| filter(& x))
374
377
};
375
378
376
379
// Sort the tests alphabetically
@@ -399,12 +402,12 @@ fn run_test(+test: TestDesc, monitor_ch: comm::Chan<MonitorMsg>) {
399
402
result_future = Some(move r);
400
403
}).spawn(move testfn);
401
404
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);
403
406
comm::send(monitor_ch, (copy test, test_result));
404
407
};
405
408
}
406
409
407
- fn calc_result(test: TestDesc, task_succeeded: bool) -> TestResult {
410
+ fn calc_result(test: & TestDesc, task_succeeded: bool) -> TestResult {
408
411
if task_succeeded {
409
412
if test.should_fail { TrFailed }
410
413
else { TrOk }
@@ -514,7 +517,7 @@ mod tests {
514
517
ignore: true, should_fail: false},
515
518
{name: ~" 2 ", testfn: fn~() { },
516
519
ignore: false, should_fail: false}];
517
- let filtered = filter_tests(opts, tests);
520
+ let filtered = filter_tests(& opts, tests);
518
521
519
522
assert (vec::len(filtered) == 1u);
520
523
assert (filtered[0].name == ~" 1 ");
@@ -544,7 +547,7 @@ mod tests {
544
547
}
545
548
tests
546
549
};
547
- let filtered = filter_tests(opts, tests);
550
+ let filtered = filter_tests(& opts, tests);
548
551
549
552
let expected =
550
553
~[~" int:: test_pow", ~" int:: test_to_str", ~" sha1:: test",
0 commit comments