Skip to content

Commit

Permalink
modernizes unit tests from tg (#2163)
Browse files Browse the repository at this point in the history
  • Loading branch information
harryob committed Jan 13, 2023
1 parent ee2fb9c commit 8dd5758
Show file tree
Hide file tree
Showing 59 changed files with 817 additions and 1,099 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/ci_suite.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,35 @@ jobs:
source $HOME/BYOND/byond/bin/byondsetup
tools/build/build --ci dm -DCIBUILDING -DCITESTING -DALL_MAPS
find_all_maps:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
name: Find Maps to Test
runs-on: ubuntu-20.04
outputs:
maps: ${{ steps.map_finder.outputs.maps }}
concurrency:
group: find_all_maps-${{ github.ref }}
cancel-in-progress: true
steps:
- uses: actions/checkout@v3
- name: Find Maps
id: map_finder
run: |
echo "$(ls -mw0 maps/*.json)" > maps_output.txt
sed -i -e s+maps/+\"+g -e s+.json+\"+g maps_output.txt
echo "Maps: $(cat maps_output.txt)"
echo "maps={\"paths\":[$(cat maps_output.txt)]}" >> $GITHUB_OUTPUT
run_all_tests:
if: "!contains(github.event.head_commit.message, '[ci skip]')"
name: Unit Tests
needs: [find_all_maps]
strategy:
fail-fast: false
matrix:
map: ${{ fromJSON(needs.find_all_maps.outputs.maps).paths }}
concurrency:
group: run_all_tests-${{ github.ref }}-${{ matrix.map }}
cancel-in-progress: true
uses: ./.github/workflows/run_unit_tests.yml
with:
map: ${{ matrix.map }}
45 changes: 45 additions & 0 deletions .github/workflows/run_unit_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# This is a reusable workflow to run unit tests on a single map.
# This is run for every single map in ci_suite.yml. You might want to edit that instead.
name: Run Unit Tests
on:
workflow_call:
inputs:
map:
required: true
type: string
major:
required: false
type: string
minor:
required: false
type: string
jobs:
run_unit_tests:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Restore BYOND cache
uses: actions/cache@v3
with:
path: ~/BYOND
key: ${{ runner.os }}-byond-${{ secrets.CACHE_PURGE_KEY }}
- name: Install rust-g
run: |
sudo dpkg --add-architecture i386
sudo apt update || true
sudo apt install -o APT::Immediate-Configure=false libssl1.1:i386
bash tools/ci/install_rust_g.sh
- name: Configure version
run: |
echo "BYOND_MAJOR=${{ inputs.major }}" >> $GITHUB_ENV
echo "BYOND_MINOR=${{ inputs.minor }}" >> $GITHUB_ENV
if: ${{ inputs.major }}
- name: Compile Tests
run: |
bash tools/ci/install_byond.sh
source $HOME/BYOND/byond/bin/byondsetup
tools/build/build --ci dm -DCIBUILDING -DANSICOLORS
- name: Run Tests
run: |
source $HOME/BYOND/byond/bin/byondsetup
bash tools/ci/run_server.sh ${{ inputs.map }}
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"EditorConfig.EditorConfig",
"anturk.dmi-editor",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
"esbenp.prettier-vscode",
"donkie.vscode-tgstation-test-adapter"
]
}
19 changes: 3 additions & 16 deletions ColonialMarinesALPHA.dme
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// BEGIN_FILE_DIR
#define FILE_DIR .
// END_FILE_DIR

// BEGIN_PREFERENCES
#define DEBUG
// END_PREFERENCES
Expand Down Expand Up @@ -89,13 +90,13 @@
#include "code\__DEFINES\subsystems.dm"
#include "code\__DEFINES\surgery.dm"
#include "code\__DEFINES\techtree.dm"
#include "code\__DEFINES\tests.dm"
#include "code\__DEFINES\text.dm"
#include "code\__DEFINES\tgs.config.dm"
#include "code\__DEFINES\tgs.dm"
#include "code\__DEFINES\tgui.dm"
#include "code\__DEFINES\traits.dm"
#include "code\__DEFINES\turf_flags.dm"
#include "code\__DEFINES\unit_tests.dm"
#include "code\__DEFINES\urls.dm"
#include "code\__DEFINES\vehicle.dm"
#include "code\__DEFINES\vendors.dm"
Expand Down Expand Up @@ -2071,21 +2072,6 @@
#include "code\modules\teleporters\teleporter_admin_verbs.dm"
#include "code\modules\teleporters\teleporter_console.dm"
#include "code\modules\teleporters\teleporter_landmarks.dm"
#include "code\modules\test\test_case.dm"
#include "code\modules\test\test_manager.dm"
#include "code\modules\test\test_verbs.dm"
#include "code\modules\test\maps\test_no_blocked_doors.dm"
#include "code\modules\test\maps\test_no_blocked_windows.dm"
#include "code\modules\test\maps\test_no_space_inside.dm"
#include "code\modules\test\maps\test_pipes_connected.dm"
#include "code\modules\test\maps\test_set_maps.dm"
#include "code\modules\test\sprites\test_hair_sprites.dm"
#include "code\modules\test\sprites\test_plating_sprites.dm"
#include "code\modules\test\sprites\test_set_sprites.dm"
#include "code\modules\test\testenv\test_area.dm"
#include "code\modules\test\testenv\test_environment.dm"
#include "code\modules\test\testenv\environments\tank_gallery.dm"
#include "code\modules\test\testenv\environments\example\envstring.dm"
#include "code\modules\tgchat\cm_shims.dm"
#include "code\modules\tgchat\message.dm"
#include "code\modules\tgchat\to_chat.dm"
Expand Down Expand Up @@ -2129,6 +2115,7 @@
#include "code\modules\tgui_panel\external.dm"
#include "code\modules\tgui_panel\telemetry.dm"
#include "code\modules\tgui_panel\tgui_panel.dm"
#include "code\modules\unit_tests\_unit_tests.dm"
#include "code\modules\vehicles\cargo_train.dm"
#include "code\modules\vehicles\powerloader.dm"
#include "code\modules\vehicles\train.dm"
Expand Down
15 changes: 0 additions & 15 deletions code/__DEFINES/tests.dm

This file was deleted.

1 change: 1 addition & 0 deletions code/__DEFINES/typecheck/generic_types.dm
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
#define issurface(X) (istype(X, /obj/structure/surface))
#define ismovableatom(A) (ismovable(A))
#define isatom(A) (isloc(A))
#define isfloorturf(A) (istype(A, /turf/open/floor))
20 changes: 20 additions & 0 deletions code/__DEFINES/unit_tests.dm
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// Are tests enabled with no focus?
/// Use this when performing test assertions outside of a unit test,
/// since a focused test means that you're trying to run a test quickly.
/// If a parameter is provided, will check if the focus is on that test name.
/// For example, PERFORM_ALL_TESTS(log_mapping) will only run if either
/// no test is focused, or the focus is log_mapping.
#ifdef UNIT_TESTS
// Bit of a trick here, if focus isn't passed in then it'll check for /datum/unit_test/, which is never the case.
#define PERFORM_ALL_TESTS(focus...) (isnull(GLOB.focused_test) || GLOB.focused_test == /datum/unit_test/##focus)
#else
// UNLINT necessary here so that if (PERFORM_ALL_TESTS()) works
#define PERFORM_ALL_TESTS(...) UNLINT(FALSE)
#endif

/// ASSERT(), but it only actually does anything during unit tests
#ifdef UNIT_TESTS
#define TEST_ONLY_ASSERT(test, explanation) if(!(test)) {CRASH(explanation)}
#else
#define TEST_ONLY_ASSERT(test, explanation)
#endif
14 changes: 10 additions & 4 deletions code/__HELPERS/logging.dm
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
#define SEND_SOUND(target, sound) DIRECT_OUTPUT(target, sound)
#define WRITE_FILE(file, text) DIRECT_OUTPUT(file, text)

//This is an external call, "true" and "false" are how rust parses out booleans
#define WRITE_LOG(log, text) rustg_log_write(log, text, "true")
#define WRITE_LOG_NO_FORMAT(log, text) rustg_log_write(log, text, "false")

//print an error message to world.log


Expand All @@ -12,7 +16,6 @@

/var/global/log_end= world.system_type == UNIX ? ascii2text(13) : ""


/proc/error(msg)
world.log << "## ERROR: [msg][log_end]"
GLOB.STUI.debug.Add("\[[time_stamp()]]DEBUG: [msg]")
Expand Down Expand Up @@ -201,9 +204,6 @@
GLOB.STUI.tgui.Add("\[[time_stamp()]]TGUI: [entry]")
GLOB.STUI.processing |= STUI_LOG_TGUI

//wrapper macros for easier grepping
#define WRITE_LOG(log, text) rustg_log_write(log, text, "true")

GLOBAL_VAR(config_error_log)
GLOBAL_PROTECT(config_error_log)

Expand All @@ -214,3 +214,9 @@ GLOBAL_PROTECT(config_error_log)

/proc/log_admin_private(text)
log_admin(text)

#if defined(UNIT_TESTS) || defined(SPACEMAN_DMM)
/proc/log_test(text)
WRITE_LOG(GLOB.test_log, text)
SEND_TEXT(world.log, text)
#endif
6 changes: 6 additions & 0 deletions code/_compile_options.dm
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,9 @@
// If this is uncommented, will attempt to load prof.dll (windows) or libprof.so (unix)
// byond-tracy is not shipped with CM code. Build it yourself here: https://github.com/mafemergency/byond-tracy/
//#define BYOND_TRACY

#ifdef CIBUILDING
#define UNIT_TESTS
#endif

//#define UNIT_TESTS //If this is uncommented, we do a single run though of the game setup and tear down process with unit tests in between
2 changes: 2 additions & 0 deletions code/_globalvars/lists/mapping_globals.dm
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,5 @@ GLOBAL_LIST_EMPTY_TYPED(objective_landmarks_science, /obj/effect/landmark/object

GLOBAL_LIST_EMPTY(comm_tower_landmarks_net_one)
GLOBAL_LIST_EMPTY(comm_tower_landmarks_net_two)

GLOBAL_LIST_EMPTY(landmarks_list) //list of all landmarks created
4 changes: 4 additions & 0 deletions code/controllers/subsystem/atoms.dm
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,16 @@ SUBSYSTEM_DEF(atoms)
BadInitializeCalls[the_type] |= BAD_INIT_QDEL_BEFORE
return TRUE

#ifdef UNIT_TESTS
var/start_tick = world.time
#endif

var/result = A.Initialize(arglist(arguments))

#ifdef UNIT_TESTS
if(start_tick != world.time)
BadInitializeCalls[the_type] |= BAD_INIT_SLEPT
#endif

var/qdeleted = FALSE

Expand Down
1 change: 0 additions & 1 deletion code/game/area/Sulaco.dm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
/area/shuttle
ceiling = CEILING_METAL
requires_power = 0
test_exemptions = MAP_TEST_EXEMPTION_SPACE
ambience_exterior = AMBIENCE_ALMAYER
ceiling_muffle = FALSE

Expand Down
4 changes: 4 additions & 0 deletions code/game/area/admin_level.dm
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,7 @@
icon_state = "green"
requires_power = 0
flags_area = AREA_NOTUNNEL

/area/misc/testroom
requires_power = FALSE
name = "Test Room"
1 change: 0 additions & 1 deletion code/game/area/almayer.dm
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,6 @@
/area/almayer/evacuation/pod18

/area/almayer/evacuation/stranded
test_exemptions = MAP_TEST_EXEMPTION_SPACE

//Placeholder.
/area/almayer/evacuation/stranded/pod1
Expand Down
1 change: 0 additions & 1 deletion code/game/area/space_station_13_areas.dm
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ NOTE: there are two lists of areas in the end of this file: centcom and station
temperature = TCMB
pressure = 0
flags_area = AREA_NOTUNNEL
test_exemptions = MAP_TEST_EXEMPTION_SPACE
weather_enabled = FALSE

/area/engine
Expand Down
15 changes: 15 additions & 0 deletions code/game/objects/effects/landmarks/landmarks.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,13 @@

/obj/effect/landmark/Initialize(mapload, ...)
. = ..()
GLOB.landmarks_list += src
invisibility = invisibility_value

/obj/effect/landmark/Destroy()
GLOB.landmarks_list -= src
return ..()

/obj/effect/landmark/newplayer_start
name = "New player start"

Expand Down Expand Up @@ -451,3 +456,13 @@

/obj/effect/landmark/zombie/infinite
infinite_spawns = TRUE

/// 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"
4 changes: 3 additions & 1 deletion code/game/objects/effects/spawners/random.dm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
// creates the random item
/obj/effect/spawner/random/proc/spawn_item()
var/build_path = item_to_spawn()
if(isnull(build_path))
return
return (new build_path(src.loc))


Expand Down Expand Up @@ -142,7 +144,7 @@
desc = "This is a random kit."
icon_state = "random_kit"

/obj/effect/spawner/random/toy/item_to_spawn()
/obj/effect/spawner/random/supply_kit/item_to_spawn()
return pick(prob(3);/obj/item/storage/box/kit/pursuit,\
prob(3);/obj/item/storage/box/kit/mini_intel,\
prob(3);/obj/item/storage/box/kit/mini_jtac,\
Expand Down
5 changes: 5 additions & 0 deletions code/game/runtimes.dm
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ GLOBAL_REAL(runtime_hashes, /list)
GLOBAL_REAL(early_init_runtimes, /list)
GLOBAL_REAL_VAR(early_init_runtimes_count)

GLOBAL_VAR_INIT(total_runtimes, GLOB.total_runtimes || 0)
GLOBAL_VAR_INIT(total_runtimes_skipped, 0)

/world/Error(var/exception/E)
GLOB.total_runtimes++

..()
if(!runtime_hashes)
runtime_hashes = list()
Expand Down
Loading

0 comments on commit 8dd5758

Please sign in to comment.