2022-06-02 04:13:43 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
# Creates a structure that contains all the data about the results of running
|
|
|
|
# tests. This was created to make an intermediate step organizing the result
|
|
|
|
# of a run and exporting it in a specific format. This can also serve as a
|
|
|
|
# unofficial GUT export format.
|
|
|
|
# ------------------------------------------------------------------------------
|
2023-01-20 23:34:39 +01:00
|
|
|
var _utils = load("res://addons/gut/utils.gd").get_instance()
|
2023-01-07 20:26:17 +01:00
|
|
|
var json = JSON.new()
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
func _export_tests(collected_script):
|
2022-06-02 04:13:43 +02:00
|
|
|
var to_return = {}
|
2024-01-06 11:27:15 +01:00
|
|
|
var tests = collected_script.tests
|
|
|
|
for test in tests:
|
|
|
|
if test.get_status_text() != GutUtils.TEST_STATUSES.NOT_RUN:
|
|
|
|
to_return[test.name] = {
|
|
|
|
"status": test.get_status_text(),
|
|
|
|
"passing": test.pass_texts,
|
|
|
|
"failing": test.fail_texts,
|
|
|
|
"pending": test.pending_texts,
|
|
|
|
"orphans": test.orphans
|
|
|
|
}
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
return to_return
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2022-06-02 04:13:43 +02:00
|
|
|
# TODO
|
|
|
|
# errors
|
2024-01-06 11:27:15 +01:00
|
|
|
func _export_scripts(collector):
|
|
|
|
if collector == null:
|
2022-06-02 04:13:43 +02:00
|
|
|
return {}
|
|
|
|
|
|
|
|
var scripts = {}
|
|
|
|
|
2024-01-06 11:27:15 +01:00
|
|
|
for s in collector.scripts:
|
|
|
|
var test_data = _export_tests(s)
|
|
|
|
scripts[s.get_full_name()] = {
|
2023-01-20 23:34:39 +01:00
|
|
|
"props":
|
|
|
|
{
|
2024-01-06 11:27:15 +01:00
|
|
|
"tests": test_data.keys().size(),
|
2023-01-20 23:34:39 +01:00
|
|
|
"pending": s.get_pending_count(),
|
|
|
|
"failures": s.get_fail_count(),
|
2022-06-02 04:13:43 +02:00
|
|
|
},
|
2024-01-06 11:27:15 +01:00
|
|
|
"tests": test_data
|
2022-06-02 04:13:43 +02:00
|
|
|
}
|
|
|
|
return scripts
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
|
2022-06-02 04:13:43 +02:00
|
|
|
func _make_results_dict():
|
2023-01-20 23:34:39 +01:00
|
|
|
var result = {
|
|
|
|
"test_scripts":
|
|
|
|
{
|
|
|
|
"props":
|
|
|
|
{
|
|
|
|
"pending": 0,
|
|
|
|
"failures": 0,
|
|
|
|
"passing": 0,
|
|
|
|
"tests": 0,
|
|
|
|
"time": 0,
|
|
|
|
"orphans": 0,
|
|
|
|
"errors": 0,
|
|
|
|
"warnings": 0
|
2022-06-02 04:13:43 +02:00
|
|
|
},
|
2023-01-20 23:34:39 +01:00
|
|
|
"scripts": []
|
2022-06-02 04:13:43 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
# TODO
|
|
|
|
# time
|
|
|
|
# errors
|
2023-01-20 23:34:39 +01:00
|
|
|
func get_results_dictionary(gut, include_scripts = true):
|
2022-06-02 04:13:43 +02:00
|
|
|
var scripts = []
|
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
if include_scripts:
|
2024-01-06 11:27:15 +01:00
|
|
|
scripts = _export_scripts(gut.get_test_collector())
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-20 23:34:39 +01:00
|
|
|
var result = _make_results_dict()
|
2024-01-06 11:27:15 +01:00
|
|
|
|
|
|
|
var totals = gut.get_summary().get_totals()
|
|
|
|
|
|
|
|
var props = result.test_scripts.props
|
|
|
|
props.pending = totals.pending
|
|
|
|
props.failures = totals.failing
|
|
|
|
props.passing = totals.passing_tests
|
|
|
|
props.tests = totals.tests
|
|
|
|
props.errors = gut.logger.get_errors().size()
|
|
|
|
props.warnings = gut.logger.get_warnings().size()
|
|
|
|
props.time = gut.get_elapsed_time()
|
|
|
|
props.orphans = gut.get_orphan_counter().get_counter("total")
|
|
|
|
result.test_scripts.scripts = scripts
|
2022-06-02 04:13:43 +02:00
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
func write_json_file(gut, path):
|
|
|
|
var dict = get_results_dictionary(gut)
|
2023-01-20 23:34:39 +01:00
|
|
|
var json_text = json.stringify(dict, " ")
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
var f_result = _utils.write_file(path, json_text)
|
2023-01-20 23:34:39 +01:00
|
|
|
if f_result != OK:
|
2022-06-02 04:13:43 +02:00
|
|
|
var msg = str("Error: ", f_result, ". Could not create export file ", path)
|
|
|
|
_utils.get_logger().error(msg)
|
|
|
|
|
|
|
|
return f_result
|
|
|
|
|
|
|
|
|
|
|
|
func write_summary_file(gut, path):
|
|
|
|
var dict = get_results_dictionary(gut, false)
|
2023-01-20 23:34:39 +01:00
|
|
|
var json_text = json.stringify(dict, " ")
|
2022-06-02 04:13:43 +02:00
|
|
|
|
2023-01-07 20:26:17 +01:00
|
|
|
var f_result = _utils.write_file(path, json_text)
|
2023-01-20 23:34:39 +01:00
|
|
|
if f_result != OK:
|
2022-06-02 04:13:43 +02:00
|
|
|
var msg = str("Error: ", f_result, ". Could not create export file ", path)
|
|
|
|
_utils.get_logger().error(msg)
|
|
|
|
|
|
|
|
return f_result
|