Skip to content

Commit

Permalink
Simplify unit test dummy mob creation
Browse files Browse the repository at this point in the history
  • Loading branch information
out-of-phaze committed Jan 21, 2025
1 parent d3b1438 commit d01e724
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 21 deletions.
31 changes: 13 additions & 18 deletions code/unit_tests/equipment_tests.dm
Original file line number Diff line number Diff line change
@@ -1,42 +1,37 @@
/datum/unit_test/vision_glasses
name = "EQUIPMENT: Vision Template"
template = /datum/unit_test/vision_glasses
var/mob/living/human/H = null
var/mob/living/human/subject = null
var/expectation = SEE_INVISIBLE_NOLIGHTING
var/glasses_type = null
async = 1

/datum/unit_test/vision_glasses/start_test()
var/list/test = create_test_mob_with_mind(get_safe_turf(), /mob/living/human)
if(isnull(test))
fail("Check Runtimed in Mob creation")

if(test["result"] == FAILURE)
fail(test["msg"])
async = 0
return 0

H = locate(test["mobref"])
H.equip_to_slot(new glasses_type(H), slot_glasses_str)
subject = new(get_safe_turf(), SPECIES_HUMAN) // force human so default map species doesn't mess with anything
subject.equip_to_slot(new glasses_type(subject), slot_glasses_str)
return 1

/datum/unit_test/vision_glasses/check_result()

if(isnull(H) || H.life_tick < 2)
if(isnull(subject) || subject.life_tick < 2)
return 0

if(isnull(H.get_equipped_item(slot_glasses_str)))
if(isnull(subject.get_equipped_item(slot_glasses_str)))
fail("Mob doesn't have glasses on")

H.handle_vision() // Because Life has a client check that bypasses updating vision
subject.handle_vision() // Because Life has a client check that bypasses updating vision

if(H.see_invisible == expectation)
pass("Mob See invisible is [H.see_invisible]")
if(subject.see_invisible == expectation)
pass("Mob See invisible is [subject.see_invisible]")
else
fail("Mob See invisible is [H.see_invisible] / expected [expectation]")
fail("Mob See invisible is [subject.see_invisible] / expected [expectation]")

return 1

/datum/unit_test/vision_glasses/teardown_test()
QDEL_NULL(subject)
. = ..()

/datum/unit_test/vision_glasses/NVG
name = "EQUIPMENT: NVG see_invis"
glasses_type = /obj/item/clothing/glasses/night
Expand Down
4 changes: 1 addition & 3 deletions code/unit_tests/mob_tests.dm
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,7 @@

// ============================================================================

var/global/default_mobloc = null

/proc/create_test_mob_with_mind(var/turf/mobloc, var/mobtype = /mob/living/human)
/datum/unit_test/mob_damage/proc/create_test_mob_with_mind(var/turf/mobloc, var/mobtype = /mob/living/human)
var/list/test_result = list("result" = FAILURE, "msg" = "", "mobref" = null)

if(!mobloc)
Expand Down

0 comments on commit d01e724

Please sign in to comment.