Skip to content

Commit

Permalink
Ports the tg unit test box (#13824)
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmixo authored Aug 20, 2023
1 parent 6419643 commit 83e05cc
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 42 deletions.
79 changes: 79 additions & 0 deletions _maps/templates/unit_tests.dmm
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
//MAP CONVERTED BY dmm2tgm.py THIS HEADER COMMENT PREVENTS RECONVERSION, DO NOT REMOVE
"a" = (
/turf/closed/wall,
/area/testroom)
"m" = (
/turf/open/floor/iron,
/area/testroom)
"r" = (
/obj/effect/landmark/unit_test_top_right,
/turf/open/floor/iron,
/area/testroom)
"L" = (
/obj/effect/landmark/unit_test_bottom_left,
/turf/open/floor/iron,
/area/testroom)

(1,1,1) = {"
a
a
a
a
a
a
a
"}
(2,1,1) = {"
a
m
m
m
m
L
a
"}
(3,1,1) = {"
a
m
m
m
m
m
a
"}
(4,1,1) = {"
a
m
m
m
m
m
a
"}
(5,1,1) = {"
a
m
m
m
m
m
a
"}
(6,1,1) = {"
a
r
m
m
m
m
a
"}
(7,1,1) = {"
a
a
a
a
a
a
a
"}
8 changes: 8 additions & 0 deletions code/game/area/general.dm
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,14 @@
static_lighting = FALSE
base_lighting_alpha = 255

/area/testroom
requires_power = FALSE
// Mobs should be able to see inside the testroom
static_lighting = FALSE
base_lighting_alpha = 255
name = "Test Room"
icon_state = "test_room"


/area/syndicate_mothership
name = "Abandoned Syndicate Base"
Expand Down
10 changes: 10 additions & 0 deletions code/game/objects/effects/landmarks/landmarks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -485,3 +485,13 @@
/obj/effect/landmark/eord_roomba/Destroy()
GLOB.eord_roomba_spawns -= src
return ..()

/// Marks the bottom left of the testing zone.
/// In landmarks.dm and not unit_test.dm so it is always active in the mapping tools.
/obj/effect/landmark/unit_test_bottom_left
name = "unit test zone bottom left"

/// Marks the top right of the testing zone.
/// In landmarks.dm and not unit_test.dm so it is always active in the mapping tools.
/obj/effect/landmark/unit_test_top_right
name = "unit test zone top right"
1 change: 1 addition & 0 deletions code/game/world.dm
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ GLOBAL_VAR(restart_counter)
//trigger things to run the whole process
Master.sleep_offline_after_initializations = FALSE
SSticker.start_immediately = TRUE
SSticker.bypass_checks = TRUE
CONFIG_SET(number/round_end_countdown, 0)
var/datum/callback/cb
#ifdef UNIT_TESTS
Expand Down
10 changes: 5 additions & 5 deletions code/modules/unit_tests/connect_loc.dm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
SEND_SIGNAL(current_turf, COMSIG_MOCK_SIGNAL)
TEST_ASSERT_EQUAL(watcher.times_called, 1, "After firing mock signal, connect_loc didn't send it")

watcher.forceMove(run_loc_top_right)
watcher.forceMove(run_loc_floor_top_right)

SEND_SIGNAL(current_turf, COMSIG_MOCK_SIGNAL)
TEST_ASSERT_EQUAL(watcher.times_called, 1, "Mock signal was fired on old turf, but connect_loc still picked it up")
Expand All @@ -25,7 +25,7 @@
var/old_turf_type

/datum/unit_test/connect_loc_change_turf/Run()
var/obj/item/watches_mock_calls/watcher = allocate(/obj/item/watches_mock_calls, run_loc_bottom_left)
var/obj/item/watches_mock_calls/watcher = allocate(/obj/item/watches_mock_calls, run_loc_floor_bottom_left)

var/turf/current_turf = get_turf(watcher)
old_turf_type = current_turf.type
Expand All @@ -43,17 +43,17 @@
TEST_ASSERT_EQUAL(watcher.times_called, 3, "After changing turf a second time, connect_loc didn't reconnect it")

/datum/unit_test/connect_loc_change_turf/Destroy()
run_loc_bottom_left.ChangeTurf(old_turf_type)
run_loc_floor_bottom_left.ChangeTurf(old_turf_type)
return ..()

/// Tests that multiple objects can have connect_loc on the same turf without runtimes.
/datum/unit_test/connect_loc_multiple_on_turf

/datum/unit_test/connect_loc_multiple_on_turf/Run()
var/obj/item/watches_mock_calls/watcher_one = allocate(/obj/item/watches_mock_calls, run_loc_bottom_left)
var/obj/item/watches_mock_calls/watcher_one = allocate(/obj/item/watches_mock_calls, run_loc_floor_bottom_left)
qdel(watcher_one)

var/obj/item/watches_mock_calls/watcher_two = allocate(/obj/item/watches_mock_calls, run_loc_bottom_left)
var/obj/item/watches_mock_calls/watcher_two = allocate(/obj/item/watches_mock_calls, run_loc_floor_bottom_left)
qdel(watcher_two)

/obj/item/watches_mock_calls
Expand Down
47 changes: 26 additions & 21 deletions code/modules/unit_tests/unit_test.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand All @@ -18,38 +18,39 @@ GLOBAL_VAR_INIT(failed_any_test, FALSE)
//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/plating
/// The top right floor turf of the testing zone
var/turf/run_loc_floor_top_right

//internal shit
var/focus = FALSE
var/succeeded = TRUE
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)
// 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)
QDEL_LIST(allocated)
return ..()

Expand All @@ -69,9 +70,9 @@ GLOBAL_VAR_INIT(failed_any_test, FALSE)
/datum/unit_test/proc/allocate(type, ...)
var/list/arguments = args.Copy(2)
if (!length(arguments))
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
Expand Down Expand Up @@ -122,3 +123,7 @@ GLOBAL_VAR_INIT(failed_any_test, FALSE)

SSticker.force_ending = TRUE
SSticker.Reboot()

/datum/map_template/unit_tests
name = "Unit Tests Zone"
mappath = "_maps/templates/unit_tests.dmm"
16 changes: 1 addition & 15 deletions code/modules/unit_tests/weed_ability.dm
Original file line number Diff line number Diff line change
@@ -1,21 +1,7 @@
/datum/unit_test/weed_ability
var/turf/open/open_tile
var/turf/claimed_tile

/datum/unit_test/weed_ability/New()
..()

//create a tile so we can drop the weeds
claimed_tile = run_loc_bottom_left
open_tile = new(locate(run_loc_bottom_left.x, run_loc_bottom_left.y, run_loc_bottom_left.z))


/datum/unit_test/weed_ability/Destroy()
open_tile.copyTurf(claimed_tile)
return ..()

/datum/unit_test/weed_ability/Run()
var/mob/living/carbon/xenomorph/drone/drone = new(open_tile)
var/mob/living/carbon/xenomorph/drone/drone = new(run_loc_floor_bottom_left)
var/datum/action/xeno_action/activable/plant_weeds/weed = drone.actions_by_path[/datum/action/xeno_action/activable/plant_weeds]
if(!weed.can_use_action())
Fail("Drone could not activate weed ability!")
Expand Down
2 changes: 1 addition & 1 deletion code/modules/unit_tests/weed_spread.dm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/datum/unit_test/weed_spread/Run()
var/obj/alien/weeds/node/node = new(locate(run_loc_bottom_left.x+1, run_loc_bottom_left.y+1, run_loc_bottom_left.z))
var/obj/alien/weeds/node/node = new(locate(run_loc_floor_bottom_left.x+1, run_loc_floor_bottom_left.y+1, run_loc_floor_bottom_left.z))
sleep(6 SECONDS)
var/found = FALSE
var/turf/origin = get_turf(node)
Expand Down
1 change: 1 addition & 0 deletions tgmc.dme
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
// BEGIN_INCLUDE
#include "_maps\_basemap.dm"
#include "_maps\map_files\generic\Admin_Level.dmm"
#include "_maps\templates\unit_tests.dmm"
#include "code\__byond_version_compat.dm"
#include "code\_compile_options.dm"
#include "code\world.dm"
Expand Down

0 comments on commit 83e05cc

Please sign in to comment.