mirror of
https://github.com/Aurorastation/Aurora.3.git
synced 2026-08-24 13:30:42 +01:00
Ruins sanitization and unit test (#18923)
Properly split and use prefixes and suffixes, unit test to verify the file exists and is not empty, and that the format convention is respected
This commit is contained in:
@@ -49,3 +49,50 @@
|
||||
|
||||
TEST_PASS("All the ruins in [src.name] loaded successfully!")
|
||||
return UNIT_TEST_PASSED
|
||||
|
||||
/datum/unit_test/ruins_test/all_files_valid
|
||||
name = "All Ruins Files Exist"
|
||||
groups = list("generic") //This runs as a generic test as we only need to pass them once, not in every pod
|
||||
|
||||
/datum/unit_test/ruins_test/all_files_valid/start_test()
|
||||
|
||||
. = UNIT_TEST_PASSED
|
||||
|
||||
//Look into every ruin, and see if all the file paths are valid (the file exists)
|
||||
//or otherwise do not respect the convention
|
||||
for(var/ruin in subtypesof(/datum/map_template/ruin))
|
||||
LOG_GITHUB_NOTICE("Testing files for ruin [ruin]")
|
||||
|
||||
var/datum/map_template/ruin/tested_ruin = new ruin()
|
||||
|
||||
for(var/path in tested_ruin.mappaths)
|
||||
LOG_GITHUB_DEBUG("Now testing [path] for ruin [ruin]")
|
||||
|
||||
//Path format must be respected, start without a slash, and end with a slash
|
||||
if(!initial(tested_ruin.prefix) || tested_ruin.prefix[1] == "/" || tested_ruin.prefix[length_char(tested_ruin.prefix)] != "/")
|
||||
TEST_FAIL("Ruin [tested_ruin.name] has an invalid prefix path: [tested_ruin.prefix]")
|
||||
. = UNIT_TEST_FAILED
|
||||
|
||||
//No subfolders in the suffixes list
|
||||
var/regex/no_subfolders_in_suffixes = regex(@"[\\\/]+")
|
||||
for(var/suffix in tested_ruin.suffixes)
|
||||
LOG_GITHUB_DEBUG("Checking suffix [suffix]")
|
||||
if(no_subfolders_in_suffixes.Find(suffix))
|
||||
TEST_FAIL("Ruin [ruin] contains a slash or a backslash in the suffixes list!")
|
||||
. = UNIT_TEST_FAILED
|
||||
|
||||
//See if the file actually exists
|
||||
var/file_content = file2text(file(path))
|
||||
if(!length(file_content))
|
||||
TEST_FAIL("Ruin [ruin] - [path] have paths that do not exist or are empty!")
|
||||
. = UNIT_TEST_FAILED
|
||||
|
||||
|
||||
|
||||
if(. == UNIT_TEST_PASSED)
|
||||
TEST_PASS("All ruins have valid files!")
|
||||
return UNIT_TEST_PASSED
|
||||
|
||||
else
|
||||
TEST_FAIL("Some ruins have invalid paths, read above!")
|
||||
return UNIT_TEST_FAILED
|
||||
|
||||
Reference in New Issue
Block a user