Merge pull request #15422 from AffectedArc07/rust-version-sanity

RustG version + log format unit tests
This commit is contained in:
Fox McCloud
2021-02-24 03:42:48 -05:00
committed by GitHub
8 changed files with 144 additions and 1 deletions
+2
View File
@@ -3,8 +3,10 @@
#ifdef UNIT_TESTS
#include "component_tests.dm"
#include "log_format.dm"
#include "map_templates.dm"
#include "reagent_id_typos.dm"
#include "rustg_version.dm"
#include "spawn_humans.dm"
#include "sql.dm"
#include "subsystem_init.dm"
+26
View File
@@ -0,0 +1,26 @@
// This exists so that logs are the designated format. If they arent, it breaks logging tooling. Also 8601 is king.
#define TEST_MESSAGE "Log time format test"
#define TEST_LOG_FILE "data/ci_testing.log"
/proc/generate_test_log_message(time)
var/date_portion = time2text(time, "YYYY-MM-DD")
var/time_portion = time2text(time, "hh:mm:ss")
return "\[[date_portion]T[time_portion]] [TEST_MESSAGE]"
/datum/unit_test/log_format/Run()
// Generate a list of valid log timestamps. It can be the current time, or up to 2 seconds later to account for spurious CI lag
var/valid_lines = list(
"[generate_test_log_message(world.timeofday)]",
"[generate_test_log_message(world.timeofday + 10)]",
"[generate_test_log_message(world.timeofday + 20)]",
)
rustg_log_write(TEST_LOG_FILE, TEST_MESSAGE)
var/list/lines = file2list(TEST_LOG_FILE)
if(!(lines[1] in valid_lines))
Fail("RUSTG log format is not valid 8601 format. Expected '[generate_test_log_message(world.timeofday)]', got '[lines[1]]'")
#undef TEST_MESSAGE
#undef TEST_LOG_FILE
+4
View File
@@ -0,0 +1,4 @@
/datum/unit_test/rustg_version/Run()
var/library_version = rustg_get_version()
if(library_version != RUST_G_VERSION)
Fail("Invalid RUSTG Version. Library is [library_version], but in-code API is [RUST_G_VERSION]")