forked from github/server
allow control over stderr logging from tests.
separate test_cleanup from test_setup.
This commit is contained in:
parent
2eb9b5c5ea
commit
1c5fcded9f
|
@ -13,13 +13,14 @@ static void test_create_a_spell(CuTest * tc)
|
||||||
{
|
{
|
||||||
spell * sp;
|
spell * sp;
|
||||||
|
|
||||||
test_cleanup();
|
test_setup();
|
||||||
CuAssertPtrEquals(tc, 0, spells);
|
CuAssertPtrEquals(tc, 0, spells);
|
||||||
CuAssertPtrEquals(tc, 0, find_spell("testspell"));
|
CuAssertPtrEquals(tc, 0, find_spell("testspell"));
|
||||||
|
|
||||||
sp = create_spell("testspell", 0);
|
sp = create_spell("testspell", 0);
|
||||||
CuAssertPtrEquals(tc, sp, find_spell("testspell"));
|
CuAssertPtrEquals(tc, sp, find_spell("testspell"));
|
||||||
CuAssertPtrNotNull(tc, spells);
|
CuAssertPtrNotNull(tc, spells);
|
||||||
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_create_duplicate_spell(CuTest * tc)
|
static void test_create_duplicate_spell(CuTest * tc)
|
||||||
|
@ -27,12 +28,13 @@ static void test_create_duplicate_spell(CuTest * tc)
|
||||||
spell *sp;
|
spell *sp;
|
||||||
/* FIXME: this test emits ERROR messages (duplicate spells), inject a logger to verify that */
|
/* FIXME: this test emits ERROR messages (duplicate spells), inject a logger to verify that */
|
||||||
|
|
||||||
test_cleanup();
|
test_setup();
|
||||||
CuAssertPtrEquals(tc, 0, find_spell("testspell"));
|
CuAssertPtrEquals(tc, 0, find_spell("testspell"));
|
||||||
|
|
||||||
sp = create_spell("testspell", 0);
|
sp = create_spell("testspell", 0);
|
||||||
CuAssertPtrEquals(tc, 0, create_spell("testspell", 0));
|
CuAssertPtrEquals(tc, 0, create_spell("testspell", 0));
|
||||||
CuAssertPtrEquals(tc, sp, find_spell("testspell"));
|
CuAssertPtrEquals(tc, sp, find_spell("testspell"));
|
||||||
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void test_create_spell_with_id(CuTest * tc)
|
static void test_create_spell_with_id(CuTest * tc)
|
||||||
|
@ -40,12 +42,13 @@ static void test_create_spell_with_id(CuTest * tc)
|
||||||
spell *sp;
|
spell *sp;
|
||||||
/* FIXME: this test emits ERROR messages (duplicate spells), inject a logger to verify that */
|
/* FIXME: this test emits ERROR messages (duplicate spells), inject a logger to verify that */
|
||||||
|
|
||||||
test_cleanup();
|
test_setup();
|
||||||
CuAssertPtrEquals(tc, 0, find_spellbyid(42));
|
CuAssertPtrEquals(tc, 0, find_spellbyid(42));
|
||||||
sp = create_spell("testspell", 42);
|
sp = create_spell("testspell", 42);
|
||||||
CuAssertPtrEquals(tc, sp, find_spellbyid(42));
|
CuAssertPtrEquals(tc, sp, find_spellbyid(42));
|
||||||
CuAssertPtrEquals(tc, 0, create_spell("testspell", 47));
|
CuAssertPtrEquals(tc, 0, create_spell("testspell", 47));
|
||||||
CuAssertPtrEquals(tc, 0, find_spellbyid(47));
|
CuAssertPtrEquals(tc, 0, find_spellbyid(47));
|
||||||
|
test_cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
CuSuite *get_spell_suite(void)
|
CuSuite *get_spell_suite(void)
|
||||||
|
|
|
@ -158,7 +158,6 @@ int RunAllTests(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char ** argv) {
|
int main(int argc, char ** argv) {
|
||||||
log_to_file(LOG_CPERROR, stderr);
|
|
||||||
++argv;
|
++argv;
|
||||||
--argc;
|
--argc;
|
||||||
if (argc > 0 && strcmp("--list", argv[0]) == 0) {
|
if (argc > 0 && strcmp("--list", argv[0]) == 0) {
|
||||||
|
|
31
src/tests.c
31
src/tests.c
|
@ -123,10 +123,24 @@ struct unit *test_create_unit(struct faction *f, struct region *r)
|
||||||
return create_unit(r, f, 1, rc ? rc : rc_get_or_create("human"), 0, 0, 0);
|
return create_unit(r, f, 1, rc ? rc : rc_get_or_create("human"), 0, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_cleanup(void)
|
void test_log_stderr(int flags) {
|
||||||
{
|
static struct log_t *stderrlog;
|
||||||
int i;
|
if (flags) {
|
||||||
|
if (stderrlog) {
|
||||||
|
log_error("stderr logging is still active. did you call test_cleanup?");
|
||||||
|
log_destroy(stderrlog);
|
||||||
|
}
|
||||||
|
stderrlog = log_to_file(flags, stderr);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
log_destroy(stderrlog);
|
||||||
|
stderrlog = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void test_reset(void) {
|
||||||
|
int i;
|
||||||
default_locale = 0;
|
default_locale = 0;
|
||||||
free_gamedata();
|
free_gamedata();
|
||||||
free_terrains();
|
free_terrains();
|
||||||
|
@ -158,6 +172,17 @@ void test_cleanup(void)
|
||||||
random_source_reset();
|
random_source_reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_setup(void) {
|
||||||
|
test_log_stderr(LOG_CPERROR);
|
||||||
|
test_reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_cleanup(void)
|
||||||
|
{
|
||||||
|
test_reset();
|
||||||
|
test_log_stderr(0);
|
||||||
|
}
|
||||||
|
|
||||||
terrain_type *
|
terrain_type *
|
||||||
test_create_terrain(const char * name, unsigned int flags)
|
test_create_terrain(const char * name, unsigned int flags)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,7 +29,9 @@ extern "C" {
|
||||||
|
|
||||||
struct CuTest;
|
struct CuTest;
|
||||||
|
|
||||||
|
void test_setup(void);
|
||||||
void test_cleanup(void);
|
void test_cleanup(void);
|
||||||
|
void test_log_stderr(int on);
|
||||||
|
|
||||||
struct locale * test_create_locale(void);
|
struct locale * test_create_locale(void);
|
||||||
struct terrain_type * test_create_terrain(const char * name, unsigned int flags);
|
struct terrain_type * test_create_terrain(const char * name, unsigned int flags);
|
||||||
|
|
Loading…
Reference in New Issue