Files
Bubberstation/code/modules/unit_tests/modify_fantasy_variable.dm
san7890 63f7eb1a6a Fixes Ticked File Enforcement and Missing Unit Test (and makes said Unit Test Compile) (and genericizes the C&D list to the base unit test datum) (#77632)
Closes #77631

## About The Pull Request

Hey there,

Ticked File Enforcement simply wasn't catching files that were missed.
That's a bit stupid, so I decided to look into what the issue might be,
and whoopsie daisies I did double periods back in #76592
(020ac24053).

![image](https://github.com/tgstation/tgstation/assets/34697715/6023afe8-313d-4550-9a60-58a8bc211b4f)

I also added some debug info and some more checks to prevent such a
break from happening again on runtime of this script. I thought it was a
weird string concatenation issue (and not the simple break I thought it
was), so I rewrote how it adds `glob`s. I think it's cleaner so I'll
keep it anyhow

This PR also corrects the oversight of the missing unit test (introduced
in #77218 (69827604c4)) by reticking it in
the `_unit_tests.dm` file, and also makes it compile because it didn't
do that.

I also then had to do some more work to get the unit test to work.
* Genericizes the Create-and-Destroy "ignore" list to be a static list
on `/datum/unit_test` to allow it to be shared between these types of
tests that we need to test.
* Adds that list to C&D and the broken unit test regarding fantasy
bonuses
* Fixes some actually broken that the unit test was made to catch (beam
rifles, butterdogs and other slippery items, random ingredient boxes).
* Adds cases for things that the unit test and overall framework really
shouldn't be altering anyways (mythril), and was likely causing
inappropriate stack traces on master

## Why It's Good For The Game

Unit Tests WORK. Tools WORK.


![image](https://github.com/tgstation/tgstation/assets/34697715/9a59c0db-7a33-4546-918b-c73372a5b867)


## Changelog

🆑
fix: Beam rifles will no longer inappropriately retain any bonuses they
may gain from wizardry.
fix: Inappropriate stack traces over bonuses being applied to components
that gain bonuses innately (like Mythril stacks) should cease.
/🆑
2023-08-15 23:51:26 -07:00

47 lines
2.1 KiB
Plaintext

// Unit test to make sure that there are no duplicate keys when modify_fantasy_variable is called when applying fantasy bonuses.
// Also to make sure the fantasy_modifications list is null when fantasy bonuses are removed.
/datum/unit_test/modify_fantasy_variable
priority = TEST_LONGER
/datum/unit_test/modify_fantasy_variable/Run()
var/list/applicable_types = subtypesof(/obj/item) - uncreatables
for(var/obj/item/path as anything in applicable_types)
var/obj/item/object = allocate(path)
// objects will have fantasy bonuses inherent to their type (like butterdogs and the slippery component), so we need to take this into account
var/number_of_extant_bonuses = LAZYLEN(object.fantasy_modifications)
#define TEST_SUCCESS LAZYLEN(object.fantasy_modifications) == number_of_extant_bonuses
// Try positive
object.apply_fantasy_bonuses(bonus = 5)
object.remove_fantasy_bonuses(bonus = 5)
TEST_ASSERT(TEST_SUCCESS, generate_failure_message(object))
// Then negative
object.apply_fantasy_bonuses(bonus = -5)
object.remove_fantasy_bonuses(bonus = -5)
TEST_ASSERT(TEST_SUCCESS, generate_failure_message(object))
// Now try the extremes of each
object.apply_fantasy_bonuses(bonus = 500)
object.remove_fantasy_bonuses(bonus = 500)
TEST_ASSERT(TEST_SUCCESS, generate_failure_message(object))
object.apply_fantasy_bonuses(bonus = -500)
object.remove_fantasy_bonuses(bonus = -500)
TEST_ASSERT(TEST_SUCCESS, generate_failure_message(object))
/// Returns a string that we use to describe the failure of the test.
/datum/unit_test/modify_fantasy_variable/proc/generate_failure_message(obj/item/failed_object)
var/list/cached_modifications = failed_object.fantasy_modifications
var/length_of_modifications = LAZYLEN(cached_modifications)
var/list/failure_messages = list("Error found when adding+removing fantasy bonuses for [failed_object.type].")
failure_messages += "The length of the fantasy_modifications list was [length_of_modifications]."
if(length_of_modifications)
failure_messages += "The fantasy_modifications list was [cached_modifications.Join(", ")]."
return failure_messages.Join(" ")
#undef TEST_SUCCESS