@@ -13,15 +13,15 @@ use libc::size_t;
13
13
use task:: TaskBuilder ;
14
14
use comm = core:: comm;
15
15
16
- export test_name ;
17
- export test_fn ;
18
- export test_desc ;
16
+ export TestName ;
17
+ export TestFn ;
18
+ export TestDesc ;
19
19
export test_main;
20
- export test_result ;
21
- export test_opts ;
22
- export tr_ok ;
23
- export tr_failed ;
24
- export tr_ignored ;
20
+ export TestResult ;
21
+ export TestOpts ;
22
+ export TrOk ;
23
+ export TrFailed ;
24
+ export TrIgnored ;
25
25
export run_tests_console;
26
26
27
27
#[ abi = "cdecl" ]
@@ -33,26 +33,26 @@ extern mod rustrt {
33
33
// paths; i.e. it should be a series of identifiers seperated by double
34
34
// colons. This way if some test runner wants to arrange the tests
35
35
// hierarchically it may.
36
- type test_name = ~str ;
36
+ type TestName = ~str ;
37
37
38
38
// A function that runs a test. If the function returns successfully,
39
39
// the test succeeds; if the function fails then the test fails. We
40
40
// may need to come up with a more clever definition of test in order
41
41
// to support isolation of tests into tasks.
42
- type test_fn = fn ~( ) ;
42
+ type TestFn = fn ~( ) ;
43
43
44
44
// The definition of a single test. A test runner will run a list of
45
45
// these.
46
- type test_desc = {
47
- name : test_name ,
48
- fn : test_fn ,
46
+ type TestDesc = {
47
+ name : TestName ,
48
+ fn : TestFn ,
49
49
ignore : bool ,
50
50
should_fail : bool
51
51
} ;
52
52
53
53
// The default console test runner. It accepts the command line
54
54
// arguments and a vector of test_descs (generated at compile time).
55
- fn test_main ( args : ~[ ~str ] , tests : ~[ test_desc ] ) {
55
+ fn test_main ( args : ~[ ~str ] , tests : ~[ TestDesc ] ) {
56
56
let opts =
57
57
match parse_opts ( args) {
58
58
either:: Left ( o) => o,
@@ -61,13 +61,13 @@ fn test_main(args: ~[~str], tests: ~[test_desc]) {
61
61
if !run_tests_console ( opts, tests) { fail ~"Some tests failed"; }
62
62
}
63
63
64
- type test_opts = { filter : Option < ~str > , run_ignored : bool ,
64
+ type TestOpts = { filter : Option < ~str > , run_ignored : bool ,
65
65
logfile : Option < ~str > } ;
66
66
67
- type opt_res = Either < test_opts , ~str > ;
67
+ type OptRes = Either < TestOpts , ~str > ;
68
68
69
69
// Parses command line arguments into test options
70
- fn parse_opts ( args : ~[ ~str ] ) -> opt_res {
70
+ fn parse_opts ( args : ~[ ~str ] ) -> OptRes {
71
71
let args_ = vec:: tail ( args) ;
72
72
let opts = ~[ getopts:: optflag ( ~"ignored") , getopts:: optopt ( ~"logfile") ] ;
73
73
let matches =
@@ -90,55 +90,55 @@ fn parse_opts(args: ~[~str]) -> opt_res {
90
90
return either:: Left ( test_opts) ;
91
91
}
92
92
93
- enum test_result { tr_ok , tr_failed , tr_ignored , }
93
+ enum TestResult { TrOk , TrFailed , TrIgnored , }
94
94
95
- impl test_result : Eq {
96
- pure fn eq ( & & other: test_result ) -> bool {
95
+ impl TestResult : Eq {
96
+ pure fn eq ( & & other: TestResult ) -> bool {
97
97
( self as uint ) == ( other as uint )
98
98
}
99
99
}
100
100
101
- type console_test_state =
101
+ type ConsoleTestState =
102
102
@{ out : io:: Writer ,
103
103
log_out : Option < io:: Writer > ,
104
104
use_color : bool ,
105
105
mut total : uint ,
106
106
mut passed : uint ,
107
107
mut failed : uint ,
108
108
mut ignored : uint ,
109
- mut failures : ~[ test_desc ] } ;
109
+ mut failures : ~[ TestDesc ] } ;
110
110
111
111
// A simple console test runner
112
- fn run_tests_console( opts : test_opts ,
113
- tests : ~[ test_desc ] ) -> bool {
112
+ fn run_tests_console( opts : TestOpts ,
113
+ tests : ~[ TestDesc ] ) -> bool {
114
114
115
- fn callback ( event : testevent , st : console_test_state ) {
115
+ fn callback ( event : TestEvent , st : ConsoleTestState ) {
116
116
debug ! ( "callback(event=%?)" , event) ;
117
117
match event {
118
- te_filtered ( filtered_tests) => {
118
+ TeFiltered ( filtered_tests) => {
119
119
st. total = vec:: len ( filtered_tests) ;
120
120
let noun = if st. total != 1 u { ~"tests" } else { ~"test" } ;
121
121
st. out . write_line ( fmt ! ( "\n running %u %s" , st. total, noun) ) ;
122
122
}
123
- te_wait ( test) => st. out . write_str ( fmt ! ( "test %s ... " , test. name) ) ,
124
- te_result ( test, result) => {
123
+ TeWait ( test) => st. out . write_str ( fmt ! ( "test %s ... " , test. name) ) ,
124
+ TeResult ( test, result) => {
125
125
match st. log_out {
126
126
Some ( f) => write_log ( f, result, test) ,
127
127
None => ( )
128
128
}
129
129
match result {
130
- tr_ok => {
130
+ TrOk => {
131
131
st. passed += 1 u;
132
132
write_ok ( st. out , st. use_color ) ;
133
133
st. out . write_line ( ~"") ;
134
134
}
135
- tr_failed => {
135
+ TrFailed => {
136
136
st. failed += 1 u;
137
137
write_failed ( st. out , st. use_color ) ;
138
138
st. out . write_line ( ~"") ;
139
139
vec:: push ( st. failures , copy test) ;
140
140
}
141
- tr_ignored => {
141
+ TrIgnored => {
142
142
st. ignored += 1 u;
143
143
write_ignored ( st. out , st. use_color ) ;
144
144
st. out . write_line ( ~"") ;
@@ -188,12 +188,12 @@ fn run_tests_console(opts: test_opts,
188
188
189
189
return success;
190
190
191
- fn write_log( out : io:: Writer , result : test_result , test : test_desc ) {
191
+ fn write_log( out : io:: Writer , result : TestResult , test : TestDesc ) {
192
192
out. write_line ( fmt!( "%s %s" ,
193
193
match result {
194
- tr_ok => ~"ok",
195
- tr_failed => ~" failed",
196
- tr_ignored => ~" ignored"
194
+ TrOk => ~"ok",
195
+ TrFailed => ~" failed",
196
+ TrIgnored => ~" ignored"
197
197
}, test.name));
198
198
}
199
199
@@ -220,7 +220,7 @@ fn run_tests_console(opts: test_opts,
220
220
}
221
221
}
222
222
223
- fn print_failures(st: console_test_state ) {
223
+ fn print_failures(st: ConsoleTestState ) {
224
224
st.out.write_line(~" \n failures: ");
225
225
let failures = copy st.failures;
226
226
let failures = vec::map(failures, |test| test.name);
@@ -270,19 +270,19 @@ fn should_sort_failures_before_printing_them() {
270
270
271
271
fn use_color() -> bool { return get_concurrency() == 1u; }
272
272
273
- enum testevent {
274
- te_filtered (~[test_desc ]),
275
- te_wait(test_desc ),
276
- te_result(test_desc, test_result ),
273
+ enum TestEvent {
274
+ TeFiltered (~[TestDesc ]),
275
+ TeWait(TestDesc ),
276
+ TeResult(TestDesc, TestResult ),
277
277
}
278
278
279
- type monitor_msg = (test_desc, test_result );
279
+ type MonitorMsg = (TestDesc, TestResult );
280
280
281
- fn run_tests(opts: test_opts , tests: ~[test_desc ],
282
- callback: fn@(testevent )) {
281
+ fn run_tests(opts: TestOpts , tests: ~[TestDesc ],
282
+ callback: fn@(TestEvent )) {
283
283
284
284
let mut filtered_tests = filter_tests(opts, tests);
285
- callback(te_filtered (copy filtered_tests));
285
+ callback(TeFiltered (copy filtered_tests));
286
286
287
287
// It's tempting to just spawn all the tests at once, but since we have
288
288
// many tests that run in other processes we would be making a big mess.
@@ -304,7 +304,7 @@ fn run_tests(opts: test_opts, tests: ~[test_desc],
304
304
// We are doing one test at a time so we can print the name
305
305
// of the test before we run it. Useful for debugging tests
306
306
// that hang forever.
307
- callback(te_wait (copy test));
307
+ callback(TeWait (copy test));
308
308
}
309
309
run_test(test, ch);
310
310
wait_idx += 1u;
@@ -313,9 +313,9 @@ fn run_tests(opts: test_opts, tests: ~[test_desc],
313
313
314
314
let (test, result) = core::comm::recv(p);
315
315
if concurrency != 1u {
316
- callback(te_wait (copy test));
316
+ callback(TeWait (copy test));
317
317
}
318
- callback(te_result (test, result));
318
+ callback(TeResult (test, result));
319
319
wait_idx -= 1u;
320
320
done_idx += 1u;
321
321
}
@@ -335,8 +335,8 @@ fn get_concurrency() -> uint {
335
335
}
336
336
337
337
#[allow(non_implicitly_copyable_typarams)]
338
- fn filter_tests(opts: test_opts ,
339
- tests: ~[test_desc ]) -> ~[test_desc ] {
338
+ fn filter_tests(opts: TestOpts ,
339
+ tests: ~[TestDesc ]) -> ~[TestDesc ] {
340
340
let mut filtered = copy tests;
341
341
342
342
// Remove tests that don't match the test filter
@@ -349,8 +349,8 @@ fn filter_tests(opts: test_opts,
349
349
option::None => ~" "
350
350
};
351
351
352
- fn filter_fn(test: test_desc , filter_str: ~str) ->
353
- Option<test_desc > {
352
+ fn filter_fn(test: TestDesc , filter_str: ~str) ->
353
+ Option<TestDesc > {
354
354
if str::contains(test.name, filter_str) {
355
355
return option::Some(copy test);
356
356
} else { return option::None; }
@@ -363,7 +363,7 @@ fn filter_tests(opts: test_opts,
363
363
filtered = if !opts.run_ignored {
364
364
filtered
365
365
} else {
366
- fn filter(test: test_desc ) -> Option<test_desc > {
366
+ fn filter(test: TestDesc ) -> Option<TestDesc > {
367
367
if test.ignore {
368
368
return option::Some({name: test.name,
369
369
fn: copy test.fn,
@@ -377,7 +377,7 @@ fn filter_tests(opts: test_opts,
377
377
378
378
// Sort the tests alphabetically
379
379
filtered = {
380
- pure fn lteq(t1: &test_desc , t2: &test_desc ) -> bool {
380
+ pure fn lteq(t1: &TestDesc , t2: &TestDesc ) -> bool {
381
381
str::le(t1.name, t2.name)
382
382
}
383
383
sort::merge_sort(lteq, filtered)
@@ -386,11 +386,11 @@ fn filter_tests(opts: test_opts,
386
386
return filtered;
387
387
}
388
388
389
- type test_future = {test: test_desc , wait: fn@() -> test_result };
389
+ type TestFuture = {test: TestDesc , wait: fn@() -> TestResult };
390
390
391
- fn run_test(+test: test_desc , monitor_ch: comm::Chan<monitor_msg >) {
391
+ fn run_test(+test: TestDesc , monitor_ch: comm::Chan<MonitorMsg >) {
392
392
if test.ignore {
393
- core::comm::send(monitor_ch, (copy test, tr_ignored ));
393
+ core::comm::send(monitor_ch, (copy test, TrIgnored ));
394
394
return;
395
395
}
396
396
@@ -406,13 +406,13 @@ fn run_test(+test: test_desc, monitor_ch: comm::Chan<monitor_msg>) {
406
406
};
407
407
}
408
408
409
- fn calc_result(test: test_desc , task_succeeded: bool) -> test_result {
409
+ fn calc_result(test: TestDesc , task_succeeded: bool) -> TestResult {
410
410
if task_succeeded {
411
- if test.should_fail { tr_failed }
412
- else { tr_ok }
411
+ if test.should_fail { TrFailed }
412
+ else { TrOk }
413
413
} else {
414
- if test.should_fail { tr_ok }
415
- else { tr_failed }
414
+ if test.should_fail { TrOk }
415
+ else { TrFailed }
416
416
}
417
417
}
418
418
@@ -432,7 +432,7 @@ mod tests {
432
432
let ch = core::comm::Chan(p);
433
433
run_test(desc, ch);
434
434
let (_, res) = core::comm::recv(p);
435
- assert res != tr_ok ;
435
+ assert res != TrOk ;
436
436
}
437
437
438
438
#[test]
@@ -448,7 +448,7 @@ mod tests {
448
448
let ch = core::comm::Chan(p);
449
449
run_test(desc, ch);
450
450
let (_, res) = core::comm::recv(p);
451
- assert res == tr_ignored ;
451
+ assert res == TrIgnored ;
452
452
}
453
453
454
454
#[test]
@@ -465,7 +465,7 @@ mod tests {
465
465
let ch = core::comm::Chan(p);
466
466
run_test(desc, ch);
467
467
let (_, res) = core::comm::recv(p);
468
- assert res == tr_ok ;
468
+ assert res == TrOk ;
469
469
}
470
470
471
471
#[test]
@@ -481,7 +481,7 @@ mod tests {
481
481
let ch = core::comm::Chan(p);
482
482
run_test(desc, ch);
483
483
let (_, res) = core::comm::recv(p);
484
- assert res == tr_failed ;
484
+ assert res == TrFailed ;
485
485
}
486
486
487
487
#[test]
0 commit comments