mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-01-03 22:12:38 +00:00
Terminal Colors Green and Red for success states.
This commit is contained in:
@@ -8,6 +8,9 @@
|
||||
|
||||
//
|
||||
// Tests Life() and mob breathing in space.
|
||||
//
|
||||
|
||||
|
||||
|
||||
datum/unit_test/human_breath
|
||||
name = "MOB: Human Suffocates in Space"
|
||||
@@ -42,7 +45,31 @@ datum/unit_test/human_breath/check_result()
|
||||
fail("Mob is not taking oxygen damage. Oxyloss is [ending_oxyloss]")
|
||||
|
||||
qdel(H)
|
||||
return 1 // return 1 to show we're done.
|
||||
return 1 // return 1 to show we're done and don't want to recheck the result.
|
||||
|
||||
// ============================================================================
|
||||
|
||||
//#define BRUTE "brute"
|
||||
//#define BURN "fire"
|
||||
//#define TOX "tox"
|
||||
//#define OXY "oxy"
|
||||
//#define CLONE "clone"
|
||||
//#define HALLOSS "halloss"
|
||||
|
||||
|
||||
proc/create_test_mob_with_mind(var/turf/mobloc = null)
|
||||
if(isnull(mobloc))
|
||||
mobloc = locate("landmark*tdome1")
|
||||
if(mobloc)
|
||||
return 0
|
||||
|
||||
|
||||
return 1
|
||||
|
||||
datum/unit_test/mob_damage
|
||||
name = "MOB: Template for enviromental damage"
|
||||
var/mob/living/carbon/human/testmob = null
|
||||
var/damagetype = BRUTE
|
||||
|
||||
|
||||
datum/unit_test/mob_damage
|
||||
|
||||
@@ -1,22 +1,56 @@
|
||||
/* Unit Tests originally designed by Ccomp5950
|
||||
*
|
||||
* Tests are created to prevent changes that would create bugs or change expected behaviour.
|
||||
* For the most part I think any test can be created that doesn't require a client in a mob or require a game mode other then extended
|
||||
*
|
||||
* The easiest way to make effective tests is to create a "template" if you intend to run the same test over and over and make your actual
|
||||
* tests be a "child object" of those templates. Be sure and name your templates with the word "template" somewhere in var/name.
|
||||
*
|
||||
* The goal is to have all sorts of tests that run and to run them as quickly as possible.
|
||||
*
|
||||
* Tests that require time to run we instead just check back on their results later instead of waiting around in a sleep(1) for each test.
|
||||
* This allows us to finish unit testing quicker since we can start other tests while we're waiting on that one to finish.
|
||||
*
|
||||
* An example of that is listed in mob_tests.dm with the human_breath test. We spawn the mob in space and set the async flag to 1 so that we run the check later.
|
||||
* After 10 life ticks for that mob we check it's oxyloss but while that is going on we've already ran other tests.
|
||||
*
|
||||
* If your test requires a significant amount of time...cheat on the timers. Either speed up the process/life runs or do as we did in the timers for the shuttle
|
||||
* transfers in zas_tests.dm we move a shuttle but instead of waiting 3 minutes we set the travel time to a very low number.
|
||||
*
|
||||
* At the same time, Unit tests are intended to reflect standard usage so avoid changing to much about how stuff is processed.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
var/all_unit_tests_passed = 1
|
||||
var/failed_unit_tests = 0
|
||||
var/total_unit_tests = 0
|
||||
var/ascii_esc = ascii2text(27)
|
||||
var/ascii_red = "[ascii_esc]\[31m"
|
||||
var/ascii_green = "[ascii_esc]\[32m"
|
||||
var/ascii_reset = "[ascii_esc]\[0m"
|
||||
|
||||
|
||||
// We list these here so we can remove them from the for loop running this.
|
||||
// Templates aren't intended to be ran but just serve as a way to create child objects of it with inheritable tests for quick test creation.
|
||||
|
||||
datum/unit_test
|
||||
var/name = "Fix Me"
|
||||
var/name = "template - should not be ran."
|
||||
var/disabled = 0 // If we want to keep a unit test in the codebase but not run it for some reason.
|
||||
var/async = 0 // If the check can be left to do it's own thing, you must define a check_result() proc if you use this.
|
||||
var/reported = 0
|
||||
var/reported = 0 // If it's reported a success or failure. Any tests that have not are assumed to be failures.
|
||||
var/why_disabled = "" // If we disable a unit test we will display why so it reminds us to check back on it later.
|
||||
|
||||
|
||||
datum/unit_test/proc/fail(var/message)
|
||||
all_unit_tests_passed = 0
|
||||
failed_unit_tests++
|
||||
reported = 1
|
||||
log_unit_test("!!! FAILURE !!! \[[name]\]: [message]")
|
||||
log_unit_test("[ascii_red]!!! FAILURE !!! \[[name]\]: [message][ascii_reset]")
|
||||
|
||||
datum/unit_test/proc/pass(var/message)
|
||||
reported = 1
|
||||
log_unit_test("*** SUCCESS *** \[[name]\]: [message]")
|
||||
log_unit_test("[ascii_green]*** SUCCESS *** \[[name]\]: [message][ascii_reset]")
|
||||
|
||||
datum/unit_test/proc/start_test()
|
||||
fail("No test proc.")
|
||||
@@ -29,7 +63,7 @@ datum/unit_test/proc/check_result()
|
||||
proc/load_unit_test_changes()
|
||||
|
||||
if(config.generate_asteroid != 1)
|
||||
log_unit_test("Overiding Configuration option for Asteroid Generation")
|
||||
log_unit_test("Overiding Configuration option for Asteroid Generation to ENABLED")
|
||||
config.generate_asteroid = 1 // The default map requires it, the example config doesn't have this enabled.
|
||||
|
||||
|
||||
@@ -48,7 +82,7 @@ proc/initialize_unit_tests()
|
||||
|
||||
var/said_msg = 0
|
||||
while(ticker.pregame_timeleft && ticker.pregame_timeleft > 160) // Make sure the initial startup is complete.
|
||||
if(ticker.pregame_timeleft < 178 && !said_msg)
|
||||
if(ticker.pregame_timeleft < 175 && !said_msg)
|
||||
said_msg = 1
|
||||
log_unit_test("Pregame Count down has started, giving it 20 seconds to finish.")
|
||||
sleep(1)
|
||||
@@ -59,15 +93,14 @@ proc/initialize_unit_tests()
|
||||
|
||||
ticker.current_state = GAME_STATE_SETTING_UP
|
||||
|
||||
log_unit_test("RoundStart: waiting 10 seconds to start tests.")
|
||||
log_unit_test("Round has been started. Waiting 10 seconds to start tests.")
|
||||
sleep(100)
|
||||
|
||||
//
|
||||
// Run Tests
|
||||
//
|
||||
|
||||
var/list/test_datums = typesof(/datum/unit_test) - /datum/unit_test
|
||||
|
||||
var/list/test_datums = typesof(/datum/unit_test)
|
||||
|
||||
var/list/async_test = list()
|
||||
var/list/started_tests = list()
|
||||
@@ -76,9 +109,12 @@ proc/initialize_unit_tests()
|
||||
|
||||
for (var/test in test_datums)
|
||||
var/datum/unit_test/d = new test()
|
||||
|
||||
|
||||
if(d.disabled)
|
||||
qdel(d)
|
||||
d.pass("[ascii_red]Check Disabled: [d.why_disabled]")
|
||||
continue
|
||||
|
||||
if(findtext(d.name, "template"))
|
||||
continue
|
||||
|
||||
if(isnull(d.start_test())) // Start the test.
|
||||
@@ -107,11 +143,9 @@ proc/initialize_unit_tests()
|
||||
if(!test.reported)
|
||||
test.fail("Test failed to report a result.")
|
||||
|
||||
|
||||
|
||||
if(all_unit_tests_passed)
|
||||
log_unit_test("**** All Unit Tests Passed \[[total_unit_tests]\] ****")
|
||||
log_unit_test("[ascii_green]**** All Unit Tests Passed \[[total_unit_tests]\] ****[ascii_reset]")
|
||||
world.Del()
|
||||
else
|
||||
log_unit_test("**** \[[failed_unit_tests]\\[total_unit_tests]\] Unit Tests Failed ****")
|
||||
log_unit_test("[ascii_red]**** \[[failed_unit_tests]\\[total_unit_tests]\] Unit Tests Failed ****[ascii_reset]")
|
||||
world.Del()
|
||||
|
||||
@@ -10,25 +10,28 @@
|
||||
#define UT_VACUUM 2 // Vacume on simulated turfs
|
||||
#define UT_NORMAL_COLD 3 // Cold but standard atmosphere.
|
||||
|
||||
#define FAILURE 0
|
||||
#define SUCCESS 1
|
||||
|
||||
//
|
||||
// Generic check for an area.
|
||||
//
|
||||
|
||||
datum/unit_test/zas_area_test
|
||||
name = "ZAS: Area Test Template"
|
||||
disabled = 1 // For all child objects we have to put 0 so the test runs
|
||||
var/area_path = null // Put the area you are testing here.
|
||||
var/expectation = UT_NORMAL // If the area is supposed to be a vacume set to 1
|
||||
var/expectation = UT_NORMAL // See defines above.
|
||||
|
||||
datum/unit_test/zas_area_test/start_test()
|
||||
var/list/result = test_air_in_area(area_path, expectation)
|
||||
if(isnull(result))
|
||||
var/list/test = test_air_in_area(area_path, expectation)
|
||||
|
||||
if(isnull(test))
|
||||
fail("Check Runtimed")
|
||||
|
||||
if(result["success"])
|
||||
pass(result["msg"])
|
||||
if(test["result"] == SUCCESS)
|
||||
pass(test["msg"])
|
||||
else
|
||||
fail(result["msg"])
|
||||
fail(test["msg"])
|
||||
return 1
|
||||
|
||||
// ==================================================================================================
|
||||
@@ -37,10 +40,13 @@ datum/unit_test/zas_area_test/start_test()
|
||||
// The primary helper proc.
|
||||
//
|
||||
proc/test_air_in_area(var/test_area, var/expectation = UT_NORMAL)
|
||||
var/test_result = list("result" = FAILURE, "msg" = "")
|
||||
|
||||
var/area/A = locate(test_area)
|
||||
|
||||
if(!istype(A, test_area))
|
||||
return(list("success" = 0, "msg" = "Unable to get [test_area]"))
|
||||
test_result["msg"] = "Unable to get [test_area]"
|
||||
return test_result
|
||||
|
||||
var/list/GM_checked = list()
|
||||
|
||||
@@ -61,29 +67,36 @@ proc/test_air_in_area(var/test_area, var/expectation = UT_NORMAL)
|
||||
|
||||
if(UT_VACUUM)
|
||||
if(pressure > 10)
|
||||
return(list("success" = 0, "msg" = "Pressure out of bounds: [pressure] | [t_msg]"))
|
||||
test_result["msg"] = "Pressure out of bounds: [pressure] | [t_msg]"
|
||||
return test_result
|
||||
|
||||
|
||||
if(UT_NORMAL || UT_NORMAL_COLD)
|
||||
if(abs(pressure - ONE_ATMOSPHERE) > 10)
|
||||
return(list("success" = 0, "msg" = "Pressure out of bounds: [pressure] | [t_msg]"))
|
||||
test_result["msg"] = "Pressure out of bounds: [pressure] | [t_msg]"
|
||||
return test_result
|
||||
|
||||
if(expectation == UT_NORMAL)
|
||||
|
||||
if(abs(temp - T20C) > 10)
|
||||
return(list("success" = 0, "msg" = "Temperature out of bounds: [temp] | [t_msg]"))
|
||||
test_result["msg"] = "Temperature out of bounds: [temp] | [t_msg]"
|
||||
return test_result
|
||||
|
||||
if(expectation == UT_NORMAL_COLD)
|
||||
|
||||
if(temp > 120)
|
||||
return(list("success" = 0, "msg" = "Temperature out of bounds: [temp] | [t_msg]"))
|
||||
test_result["msg"] = "Temperature out of bounds: [temp] | [t_msg]"
|
||||
return test_result
|
||||
|
||||
GM_checked.Add(GM)
|
||||
|
||||
if(GM_checked.len)
|
||||
return(list("success"=1, "msg" = "Checked [GM_checked.len] zones"))
|
||||
test_result["result"] = SUCCESS
|
||||
test_result["msg"] = "Checked [GM_checked.len] zones"
|
||||
else
|
||||
return(list("success"=0, "msg" = "No zones checked."))
|
||||
test_result["msg"] = "No zones checked."
|
||||
|
||||
return test_result
|
||||
|
||||
|
||||
// ==================================================================================================
|
||||
@@ -91,73 +104,61 @@ proc/test_air_in_area(var/test_area, var/expectation = UT_NORMAL)
|
||||
datum/unit_test/zas_area_test/supply_centcomm
|
||||
name = "ZAS: Supply Shuttle (CentComm)"
|
||||
area_path = /area/supply/dock
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/emergency_shuttle
|
||||
name = "ZAS: Emergency Shuttle"
|
||||
area_path = /area/shuttle/escape/centcom
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/ai_chamber
|
||||
name = "ZAS: AI Chamber"
|
||||
area_path = /area/turret_protected/ai
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/arrival_maint
|
||||
name = "ZAS: Arrival Maintenance"
|
||||
area_path = /area/maintenance/arrivals
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/mining_shuttle_at_station
|
||||
name = "ZAS: Mining Shuttle (Station)"
|
||||
area_path = /area/shuttle/mining/station
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/
|
||||
name = "ZAS: Cargo Maintenance"
|
||||
area_path = /area/maintenance/cargo
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/eng_shuttle
|
||||
name = "ZAS: Construction Site Shuttle (Station)"
|
||||
area_path = /area/shuttle/constructionsite/station
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/incinerator
|
||||
name = "ZAS: Incinerator"
|
||||
area_path = /area/maintenance/incinerator
|
||||
disabled = 1 //Failing currently for existing bug: #11846
|
||||
disabled = 1
|
||||
why_disabled = "Failing currently for existing bug: #11846"
|
||||
|
||||
datum/unit_test/zas_area_test/virology
|
||||
name = "ZAS: Virology"
|
||||
area_path = /area/medical/virology
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/xenobio
|
||||
name = "ZAS: Xenobiology"
|
||||
area_path = /area/rnd/xenobiology
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/research_maint_starboard
|
||||
name = "ZAS: Research Starboard Maintenance"
|
||||
area_path = /area/maintenance/research_starboard
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/west_hall_mining_outpost
|
||||
name = "ZAS: Mining outpost West Hallway"
|
||||
area_path = /area/outpost/mining_main/west_hall
|
||||
disabled = 0
|
||||
|
||||
datum/unit_test/zas_area_test/mining_area
|
||||
name = "ZAS: Mining Area (Vacume)"
|
||||
area_path = /area/mine/explored
|
||||
disabled = 0
|
||||
expectation = UT_VACUUM
|
||||
|
||||
datum/unit_test/zas_area_test/
|
||||
name = "ZAS: Cargo Bay"
|
||||
name = "ZAS: Cargo Bay"
|
||||
area_path = /area/quartermaster/storage
|
||||
disabled = 0
|
||||
|
||||
|
||||
// ==================================================================================================
|
||||
@@ -167,7 +168,6 @@ datum/unit_test/zas_area_test/
|
||||
|
||||
datum/unit_test/zas_supply_shuttle_moved
|
||||
name = "ZAS: Supply Shuttle (When Moved)"
|
||||
|
||||
async=1 // We're moving the shuttle using built in procs.
|
||||
|
||||
var/datum/shuttle/ferry/supply/Shuttle = null
|
||||
@@ -200,17 +200,19 @@ datum/unit_test/zas_supply_shuttle_moved/check_result()
|
||||
|
||||
sleep(20) // Give ZAS a chance to catchup.
|
||||
|
||||
var/list/result = test_air_in_area(/area/supply/station)
|
||||
if(isnull(result))
|
||||
var/list/test = test_air_in_area(/area/supply/station)
|
||||
if(isnull(test))
|
||||
fail("Check Runtimed")
|
||||
return 1
|
||||
|
||||
if(result["success"])
|
||||
pass(result["msg"])
|
||||
if(test["result"] == SUCCESS)
|
||||
pass(test["msg"])
|
||||
else
|
||||
fail(result["msg"])
|
||||
fail(test["msg"])
|
||||
return 1
|
||||
|
||||
#undef UT_NORMAL
|
||||
#undef UT_VACUUM
|
||||
#undef UT_NORMAL_COLD
|
||||
#undef SUCCESS
|
||||
#undef FAILURE
|
||||
|
||||
Reference in New Issue
Block a user