diff --git a/src/alchemy.test.c b/src/alchemy.test.c index 7e2e5b399..7fd2da8e1 100644 --- a/src/alchemy.test.c +++ b/src/alchemy.test.c @@ -25,7 +25,7 @@ static void test_herbsearch(CuTest * tc) region *r; const item_type *itype; - test_cleanup(); + test_setup(); r = test_create_region(0, 0, 0); rc = rc_get_or_create("dragon"); rc->flags |= RCF_UNARMEDGUARD; diff --git a/src/attributes/otherfaction.test.c b/src/attributes/otherfaction.test.c index 8e3d09b0a..a28d9f470 100644 --- a/src/attributes/otherfaction.test.c +++ b/src/attributes/otherfaction.test.c @@ -16,7 +16,7 @@ #include static void test_rules(CuTest *tc) { - test_cleanup(); + test_setup(); config_set("stealth.faction.other", NULL); CuAssertIntEquals(tc, true, rule_stealth_other()); config_set("stealth.faction.other", "0"); @@ -37,7 +37,7 @@ static void test_otherfaction(CuTest *tc) { unit *u; faction *f; - test_cleanup(); + test_setup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); f = test_create_faction(0); config_set("stealth.faction.other", "1"); diff --git a/src/kernel/alliance.test.c b/src/kernel/alliance.test.c index 8432f1692..72a31a42c 100644 --- a/src/kernel/alliance.test.c +++ b/src/kernel/alliance.test.c @@ -17,7 +17,6 @@ typedef struct alliance_fixture { } alliance_fixture; static void setup_alliance(alliance_fixture *fix) { - test_cleanup(); test_create_world(); fix->rc = test_create_race("human"); fix->f1 = test_create_faction(fix->rc); @@ -28,7 +27,7 @@ static void setup_alliance(alliance_fixture *fix) { static void test_alliance_make(CuTest *tc) { alliance * al; - test_cleanup(); + test_setup(); assert(!alliances); al = makealliance(1, "Hodor"); CuAssertPtrNotNull(tc, al); @@ -50,6 +49,7 @@ static void test_alliance_join(CuTest *tc) { alliance_fixture fix; alliance * al; + test_setup(); setup_alliance(&fix); CuAssertPtrEquals(tc, 0, fix.f1->alliance); CuAssertPtrEquals(tc, 0, fix.f2->alliance); @@ -69,7 +69,7 @@ static void test_alliance_dead_faction(CuTest *tc) { faction *f, *f2; alliance *al; - test_cleanup(); + test_setup(); f = test_create_faction(0); f2 = test_create_faction(0); al = makealliance(42, "Hodor"); @@ -91,7 +91,7 @@ static void test_alliance_cmd(CuTest *tc) { struct region *r; struct alliance *al; - test_cleanup(); + test_setup(); r = test_create_region(0, 0, 0); u1 = test_create_unit(test_create_faction(0), r); u2 = test_create_unit(test_create_faction(0), r); @@ -118,7 +118,7 @@ static void test_alliance_cmd_kick(CuTest *tc) { struct region *r; struct alliance *al; - test_cleanup(); + test_setup(); al = makealliance(42, "Hodor"); r = test_create_region(0, 0, 0); u1 = test_create_unit(test_create_faction(0), r); @@ -138,7 +138,7 @@ static void test_alliance_cmd_no_invite(CuTest *tc) { unit *u1, *u2; struct region *r; - test_cleanup(); + test_setup(); r = test_create_region(0, 0, 0); u1 = test_create_unit(test_create_faction(0), r); u2 = test_create_unit(test_create_faction(0), r); @@ -159,7 +159,7 @@ static void test_alliance_cmd_leave(CuTest *tc) { struct region *r; struct alliance *al; - test_cleanup(); + test_setup(); al = makealliance(42, "Hodor"); r = test_create_region(0, 0, 0); u1 = test_create_unit(test_create_faction(0), r); @@ -180,7 +180,7 @@ static void test_alliance_cmd_transfer(CuTest *tc) { struct region *r; struct alliance *al; - test_cleanup(); + test_setup(); al = makealliance(42, "Hodor"); r = test_create_region(0, 0, 0); u1 = test_create_unit(test_create_faction(0), r); diff --git a/src/kernel/spell.test.c b/src/kernel/spell.test.c index 60665a591..db167adce 100644 --- a/src/kernel/spell.test.c +++ b/src/kernel/spell.test.c @@ -29,6 +29,7 @@ static void test_create_duplicate_spell(CuTest * tc) /* FIXME: this test emits ERROR messages (duplicate spells), inject a logger to verify that */ test_setup(); + test_log_stderr(0); CuAssertPtrEquals(tc, 0, find_spell("testspell")); sp = create_spell("testspell", 0); @@ -43,6 +44,7 @@ static void test_create_spell_with_id(CuTest * tc) /* FIXME: this test emits ERROR messages (duplicate spells), inject a logger to verify that */ test_setup(); + test_log_stderr(0); CuAssertPtrEquals(tc, 0, find_spellbyid(42)); sp = create_spell("testspell", 42); CuAssertPtrEquals(tc, sp, find_spellbyid(42)); diff --git a/src/prefix.test.c b/src/prefix.test.c index 44c0d845d..222c19f85 100644 --- a/src/prefix.test.c +++ b/src/prefix.test.c @@ -6,7 +6,7 @@ #include static void test_add_prefix(CuTest *tc) { - test_cleanup(); + test_setup(); CuAssertPtrEquals(tc, 0, race_prefixes); add_raceprefix("sea"); CuAssertPtrNotNull(tc, race_prefixes); @@ -26,4 +26,4 @@ CuSuite *get_prefix_suite(void) CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_add_prefix); return suite; -} \ No newline at end of file +} diff --git a/src/spy.test.c b/src/spy.test.c index b843306f1..299e4b3a6 100644 --- a/src/spy.test.c +++ b/src/spy.test.c @@ -32,7 +32,7 @@ typedef struct { } spy_fixture; static void setup_spy(spy_fixture *fix) { - test_cleanup(); + test_setup(); fix->r = test_create_region(0, 0, NULL); fix->spy = test_create_unit(test_create_faction(NULL), fix->r); fix->victim = test_create_unit(test_create_faction(NULL), fix->r); @@ -88,7 +88,7 @@ static void test_all_spy_message(CuTest *tc) { static void setup_sabotage(void) { struct locale *lang; - test_cleanup(); + test_setup(); lang = get_or_create_locale("de"); locale_setstring(lang, parameters[P_SHIP], "SCHIFF"); locale_setstring(lang, parameters[P_ANY], "ALLE"); diff --git a/src/study.test.c b/src/study.test.c index 7e0eb8744..f12fc25df 100644 --- a/src/study.test.c +++ b/src/study.test.c @@ -70,7 +70,7 @@ static void setup_study(study_fixture *fix, skill_t sk) { struct locale *lang; assert(fix); - test_cleanup(); + test_setup(); config_set("study.random_progress", "0"); test_create_world(); r = findregion(0, 0); @@ -138,7 +138,7 @@ static void test_study_bug_2194(CuTest *tc) { struct locale * loc; building * b; - test_cleanup(); + test_setup(); random_source_inject_constant(0.0); init_resources(); loc = get_or_create_locale("de"); @@ -195,7 +195,7 @@ static void test_produceexp(CuTest *tc) { unit *u; g_tc = tc; - test_cleanup(); + test_setup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); scale_number(u, 2); config_set("study.produceexp", "20"); @@ -210,7 +210,7 @@ static void test_academy_building(CuTest *tc) { building * b; message * msg; - test_cleanup(); + test_setup(); mt_register(mt_new_va("teach_asgood", "unit:unit", "region:region", "command:order", "student:unit", 0)); random_source_inject_constant(0.0); @@ -253,7 +253,7 @@ static void test_academy_building(CuTest *tc) { void test_learn_skill_single(CuTest *tc) { unit *u; skill *sv; - test_cleanup(); + test_setup(); config_set("study.random_progress", "0"); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); learn_skill(u, SK_ALCHEMY, STUDYDAYS); @@ -272,7 +272,7 @@ void test_learn_skill_single(CuTest *tc) { void test_learn_skill_multi(CuTest *tc) { unit *u; skill *sv; - test_cleanup(); + test_setup(); config_set("study.random_progress", "0"); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); scale_number(u, 10); @@ -292,7 +292,7 @@ void test_learn_skill_multi(CuTest *tc) { static void test_demon_skillchanges(CuTest *tc) { unit * u; race * rc; - test_cleanup(); + test_setup(); rc = test_create_race("demon"); CuAssertPtrEquals(tc, rc, get_race(RC_DAEMON)); u = test_create_unit(test_create_faction(rc), 0); @@ -305,7 +305,7 @@ static void test_demon_skillchanges(CuTest *tc) { static void test_study_cmd(CuTest *tc) { unit *u; - test_cleanup(); + test_setup(); init_resources(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); u->thisorder = create_order(K_STUDY, u->faction->locale, "CROSSBOW"); @@ -321,7 +321,7 @@ static void test_study_cmd(CuTest *tc) { static void test_study_cost(CuTest *tc) { unit *u; const struct item_type *itype; - test_cleanup(); + test_setup(); init_resources(); itype = get_resourcetype(R_SILVER)->itype; u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); @@ -340,7 +340,7 @@ static void test_study_cost(CuTest *tc) { static void test_teach_cmd(CuTest *tc) { unit *u, *ut; - test_cleanup(); + test_setup(); init_resources(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); scale_number(u, 10); @@ -360,7 +360,7 @@ static void test_teach_cmd(CuTest *tc) { static void test_teach_two(CuTest *tc) { unit *u1, *u2, *ut; - test_cleanup(); + test_setup(); init_resources(); u1 = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); scale_number(u1, 5); @@ -390,7 +390,7 @@ static void test_teach_two_skills(CuTest *tc) { faction *f; region *r; - test_cleanup(); + test_setup(); init_resources(); f = test_create_faction(0); r = test_create_region(0, 0, 0); @@ -420,7 +420,7 @@ static void test_teach_two_skills(CuTest *tc) { static void test_teach_one_to_many(CuTest *tc) { unit *u, *ut; - test_cleanup(); + test_setup(); init_resources(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); scale_number(u, 20); @@ -440,7 +440,7 @@ static void test_teach_one_to_many(CuTest *tc) { static void test_teach_many_to_one(CuTest *tc) { unit *u, *u1, *u2; - test_cleanup(); + test_setup(); init_resources(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); scale_number(u, 20); @@ -467,7 +467,7 @@ static void test_teach_many_to_many(CuTest *tc) { region *r; faction *f; - test_cleanup(); + test_setup(); init_resources(); f = test_create_faction(0); r = test_create_region(0, 0, 0); diff --git a/src/tests.c b/src/tests.c index 5d359813d..54779c450 100644 --- a/src/tests.c +++ b/src/tests.c @@ -133,7 +133,12 @@ void test_log_stderr(int flags) { stderrlog = log_to_file(flags, stderr); } else { - log_destroy(stderrlog); + if (stderrlog) { + log_destroy(stderrlog); + } + else { + log_warning("stderr logging is inactive. did you call test_cleanup twice?"); + } stderrlog = 0; } diff --git a/src/triggers/shock.test.c b/src/triggers/shock.test.c index 77bc192dc..058dfaae3 100644 --- a/src/triggers/shock.test.c +++ b/src/triggers/shock.test.c @@ -12,8 +12,8 @@ static void test_shock(CuTest *tc) { unit *u; trigger *tt; - test_cleanup(); + test_setup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); create_mage(u, M_GRAY); set_level(u, SK_MAGIC, 5); @@ -32,8 +32,8 @@ static void test_shock(CuTest *tc) { static void test_shock_low(CuTest *tc) { unit *u; trigger *tt; - test_cleanup(); + test_setup(); u = test_create_unit(test_create_faction(0), test_create_region(0, 0, 0)); create_mage(u, M_GRAY); set_level(u, SK_MAGIC, 5); diff --git a/src/upkeep.test.c b/src/upkeep.test.c index bba43a95f..1013314aa 100644 --- a/src/upkeep.test.c +++ b/src/upkeep.test.c @@ -19,7 +19,7 @@ void test_upkeep_default(CuTest * tc) faction *f1, *f2; const item_type *i_silver; - test_cleanup(); + test_setup(); test_create_world(); i_silver = it_find("money"); @@ -50,7 +50,7 @@ void test_upkeep_hunger_damage(CuTest * tc) faction *f1; const item_type *i_silver; - test_cleanup(); + test_setup(); test_create_world(); i_silver = it_find("money"); @@ -75,7 +75,7 @@ void test_upkeep_from_pool(CuTest * tc) unit *u1, *u2; const item_type *i_silver; - test_cleanup(); + test_setup(); test_create_world(); i_silver = it_find("money"); @@ -108,7 +108,7 @@ void test_upkeep_from_friend(CuTest * tc) faction *f1, *f2; const item_type *i_silver; - test_cleanup(); + test_setup(); test_create_world(); i_silver = it_find("money"); @@ -142,7 +142,7 @@ void test_upkeep_free(CuTest * tc) unit *u; const item_type *i_silver; - test_cleanup(); + test_setup(); test_create_world(); i_silver = it_find("money"); diff --git a/src/vortex.test.c b/src/vortex.test.c index 78a04535f..21ea6596c 100644 --- a/src/vortex.test.c +++ b/src/vortex.test.c @@ -22,7 +22,7 @@ static void test_move_to_vortex(CuTest *tc) { unit *u; struct locale *lang; - test_cleanup(); + test_setup(); lang = get_or_create_locale("en"); locale_setstring(lang, "vortex", "wirbel"); init_locale(lang); diff --git a/src/wormhole.test.c b/src/wormhole.test.c index 03bf14ab9..ec93c5b4c 100644 --- a/src/wormhole.test.c +++ b/src/wormhole.test.c @@ -22,7 +22,7 @@ static void test_make_wormholes(CuTest *tc) { terrain_type *t_plain; building_type *btype; - test_cleanup(); + test_setup(); t_plain = test_create_terrain("plain", LAND_REGION); btype = test_create_buildingtype("wormhole"); match[0] = r1 = test_create_region(0, 0, t_plain); @@ -44,7 +44,7 @@ static void test_sort_wormhole_regions(CuTest *tc) { terrain_type *t_plain; quicklist *rlist = 0; - test_cleanup(); + test_setup(); t_plain = test_create_terrain("plain", LAND_REGION); r1 = test_create_region(0, 0, t_plain); r2 = test_create_region(1, 0, t_plain);