Files
Bubberstation/code/modules/unit_tests/preferences.dm
Tastyfish bca463316b Makes integration test results be in color and have annotations (#66649)
About The Pull Request

    Separated compiling the integration tests and running them as separate steps for organization purposes.
    Added a TEST_ASSERT_NULL(value, reason) and TEST_ASSERT_NOTNULL(value, reason) because those are conceptually simple tests.
    Makes the PASS and FAIL prefixes in the integration test log be green and red for better readability.
    Failure reasons now display the file and line number.
        In order to achieve this, direct calls to Fail() are now wrapped in a macro, TEST_FAIL(), as Fail() itself needs preprocessor stuff passed to it.
        In the midst of updating it, I noticed multiple cases of tests directly calling Fail() and returning when they should have used a better macro, so those were updated. There was at least one case where it appeared that the code assumed that the test ended at Fail(), but made no attempt to do so, such as with the RCD test.
        Feel free to double check all of the changed unit tests in case I made a functional behavior change, but they currently pass.
    To take advantage of the previous change, failures are now marked as annotations. Note that outside of github, this creates an ugly-looking line but the primary environment is as a github action.

Examples with intentionally botched unit test:

image

image

image
Why It's Good For The Game

Makes inspecting failed unit tests significantly easier.
Changelog

N/A
2022-05-04 13:19:01 +12:00

52 lines
2.1 KiB
Plaintext

/// Requires all preferences to implement required methods.
/datum/unit_test/preferences_implement_everything
/datum/unit_test/preferences_implement_everything/Run()
var/datum/preferences/preferences = new
var/mob/living/carbon/human/human = allocate(/mob/living/carbon/human)
for (var/preference_type in GLOB.preference_entries)
var/datum/preference/preference = GLOB.preference_entries[preference_type]
if (preference.savefile_identifier == PREFERENCE_CHARACTER)
preference.apply_to_human(human, preference.create_informed_default_value(preferences))
if (istype(preference, /datum/preference/choiced))
var/datum/preference/choiced/choiced_preference = preference
choiced_preference.init_possible_values()
// Smoke-test is_valid
preference.is_valid(TRUE)
preference.is_valid("string")
preference.is_valid(100)
preference.is_valid(list(1, 2, 3))
/// Requires all preferences to have a valid, unique savefile_identifier.
/datum/unit_test/preferences_valid_savefile_key
/datum/unit_test/preferences_valid_savefile_key/Run()
var/list/known_savefile_keys = list()
for (var/preference_type in GLOB.preference_entries)
var/datum/preference/preference = GLOB.preference_entries[preference_type]
if (!istext(preference.savefile_key))
TEST_FAIL("[preference_type] has an invalid savefile_key.")
if (preference.savefile_key in known_savefile_keys)
TEST_FAIL("[preference_type] has a non-unique savefile_key `[preference.savefile_key]`!")
known_savefile_keys += preference.savefile_key
/// Requires all main features have a main_feature_name
/datum/unit_test/preferences_valid_main_feature_name
/datum/unit_test/preferences_valid_main_feature_name/Run()
for (var/preference_type in GLOB.preference_entries)
var/datum/preference/choiced/preference = GLOB.preference_entries[preference_type]
if (!istype(preference))
continue
if (preference.category != PREFERENCE_CATEGORY_FEATURES && preference.category != PREFERENCE_CATEGORY_CLOTHING)
continue
TEST_ASSERT(!isnull(preference.main_feature_name), "Preference [preference_type] does not have a main_feature_name set!")