@@ -8,10 +8,13 @@ export test_fn;
8
8
export test_desc;
9
9
export test_main;
10
10
export test_result;
11
+ export test_opts;
11
12
export tr_ok;
12
13
export tr_failed;
13
14
export tr_ignored;
14
15
export run_test;
16
+ export filter_tests;
17
+ export parse_opts;
15
18
16
19
// The name of a test. By convention this follows the rules for rust
17
20
// paths, i.e it should be a series of identifiers seperated by double
@@ -34,19 +37,52 @@ type test_desc = rec(test_name name,
34
37
// The default console test runner. It accepts the command line
35
38
// arguments and a vector of test_descs (generated at compile time).
36
39
fn test_main( & vec[ str] args , & test_desc[ ] tests) {
37
- if ( !run_tests( parse_opts( args) , tests) ) {
40
+ auto ivec_args = {
41
+ auto iargs = ~[ ] ;
42
+ for ( str arg in args) {
43
+ iargs += ~[ arg ]
44
+ }
45
+ iargs
46
+ } ;
47
+ check ivec:: is_not_empty ( ivec_args) ;
48
+ auto opts = alt ( parse_opts ( ivec_args) ) {
49
+ either:: left ( ?o) { o }
50
+ either:: right ( ?m) { fail m }
51
+ } ;
52
+ if ( !run_tests ( opts, tests) ) {
38
53
fail "Some tests failed" ;
39
54
}
40
55
}
41
56
42
- type test_opts = rec ( option:: t[ str] filter ) ;
57
+ type test_opts = rec ( option:: t[ str] filter,
58
+ bool run_ignored) ;
59
+
60
+ type opt_res = either:: t[ test_opts, str ] ;
61
+
62
+ // Parses command line arguments into test options
63
+ fn parse_opts( & str[ ] args) : ivec:: is_not_empty ( args) -> opt_res {
64
+
65
+ // FIXME (#649): Shouldn't have to check here
66
+ check ivec:: is_not_empty ( args) ;
67
+ auto args_ = ivec:: tail ( args) ;
68
+ auto opts = ~[ getopts:: optflag ( "ignored" ) ] ;
69
+ auto match = alt ( getopts:: getopts_ivec ( args_, opts) ) {
70
+ getopts:: success ( ?m) { m }
71
+ getopts:: failure ( ?f) { ret either:: right ( getopts:: fail_str ( f) ) }
72
+ } ;
73
+
74
+ auto filter = if ( vec:: len( match . free ) > 0 u) {
75
+ option:: some ( match . free. ( 0 ) )
76
+ } else {
77
+ option:: none
78
+ } ;
79
+
80
+ auto run_ignored = getopts:: opt_present( match , "ignored" ) ;
81
+
82
+ auto test_opts = rec ( filter = filter,
83
+ run_ignored = run_ignored) ;
43
84
44
- fn parse_opts ( & vec[ str] args) -> test_opts {
45
- rec( filter = if ( vec:: len ( args) > 1 u) {
46
- option:: some ( args. ( 1 ) )
47
- } else {
48
- option:: none
49
- } )
85
+ ret either:: left ( test_opts) ;
50
86
}
51
87
52
88
tag test_result {
@@ -135,23 +171,43 @@ fn run_tests(&test_opts opts, &test_desc[] tests) -> bool {
135
171
}
136
172
137
173
fn filter_tests( & test_opts opts, & test_desc[ ] tests) -> test_desc[ ] {
138
- if ( option:: is_none ( opts. filter ) ) {
139
- ret tests ;
140
- }
174
+ auto filtered = tests;
141
175
142
- auto filter_str = alt opts. filter { option:: some ( ?f) { f }
143
- option:: none { "" } } ;
176
+ filtered = if ( option:: is_none( opts. filter) ) {
177
+ filtered
178
+ } else {
179
+ auto filter_str = alt opts. filter { option : : some( ?f) { f }
180
+ option:: none { "" } } ;
181
+
182
+ auto filter = bind fn( & test_desc test,
183
+ str filter_str) -> option:: t[ test_desc] {
184
+ if ( str:: find( test. name, filter_str) >= 0 ) {
185
+ ret option:: some( test) ;
186
+ } else {
187
+ ret option:: none;
188
+ }
189
+ } ( _, filter_str) ;
144
190
145
- auto filter = bind fn( & test_desc test,
146
- str filter_str) -> option:: t[ test_desc] {
147
- if ( str:: find ( test. name , filter_str) >= 0 ) {
148
- ret option:: some ( test) ;
149
- } else {
150
- ret option:: none;
151
- }
152
- } ( _, filter_str) ;
191
+ ivec:: filter_map( filter, filtered)
192
+ } ;
193
+
194
+ filtered = if ( !opts. run_ignored) {
195
+ filtered
196
+ } else {
197
+ auto filter = fn ( & test_desc test) -> option:: t[ test_desc] {
198
+ if ( test. ignore) {
199
+ ret option:: some( rec( name = test. name,
200
+ fn = test. fn ,
201
+ ignore = false) ) ;
202
+ } else {
203
+ ret option:: none;
204
+ }
205
+ } ;
206
+
207
+ ivec:: filter_map( filter, filtered)
208
+ } ;
153
209
154
- ret ivec :: filter_map ( filter , tests ) ;
210
+ ret filtered ;
155
211
}
156
212
157
213
fn run_test( & test_desc test) -> test_result {
0 commit comments