Skip to content

Commit f69c699

Browse files
francinumKapu1178
andauthored
Unit test re-organization (#1158)
* Unit test re-organization * awdawdadwadwdawdw * pain, with a side of suffering * gsfdgsffsdgdfgsdfsgfsgd * asdfasdf * waw * waw2 * Let's try this. * Collapsible success, Fucked up elsewhere * slug * Screenshot test priority and names --------- Co-authored-by: Kapu1178 <[email protected]>
1 parent e47b838 commit f69c699

File tree

149 files changed

+355
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

149 files changed

+355
-293
lines changed

.github/workflows/ci_suite.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ jobs:
186186
run: npm i
187187
working-directory: tools/screenshot-test-comparison
188188
- name: Run screenshot comparison
189-
run: node tools/screenshot-test-comparison/index.js artifacts code/modules/unit_tests/screenshots artifacts/screenshot_comparisons
189+
run: node tools/screenshot-test-comparison/index.js artifacts code/modules/unit_tests/screenshots/data artifacts/screenshot_comparisons
190190
# workflow_run does not give you the PR it ran on,
191191
# even through the thing literally named "matching pull requests".
192192
# However, in GraphQL, you can check if the check suite was ran

code/game/objects/items/stacks/cash.dm

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
stack_name = "wad"
66
multiple_gender = NEUTER
77

8+
abstract_type = /obj/item/stack/spacecash
9+
810
icon = 'icons/obj/economy.dmi'
911
icon_state = null
1012
amount = 1

code/game/objects/items/stacks/license_plates.dm

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
icon_state = "empty_plate"
66
novariants = FALSE
77
max_amount = 50
8+
abstract_type = /obj/item/stack/license_plates
9+
810

911
/obj/item/stack/license_plates/empty
1012
name = "empty license plates"

code/game/objects/items/stacks/sheets/mineral.dm

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ GLOBAL_LIST_INIT(sandstone_recipes, list ( \
2828
new/datum/stack_recipe("Breakdown into sand", /obj/item/stack/ore/glass, 1, one_per_turf = FALSE, on_floor = TRUE) \
2929
))
3030

31+
/obj/item/stack/sheet/mineral
32+
abstract_type = /obj/item/stack/sheet/mineral
33+
3134
/obj/item/stack/sheet/mineral/sandstone
3235
name = "sandstone bricks"
3336
desc = "This appears to be a combination of both sand and stone."

code/game/objects/items/stacks/sheets/sheets.dm

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
righthand_file = 'icons/mob/inhands/misc/sheets_righthand.dmi'
55
full_w_class = WEIGHT_CLASS_NORMAL
66

7+
abstract_type = /obj/item/stack/sheet
8+
79
force = 5
810
throwforce = 5
911
max_amount = 50

code/game/objects/items/stacks/tiles/tile_mineral.dm

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/obj/item/stack/tile/mineral
2+
abstract_type = /obj/item/stack/tile/mineral
23
/// Determines what stack is gotten out of us when welded.
34
var/mineralType = null
45

code/game/objects/items/stacks/tiles/tile_types.dm

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
max_amount = 60
1818
novariants = TRUE
1919
material_flags = MATERIAL_EFFECTS
20+
abstract_type = /obj/item/stack/tile
2021
/// What type of turf does this tile produce.
2122
var/turf_type = null
2223
/// What dir will the turf have?

code/modules/mining/ores_coins.dm

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
material_flags = MATERIAL_EFFECTS
1818
novariants = TRUE // Ore stacks handle their icon updates themselves to keep the illusion that there's more going
1919

20+
abstract_type = /obj/item/stack/ore
21+
2022
var/list/stack_overlays
2123
/// How many points this ore gets you from the ore redemption machine
2224
var/points = 0

code/modules/unit_tests/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ You can find more information about all of these from their respective doc comme
6969

7070
`TEST_FOCUS(test_path)` - *Only* run the test provided within the parameters. Useful for reducing noise. For example, if we only want to run our example square test, we can add `TEST_FOCUS(/datum/unit_test/square)`. Should *never* be pushed in a pull request--you will be laughed at.
7171

72+
`TEST_SKIP(reason)` - Mark a test as skipped, and stops the test. This is mostly used for map tests that shouldn't run on test maps, which likely have very strange setups that wouldn't be allowed in a normal, production map.
73+
7274
## Final Notes
7375

7476
- Writing tests before you attempt to fix the bug can actually speed up development a lot! It means you don't have to go in game and folllow the same exact steps manually every time. This process is known as "TDD" (test driven development). Write the test first, make sure it fails, *then* start work on the fix/feature, and you'll know you're done when your tests pass. If you do try this, do make sure to confirm in a non-testing environment just to double check.

code/modules/unit_tests/__unit_tests.dm

+4-27
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,18 @@
9090
#include "_unit_test.dm"
9191

9292
// Category Includes
93+
#include "atmospherics\__include.dm"
94+
#include "combat\__include.dm"
9395
#include "mapping_standards\__include.dm"
96+
#include "reagents\__include.dm"
97+
#include "screenshots\__include.dm"
9498

9599
// Single File Includes
96100
#include "achievements.dm"
97101
#include "adenosine.dm"
98102
#include "anchored_mobs.dm"
99103
#include "anonymous_themes.dm"
100104
#include "area_contents.dm"
101-
#include "atmos_moles_tests.dm"
102105
#include "autowiki.dm"
103106
#include "baseturfs.dm"
104107
#include "bespoke_id.dm"
@@ -112,15 +115,6 @@
112115
#include "circuit_component_category.dm"
113116
#include "closets.dm"
114117
#include "codex.dm"
115-
#include "combat.dm"
116-
#include "combat_blocking.dm"
117-
#include "combat_cuffs.dm"
118-
#include "combat_door_click.dm"
119-
#include "combat_dropper.dm"
120-
#include "combat_emp_flashlight.dm"
121-
#include "combat_flash.dm"
122-
#include "combat_pistol_whip.dm"
123-
#include "combat_stamina.dm"
124118
#include "component_tests.dm"
125119
#include "confusion.dm"
126120
#include "connect_loc.dm"
@@ -134,8 +128,6 @@
134128
#include "egg_glands.dm"
135129
#include "emoting.dm"
136130
#include "food_edibility_check.dm"
137-
#include "gas_transfer.dm"
138-
#include "gas_validation.dm"
139131
#include "get_turf_pixel.dm"
140132
#include "grabbing.dm"
141133
#include "greyscale_config.dm"
@@ -164,23 +156,13 @@
164156
#include "objectives.dm"
165157
#include "outfit_sanity.dm"
166158
#include "paintings.dm"
167-
#include "pills.dm"
168159
#include "plantgrowth_tests.dm"
169160
#include "preferences.dm"
170161
#include "projectiles.dm"
171162
#include "quirks.dm"
172163
#include "rcd.dm"
173-
#include "reagent_descriptions.dm"
174-
#include "reagent_id_typos.dm"
175-
#include "reagent_mod_expose.dm"
176-
#include "reagent_mod_procs.dm"
177-
#include "reagent_names.dm"
178-
#include "reagent_recipe_collisions.dm"
179164
#include "resist.dm"
180165
#include "say.dm"
181-
#include "screenshot_antag_icons.dm"
182-
#include "screenshot_basic.dm"
183-
#include "screenshot_humanoids.dm"
184166
#include "serving_tray.dm"
185167
#include "siunit.dm"
186168
#include "slapcraft_sanity.dm"
@@ -189,11 +171,6 @@
189171
#include "species_config_sanity.dm"
190172
#include "species_unique_id.dm"
191173
#include "species_whitelists.dm"
192-
#include "spell_invocations.dm"
193-
#include "spell_mindswap.dm"
194-
#include "spell_names.dm"
195-
#include "spell_shapeshift.dm"
196-
#include "spell_timestop.dm"
197174
#include "stack_singular_name.dm"
198175
#include "stomach.dm"
199176
#include "strippable.dm"

code/modules/unit_tests/_unit_test.dm

+5-25
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ GLOBAL_VAR(test_log)
1818
GLOBAL_LIST_EMPTY(unit_test_mapping_logs)
1919

2020
/datum/unit_test
21+
/// Optional 'Descriptive Name' that replaces the typepath in log messages.
22+
var/name = null
23+
24+
2125
//Bit of metadata for the future maybe
2226
var/list/procs_tested
2327

@@ -91,30 +95,6 @@ GLOBAL_LIST_EMPTY(unit_test_mapping_logs)
9195
allocated += instance
9296
return instance
9397

94-
/datum/unit_test/proc/test_screenshot(name, icon/icon)
95-
if (!istype(icon))
96-
TEST_FAIL("[icon] is not an icon.")
97-
return
98-
99-
var/path_prefix = replacetext(replacetext("[type]", "/datum/unit_test/", ""), "/", "_")
100-
name = replacetext(name, "/", "_")
101-
102-
var/filename = "code/modules/unit_tests/screenshots/[path_prefix]_[name].png"
103-
104-
if (fexists(filename))
105-
var/data_filename = "data/screenshots/[path_prefix]_[name].png"
106-
fcopy(icon, data_filename)
107-
log_test("[path_prefix]_[name] was found, putting in data/screenshots")
108-
else if (fexists("code"))
109-
// We are probably running in a local build
110-
fcopy(icon, filename)
111-
TEST_FAIL("Screenshot for [name] did not exist. One has been created.")
112-
else
113-
// We are probably running in real CI, so just pretend it worked and move on
114-
fcopy(icon, "data/screenshots_new/[path_prefix]_[name].png")
115-
116-
log_test("[path_prefix]_[name] was put in data/screenshots_new")
117-
11898
/proc/RunUnitTest(test_path, list/test_results)
11999
var/datum/unit_test/test = new test_path
120100

@@ -139,7 +119,7 @@ GLOBAL_LIST_EMPTY(unit_test_mapping_logs)
139119
test_log_prefix = TEST_OUTPUT_MAGENTA("BAD STATUS [test.test_status]")
140120

141121
var/list/log_entry = list(
142-
"[test_log_prefix]: [test_path] [(test.test_status != UNIT_TEST_SKIPPED ? "[duration / 10]s" : "| [test.skip_reason]")]",
122+
"[test_log_prefix]: [test.name || test_path] [(test.test_status != UNIT_TEST_SKIPPED ? "[duration / 10]s" : "| [test.skip_reason]")]",
143123
)
144124
var/list/fail_reasons = test.fail_reasons
145125
var/map_name = SSmapping.config.map_name
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
#include "_atmospherics.dm"
3+
4+
#include "atmos_moles_tests.dm"
5+
// #include "gas_transfer.dm" //I think this test was eaten by the above file? kapu pls
6+
#include "gas_validation.dm"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/datum/unit_test/atmospherics
2+
abstract_type = /datum/unit_test/atmospherics
3+
4+
/datum/unit_test/atmospherics/proc/create_gas_mixes(gas_mix_data)
5+
var/list/gas_mixes = list()
6+
for(var/mix_name in gas_mix_data)
7+
var/list/mix_data = gas_mix_data[mix_name]
8+
9+
var/datum/gas_mixture/gas_mix = new (CELL_VOLUME, mix_data["temperature"])
10+
11+
var/list/initial_gas = mix_data["initial_gas"]
12+
if(initial_gas.len)
13+
var/list/gas_args = list()
14+
for(var/gasid in initial_gas)
15+
gas_args += gasid
16+
gas_args += initial_gas[gasid]
17+
gas_mix.adjustMultipleGases(arglist(gas_args))
18+
19+
gas_mixes[mix_name] = gas_mix
20+
return gas_mixes
21+
22+
/datum/unit_test/atmospherics/proc/gas_amount_changes(list/before_gas_mixes, list/after_gas_mixes)
23+
var/list/result = list()
24+
for(var/mix_name in before_gas_mixes & after_gas_mixes)
25+
var/change = list()
26+
27+
var/datum/gas_mixture/before = before_gas_mixes[mix_name]
28+
var/datum/gas_mixture/after = after_gas_mixes[mix_name]
29+
30+
var/list/all_gases = before.gas | after.gas
31+
for(var/gasid in all_gases)
32+
change[gasid] = after.getGroupGas(gasid) - before.getGroupGas(gasid)
33+
34+
result[mix_name] = change
35+
36+
return result
37+
38+
/datum/unit_test/atmospherics/proc/check_moles_conserved(case_name, list/before_gas_mixes, list/after_gas_mixes)
39+
for(var/gasid in xgm_gas_data.gases)
40+
var/before = 0
41+
for(var/gasmix in before_gas_mixes)
42+
var/datum/gas_mixture/G = before_gas_mixes[gasmix]
43+
before += G.getGroupGas(gasid)
44+
45+
var/after = 0
46+
for(var/gasmix in after_gas_mixes)
47+
var/datum/gas_mixture/G = after_gas_mixes[gasmix]
48+
after += G.getGroupGas(gasid)
49+
50+
if(abs(before - after) > ATMOS_PRECISION)
51+
Fail("expected [before] moles of [gasid], found [after] moles.")

0 commit comments

Comments
 (0)