From 5f800f57dfec0b55e85345bc620ec20127f09430 Mon Sep 17 00:00:00 2001 From: Charlie <69320440+hal9000PR@users.noreply.github.com> Date: Mon, 9 May 2022 14:56:02 +0100 Subject: [PATCH] unit tests (#17749) --- code/datums/uplink_item.dm | 8 ++++-- code/game/gamemodes/wizard/spellbook.dm | 4 +-- code/modules/unit_tests/_unit_tests.dm | 1 + .../unit_tests/purchase_reference_test.dm | 28 +++++++++++++++++++ 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 code/modules/unit_tests/purchase_reference_test.dm diff --git a/code/datums/uplink_item.dm b/code/datums/uplink_item.dm index e850e79257e..015977f0ffc 100644 --- a/code/datums/uplink_item.dm +++ b/code/datums/uplink_item.dm @@ -66,7 +66,7 @@ GLOBAL_LIST_INIT(uplink_items, subtypesof(/datum/uplink_item)) var/name = "item name" var/category = "item category" var/desc = "Item Description" - var/reference = "Item Reference" + var/reference = null var/item = null var/cost = 0 var/last = 0 // Appear last @@ -314,7 +314,7 @@ GLOBAL_LIST_INIT(uplink_items, subtypesof(/datum/uplink_item)) /datum/uplink_item/jobspecific/pickpocketgloves name = "Pickpocket's Gloves" desc = "A pair of sleek gloves to aid in pickpocketing. While wearing these, you can loot your target without them knowing. Pickpocketing puts the item directly into your hand." - reference = "PG" + reference = "PPG" item = /obj/item/clothing/gloves/color/black/thief cost = 6 job = list("Assistant") @@ -1061,6 +1061,7 @@ GLOBAL_LIST_INIT(uplink_items, subtypesof(/datum/uplink_item)) /datum/uplink_item/explosives/detomatix/nuclear desc = "When inserted into a personal digital assistant, this cartridge gives you five opportunities to detonate PDAs of crewmembers who have their message feature enabled. The concussive effect from the explosion will knock the recipient out for a short period, and deafen them for longer. It has a chance to detonate your PDA. This version comes with a program to toggle your nuclear shuttle blast doors remotely." item = /obj/item/cartridge/syndicate/nuclear + reference = "DEPCN" excludefrom = list() gamemodes = list(/datum/game_mode/nuclear) @@ -1075,6 +1076,7 @@ GLOBAL_LIST_INIT(uplink_items, subtypesof(/datum/uplink_item)) /datum/uplink_item/explosives/grenadier name = "Grenadier's belt" desc = "A belt containing 26 lethally dangerous and destructive grenades." + reference = "GRB" item = /obj/item/storage/belt/grenade/full cost = 30 surplus = 0 @@ -1534,7 +1536,7 @@ GLOBAL_LIST_INIT(uplink_items, subtypesof(/datum/uplink_item)) name = "Dropwall generator box" desc = "A box of 5 dropwall shield generators, which can be used to make temporary directional shields that block projectiles, thrown objects, and reduce explosions. Configure the direction before throwing." item = /obj/item/storage/box/syndie_kit/dropwall - reference = "ESD" + reference = "DWG" cost = 10 gamemodes = list(/datum/game_mode/nuclear) diff --git a/code/game/gamemodes/wizard/spellbook.dm b/code/game/gamemodes/wizard/spellbook.dm index 5c85e5128fa..cc0857d362b 100644 --- a/code/game/gamemodes/wizard/spellbook.dm +++ b/code/game/gamemodes/wizard/spellbook.dm @@ -4,7 +4,7 @@ var/spell_type = null var/desc = "" var/category = "Offensive" - var/log_name = "XX" //What it shows up as in logs + var/log_name = null //What it shows up as in logs var/cost = 2 var/refundable = TRUE var/obj/effect/proc_holder/spell/S = null //Since spellbooks can be used by only one person anyway we can track the actual spell @@ -289,7 +289,7 @@ /datum/spellbook_entry/charge name = "Charge" spell_type = /obj/effect/proc_holder/spell/charge - log_name = "CH" + log_name = "CHG" category = "Assistance" cost = 1 diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index 077d2efe464..1bcb832f6fd 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -7,6 +7,7 @@ #include "crafting_lists.dm" #include "log_format.dm" #include "map_templates.dm" +#include "purchase_reference_test.dm" #include "reagent_id_typos.dm" #include "rustg_version.dm" #include "spawn_humans.dm" diff --git a/code/modules/unit_tests/purchase_reference_test.dm b/code/modules/unit_tests/purchase_reference_test.dm new file mode 100644 index 00000000000..d5547dbc5e9 --- /dev/null +++ b/code/modules/unit_tests/purchase_reference_test.dm @@ -0,0 +1,28 @@ +// tests if there are duplicate or null refs/lognames for uplink items and spellbook items respectively +/datum/unit_test/uplink_refs/Run() + var/list/uplink_refs = list() + for(var/datum/uplink_item/I as anything in subtypesof(/datum/uplink_item)) + if(isnull(initial(I.item))) + continue //don't test them if they don't have an item + var/uplink_ref = initial(I.reference) + if(isnull(uplink_ref)) + Fail("uplink item [initial(I.name)] has no reference") + continue + if(uplink_ref in uplink_refs) + Fail("uplink reference [uplink_ref] is used multiple times") + uplink_refs += uplink_ref + +/datum/unit_test/spellbook_refs/Run() + var/list/spell_refs = list() + var/list/blacklist = list(/datum/spellbook_entry/summon, + /datum/spellbook_entry/item, + /datum/spellbook_entry/loadout,) + for(var/datum/spellbook_entry/entry as anything in subtypesof(/datum/spellbook_entry) - blacklist) + var/spell_ref = initial(entry.log_name) + if(isnull(spell_ref)) + Fail("spellbook entry [initial(entry.name)] has no reference") + continue + if(spell_ref in spell_refs) + Fail("spellbook reference [spell_ref] is used multiple times") + spell_refs += spell_ref +