Skip to content

Commit 8320372

Browse files
committed
allow running a single test at once
1 parent 6af4023 commit 8320372

File tree

2 files changed

+297
-290
lines changed

2 files changed

+297
-290
lines changed

tests/src/main.rs

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ struct TestOptions {
2828
help: bool,
2929
#[options(help = "run tests")]
3030
test: bool,
31+
#[options(help = "run single tests")]
32+
test_single: Option<String>,
3133
#[options(help = "count cycles")]
3234
cycles: bool,
3335
#[options(help = "set SPS seed", parse(try_from_str = "parse_hex"))]
@@ -44,28 +46,36 @@ struct TestOptions {
4446
fn main() {
4547
let options = TestOptions::parse_args_default_or_exit();
4648

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+
4762
// run tests
4863
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+
}
6979
}
7080

7181
// count cycles

0 commit comments

Comments
 (0)