From e1647d0e36ea56b226b6e1c128c838af387573be Mon Sep 17 00:00:00 2001 From: AffectedArc07 <25063394+AffectedArc07@users.noreply.github.com> Date: Thu, 1 Jul 2021 22:47:06 +0100 Subject: [PATCH] Unit tests! --- code/datums/helper_datums/map_template.dm | 2 + code/datums/ruins/lavaland.dm | 2 + code/modules/unit_tests/_unit_tests.dm | 1 + code/modules/unit_tests/config_sanity.dm | 61 +++++++++++++++++++++++ code/modules/unit_tests/map_templates.dm | 4 ++ config/example/config.toml | 27 ++++++---- 6 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 code/modules/unit_tests/config_sanity.dm diff --git a/code/datums/helper_datums/map_template.dm b/code/datums/helper_datums/map_template.dm index b526f370d03..3b942850108 100644 --- a/code/datums/helper_datums/map_template.dm +++ b/code/datums/helper_datums/map_template.dm @@ -5,6 +5,8 @@ var/mappath = null var/mapfile = null var/loaded = 0 // Times loaded this round + /// Do we exclude this from CI checks? If so, set this to the templates pathtype itself to avoid it getting passed down + var/ci_exclude = null // DO NOT SET THIS IF YOU DO NOT KNOW WHAT YOU ARE DOING /datum/map_template/New(path = null, map = null, rename = null) if(path) diff --git a/code/datums/ruins/lavaland.dm b/code/datums/ruins/lavaland.dm index 5110058674a..8521e77fff0 100644 --- a/code/datums/ruins/lavaland.dm +++ b/code/datums/ruins/lavaland.dm @@ -4,6 +4,7 @@ /datum/map_template/ruin/lavaland/biodome cost = 5 allow_duplicates = FALSE + ci_exclude = /datum/map_template/ruin/lavaland/biodome // This is a parent holder, not a ruin itself /datum/map_template/ruin/lavaland/biodome/beach name = "Biodome Beach" @@ -71,6 +72,7 @@ /datum/map_template/ruin/lavaland/sin cost = 10 allow_duplicates = FALSE + ci_exclude = /datum/map_template/ruin/lavaland/sin // This is a parent holder, not a ruin itself /datum/map_template/ruin/lavaland/sin/envy name = "Ruin of Envy" diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index 08297e97bc0..d929acd58ca 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -3,6 +3,7 @@ #ifdef UNIT_TESTS #include "component_tests.dm" +#include "config_sanity.dm" #include "crafting_lists.dm" #include "log_format.dm" #include "map_templates.dm" diff --git a/code/modules/unit_tests/config_sanity.dm b/code/modules/unit_tests/config_sanity.dm new file mode 100644 index 00000000000..91de8f1c639 --- /dev/null +++ b/code/modules/unit_tests/config_sanity.dm @@ -0,0 +1,61 @@ +// This one test does multiple config things +///datum/unit_test/config_stanity/Run() +/client/verb/test_config_sanity() + // First test the ruins. Space then lava. + var/list/config_space_ruins = GLOB.configuration.ruins.active_space_ruins.Copy() // Copy so we dont remove + var/list/datum/map_template/ruin/space/game_space_ruins = list() + + // Yes I know this is inefficient. Sue me. + for(var/path in subtypesof(/datum/map_template/ruin/space)) + var/datum/map_template/ruin/space/S = new path() + // istype() doesnt work here. Dont even try it. + if(S.ci_exclude == S.type) + continue + game_space_ruins.Add(S) + + for(var/datum/map_template/ruin/space/S in game_space_ruins) + if(S.mappath in config_space_ruins) + // Remove both + game_space_ruins -= S + config_space_ruins -= S.mappath + + // Do not confuse this with the map_templates unit test. They do different things!!!!! + if(length(game_space_ruins)) + Fail("Space ruins exist in the game code that do not exist in the config file") + for(var/datum/map_template/ruin/space/S in game_space_ruins) + Fail("Ruin [S.type] does not have a valid map path ([S.mappath])") + + if(length(config_space_ruins)) + Fail("Space ruins exist in the game config that do not have associated datums") + for(var/path in config_space_ruins) + Fail("- [path]") + + + // Now for lava ruins + var/list/config_lava_ruins = GLOB.configuration.ruins.active_lava_ruins.Copy() // Copy so we dont remove + var/list/datum/map_template/ruin/space/game_lava_ruins = list() + + // Yes I know this is inefficient. Sue me. + for(var/path in subtypesof(/datum/map_template/ruin/lavaland)) + var/datum/map_template/ruin/lavaland/L = new path() + // istype() doesnt work here. Dont even try it. + if(L.ci_exclude == L.type) + continue + game_lava_ruins.Add(L) + + for(var/datum/map_template/ruin/lavaland/L in game_lava_ruins) + if(L.mappath in config_lava_ruins) + // Remove both + game_lava_ruins -= L + config_lava_ruins -= L.mappath + + // Do not confuse this with the map_templates unit test. They do different things!!!!! + if(length(game_lava_ruins)) + Fail("Lava ruins exist in the game code that do not exist in the config file") + for(var/datum/map_template/ruin/lavaland/L in game_lava_ruins) + Fail("Ruin [L.type] does not have a valid map path ([L.mappath])") + + if(length(config_lava_ruins)) + Fail("Lava ruins exist in the game config that do not have associated datums") + for(var/path in config_lava_ruins) + Fail("- [path]") diff --git a/code/modules/unit_tests/map_templates.dm b/code/modules/unit_tests/map_templates.dm index b590526a46b..55834d8d171 100644 --- a/code/modules/unit_tests/map_templates.dm +++ b/code/modules/unit_tests/map_templates.dm @@ -2,6 +2,10 @@ var/list/datum/map_template/templates = subtypesof(/datum/map_template) for(var/I in templates) var/datum/map_template/MT = new I // The new is important here to ensure stuff gets set properly + if(MT.ci_exclude == MT.type) + continue // Check if it even has a path and if so, does it exist if(MT.mappath && !fexists(MT.mappath)) Fail("The map file for [MT.type] does not exist!") + if(MT.mappath && !findtext(MT.mappath, ".dmm")) + Fail("The map file for [MT.type] is not a map!") diff --git a/config/example/config.toml b/config/example/config.toml index f255d84d4cc..80e768d1d37 100644 --- a/config/example/config.toml +++ b/config/example/config.toml @@ -611,6 +611,14 @@ active_space_ruins = [ "_maps/map_files/RandomRuins/SpaceRuins/intactemptyship.dmm", "_maps/map_files/RandomRuins/SpaceRuins/mechtransport.dmm", "_maps/map_files/RandomRuins/SpaceRuins/turretedoutpost.dmm", + "_maps/map_files/RandomRuins/SpaceRuins/debris1.dmm", + "_maps/map_files/RandomRuins/SpaceRuins/debris2.dmm", + "_maps/map_files/RandomRuins/SpaceRuins/debris3.dmm", + "_maps/map_files/RandomRuins/SpaceRuins/listeningpost.dmm", + "_maps/map_files/RandomRuins/SpaceRuins/oldstation.dmm", + "_maps/map_files/RandomRuins/SpaceRuins/onehalf.dmm", + "_maps/map_files/RandomRuins/SpaceRuins/syndiecakesfactory.dmm", + "_maps/map_files/RandomRuins/SpaceRuins/wizardcrash.dmm", ### The following ruins are based from past pre-spawned Zlevel content ### "_maps/map_files/RandomRuins/SpaceRuins/abandonedtele.dmm", @@ -631,7 +639,7 @@ active_space_ruins = [ # The following is a force-spawned ruin consisting mostly of empty space with a shuttle docking port for the free golem shuttle # Disabling it will lead to the free golem shuttle sometimes being stuck on lavaland. - "_maps/map_files/RandomRuins/SpaceRuins/golemtarget.dmm" + "_maps/map_files/RandomRuins/SpaceRuins/golemtarget.dmm", ] # List of all ruins that can generate on lavaland # Commenting something out in here DISABLES IT FROM SPAWNING @@ -642,31 +650,32 @@ active_lava_ruins = [ "_maps/map_files/RandomRuins/LavaRuins/lavaland_biodome_winter.dmm", ##RESPAWN "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_ash_walker1.dmm", + "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_golem_ship.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_hermit.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_seed_vault.dmm", ##SIN "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_envy.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_gluttony.dmm", - # Greed blacklisted because its reward (dice) has a 1/20 chance of making you a wizard - #"_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_greed.dmm", + # Greed blacklisted on production because its reward (dice) has a 1/20 chance of making you a wizard + "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_greed.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_pride.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_sloth.dmm", ##MEGAFAUNA "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_blooddrunk1.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_blooddrunk2.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_blooddrunk3.dmm", - #re-removed 7/24/2020, I ran a month-long test of hierophant Jun-Jul and the staff was still too strong. https://github.com/ParadiseSS13/Paradise/pull/13542 - #"_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_hierophant.dmm", + # Re-removed 7/24/2020, I ran a month-long test of hierophant Jun-Jul and the staff was still too strong. https://github.com/ParadiseSS13/Paradise/pull/13542 + "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_hierophant.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_swarmer_crash.dmm", ##MISC "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_animal_hospital.dmm", - # Cube blacklisted because it contains a wishgranter that gives you hijack on use - #"_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_cube.dmm", + # Cube blacklisted on production because it contains a wishgranter that gives you hijack on use + "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_cube.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_cultaltar.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_dead_ratvar.dmm", - "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_fountain_hell.dmm", - "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_pizza_party.dmm", + "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_fountain_hall.dmm", + "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_pizzaparty.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_puzzle.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_random_ripley.dmm", "_maps/map_files/RandomRuins/LavaRuins/lavaland_surface_survivalpod.dmm",