Skip to content

Commit

Permalink
sort unit tests by name inside of each priority bracket (#1185)
Browse files Browse the repository at this point in the history
* sort unit tests by name inside of each priority bracket

* maybe better?

* im dum

* try to fix this cringe

* cleaner

* add names to combat tests
  • Loading branch information
Kapu1178 authored Jan 14, 2025
1 parent dedc334 commit 8f48eec
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 1 deletion.
5 changes: 5 additions & 0 deletions code/__HELPERS/cmp.dm
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
/proc/cmp_name_dsc(atom/a, atom/b)
return sorttext(a.name, b.name)

/proc/cmp_name_or_type_asc(atom/a, atom/b)
var/comp_a = a.name || "[a.type]"
var/comp_b = b.name || "[b.type]"
return sorttext(comp_b, comp_a)

GLOBAL_VAR_INIT(cmp_field, "name")
/proc/cmp_records_asc(datum/data/record/a, datum/data/record/b)
return sorttext(b.fields[GLOB.cmp_field], a.fields[GLOB.cmp_field])
Expand Down
23 changes: 23 additions & 0 deletions code/modules/unit_tests/_unit_test.dm
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ GLOBAL_LIST_EMPTY(unit_test_mapping_logs)
if (istype(content, /obj/effect/landmark))
continue
qdel(content)

for(var/mob/dead/observer/ghost in GLOB.dead_mob_list)
if(!ghost.client)
ghost.key = null
qdel(ghost)

return ..()

/datum/unit_test/proc/Run()
Expand Down Expand Up @@ -171,6 +177,23 @@ GLOBAL_LIST_EMPTY(unit_test_mapping_logs)

tests_to_run = sortTim(tests_to_run, GLOBAL_PROC_REF(cmp_unit_test_priority))

/// Create a list of every unit test for each priority value
var/list/priority_buckets = list()
for(var/datum/unit_test/test as anything in tests_to_run)
var/priority_str = "[test.priority]"
if(!(priority_str in priority_buckets))
priority_buckets[priority_str] = list()

priority_buckets[priority_str] += test

/// Sort them by name within those buckets
for(var/priority_str in priority_buckets)
sortTim(priority_buckets[priority_str], GLOBAL_PROC_REF(cmp_name_or_type_asc))

tests_to_run = list()
for(var/priority_str in priority_buckets)
tests_to_run += priority_buckets[priority_str]

var/list/test_results = list()

for(var/unit_path in tests_to_run)
Expand Down
14 changes: 14 additions & 0 deletions code/modules/unit_tests/combat/combat.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/datum/unit_test/combat/harm_punch
name = "COMBAT: Punching Shall Deal Damage"

/datum/unit_test/combat/harm_punch/Run()
var/mob/living/carbon/human/puncher = allocate(/mob/living/carbon/human)
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human)
Expand All @@ -10,6 +13,9 @@

TEST_ASSERT(victim.getBruteLoss() > 0, "Victim took no brute damage after being punched")

/datum/unit_test/combat/harm_melee
name = "COMBAT: Toolboxes Shall Deal Damage"

/datum/unit_test/combat/harm_melee/Run()
var/mob/living/carbon/human/tider = allocate(/mob/living/carbon/human)
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human)
Expand All @@ -21,6 +27,9 @@

TEST_ASSERT(victim.getBruteLoss() > 0, "Victim took no brute damage after being hit by a toolbox")

/datum/unit_test/combat/harm_different_damage
name = "COMBAT: Welding Tools Shall Deal Burn Damage"

/datum/unit_test/combat/harm_different_damage/Run()
var/mob/living/carbon/human/attacker = allocate(/mob/living/carbon/human)
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human)
Expand All @@ -36,6 +45,7 @@
TEST_ASSERT(victim.getFireLoss() > 0, "Victim took no burn damage after being hit by a lit welding tool")

/datum/unit_test/combat/attack_chain
name = "COMBAT: Attack Chain Sanity"
var/attack_hit
var/post_attack_hit
var/pre_attack_hit
Expand Down Expand Up @@ -69,6 +79,9 @@
TEST_ASSERT(attack_hit, "Attack signal was not fired")
TEST_ASSERT(post_attack_hit, "Post-attack signal was not fired")

/datum/unit_test/combat/non_standard_damage
name = "COMBAT: Brain Damage Shall Kill"

/datum/unit_test/combat/non_standard_damage/Run()
var/mob/living/carbon/human/man = allocate(/mob/living/carbon/human)

Expand All @@ -77,6 +90,7 @@

/// Tests you can punch yourself
/datum/unit_test/combat/self_punch
name = "COMBAT: You Can Punch Yourself"

/datum/unit_test/combat/self_punch/Run()
var/mob/living/carbon/human/dummy = allocate(/mob/living/carbon/human/consistent)
Expand Down
1 change: 0 additions & 1 deletion code/modules/unit_tests/combat/combat_blocking.dm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/datum/unit_test/combat/armed_blocking
name = "COMBAT/BLOCKING: Items Must Block Armed Attacks"


/datum/unit_test/combat/armed_blocking/Run()
var/mob/living/carbon/human/consistent/attacker = ALLOCATE_BOTTOM_LEFT()
var/mob/living/carbon/human/consistent/victim = ALLOCATE_BOTTOM_LEFT()
Expand Down
1 change: 1 addition & 0 deletions code/modules/unit_tests/combat/combat_door_click.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Tests that airlocks can be closed by clicking on the floor, as [/datum/component/redirect_attack_hand_from_turf ] dictates
/datum/unit_test/combat/door_click
name = "COMBAT/INTERACTION: Doors Shall Open and Close On Click."

/datum/unit_test/combat/door_click/Run()
var/mob/living/carbon/human/consistent/tider = ALLOCATE_BOTTOM_LEFT()
Expand Down
1 change: 1 addition & 0 deletions code/modules/unit_tests/combat/combat_emp_flashlight.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Test EMP flashlight EMPs people you point it at
/datum/unit_test/combat/emp_flashlight
name = "COMBAT/MISC: EMP Flashlight Shall EMP On Click"
var/sig_caught = 0

/datum/unit_test/combat/emp_flashlight/Run()
Expand Down
3 changes: 3 additions & 0 deletions code/modules/unit_tests/combat/combat_flash.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Tests that flashes, well, flash.
/datum/unit_test/combat/flash_click
name = "COMBAT/FLASH: Flashes Shall Deal Stamina Damage"
var/apply_verb = "while Attacker was not on combat mode"

/datum/unit_test/combat/flash_click/Run()
Expand All @@ -22,6 +23,7 @@

/// Tests that flashes flash on combat mode.
/datum/unit_test/combat/flash_click/combat_mode
name = "COMBAT/FLASH: Flashes Shall Deal Stamina Damage (Combat Mode)"
apply_verb = "while Attacker was on combat mode"

/datum/unit_test/combat/flash_click/combat_mode/ready_subjects(mob/living/carbon/human/attacker, mob/living/carbon/human/victim)
Expand All @@ -30,6 +32,7 @@

/// Tests that flashes do not flash if wearing protection.
/datum/unit_test/combat/flash_click/flash_protection
name = "COMBAT/FLASH: Flashes Shall Deal Not Deal Stamina Damage To Flash Immune"
apply_verb = "while wearing flash protection"

/datum/unit_test/combat/flash_click/flash_protection/ready_subjects(mob/living/carbon/human/attacker, mob/living/carbon/human/victim)
Expand Down
1 change: 1 addition & 0 deletions code/modules/unit_tests/combat/combat_pistol_whip.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Tests that guns (bayonetted or otherwise) are able to be used as melee weapons in close range
/datum/unit_test/combat/pistol_whip
name = "COMBAT/GUNS: Guns Shall Melee With Combat Mode and Point-Blank Without"

/datum/unit_test/combat/pistol_whip/Run()
var/mob/living/carbon/human/consistent/attacker = ALLOCATE_BOTTOM_LEFT()
Expand Down
6 changes: 6 additions & 0 deletions code/modules/unit_tests/combat/combat_stamina.dm
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/datum/unit_test/combat/stamina_swing
name = "COMBAT/STAMINA: Attacking Shall Consume Stamina"

/datum/unit_test/combat/stamina_swing/Run()
var/mob/living/carbon/human/consistent/attacker = ALLOCATE_BOTTOM_LEFT()
var/mob/living/carbon/human/consistent/victim = ALLOCATE_BOTTOM_LEFT()
Expand All @@ -14,6 +17,9 @@
var/actual_loss = attacker.stamina.loss
TEST_ASSERT_EQUAL(actual_loss, expected_loss, "Attacker didn't lose 50 stamina, lost [actual_loss] instead.")

/datum/unit_test/combat/stamina_damage
name = "COMBAT/STAMINA: Melee Victim Shall Lose Stamina"

/datum/unit_test/combat/stamina_damage/Run()
var/mob/living/carbon/human/consistent/attacker = ALLOCATE_BOTTOM_LEFT()
var/mob/living/carbon/human/consistent/victim = ALLOCATE_BOTTOM_LEFT()
Expand Down
1 change: 1 addition & 0 deletions code/modules/unit_tests/create_and_destroy.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
///Delete one of every type, sleep a while, then check to see if anything has gone fucky
/datum/unit_test/create_and_destroy
name = "DEL THE WORLD: All Atoms Shall Cleanly Initialize and Destroy"
//You absolutely must run last
priority = TEST_DEL_WORLD

Expand Down

0 comments on commit 8f48eec

Please sign in to comment.