Skip to content

Commit

Permalink
Added a standardized json unit test results log and added my vscode t…
Browse files Browse the repository at this point in the history
…est runner to recommendations (tgstation#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.
  • Loading branch information
Donkie authored Jan 10, 2021
1 parent 116a572 commit e71e7cb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
]
}
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@
}
],
"files.eol": "\n",
"gitlens.advanced.blame.customArguments": ["-w"]
"gitlens.advanced.blame.customArguments": ["-w"],
"tgstationTestExplorer.project.resultsType": "json"
}
5 changes: 5 additions & 0 deletions code/modules/unit_tests/_unit_tests.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 12 additions & 3 deletions code/modules/unit_tests/unit_test.dm
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

0 comments on commit e71e7cb

Please sign in to comment.