Added a standardized json unit test results log and added my vscode test runner to recommendations (#56058)

Link to the test explorer: https://marketplace.visualstudio.com/items?itemName=Donkie.vscode-tgstation-test-adapter

The test explorer adapter lets you compile and run the code in one click of a button, with no messing about with defines necessary

The extension supports reading test results from the unit test logs, but its shitty having to parse logs for that, so this PR also adds support for a somewhat standardized method of logging unit test results to a json file instead.
This commit is contained in:
Donkie
2021-01-10 21:31:17 +01:00
committed by GitHub
parent 116a572a98
commit e71e7cbbe2
4 changed files with 21 additions and 5 deletions

View File

@@ -5,6 +5,7 @@
"EditorConfig.EditorConfig", "EditorConfig.EditorConfig",
"arcanis.vscode-zipfs", "arcanis.vscode-zipfs",
"dbaeumer.vscode-eslint", "dbaeumer.vscode-eslint",
"kevinkyang.auto-comment-blocks" "kevinkyang.auto-comment-blocks",
"Donkie.vscode-tgstation-test-adapter"
] ]
} }

View File

@@ -14,5 +14,6 @@
} }
], ],
"files.eol": "\n", "files.eol": "\n",
"gitlens.advanced.blame.customArguments": ["-w"] "gitlens.advanced.blame.customArguments": ["-w"],
"tgstationTestExplorer.project.resultsType": "json"
} }

View File

@@ -32,6 +32,11 @@
/// Intended to be used in the manner of `TEST_FOCUS(/datum/unit_test/math)` /// Intended to be used in the manner of `TEST_FOCUS(/datum/unit_test/math)`
#define TEST_FOCUS(test_path) ##test_path { focus = TRUE; } #define TEST_FOCUS(test_path) ##test_path { focus = TRUE; }
/// Constants indicating unit test completion status
#define UNIT_TEST_PASSED 0
#define UNIT_TEST_FAILED 1
#define UNIT_TEST_SKIPPED 2
#include "anchored_mobs.dm" #include "anchored_mobs.dm"
#include "bespoke_id.dm" #include "bespoke_id.dm"
#include "binary_insert.dm" #include "binary_insert.dm"

View File

@@ -87,6 +87,8 @@ GLOBAL_VAR(test_log)
tests_to_run = list(test_to_run) tests_to_run = list(test_to_run)
break break
var/list/test_results = list()
for(var/I in tests_to_run) for(var/I in tests_to_run)
var/datum/unit_test/test = new I var/datum/unit_test/test = new I
@@ -102,12 +104,19 @@ GLOBAL_VAR(test_log)
var/list/log_entry = list("[test.succeeded ? "PASS" : "FAIL"]: [I] [duration / 10]s") var/list/log_entry = list("[test.succeeded ? "PASS" : "FAIL"]: [I] [duration / 10]s")
var/list/fail_reasons = test.fail_reasons var/list/fail_reasons = test.fail_reasons
qdel(test)
for(var/J in 1 to LAZYLEN(fail_reasons)) for(var/J in 1 to LAZYLEN(fail_reasons))
log_entry += "\tREASON #[J]: [fail_reasons[J]]" log_entry += "\tREASON #[J]: [fail_reasons[J]]"
log_test(log_entry.Join("\n")) var/message = log_entry.Join("\n")
log_test(message)
test_results[I] = list("status" = test.succeeded ? UNIT_TEST_PASSED : UNIT_TEST_FAILED, "message" = message, "name" = I)
qdel(test)
CHECK_TICK CHECK_TICK
var/file_name = "data/unit_tests.json"
fdel(file_name)
file(file_name) << json_encode(test_results)
SSticker.force_ending = TRUE SSticker.force_ending = TRUE