17
17
18
18
19
19
use getopts;
20
+ use getopts:: groups;
20
21
use json:: ToJson ;
21
22
use json;
22
23
use serialize:: Decodable ;
@@ -28,6 +29,7 @@ use time::precise_time_ns;
28
29
use treemap:: TreeMap ;
29
30
30
31
use std:: comm:: { stream, SharedChan } ;
32
+ use std:: libc;
31
33
use std:: either;
32
34
use std:: io;
33
35
use std:: result;
@@ -156,22 +158,64 @@ pub struct TestOpts {
156
158
157
159
type OptRes = Either < TestOpts , ~str > ;
158
160
161
+ fn optgroups ( ) -> ~[ getopts:: groups:: OptGroup ] {
162
+ ~[ groups:: optflag ( "" , "ignored" , "Run ignored tests" ) ,
163
+ groups:: optflag ( "" , "test" , "Run tests and not benchmarks" ) ,
164
+ groups:: optflag ( "" , "bench" , "Run benchmarks instead of tests" ) ,
165
+ groups:: optflag ( "h" , "help" , "Display this message (longer with --help)" ) ,
166
+ groups:: optopt ( "" , "save-metrics" , "Location to save bench metrics" ,
167
+ "PATH" ) ,
168
+ groups:: optopt ( "" , "ratchet-metrics" ,
169
+ "Location to load and save metrics from. The metrics \
170
+ loaded are cause benchmarks to fail if they run too \
171
+ slowly", "PATH" ) ,
172
+ groups:: optopt ( "" , "ratchet-noise-percent" ,
173
+ "Tests within N% of the recorded metrics will be \
174
+ considered as passing", "PERCENTAGE" ) ,
175
+ groups:: optopt ( "" , "logfile" , "Write logs to the specified file instead \
176
+ of stdout", "PATH" ) ]
177
+ }
178
+
179
+ fn usage ( binary : & str , helpstr : & str ) -> ! {
180
+ let message = fmt ! ( "Usage: %s [OPTIONS] [FILTER]" , binary) ;
181
+ println ( groups:: usage ( message, optgroups ( ) ) ) ;
182
+ if helpstr == "help" {
183
+ println ( "\
184
+ The FILTER is matched against the name of all tests to run, and if any tests
185
+ have a substring match, only those tests are run.
186
+
187
+ By default, all tests are run in parallel. This can be altered with the
188
+ RUST_THREADS environment variable when running tests (set it to 1).
189
+
190
+ Test Attributes:
191
+
192
+ #[test] - Indicates a function is a test to be run. This function
193
+ takes no arguments.
194
+ #[bench] - Indicates a function is a benchmark to be run. This
195
+ function takes one argument (extra::test::BenchHarness).
196
+ #[should_fail] - This function (also labeled with #[test]) will only pass if
197
+ the code causes a failure (an assertion failure or fail!)
198
+ #[ignore] - When applied to a function which is already attributed as a
199
+ test, then the test runner will ignore these tests during
200
+ normal test runs. Running with --ignored will run these
201
+ tests. This may also be written as #[ignore(cfg(...))] to
202
+ ignore the test on certain configurations." ) ;
203
+ }
204
+ unsafe { libc:: exit ( 0 ) }
205
+ }
206
+
159
207
// Parses command line arguments into test options
160
208
pub fn parse_opts ( args : & [ ~str ] ) -> OptRes {
161
209
let args_ = args. tail ( ) ;
162
- let opts = ~[ getopts:: optflag ( "ignored" ) ,
163
- getopts:: optflag ( "test" ) ,
164
- getopts:: optflag ( "bench" ) ,
165
- getopts:: optopt ( "save-metrics" ) ,
166
- getopts:: optopt ( "ratchet-metrics" ) ,
167
- getopts:: optopt ( "ratchet-noise-percent" ) ,
168
- getopts:: optopt ( "logfile" ) ] ;
169
210
let matches =
170
- match getopts :: getopts ( args_, opts ) {
211
+ match groups :: getopts ( args_, optgroups ( ) ) {
171
212
Ok ( m) => m,
172
213
Err ( f) => return either:: Right ( getopts:: fail_str ( f) )
173
214
} ;
174
215
216
+ if getopts:: opt_present ( & matches, "h" ) { usage ( args[ 0 ] , "h" ) ; }
217
+ if getopts:: opt_present ( & matches, "help" ) { usage ( args[ 0 ] , "help" ) ; }
218
+
175
219
let filter =
176
220
if matches. free . len ( ) > 0 {
177
221
Some ( copy ( matches) . free [ 0 ] )
0 commit comments