32
32
html_favicon_url = "http://www.rust-lang.org/favicon.ico" ,
33
33
html_root_url = "http://static.rust-lang.org/doc/master" ) ]
34
34
35
- #![ feature( asm, macro_rules) ]
35
+ #![ feature( asm, macro_rules, phase ) ]
36
36
#![ deny( deprecated_owned_vector) ]
37
37
38
38
extern crate collections;
@@ -83,7 +83,7 @@ pub mod stats;
83
83
// colons. This way if some test runner wants to arrange the tests
84
84
// hierarchically it may.
85
85
86
- #[ deriving( Clone ) ]
86
+ #[ deriving( Clone , Eq , TotalEq , Hash ) ]
87
87
pub enum TestName {
88
88
StaticTestName ( & ' static str ) ,
89
89
DynTestName ( StrBuf )
@@ -156,6 +156,19 @@ impl TestFn {
156
156
}
157
157
}
158
158
159
+ impl fmt:: Show for TestFn {
160
+ fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
161
+ f. write ( match * self {
162
+ StaticTestFn ( ..) => "StaticTestFn(..)" ,
163
+ StaticBenchFn ( ..) => "StaticBenchFn(..)" ,
164
+ StaticMetricFn ( ..) => "StaticMetricFn(..)" ,
165
+ DynTestFn ( ..) => "DynTestFn(..)" ,
166
+ DynMetricFn ( ..) => "DynMetricFn(..)" ,
167
+ DynBenchFn ( ..) => "DynBenchFn(..)"
168
+ } . as_bytes ( ) )
169
+ }
170
+ }
171
+
159
172
/// Manager of the benchmarking runs.
160
173
///
161
174
/// This is feed into functions marked with `#[bench]` to allow for
@@ -170,13 +183,14 @@ pub struct Bencher {
170
183
171
184
// The definition of a single test. A test runner will run a list of
172
185
// these.
173
- #[ deriving( Clone ) ]
186
+ #[ deriving( Clone , Show , Eq , TotalEq , Hash ) ]
174
187
pub struct TestDesc {
175
188
pub name : TestName ,
176
189
pub ignore : bool ,
177
190
pub should_fail : bool ,
178
191
}
179
192
193
+ #[ deriving( Show ) ]
180
194
pub struct TestDescAndFn {
181
195
pub desc : TestDesc ,
182
196
pub testfn : TestFn ,
@@ -242,15 +256,9 @@ pub fn test_main(args: &[StrBuf], tests: Vec<TestDescAndFn> ) {
242
256
pub fn test_main_static ( args : & [ StrBuf ] , tests : & [ TestDescAndFn ] ) {
243
257
let owned_tests = tests. iter ( ) . map ( |t| {
244
258
match t. testfn {
245
- StaticTestFn ( f) =>
246
- TestDescAndFn { testfn : StaticTestFn ( f) , desc : t. desc . clone ( ) } ,
247
-
248
- StaticBenchFn ( f) =>
249
- TestDescAndFn { testfn : StaticBenchFn ( f) , desc : t. desc . clone ( ) } ,
250
-
251
- _ => {
252
- fail ! ( "non-static tests passed to test::test_main_static" ) ;
253
- }
259
+ StaticTestFn ( f) => TestDescAndFn { testfn : StaticTestFn ( f) , desc : t. desc . clone ( ) } ,
260
+ StaticBenchFn ( f) => TestDescAndFn { testfn : StaticBenchFn ( f) , desc : t. desc . clone ( ) } ,
261
+ _ => fail ! ( "non-static tests passed to test::test_main_static" )
254
262
}
255
263
} ) . collect ( ) ;
256
264
test_main ( args, owned_tests)
@@ -419,8 +427,15 @@ pub fn opt_shard(maybestr: Option<StrBuf>) -> Option<(uint,uint)> {
419
427
None => None ,
420
428
Some ( s) => {
421
429
let mut it = s. as_slice ( ) . split ( '.' ) ;
422
- match ( it. next ( ) . and_then ( from_str) , it. next ( ) . and_then ( from_str) , it. next ( ) ) {
423
- ( Some ( a) , Some ( b) , None ) => Some ( ( a, b) ) ,
430
+ match ( it. next ( ) . and_then ( from_str :: < uint > ) , it. next ( ) . and_then ( from_str :: < uint > ) ,
431
+ it. next ( ) ) {
432
+ ( Some ( a) , Some ( b) , None ) => {
433
+ if a <= 0 || a > b {
434
+ fail ! ( "tried to run shard {a}.{b}, but {a} is out of bounds \
435
+ (should be between 1 and {b}", a=a, b=b)
436
+ }
437
+ Some ( ( a, b) )
438
+ }
424
439
_ => None ,
425
440
}
426
441
}
@@ -739,10 +754,9 @@ pub fn fmt_bench_samples(bs: &BenchSamples) -> StrBuf {
739
754
}
740
755
741
756
// A simple console test runner
742
- pub fn run_tests_console ( opts : & TestOpts ,
743
- tests : Vec < TestDescAndFn > ) -> io:: IoResult < bool > {
744
- fn callback < T : Writer > ( event : & TestEvent ,
745
- st : & mut ConsoleTestState < T > ) -> io:: IoResult < ( ) > {
757
+ pub fn run_tests_console ( opts : & TestOpts , tests : Vec < TestDescAndFn > ) -> io:: IoResult < bool > {
758
+
759
+ fn callback < T : Writer > ( event : & TestEvent , st : & mut ConsoleTestState < T > ) -> io:: IoResult < ( ) > {
746
760
match ( * event) . clone ( ) {
747
761
TeFiltered ( ref filtered_tests) => st. write_run_start ( filtered_tests. len ( ) ) ,
748
762
TeWait ( ref test, padding) => st. write_test_start ( test, padding) ,
@@ -778,6 +792,7 @@ pub fn run_tests_console(opts: &TestOpts,
778
792
}
779
793
}
780
794
}
795
+
781
796
let mut st = try!( ConsoleTestState :: new ( opts, None :: < StdWriter > ) ) ;
782
797
fn len_if_padded ( t : & TestDescAndFn ) -> uint {
783
798
match t. testfn . padding ( ) {
@@ -933,9 +948,7 @@ fn get_concurrency() -> uint {
933
948
}
934
949
}
935
950
936
- pub fn filter_tests (
937
- opts : & TestOpts ,
938
- tests : Vec < TestDescAndFn > ) -> Vec < TestDescAndFn > {
951
+ pub fn filter_tests ( opts : & TestOpts , tests : Vec < TestDescAndFn > ) -> Vec < TestDescAndFn > {
939
952
let mut filtered = tests;
940
953
941
954
// Remove tests that don't match the test filter
@@ -973,7 +986,9 @@ pub fn filter_tests(
973
986
None => filtered,
974
987
Some ( ( a, b) ) => {
975
988
filtered. move_iter ( ) . enumerate ( )
976
- . filter ( |& ( i, _) | i % b == a)
989
+ // note: using a - 1 so that the valid shards, for example, are
990
+ // 1.2 and 2.2 instead of 0.2 and 1.2
991
+ . filter ( |& ( i, _) | i % b == ( a - 1 ) )
977
992
. map ( |( _, t) | t)
978
993
. collect ( )
979
994
}
0 commit comments