Skip to content

Commit

Permalink
minor test fixture improvements (ParadiseSS13#28207)
Browse files Browse the repository at this point in the history
* minor test fixture improvements

* make return values sane
  • Loading branch information
warriorstar-orion authored Jan 31, 2025
1 parent 01f31d3 commit 99ad70a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 2 additions & 0 deletions code/tests/_game_test.dm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ GLOBAL_LIST_EMPTY(game_test_chats)

#define TEST_ASSERT_LAST_CHATLOG(puppet, text) if(!puppet.last_chatlog_has_text(text)) { return Fail("Expected `[text]` in last chatlog but got `[puppet.get_last_chatlog()]`", __FILE__, __LINE__) }

#define TEST_ASSERT_ANY_CHATLOG(puppet, text) if(!puppet.any_chatlog_has_text(text)) { return Fail("Expected `[text]` in any chatlog but got [jointext(puppet.get_chatlogs(), "\n")]", __FILE__, __LINE__) }

/// Asserts that the two parameters passed are equal, fails otherwise
/// Optionally allows an additional message in the case of a failure
#define TEST_ASSERT_EQUAL(a, b, message) do { \
Expand Down
23 changes: 17 additions & 6 deletions code/tests/_game_test_puppeteer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@
var/datum/test_puppeteer/puppet_target = target
if(istype(puppet_target))
puppet.ClickOn(puppet_target.puppet, params)
return
else
puppet.ClickOn(target, params)

puppet.ClickOn(target, params)
puppet.next_click = world.time
puppet.next_move = world.time

Expand Down Expand Up @@ -94,14 +94,25 @@
puppet.rejuvenate()

/datum/test_puppeteer/proc/get_last_chatlog()
if(!(puppet.mind.key in GLOB.game_test_chats))
return FALSE
var/list/puppet_chat_list = GLOB.game_test_chats[puppet.mind.key]
return puppet_chat_list[length(puppet_chat_list)]
var/list/puppet_chat_list = get_chatlogs()
if(length(puppet_chat_list))
return puppet_chat_list[length(puppet_chat_list)]

/datum/test_puppeteer/proc/last_chatlog_has_text(snippet)
return findtextEx(get_last_chatlog(), snippet)

/datum/test_puppeteer/proc/any_chatlog_has_text(snippet)
for(var/chat_line in get_chatlogs())
if(findtextEx(chat_line, snippet))
return TRUE

return FALSE

/datum/test_puppeteer/proc/get_chatlogs()
if(!(puppet.mind.key in GLOB.game_test_chats))
return list()
return GLOB.game_test_chats[puppet.mind.key]

/datum/test_puppeteer/proc/find_nearby(atom_type)
for(var/turf/T in RANGE_TURFS(1, puppet))
for(var/atom/A in T.contents)
Expand Down

0 comments on commit 99ad70a

Please sign in to comment.