Skip to content

Commit af2acf9

Browse files
committed
make animations use fixed randomness in tests
1 parent 60e861e commit af2acf9

18 files changed

Lines changed: 360 additions & 216 deletions

TODO

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ weapon slots
4848
- etherblast to hit ghosts in walls
4949
- emergency teleport
5050
spells
51+
- powerword kill
52+
- rot living flesh
53+
- more lich like spells
5154
- spell points to collect
5255
- all spells are availabl
5356
- spell coupons

src/globals.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ bool g_opt_quick_start; // Start in the main menu
2727
bool g_opt_restarted_in_gfx_menu; // Post restart
2828
bool g_opt_restarted; // Post restart
2929
bool g_opt_tests; // Run tests.
30+
int g_opt_test_repeat; // Repeat tests.
3031
bool g_ptrcheck_inited; // Ptrcheck is active
3132
bool g_quitting; // Exiting the game
3233
bool g_skip_audio_and_gfx; // For tests

src/main.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ static void usage()
7474
con(" --quick-start -- Quick start inside level.");
7575
con(" --test <name> -- Run test foo only.");
7676
con(" --tests -- Run all tests.");
77+
con(" --repeat <n> -- Repeat tests n times.");
7778
con(" ");
7879
con("Code generation:");
7980
con(" --do-level-gen -- Do level gen only.");
@@ -206,6 +207,27 @@ static void parse_args(int argc, char *argv[])
206207
continue;
207208
}
208209

210+
if ((strcasecmp(argv[ i ], "--repeat") == 0) || (strcasecmp(argv[ i ], "-repeat") == 0)) {
211+
if (i == argc - 1) {
212+
usage();
213+
CROAK("missing parameter for argument, %s", argv[ i ]);
214+
}
215+
216+
char *p = nullptr; // NOLINT
217+
auto num = strtol(argv[ i + 1 ], &p, 10);
218+
if (*p != 0) {
219+
//
220+
// Level name
221+
//
222+
CROAK("specify an integer for parameter, %s", argv[ i ]);
223+
} else if (num > 0) {
224+
g_opt_test_repeat = num;
225+
}
226+
227+
i++;
228+
continue;
229+
}
230+
209231
if ((strcasecmp(argv[ i ], "--do-room-gen") == 0) || (strcasecmp(argv[ i ], "-do-room-gen") == 0)) {
210232
g_opt_do_room_gen = true;
211233
g_skip_audio_and_gfx = true;

src/my_globals.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extern bool g_opt_quick_start; // Start in the main menu
2525
extern bool g_opt_restarted_in_gfx_menu; // Post restart
2626
extern bool g_opt_restarted; // Post restart
2727
extern bool g_opt_tests; // Dungeon tests
28+
extern int g_opt_test_repeat; // Repeat tests
2829
extern bool g_ptrcheck_inited; // Ptrcheck is active
2930
extern bool g_quitting; // Exiting the game
3031
extern bool g_skip_audio_and_gfx; // For tests

src/test.cpp

Lines changed: 135 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -259,119 +259,154 @@ void tests_run(Gamep g)
259259
term_log("Running tests\n");
260260
term_log("-------------\n");
261261

262-
for (auto &test : test_name_map) {
263-
264-
bool result = false;
265-
bool skipped = false;
266-
267-
//
268-
// Test name
269-
//
270-
auto name = "test_" + test.first;
271-
auto *t = test.second;
272-
auto pre = std::format("Running {:<70s}", name);
273-
274-
//
275-
// Skip the test if needed
276-
//
277-
if (! g_opt_test_name_filter.empty()) {
278-
if (g_opt_test_name_filter == "all") {
279-
//
280-
// All tests or "--tests"
281-
//
282-
} else if (name.find(g_opt_test_name_filter) != std::string::npos) {
283-
//
284-
// Partial match e.g. "monst" for all monst tests
285-
//
286-
} else if (name != g_opt_test_name_filter) {
287-
//
288-
// Failed to match
289-
//
290-
skipped = true;
291-
continue;
262+
bool found_match = {};
263+
bool exact_match_found = {};
264+
265+
if (! g_opt_test_name_filter.empty()) {
266+
for (auto &test : test_name_map) {
267+
auto name = "test_" + test.first;
268+
if (g_opt_test_name_filter == name) {
269+
exact_match_found = true;
292270
}
293271
}
272+
}
294273

295-
g_opt_test_current = name;
274+
if (! g_opt_test_repeat) {
275+
g_opt_test_repeat = 1;
276+
}
296277

297-
//
298-
// Preamble
299-
//
300-
if (! skipped) {
301-
log("running test: %s", name.c_str());
302-
log("-------------------------------------------");
303-
}
278+
for (auto repeat = 0; repeat < g_opt_test_repeat; repeat++) {
279+
for (auto &test : test_name_map) {
280+
281+
bool result = false;
282+
bool skipped = false;
283+
284+
//
285+
// Test name
286+
//
287+
auto name = "test_" + test.first;
288+
auto *t = test.second;
289+
auto pre = std::format("Running {:<70s}", name);
290+
291+
//
292+
// Skip the test if needed
293+
//
294+
if (! g_opt_test_name_filter.empty()) {
295+
if (g_opt_test_name_filter == "all") {
296+
//
297+
// All tests or "--tests"
298+
//
299+
found_match = true;
300+
} else if (exact_match_found) {
301+
//
302+
// Exact match
303+
//
304+
if (g_opt_test_name_filter == name) {
305+
found_match = true;
306+
} else {
307+
continue;
308+
}
309+
} else if (name.find(g_opt_test_name_filter) != std::string::npos) {
310+
//
311+
// Partial match e.g. "monst" for all monst tests
312+
//
313+
found_match = true;
314+
} else if (name != g_opt_test_name_filter) {
315+
//
316+
// Failed to match
317+
//
318+
skipped = true;
319+
continue;
320+
}
321+
}
304322

305-
//
306-
// Run the test
307-
//
308-
auto started = time_ms();
309-
if (! skipped) {
310-
result = t->callback(g, t);
311-
}
312-
auto elapsed = time_ms() - started;
313-
auto how_long = std::format("(took {:.2f} secs, {} ms)", static_cast< float >(elapsed) / 1000.0, elapsed);
323+
g_opt_test_current = name;
314324

315-
//
316-
// Print the timestamp
317-
//
318-
char buf[ MAXLONGSTR ];
319-
buf[ 0 ] = '\0';
320-
get_timestamp(buf, MAXLONGSTR);
325+
//
326+
// Preamble
327+
//
328+
if (! skipped) {
329+
log("running test: %s", name.c_str());
330+
log("-------------------------------------------");
331+
}
332+
333+
//
334+
// Run the test
335+
//
336+
auto started = time_ms();
337+
if (! skipped) {
338+
result = t->callback(g, t);
339+
}
340+
auto elapsed = time_ms() - started;
341+
auto how_long = std::format("(took {:.2f} secs, {} ms)", static_cast< float >(elapsed) / 1000.0, elapsed);
342+
343+
//
344+
// Print the timestamp
345+
//
346+
char buf[ MAXLONGSTR ];
347+
buf[ 0 ] = '\0';
348+
get_timestamp(buf, MAXLONGSTR);
321349

322350
#ifdef GITHUB_BUILD
323-
std::string out(buf);
324-
325-
//
326-
// Test preamble. We print this after the test has ran to avoid messing up the output.
327-
//
328-
out += pre;
329-
330-
if (skipped) {
331-
out += "skipped";
332-
} else if (result) {
333-
passed++;
334-
out += "OK ";
335-
out += how_long;
336-
337-
log("passed %s", how_long.c_str());
338-
} else {
339-
failed++;
340-
out += "FAILED";
341-
log("failed");
342-
}
343-
std::println("{}", out);
351+
std::string out(buf);
352+
353+
//
354+
// Test preamble. We print this after the test has ran to avoid messing up the output.
355+
//
356+
out += pre;
357+
358+
if (skipped) {
359+
out += "skipped";
360+
} else if (result) {
361+
passed++;
362+
out += "OK ";
363+
out += how_long;
364+
365+
log("passed %s", how_long.c_str());
366+
} else {
367+
failed++;
368+
out += "FAILED";
369+
log("failed");
370+
}
371+
std::println("{}", out);
344372
#else
345-
term_log(buf);
346-
//
347-
// Test preamble. We print this after the test has ran to avoid messing up the output.
348-
//
349-
term_log(pre.c_str());
350-
351-
if (skipped) {
352-
term_log("%%fg=yellow$skipped%%fg=reset$\n");
353-
} else if (result) {
354-
passed++;
355-
term_log("%%fg=green$OK%%fg=reset$ ");
356-
term_log(how_long.c_str());
357-
term_log("\n");
358-
log("passed %s", how_long.c_str());
359-
} else {
360-
failed++;
361-
term_log("%%fg=red$FAILED%%fg=reset$\n");
362-
log("failed");
363-
}
373+
term_log(buf);
374+
//
375+
// Test preamble. We print this after the test has ran to avoid messing up the output.
376+
//
377+
term_log(pre.c_str());
378+
379+
if (skipped) {
380+
term_log("%%fg=yellow$skipped%%fg=reset$\n");
381+
} else if (result) {
382+
passed++;
383+
term_log("%%fg=green$OK%%fg=reset$ ");
384+
term_log(how_long.c_str());
385+
term_log("\n");
386+
log("passed %s", how_long.c_str());
387+
} else {
388+
failed++;
389+
term_log("%%fg=red$FAILED%%fg=reset$\n");
390+
log("failed");
391+
}
364392
#endif
365393

366-
if (! skipped) {
367-
log("-");
394+
if (! skipped) {
395+
log("-");
396+
}
397+
398+
//
399+
// github output seems to be buffered.
400+
//
401+
fflush(stdout);
402+
fflush(stderr);
368403
}
404+
}
369405

370-
//
371-
// github output seems to be buffered.
372-
//
373-
fflush(stdout);
374-
fflush(stderr);
406+
if (! g_opt_test_name_filter.empty()) {
407+
if (! found_match) {
408+
CROAK("found no test matching filter: %s", g_opt_test_name_filter.c_str());
409+
}
375410
}
376411

377412
test_fini();

src/tests/test_brazier_shove_into_mob.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"......."
3535
"......."
3636
"..@B!.."
37-
".....m."
37+
"......."
3838
"......."
3939
".......";
4040
std::string const expect2 // second shove, mob should be dead by now

src/tests/test_laser_over_water.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
= "xxxxxxxxxxxxxx"
3232
"x............x"
3333
"x............x"
34-
"x@:::::::::::x"
34+
"x@~:::~::~:~:x"
3535
"x............x"
3636
"x............x"
3737
"xxxxxxxxxxxxxx";
@@ -49,11 +49,11 @@
4949
}
5050

5151
//
52-
// Wait for the laser to ignite a barrel
52+
// Wait for the steam
5353
//
5454
level_dump(g, v, l, w, h);
5555
TEST_PROGRESS(t);
56-
for (auto tries = 0; tries < 5; tries++) {
56+
for (auto tries = 0; tries < 10; tries++) {
5757
TEST_LOG(t, "try: %d", tries);
5858
(void) player_fire(g, v, l, 1, 0, tp_laser_fire, bpoint(13, 3));
5959
TRACE();
@@ -71,7 +71,7 @@
7171
goto exit;
7272
}
7373

74-
TEST_ASSERT(t, game_tick_get(g, v) == 5, "final tick counter value");
74+
TEST_ASSERT(t, game_tick_get(g, v) == 10, "final tick counter value");
7575

7676
level_dump(g, v, l, w, h);
7777
TEST_PASSED(t);

src/tests/test_mob_shove_ok.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"......."
3535
"......."
3636
"...@g.."
37-
"......m"
37+
"......."
3838
"......."
3939
".......";
4040

src/tests/test_monst_maze.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@
3333
"X.x.x.X"
3434
"X.x.x.X"
3535
"X.x.x.X"
36-
"X@x..mX"
36+
"X@x.m.X"
3737
"XXXXXXX";
3838
std::string const expect2
3939
= "XXXXXXX"
40-
"X...x.X"
41-
"X.xmx.X"
40+
"X..mx.X"
41+
"X.x.x.X"
4242
"X.x.x.X"
4343
"X.x.x.X"
4444
"X@x...X"
@@ -47,8 +47,8 @@
4747
= "XXXXXXX"
4848
"X...x.X"
4949
"X.x.x.X"
50-
"Xmx.x.X"
5150
"X.x.x.X"
51+
"Xmx.x.X"
5252
"X@x...X"
5353
"XXXXXXX";
5454
std::string const expect4

0 commit comments

Comments
 (0)