From dace06e524d3913c8b169b01b7db5da5c5b65970 Mon Sep 17 00:00:00 2001 From: SkyratBot <59378654+SkyratBot@users.noreply.github.com> Date: Sun, 10 Jan 2021 23:19:03 +0100 Subject: [PATCH] [MIRROR] Added a standardized json unit test results log and added my vscode test runner to recommendations (#2627) * 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. * Added a standardized json unit test results log and added my vscode test runner to recommendations Co-authored-by: Donkie --- .vscode/extensions.json | 3 ++- .vscode/settings.json | 3 ++- code/modules/unit_tests/_unit_tests.dm | 5 +++++ code/modules/unit_tests/unit_test.dm | 15 ++++++++++++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index bf0d9d2fb96..6997491bb95 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -5,6 +5,7 @@ "EditorConfig.EditorConfig", "arcanis.vscode-zipfs", "dbaeumer.vscode-eslint", - "kevinkyang.auto-comment-blocks" + "kevinkyang.auto-comment-blocks", + "Donkie.vscode-tgstation-test-adapter" ] } diff --git a/.vscode/settings.json b/.vscode/settings.json index f95b8f7cc6b..f4f4ff2fc3d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -14,5 +14,6 @@ } ], "files.eol": "\n", - "gitlens.advanced.blame.customArguments": ["-w"] + "gitlens.advanced.blame.customArguments": ["-w"], + "tgstationTestExplorer.project.resultsType": "json" } diff --git a/code/modules/unit_tests/_unit_tests.dm b/code/modules/unit_tests/_unit_tests.dm index b01b4ac08b1..737fd3b6325 100644 --- a/code/modules/unit_tests/_unit_tests.dm +++ b/code/modules/unit_tests/_unit_tests.dm @@ -32,6 +32,11 @@ /// Intended to be used in the manner of `TEST_FOCUS(/datum/unit_test/math)` #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 "bespoke_id.dm" #include "binary_insert.dm" diff --git a/code/modules/unit_tests/unit_test.dm b/code/modules/unit_tests/unit_test.dm index 15fe6b466c2..49b3cfcfbc0 100644 --- a/code/modules/unit_tests/unit_test.dm +++ b/code/modules/unit_tests/unit_test.dm @@ -87,6 +87,8 @@ GLOBAL_VAR(test_log) tests_to_run = list(test_to_run) break + var/list/test_results = list() + for(var/I in tests_to_run) 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/fail_reasons = test.fail_reasons - qdel(test) - for(var/J in 1 to LAZYLEN(fail_reasons)) 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 + var/file_name = "data/unit_tests.json" + fdel(file_name) + file(file_name) << json_encode(test_results) + SSticker.force_ending = TRUE