Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create interaction test harness. #27643

Merged
merged 7 commits into from
Dec 23, 2024
5 changes: 5 additions & 0 deletions code/modules/interaction_tests/_interaction_tests.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#ifdef UNIT_TESTS
#include "attack_chain_interaction_test.dm"
#include "interaction_test.dm"
#include "test_puppeteer.dm"
#endif
23 changes: 23 additions & 0 deletions code/modules/interaction_tests/attack_chain_interaction_test.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/datum/interaction_test/attack_chain

/datum/interaction_test/attack_chain/Run()
var/datum/test_puppeteer/cultist = make_puppeteer()
var/datum/test_puppeteer/target = make_puppeteer_near(cultist)
cultist.puppet.mind.add_antag_datum(/datum/antagonist/cultist)
cultist.spawn_obj_in_hand(/obj/item/melee/cultblade/dagger)
cultist.set_intent("harm")
cultist.click_on(target)

if(!target.check_attack_log("Attacked with ritual dagger"))
Fail("non-cultist missing dagger attack log")
if(target.puppet.health == target.puppet.getMaxHealth())
Fail("cultist attacking non-cultist with dagger caused no damage")

target.rejuvenate()
target.puppet.mind.add_antag_datum(/datum/antagonist/cultist)

cultist.click_on(target)
if(target.puppet.health < target.puppet.getMaxHealth())
Fail("cultist attacking cultist with dagger caused damage")


34 changes: 34 additions & 0 deletions code/modules/interaction_tests/interaction_test.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/datum/interaction_test
warriorstar-orion marked this conversation as resolved.
Show resolved Hide resolved
var/list/tracked_puppets
var/succeeded = TRUE
var/list/fail_reasons

/datum/interaction_test/Destroy()
for(var/datum/test_puppeteer/puppet in tracked_puppets)
qdel(puppet)
warriorstar-orion marked this conversation as resolved.
Show resolved Hide resolved
return ..()

/datum/interaction_test/proc/Run()
SHOULD_CALL_PARENT(FALSE)
Fail("Run() not implemented")

/datum/interaction_test/proc/Fail(reason = "No reason")
succeeded = FALSE

if(!istext(reason))
reason = "FORMATTED: [reason != null ? reason : "NULL"]"
warriorstar-orion marked this conversation as resolved.
Show resolved Hide resolved

LAZYADD(fail_reasons, reason)

/datum/interaction_test/proc/make_puppeteer(carbon_type = /mob/living/carbon/human)
var/datum/test_puppeteer/puppet = new(carbon_type)
warriorstar-orion marked this conversation as resolved.
Show resolved Hide resolved
LAZYADD(tracked_puppets, puppet)
return puppet

/datum/interaction_test/proc/make_puppeteer_near(datum/test_puppeteer/near, carbon_type = /mob/living/carbon/human)
for(var/turf/T in RANGE_TURFS(1, near.puppet.loc))
warriorstar-orion marked this conversation as resolved.
Show resolved Hide resolved
if(!is_blocked_turf(T, exclude_mobs = FALSE))
var/datum/test_puppeteer/new_puppet = new(carbon_type, T)
LAZYADD(tracked_puppets, new_puppet)
return new_puppet

49 changes: 49 additions & 0 deletions code/modules/interaction_tests/test_puppeteer.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/datum/test_puppeteer
var/mob/living/carbon/puppet
var/list/tracked_atoms
warriorstar-orion marked this conversation as resolved.
Show resolved Hide resolved

/datum/test_puppeteer/New(carbon_type, turf/initial_location)
if(!initial_location)
initial_location = locate(179, 136, 1) // Center of admin testing area
puppet = new carbon_type(initial_location)
var/datum/mind/new_mind = new("interaction_test_[rand(1, 999999)]")
warriorstar-orion marked this conversation as resolved.
Show resolved Hide resolved
new_mind.transfer_to(puppet)

/datum/test_puppeteer/proc/spawn_obj_in_hand(obj_type)
warriorstar-orion marked this conversation as resolved.
Show resolved Hide resolved
var/obj/new_obj = new obj_type(null)
puppet.put_in_hands(new_obj)
warriorstar-orion marked this conversation as resolved.
Show resolved Hide resolved
LAZYADD(tracked_atoms, new_obj)
return new_obj

/datum/test_puppeteer/proc/click_on(target, params)
var/datum/test_puppeteer/puppet_target = target
if(istype(puppet_target))
puppet.ClickOn(puppet_target.puppet, params)
return

puppet.ClickOn(target, params)

/datum/test_puppeteer/proc/spawn_mob_nearby(mob_type)
for(var/turf/T in RANGE_TURFS(1, puppet))
if(!is_blocked_turf(T, exclude_mobs = FALSE))
var/mob/new_mob = new mob_type(T)
LAZYADD(tracked_atoms, new_mob)
return new_mob

/datum/test_puppeteer/Destroy(force, ...)
qdel(puppet)
for(var/atom/A in tracked_atoms)
qdel(A)

return ..()

/datum/test_puppeteer/proc/check_attack_log(snippet)
for(var/log_text in puppet.attack_log_old)
if(findtextEx(log_text, snippet))
return TRUE

/datum/test_puppeteer/proc/set_intent(new_intent)
puppet.a_intent_change(new_intent)

/datum/test_puppeteer/proc/rejuvenate()
puppet.rejuvenate()
19 changes: 19 additions & 0 deletions code/modules/unit_tests/test_runner.dm
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,25 @@

CHECK_TICK

for(var/interaction_test_type in subtypesof(/datum/interaction_test))
var/datum/interaction_test/test = new interaction_test_type
test_logs[interaction_test_type] = list()
current_test = test
var/duration = REALTIMEOFDAY

test.Run()

durations[interaction_test_type] = REALTIMEOFDAY - duration
current_test = null

if(!test.succeeded)
failed_any_test = TRUE
test_logs[interaction_test_type] += test.fail_reasons

qdel(test)

CHECK_TICK

SSticker.reboot_helper("Unit Test Reboot", "tests ended", 0)


Expand Down
1 change: 1 addition & 0 deletions paradise.dme
Original file line number Diff line number Diff line change
Expand Up @@ -2050,6 +2050,7 @@
#include "code\modules\instruments\songs\_song_ui.dm"
#include "code\modules\instruments\songs\play_legacy.dm"
#include "code\modules\instruments\songs\play_synthesized.dm"
#include "code\modules\interaction_tests\_interaction_tests.dm"
#include "code\modules\lavaland\caves_theme.dm"
#include "code\modules\lavaland\lavaland_theme.dm"
#include "code\modules\library\book.dm"
Expand Down
1 change: 1 addition & 0 deletions tools/ci/unticked_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
'paradise.dme',
'code/modules/tgs/includes.dm',
'code/modules/unit_tests/_unit_tests.dm',
'code/modules/interaction_tests/_interaction_tests.dm',
]

IGNORE_FILES = {
Expand Down
Loading