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