mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-08-25 14:08:31 +01:00
[MIRROR] Put unit tests in a box, fixes sporradic gun test failure (#3896)
* Put unit tests in a box, fixes sporradic gun test failure (#57408) * Initial commit * Fix removing old objects * Remove define * TGM * Put unit tests in a box, fixes sporradic gun test failure Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/datum/unit_test/chain_pull_through_space
|
||||
var/turf/open/space/space_tile
|
||||
var/turf/claimed_tile
|
||||
var/claimed_tile
|
||||
var/mob/living/carbon/human/alice
|
||||
var/mob/living/carbon/human/bob
|
||||
var/mob/living/carbon/human/charlie
|
||||
@@ -9,25 +9,25 @@
|
||||
..()
|
||||
|
||||
// Create a space tile that goes to another z-level
|
||||
claimed_tile = run_loc_bottom_left
|
||||
claimed_tile = run_loc_floor_bottom_left.type
|
||||
|
||||
space_tile = new(locate(run_loc_bottom_left.x, run_loc_bottom_left.y, run_loc_bottom_left.z))
|
||||
space_tile = new(locate(run_loc_floor_bottom_left.x, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
||||
space_tile.destination_x = 100
|
||||
space_tile.destination_y = 100
|
||||
space_tile.destination_z = 5
|
||||
|
||||
// Create our list of humans, all adjacent to one another
|
||||
alice = new(locate(run_loc_bottom_left.x + 2, run_loc_bottom_left.y, run_loc_bottom_left.z))
|
||||
alice = new(locate(run_loc_floor_bottom_left.x + 2, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
||||
alice.name = "Alice"
|
||||
|
||||
bob = new(locate(run_loc_bottom_left.x + 3, run_loc_bottom_left.y, run_loc_bottom_left.z))
|
||||
bob = new(locate(run_loc_floor_bottom_left.x + 3, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
||||
bob.name = "Bob"
|
||||
|
||||
charlie = new(locate(run_loc_bottom_left.x + 4, run_loc_bottom_left.y, run_loc_bottom_left.z))
|
||||
charlie = new(locate(run_loc_floor_bottom_left.x + 4, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
||||
charlie.name = "Charlie"
|
||||
|
||||
/datum/unit_test/chain_pull_through_space/Destroy()
|
||||
space_tile.copyTurf(claimed_tile)
|
||||
space_tile.ChangeTurf(claimed_tile)
|
||||
qdel(alice)
|
||||
qdel(bob)
|
||||
qdel(charlie)
|
||||
@@ -40,14 +40,14 @@
|
||||
bob.start_pulling(charlie)
|
||||
|
||||
// Walk normally to the left, make sure we're still a chain
|
||||
alice.Move(locate(run_loc_bottom_left.x + 1, run_loc_bottom_left.y, run_loc_bottom_left.z))
|
||||
if (bob.x != run_loc_bottom_left.x + 2)
|
||||
alice.Move(locate(run_loc_floor_bottom_left.x + 1, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
||||
if (bob.x != run_loc_floor_bottom_left.x + 2)
|
||||
return Fail("During normal move, Bob was not at the correct x ([bob.x])")
|
||||
if (charlie.x != run_loc_bottom_left.x + 3)
|
||||
if (charlie.x != run_loc_floor_bottom_left.x + 3)
|
||||
return Fail("During normal move, Charlie was not at the correct x ([charlie.x])")
|
||||
|
||||
// We're going through the space turf now that should teleport us
|
||||
alice.Move(run_loc_bottom_left)
|
||||
alice.Move(run_loc_floor_bottom_left)
|
||||
if (alice.z != space_tile.destination_z)
|
||||
return Fail("Alice did not teleport to the destination z-level. Current location: ([alice.x], [alice.y], [alice.z])")
|
||||
|
||||
|
||||
@@ -76,15 +76,15 @@
|
||||
var/obj/structure/barricade/dense_object = allocate(/obj/structure/barricade)
|
||||
|
||||
// Attacker --> Victim --> Empty space --> Wall
|
||||
attacker.forceMove(run_loc_bottom_left)
|
||||
victim.forceMove(locate(run_loc_bottom_left.x + 1, run_loc_bottom_left.y, run_loc_bottom_left.z))
|
||||
dense_object.forceMove(locate(run_loc_bottom_left.x + 3, run_loc_bottom_left.y, run_loc_bottom_left.z))
|
||||
attacker.forceMove(run_loc_floor_bottom_left)
|
||||
victim.forceMove(locate(run_loc_floor_bottom_left.x + 1, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
||||
dense_object.forceMove(locate(run_loc_floor_bottom_left.x + 3, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
||||
|
||||
// First disarm, world should now look like:
|
||||
// Attacker --> Empty space --> Victim --> Wall
|
||||
victim.attack_hand(attacker, list(RIGHT_CLICK = TRUE))
|
||||
|
||||
TEST_ASSERT_EQUAL(victim.loc.x, run_loc_bottom_left.x + 2, "Victim wasn't moved back after being pushed")
|
||||
TEST_ASSERT_EQUAL(victim.loc.x, run_loc_floor_bottom_left.x + 2, "Victim wasn't moved back after being pushed")
|
||||
TEST_ASSERT(!victim.has_status_effect(STATUS_EFFECT_KNOCKDOWN), "Victim was knocked down despite not being against a wall")
|
||||
TEST_ASSERT_EQUAL(victim.get_active_held_item(), toolbox, "Victim dropped toolbox despite not being against a wall")
|
||||
|
||||
@@ -93,6 +93,6 @@
|
||||
// Second disarm, victim was against wall and should be down
|
||||
victim.attack_hand(attacker, list(RIGHT_CLICK = TRUE))
|
||||
|
||||
TEST_ASSERT_EQUAL(victim.loc.x, run_loc_bottom_left.x + 2, "Victim was moved after being pushed against a wall")
|
||||
TEST_ASSERT_EQUAL(victim.loc.x, run_loc_floor_bottom_left.x + 2, "Victim was moved after being pushed against a wall")
|
||||
TEST_ASSERT(victim.has_status_effect(STATUS_EFFECT_KNOCKDOWN), "Victim was not knocked down after being pushed against a wall")
|
||||
//TEST_ASSERT_EQUAL(victim.get_active_held_item(), null, "Victim didn't drop toolbox after being pushed against a wall") //SKYRAT EDIT REMOVAL - COMBAT (knockdowns dont disarm no more)
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
var/mob/living/carbon/human/human = allocate(/mob/living/carbon/human)
|
||||
|
||||
hydroponics_tray.loc = run_loc_bottom_left
|
||||
hydroponics_tray.loc = run_loc_floor_bottom_left
|
||||
human.loc = hydroponics_tray.loc
|
||||
human.x += 1
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
var/mob/living/carbon/human/victim = allocate(/mob/living/carbon/human)
|
||||
var/mob/living/carbon/human/gunner = allocate(/mob/living/carbon/human)
|
||||
|
||||
ADD_TRAIT(victim, TRAIT_RESISTLOWPRESSURE, INNATE_TRAIT) // so pressure damage doesn't throw off our damage check
|
||||
|
||||
var/obj/item/ammo_casing/loaded_casing = test_gun.chambered
|
||||
TEST_ASSERT(loaded_casing, "Gun started without round chambered, should be loaded")
|
||||
var/obj/projectile/loaded_bullet = loaded_casing.loaded_projectile
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/datum/unit_test/spawn_humans/Run()
|
||||
var/locs = block(run_loc_bottom_left, run_loc_top_right)
|
||||
var/locs = block(run_loc_floor_bottom_left, run_loc_floor_top_right)
|
||||
|
||||
for(var/I in 1 to 5)
|
||||
new /mob/living/carbon/human(pick(locs))
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/datum/unit_test/auto_teleporter_linking/Run()
|
||||
// Put down the teleporter machinery
|
||||
var/obj/machinery/teleport/hub/hub = allocate(/obj/machinery/teleport/hub)
|
||||
var/obj/machinery/teleport/station/station = allocate(/obj/machinery/teleport/station, locate(run_loc_bottom_left.x + 1, run_loc_bottom_left.y, run_loc_bottom_left.z))
|
||||
var/obj/machinery/computer/teleporter/computer = allocate(/obj/machinery/computer/teleporter, locate(run_loc_bottom_left.x + 2, run_loc_bottom_left.y, run_loc_bottom_left.z))
|
||||
var/obj/machinery/teleport/station/station = allocate(/obj/machinery/teleport/station, locate(run_loc_floor_bottom_left.x + 1, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
||||
var/obj/machinery/computer/teleporter/computer = allocate(/obj/machinery/computer/teleporter, locate(run_loc_floor_bottom_left.x + 2, run_loc_floor_bottom_left.y, run_loc_floor_bottom_left.z))
|
||||
|
||||
TEST_ASSERT_EQUAL(hub.power_station, station, "Hub didn't link to the station")
|
||||
TEST_ASSERT_EQUAL(station.teleporter_console, computer, "Station didn't link to the teleporter console")
|
||||
|
||||
@@ -7,7 +7,7 @@ Call Fail() to fail the test (You should specify a reason)
|
||||
|
||||
You may use /New() and /Destroy() for setup/teardown respectively
|
||||
|
||||
You can use the run_loc_bottom_left and run_loc_top_right to get turfs for testing
|
||||
You can use the run_loc_floor_bottom_left and run_loc_floor_top_right to get turfs for testing
|
||||
|
||||
*/
|
||||
|
||||
@@ -19,14 +19,11 @@ GLOBAL_VAR(test_log)
|
||||
//Bit of metadata for the future maybe
|
||||
var/list/procs_tested
|
||||
|
||||
/// The bottom left turf of the testing zone
|
||||
var/turf/run_loc_bottom_left
|
||||
/// The bottom left floor turf of the testing zone
|
||||
var/turf/run_loc_floor_bottom_left
|
||||
|
||||
/// The top right turf of the testing zone
|
||||
var/turf/run_loc_top_right
|
||||
|
||||
/// The type of turf to allocate for the testing zone
|
||||
var/test_turf_type = /turf/open/floor/iron
|
||||
/// The top right floor turf of the testing zone
|
||||
var/turf/run_loc_floor_top_right
|
||||
|
||||
//internal shit
|
||||
var/focus = FALSE
|
||||
@@ -34,24 +31,28 @@ GLOBAL_VAR(test_log)
|
||||
var/list/allocated
|
||||
var/list/fail_reasons
|
||||
|
||||
var/static/datum/turf_reservation/turf_reservation
|
||||
var/static/datum/space_level/reservation
|
||||
|
||||
/datum/unit_test/New()
|
||||
if (isnull(turf_reservation))
|
||||
turf_reservation = SSmapping.RequestBlockReservation(5, 5)
|
||||
|
||||
for (var/turf/reserved_turf in turf_reservation.reserved_turfs)
|
||||
reserved_turf.ChangeTurf(test_turf_type)
|
||||
if (isnull(reservation))
|
||||
var/datum/map_template/unit_tests/template = new
|
||||
reservation = template.load_new_z()
|
||||
|
||||
allocated = new
|
||||
run_loc_bottom_left = locate(turf_reservation.bottom_left_coords[1], turf_reservation.bottom_left_coords[2], turf_reservation.bottom_left_coords[3])
|
||||
run_loc_top_right = locate(turf_reservation.top_right_coords[1], turf_reservation.top_right_coords[2], turf_reservation.top_right_coords[3])
|
||||
run_loc_floor_bottom_left = get_turf(locate(/obj/effect/landmark/unit_test_bottom_left) in GLOB.landmarks_list)
|
||||
run_loc_floor_top_right = get_turf(locate(/obj/effect/landmark/unit_test_top_right) in GLOB.landmarks_list)
|
||||
|
||||
TEST_ASSERT(isfloorturf(run_loc_floor_bottom_left), "run_loc_floor_bottom_left was not a floor ([run_loc_floor_bottom_left])")
|
||||
TEST_ASSERT(isfloorturf(run_loc_floor_top_right), "run_loc_floor_top_right was not a floor ([run_loc_floor_top_right])")
|
||||
|
||||
/datum/unit_test/Destroy()
|
||||
//clear the test area
|
||||
for(var/atom/movable/AM in block(run_loc_bottom_left, run_loc_top_right))
|
||||
qdel(AM)
|
||||
QDEL_LIST(allocated)
|
||||
// clear the test area
|
||||
for (var/turf/turf in block(locate(1, 1, run_loc_floor_bottom_left.z), locate(world.maxx, world.maxy, run_loc_floor_bottom_left.z)))
|
||||
for (var/content in turf.contents)
|
||||
if (iseffect(content))
|
||||
continue
|
||||
qdel(content)
|
||||
return ..()
|
||||
|
||||
/datum/unit_test/proc/Run()
|
||||
@@ -70,9 +71,9 @@ GLOBAL_VAR(test_log)
|
||||
/datum/unit_test/proc/allocate(type, ...)
|
||||
var/list/arguments = args.Copy(2)
|
||||
if (!arguments.len)
|
||||
arguments = list(run_loc_bottom_left)
|
||||
arguments = list(run_loc_floor_bottom_left)
|
||||
else if (arguments[1] == null)
|
||||
arguments[1] = run_loc_bottom_left
|
||||
arguments[1] = run_loc_floor_bottom_left
|
||||
var/instance = new type(arglist(arguments))
|
||||
allocated += instance
|
||||
return instance
|
||||
@@ -120,3 +121,7 @@ GLOBAL_VAR(test_log)
|
||||
file(file_name) << json_encode(test_results)
|
||||
|
||||
SSticker.force_ending = TRUE
|
||||
|
||||
/datum/map_template/unit_tests
|
||||
name = "Unit Tests Zone"
|
||||
mappath = "_maps/templates/unit_tests.dmm"
|
||||
|
||||
Reference in New Issue
Block a user