Debian Codegraph @

terps/scare/sxtester.c

raw symbols SCIP
1 /* vi: set ts=2 shiftwidth=2 expandtab:
2 *
3 * Copyright (C) 2003-2008 Simon Baldwin and Mark J. Tilford
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17 * USA
18 */
19
20 /*
21 * Module notes:
22 *
23 * o ...
24 */
25
26 #include <assert.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29
30 #include "scare.h"
31 #include "sxprotos.h"
32
33
34 /*
35 * test_run_game_script()
36 *
37 * Run the game using the given script. Returns the count of errors from
38 * the script's monitoring.
39 */
40 static sc_int
41 test_run_game_script (sc_game game, sx_script script)
42 {
43 sc_int errors;
44
45 /* Ensure completely repeatable random number sequences. */
46 sc_reseed_random_sequence (1);
47
48 /* Start interpreting the script stream. */
49 scr_start_script (game, script);
50 sc_interpret_game (game);
51
52 /* Wrap up the script interpreter and capture error count. */
53 errors = scr_finalize_script ();
54 return errors;
55 }
56
57
58 /*
59 * test_run_game_tests()
60 *
61 * Run each test in the given descriptor array, reporting the results and
62 * accumulating an error count overall. Return the total error count.
63 */
64 sc_int
65 test_run_game_tests (const sx_test_descriptor_t tests[],
66 sc_int count, sc_bool is_verbose)
67 {
68 const sx_test_descriptor_t *test;
69 sc_int errors;
70 assert (tests);
71
72 errors = 0;
73
74 /* Execute each game in turn. */
75 for (test = tests; test < tests + count; test++)
76 {
77 sc_int test_errors;
78
79 if (is_verbose)
80 {
81 sx_trace ("--- Running Test \"%s\" [\"%s\", by %s]...\n",
82 test->name,
83 sc_get_game_name (test->game),
84 sc_get_game_author (test->game));
85 }
86
87 test_errors = test_run_game_script (test->game, test->script);
88 errors += test_errors;
89
90 if (is_verbose)
91 {
92 sx_trace ("--- Test \"%s\": ", test->name);
93 if (test_errors > 0)
94 sx_trace ("%s [%ld error%s]\n",
95 "FAIL", test_errors, test_errors == 1 ? "" : "s");
96 else
97 sx_trace ("%s\n", "PASS");
98 }
99 else
100 sx_trace ("%s", test_errors > 0 ? "F" : ".");
101 fflush (stdout);
102 fflush (stderr);
103 }
104 sx_trace ("%s", is_verbose ? "" : "\n");
105
106 return errors;
107 }