diff --git a/code/modules/mob/living/living_say.dm b/code/modules/mob/living/living_say.dm index 05906418fab..1a860763867 100644 --- a/code/modules/mob/living/living_say.dm +++ b/code/modules/mob/living/living_say.dm @@ -231,7 +231,14 @@ GLOBAL_LIST_INIT(message_modes_stat_limits, list( message = "[randomnote] [message] [randomnote]" spans |= SPAN_SINGING + #ifdef UNIT_TESTS + // Saves a ref() to our arglist specifically. + // We do this because we need to check that COMSIG_MOB_SAY is getting EXACTLY this list. + last_say_args_ref = REF(args) + #endif + // Leaving this here so that anything that handles speech this way will be able to have spans affecting it and all that. + // Make sure the arglist is passed exactly - don't pass a copy of it. Say signal handlers will modify some of the parameters. var/sigreturn = SEND_SIGNAL(src, COMSIG_MOB_SAY, args, message_range) if (sigreturn & COMPONENT_UPPERCASE_SPEECH) message = uppertext(message) diff --git a/code/modules/unit_tests/say.dm b/code/modules/unit_tests/say.dm index 401572cf9e3..38ce20c43dc 100644 --- a/code/modules/unit_tests/say.dm +++ b/code/modules/unit_tests/say.dm @@ -21,3 +21,22 @@ TEST_ASSERT(!expected_mods.len, "Some message mods were expected, but were not returned by get_message_mods: [json_encode(expected_mods)]. Message: [message]") + +/// Test to verify COMSIG_MOB_SAY is sent the exact same list as the message args, as they're operated on +/datum/unit_test/say_signal + +/datum/unit_test/say_signal/Run() + var/mob/living/dummy = allocate(/mob/living) + + RegisterSignal(dummy, COMSIG_MOB_SAY, .proc/check_say) + dummy.say("Make sure the say signal gets the arglist say is past, no copies!") + +/datum/unit_test/say_signal/proc/check_say(mob/living/source, list/say_args) + SIGNAL_HANDLER + + TEST_ASSERT_EQUAL(REF(say_args), source.last_say_args_ref, "Say signal didn't get the argslist of say as a reference. \ + This is required for the signal to function in most places - do not create a new instance of a list when passing it in to the signal.") + +// For the above test to track the last use of say's message args. +/mob/living + var/last_say_args_ref