@@ -28,6 +28,8 @@ struct TestOptions {
28
28
help : bool ,
29
29
#[ options( help = "run tests" ) ]
30
30
test : bool ,
31
+ #[ options( help = "run single tests" ) ]
32
+ test_single : Option < String > ,
31
33
#[ options( help = "count cycles" ) ]
32
34
cycles : bool ,
33
35
#[ options( help = "set SPS seed" , parse( try_from_str = "parse_hex" ) ) ]
@@ -44,28 +46,36 @@ struct TestOptions {
44
46
fn main ( ) {
45
47
let options = TestOptions :: parse_args_default_or_exit ( ) ;
46
48
49
+ let tests: [ ( & str , fn ( ) ) ; 10 ] = [
50
+ ( "garbage4" , garbage:: test_garbage4_crash) ,
51
+ ( "floor" , floor:: test) ,
52
+ ( "tspins" , tspins:: test) ,
53
+ ( "top row bug" , toprow:: test) ,
54
+ ( "score" , score:: test) ,
55
+ ( "score_render" , score:: test_render) ,
56
+ ( "pushdown" , pushdown:: test) ,
57
+ ( "rng seeds" , rng:: test) ,
58
+ ( "sps" , sps:: test) ,
59
+ ( "palettes" , palettes:: test) ,
60
+ ] ;
61
+
47
62
// run tests
48
63
if options. test {
49
- garbage:: test_garbage4_crash ( ) ;
50
- println ! ( ">> garbage4 ✅" ) ;
51
- floor:: test ( ) ;
52
- println ! ( ">> floor ✅" ) ;
53
- tspins:: test ( ) ;
54
- println ! ( ">> tspins ✅" ) ;
55
- toprow:: test ( ) ;
56
- println ! ( ">> top row bug ✅" ) ;
57
- score:: test ( ) ;
58
- println ! ( ">> score ✅" ) ;
59
- score:: test_render ( ) ;
60
- println ! ( ">> score rendering ✅" ) ;
61
- pushdown:: test ( ) ;
62
- println ! ( ">> pushdown ✅" ) ;
63
- rng:: test ( ) ;
64
- println ! ( ">> rng seeds ✅" ) ;
65
- sps:: test ( ) ;
66
- println ! ( ">> sps ✅" ) ;
67
- palettes:: test_palettes ( ) ;
68
- println ! ( ">> palettes ✅" ) ;
64
+ tests. iter ( ) . for_each ( |( name, test) | {
65
+ test ( ) ;
66
+ println ! ( ">> {name} ✅" ) ;
67
+ } ) ;
68
+ }
69
+
70
+ // run single test
71
+ if let Some ( name) = options. test_single {
72
+ let found = tests. iter ( ) . find ( |& test| test. 0 == name) ;
73
+ if let Some ( test) = found {
74
+ test. 1 ( ) ;
75
+ println ! ( ">> {name} ✅" ) ;
76
+ } else {
77
+ println ! ( "no such test {name}" ) ;
78
+ }
69
79
}
70
80
71
81
// count cycles
0 commit comments