From 49c6f3769386dca6ae34e1fc6f86b2265994a344 Mon Sep 17 00:00:00 2001 From: Dominion Date: Mon, 22 May 2023 19:11:06 -0400 Subject: [PATCH] Add test helpers to test .dmes - Make long_running_test_copy.dme just include the original --- tests/DMAPI/ApiFree/Test.dm | 7 +--- tests/DMAPI/ApiFree/api_free.dme | 1 + tests/DMAPI/BasicOperation/Test.dm | 8 +--- .../BasicOperation/basic_operation_test.dme | 2 +- tests/DMAPI/LongRunning/Test.dm | 39 +++---------------- tests/DMAPI/LongRunning/long_running_test.dme | 2 +- .../LongRunning/long_running_test_copy.dme | 4 +- .../DMAPI/{tgs_include.dm => test_prelude.dm} | 1 + tests/DMAPI/test_setup.dm | 32 +++++++++++++++ tgstation-server.sln | 5 ++- 10 files changed, 48 insertions(+), 53 deletions(-) rename tests/DMAPI/{tgs_include.dm => test_prelude.dm} (75%) create mode 100644 tests/DMAPI/test_setup.dm diff --git a/tests/DMAPI/ApiFree/Test.dm b/tests/DMAPI/ApiFree/Test.dm index b7b4ae5535..a14f28aef0 100644 --- a/tests/DMAPI/ApiFree/Test.dm +++ b/tests/DMAPI/ApiFree/Test.dm @@ -1,7 +1,2 @@ -/world/New() - text2file("SUCCESS", "test_success.txt") +/world/proc/RunTest() log << "Hello world!" - -/world/Error(exception) - fdel("test_success.txt") - text2file("Runtime Error: [exception]", "test_fail_reason.txt") diff --git a/tests/DMAPI/ApiFree/api_free.dme b/tests/DMAPI/ApiFree/api_free.dme index 444e2491d8..8179f9b698 100644 --- a/tests/DMAPI/ApiFree/api_free.dme +++ b/tests/DMAPI/ApiFree/api_free.dme @@ -11,5 +11,6 @@ // END_PREFERENCES // BEGIN_INCLUDE +#include "../test_setup.dm" #include "Test.dm" // END_INCLUDE diff --git a/tests/DMAPI/BasicOperation/Test.dm b/tests/DMAPI/BasicOperation/Test.dm index 42d311056c..022088fc67 100644 --- a/tests/DMAPI/BasicOperation/Test.dm +++ b/tests/DMAPI/BasicOperation/Test.dm @@ -1,4 +1,4 @@ -/world/New() +/world/proc/RunTest() text2file("SUCCESS", "test_success.txt") log << "About to call TgsNew()" sleep_offline = FALSE @@ -6,10 +6,6 @@ log << "About to call StartAsync()" StartAsync() -/world/Error(exception) - fdel("test_success.txt") - text2file("Runtime Error: [exception]", "test_fail_reason.txt") - /proc/StartAsync() set waitfor = FALSE Run() @@ -21,7 +17,7 @@ var/list/world_params = world.params if(!("test" in world_params) || world_params["test"] != "bababooey") - text2file("Expected parameter test=bababooey but did not receive", "test_fail_reason.txt") + FailTest("Expected parameter test=bababooey but did not receive", "test_fail_reason.txt") world.log << "sleep2" sleep(150) diff --git a/tests/DMAPI/BasicOperation/basic_operation_test.dme b/tests/DMAPI/BasicOperation/basic_operation_test.dme index 92781c7e16..b927014455 100644 --- a/tests/DMAPI/BasicOperation/basic_operation_test.dme +++ b/tests/DMAPI/BasicOperation/basic_operation_test.dme @@ -12,6 +12,6 @@ // BEGIN_INCLUDE #include "Config.dm" -#include "..\tgs_include.dm" +#include "../test_prelude.dm" #include "Test.dm" // END_INCLUDE diff --git a/tests/DMAPI/LongRunning/Test.dm b/tests/DMAPI/LongRunning/Test.dm index bdf85acc45..762add090c 100644 --- a/tests/DMAPI/LongRunning/Test.dm +++ b/tests/DMAPI/LongRunning/Test.dm @@ -2,32 +2,7 @@ sleep_offline = FALSE loop_checks = FALSE -/world/Error(exception/E, datum/e_src) - var/list/usrinfo = null - var/list/splitlines = splittext(E.desc, "\n") - var/list/desclines = list() - for(var/line in splitlines) - if(length(line) < 3 || findtext(line, "source file:") || findtext(line, "usr.loc:")) - continue - if(findtext(line, "usr:")) - if(usrinfo) - desclines.Add(usrinfo) - usrinfo = null - continue // Our usr info is better, replace it - - if(copytext(line, 1, 3) != " ")//3 == length(" ") + 1 - desclines += (" " + line) // Pad any unpadded lines, so they look pretty - else - desclines += line - - if(usrinfo) //If this info isn't null, it hasn't been added yet - desclines.Add(usrinfo) - - fdel("test_success.txt") - text2file("Runtime Error: [E]", "test_fail_reason.txt") - -/world/New() - text2file("SUCCESS", "test_success.txt") +/world/proc/RunTest() log << "Initial value of sleep_offline: [sleep_offline]" sleep_offline = FALSE @@ -38,8 +13,7 @@ var/list/channels = TgsChatChannelInfo() if(!length(channels)) - text2file("Expected some chat channels!", "test_fail_reason.txt") - del(world) + FailTest("Expected some chat channels!") StartAsync() @@ -124,8 +98,7 @@ var/run_bridge_test if(tactics4) var/size = isnum(tactics4) ? tactics4 : text2num(tactics4) if(!isnum(size)) - text2file("tgs_integration_test_tactics4 wasn't a number!", "test_fail_reason.txt") - del(world) + FailTest("tgs_integration_test_tactics4 wasn't a number!") var/payload = create_payload(size) return payload @@ -182,8 +155,7 @@ var/run_bridge_test // hack hack, calling world.TgsChatChannelInfo() will try to delay until the channels come back var/datum/tgs_api/v5/api = TGS_READ_GLOBAL(tgs) if(length(api.chat_channels)) - text2file("Expected no chat channels after detach!", "test_fail_reason.txt") - del(world) + FailTest("Expected no chat channels after detach!") world.TgsChatBroadcast(new /datum/tgs_message_content("Recieved event: `[json_encode(args)]`")) @@ -299,7 +271,6 @@ var/lastTgsError // this actually gets doubled because it's in two fields for backwards compatibility, but that's fine var/list/final_result = api.Bridge(0, list("chatMessage" = list("text" = "done:[create_payload(limit * 3)]"))) if(!final_result || lastTgsError || final_result["integrationHack"] != "ok") - text2file("Failed to end bridge limit test! [(istype(final_result) ? json_encode(final_result): (final_result || "null"))]", "test_fail_reason.txt") - del(world) + FailTest("Failed to end bridge limit test! [(istype(final_result) ? json_encode(final_result): (final_result || "null"))]") api.access_identifier = old_ai diff --git a/tests/DMAPI/LongRunning/long_running_test.dme b/tests/DMAPI/LongRunning/long_running_test.dme index 92781c7e16..b927014455 100644 --- a/tests/DMAPI/LongRunning/long_running_test.dme +++ b/tests/DMAPI/LongRunning/long_running_test.dme @@ -12,6 +12,6 @@ // BEGIN_INCLUDE #include "Config.dm" -#include "..\tgs_include.dm" +#include "../test_prelude.dm" #include "Test.dm" // END_INCLUDE diff --git a/tests/DMAPI/LongRunning/long_running_test_copy.dme b/tests/DMAPI/LongRunning/long_running_test_copy.dme index 92781c7e16..b4da8e0d96 100644 --- a/tests/DMAPI/LongRunning/long_running_test_copy.dme +++ b/tests/DMAPI/LongRunning/long_running_test_copy.dme @@ -11,7 +11,5 @@ // END_PREFERENCES // BEGIN_INCLUDE -#include "Config.dm" -#include "..\tgs_include.dm" -#include "Test.dm" +#include "long_running_test.dme" // END_INCLUDE diff --git a/tests/DMAPI/tgs_include.dm b/tests/DMAPI/test_prelude.dm similarity index 75% rename from tests/DMAPI/tgs_include.dm rename to tests/DMAPI/test_prelude.dm index d60b655b94..18b7192ec1 100644 --- a/tests/DMAPI/tgs_include.dm +++ b/tests/DMAPI/test_prelude.dm @@ -1,2 +1,3 @@ #include "..\..\src\DMAPI\tgs.dm" #include "..\..\src\DMAPI\tgs\includes.dm" +#include "test_setup.dm" diff --git a/tests/DMAPI/test_setup.dm b/tests/DMAPI/test_setup.dm new file mode 100644 index 0000000000..514921d668 --- /dev/null +++ b/tests/DMAPI/test_setup.dm @@ -0,0 +1,32 @@ +/world/New() + text2file("SUCCESS", "test_success.txt") + world.RunTest() + +/world/Error(exception/E, datum/e_src) + var/list/usrinfo = null + var/list/splitlines = splittext(E.desc, "\n") + var/list/desclines = list() + for(var/line in splitlines) + if(length(line) < 3 || findtext(line, "source file:") || findtext(line, "usr.loc:")) + continue + if(findtext(line, "usr:")) + if(usrinfo) + desclines.Add(usrinfo) + usrinfo = null + continue // Our usr info is better, replace it + + if(copytext(line, 1, 3) != " ")//3 == length(" ") + 1 + desclines += (" " + line) // Pad any unpadded lines, so they look pretty + else + desclines += line + + if(usrinfo) //If this info isn't null, it hasn't been added yet + desclines.Add(usrinfo) + + FailTest("Runtime Error: [E]") + +/proc/FailTest(reason) + world.log << "TEST ERROR DM-SIDE: [reason]" + fdel("test_success.txt") + text2file(reason, "test_fail_reason.txt") + del(world) diff --git a/tgstation-server.sln b/tgstation-server.sln index 2a7bda3f3d..fa1f1bf89f 100644 --- a/tgstation-server.sln +++ b/tgstation-server.sln @@ -93,7 +93,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{3BB10856-AA0 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{82066812-6C73-4360-943B-B23F2F491261}" ProjectSection(SolutionItems) = preProject - tests\DMAPI\tgs_include.dm = tests\DMAPI\tgs_include.dm + tests\DMAPI\test_prelude.dm = tests\DMAPI\test_prelude.dm + tests\DMAPI\test_setup.dm = tests\DMAPI\test_setup.dm EndProjectSection EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "v4", "v4", "{057FAC33-CC31-4948-91C6-B0977C335890}" @@ -193,7 +194,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tgstation.Server.Migrator.C EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tgstation.Server.Host.Common", "src\Tgstation.Server.Host.Common\Tgstation.Server.Host.Common.csproj", "{CF3968A0-EA81-4464-B2D4-C7D40F6B5BCB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Tgstation.Server.Common", "src\Tgstation.Server.Common\Tgstation.Server.Common.csproj", "{70CD9A98-D31A-44A4-81D1-D02764CEEEFD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tgstation.Server.Common", "src\Tgstation.Server.Common\Tgstation.Server.Common.csproj", "{70CD9A98-D31A-44A4-81D1-D02764CEEEFD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution