diff --git a/code/modules/reagents/chemistry/holder.dm b/code/modules/reagents/chemistry/holder.dm index 9cab0471a31..fdac65e20f2 100644 --- a/code/modules/reagents/chemistry/holder.dm +++ b/code/modules/reagents/chemistry/holder.dm @@ -614,12 +614,20 @@ for(var/_reagent in cached_reagents) var/datum/reagent/R = _reagent if(R.type == reagent) - if(my_atom && isliving(my_atom)) - var/mob/living/M = my_atom + var/mob/living/mob_consumer + + if (isliving(my_atom)) + mob_consumer = my_atom + else if (istype(my_atom, /obj/item/organ)) + var/obj/item/organ/organ = my_atom + mob_consumer = organ.owner + + if (mob_consumer) if(R.metabolizing) R.metabolizing = FALSE - R.on_mob_end_metabolize(M) - R.on_mob_delete(M) + R.on_mob_end_metabolize(mob_consumer) + R.on_mob_delete(mob_consumer) + //Clear from relevant lists addiction_list -= R reagent_list -= R diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index efbf15714a5..eacac93a2ea 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -2,6 +2,7 @@ //Keep this sorted alphabetically #ifdef UNIT_TESTS + /// Asserts that a condition is true /// If the condition is not true, fails the test #define TEST_ASSERT(assertion, reason) if (!(assertion)) { return Fail("Assertion failed: [reason || "No reason"]") } @@ -14,6 +15,11 @@ /// Optionally allows an additional message in the case of a failure #define TEST_ASSERT_NOTEQUAL(a, b, message) if ((a) == (b)) { return Fail("Expected [isnull(a) ? "null" : a] to not be equal to [isnull(b) ? "null" : b].[message ? " [message]" : ""]") } +/// *Only* run the test provided within the parentheses +/// This is useful for debugging when you want to reduce noise, but should never be pushed +/// Intended to be used in the manner of `TEST_FOCUS(/datum/unit_test/math)` +#define TEST_FOCUS(test_path) ##test_path { focus = TRUE; } + #include "anchored_mobs.dm" #include "bespoke_id.dm" #include "binary_insert.dm" diff --git a/code/modules/unit_tests/metabolizing.dm b/code/modules/unit_tests/metabolizing.dm index 895762c0ecc..a8e7d84d7ee 100644 --- a/code/modules/unit_tests/metabolizing.dm +++ b/code/modules/unit_tests/metabolizing.dm @@ -17,3 +17,20 @@ /datum/unit_test/metabolization/Destroy() SSmobs.ignite() return ..() + +/datum/unit_test/on_mob_end_metabolize/Run() + var/mob/living/carbon/human/user = allocate(/mob/living/carbon/human) + var/obj/item/reagent_containers/pill/pill = allocate(/obj/item/reagent_containers/pill) + var/datum/reagent/drug/methamphetamine/meth = /datum/reagent/drug/methamphetamine + + // Give them enough meth to be consumed in 2 metabolizations + pill.reagents.add_reagent(meth, initial(meth.metabolization_rate) * 1.9) + pill.attack(user, user) + user.Life() + + TEST_ASSERT(user.has_reagent(meth), "User does not have meth in their system after consuming it") + TEST_ASSERT(user.has_movespeed_modifier(/datum/movespeed_modifier/reagent/methamphetamine), "User consumed meth, but did not gain movespeed modifier") + + user.Life() + TEST_ASSERT(!user.has_reagent(meth), "User still has meth in their system when it should've finished metabolizing") + TEST_ASSERT(!user.has_movespeed_modifier(/datum/movespeed_modifier/reagent/methamphetamine), "User still has movespeed modifier despite not containing any more meth") diff --git a/code/modules/unit_tests/unit_test.dm b/code/modules/unit_tests/unit_test.dm index 11a22097182..5f5b59cc30c 100644 --- a/code/modules/unit_tests/unit_test.dm +++ b/code/modules/unit_tests/unit_test.dm @@ -24,6 +24,7 @@ GLOBAL_VAR(test_log) var/turf/run_loc_top_right //internal shit + var/focus = FALSE var/succeeded = TRUE var/list/allocated var/list/fail_reasons @@ -66,7 +67,14 @@ GLOBAL_VAR(test_log) /proc/RunUnitTests() CHECK_TICK - for(var/I in subtypesof(/datum/unit_test)) + var/tests_to_run = subtypesof(/datum/unit_test) + for (var/_test_to_run in tests_to_run) + var/datum/unit_test/test_to_run = _test_to_run + if (initial(test_to_run.focus)) + tests_to_run = list(test_to_run) + break + + for(var/I in tests_to_run) var/datum/unit_test/test = new I GLOB.current_test = test