setting up GDUnit
Some checks failed
Create tag and build when new code gets to main / Export (push) Failing after 3m40s
Some checks failed
Create tag and build when new code gets to main / Export (push) Failing after 3m40s
This commit is contained in:
72
addons/gdUnit4/src/monitor/ErrorLogEntry.gd
Normal file
72
addons/gdUnit4/src/monitor/ErrorLogEntry.gd
Normal file
@@ -0,0 +1,72 @@
|
||||
extends RefCounted
|
||||
class_name ErrorLogEntry
|
||||
|
||||
|
||||
enum TYPE {
|
||||
SCRIPT_ERROR,
|
||||
PUSH_ERROR,
|
||||
PUSH_WARNING
|
||||
}
|
||||
|
||||
|
||||
const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
|
||||
|
||||
const PATTERN_SCRIPT_ERROR := "USER SCRIPT ERROR:"
|
||||
const PATTERN_PUSH_ERROR := "USER ERROR:"
|
||||
const PATTERN_PUSH_WARNING := "USER WARNING:"
|
||||
# With Godot 4.4 the pattern has changed
|
||||
const PATTERN_4x4_SCRIPT_ERROR := "SCRIPT ERROR:"
|
||||
const PATTERN_4x4_PUSH_ERROR := "ERROR:"
|
||||
const PATTERN_4x4_PUSH_WARNING := "WARNING:"
|
||||
|
||||
static var _regex_parse_error_line_number: RegEx
|
||||
|
||||
var _type: TYPE
|
||||
var _line: int
|
||||
var _message: String
|
||||
var _details: String
|
||||
|
||||
|
||||
func _init(type: TYPE, line: int, message: String, details: String) -> void:
|
||||
_type = type
|
||||
_line = line
|
||||
_message = message
|
||||
_details = details
|
||||
|
||||
|
||||
static func is_godot4x4() -> bool:
|
||||
return Engine.get_version_info().hex >= 0x40400
|
||||
|
||||
|
||||
static func extract_push_warning(records: PackedStringArray, index: int) -> ErrorLogEntry:
|
||||
var pattern := PATTERN_4x4_PUSH_WARNING if is_godot4x4() else PATTERN_PUSH_WARNING
|
||||
return _extract(records, index, TYPE.PUSH_WARNING, pattern)
|
||||
|
||||
|
||||
static func extract_push_error(records: PackedStringArray, index: int) -> ErrorLogEntry:
|
||||
var pattern := PATTERN_4x4_PUSH_ERROR if is_godot4x4() else PATTERN_PUSH_ERROR
|
||||
return _extract(records, index, TYPE.PUSH_ERROR, pattern)
|
||||
|
||||
|
||||
static func extract_error(records: PackedStringArray, index: int) -> ErrorLogEntry:
|
||||
var pattern := PATTERN_4x4_SCRIPT_ERROR if is_godot4x4() else PATTERN_SCRIPT_ERROR
|
||||
return _extract(records, index, TYPE.SCRIPT_ERROR, pattern)
|
||||
|
||||
|
||||
static func _extract(records: PackedStringArray, index: int, type: TYPE, pattern: String) -> ErrorLogEntry:
|
||||
var message := records[index]
|
||||
if message.begins_with(pattern):
|
||||
var error := message.replace(pattern, "").strip_edges()
|
||||
var details := records[index+1].strip_edges()
|
||||
var line := _parse_error_line_number(details)
|
||||
return ErrorLogEntry.new(type, line, error, details)
|
||||
return null
|
||||
|
||||
|
||||
static func _parse_error_line_number(record: String) -> int:
|
||||
if _regex_parse_error_line_number == null:
|
||||
_regex_parse_error_line_number = GdUnitTools.to_regex("at: .*res://.*:(\\d+)")
|
||||
var matches := _regex_parse_error_line_number.search(record)
|
||||
if matches != null:
|
||||
return matches.get_string(1).to_int()
|
||||
return -1
|
||||
1
addons/gdUnit4/src/monitor/ErrorLogEntry.gd.uid
Normal file
1
addons/gdUnit4/src/monitor/ErrorLogEntry.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://8kjgr8gyjg5f
|
||||
24
addons/gdUnit4/src/monitor/GdUnitMonitor.gd
Normal file
24
addons/gdUnit4/src/monitor/GdUnitMonitor.gd
Normal file
@@ -0,0 +1,24 @@
|
||||
# GdUnit Monitoring Base Class
|
||||
class_name GdUnitMonitor
|
||||
extends RefCounted
|
||||
|
||||
var _id :String
|
||||
|
||||
# constructs new Monitor with given id
|
||||
func _init(p_id :String) -> void:
|
||||
_id = p_id
|
||||
|
||||
|
||||
# Returns the id of the monitor to uniqe identify
|
||||
func id() -> String:
|
||||
return _id
|
||||
|
||||
|
||||
# starts monitoring
|
||||
func start() -> void:
|
||||
pass
|
||||
|
||||
|
||||
# stops monitoring
|
||||
func stop() -> void:
|
||||
pass
|
||||
1
addons/gdUnit4/src/monitor/GdUnitMonitor.gd.uid
Normal file
1
addons/gdUnit4/src/monitor/GdUnitMonitor.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://gq08i83yup2g
|
||||
27
addons/gdUnit4/src/monitor/GdUnitOrphanNodesMonitor.gd
Normal file
27
addons/gdUnit4/src/monitor/GdUnitOrphanNodesMonitor.gd
Normal file
@@ -0,0 +1,27 @@
|
||||
class_name GdUnitOrphanNodesMonitor
|
||||
extends GdUnitMonitor
|
||||
|
||||
var _initial_count := 0
|
||||
var _orphan_count := 0
|
||||
var _orphan_detection_enabled :bool
|
||||
|
||||
|
||||
func _init(name :String = "") -> void:
|
||||
super("OrphanNodesMonitor:" + name)
|
||||
_orphan_detection_enabled = GdUnitSettings.is_verbose_orphans()
|
||||
|
||||
|
||||
func start() -> void:
|
||||
_initial_count = _orphans()
|
||||
|
||||
|
||||
func stop() -> void:
|
||||
_orphan_count = max(0, _orphans() - _initial_count)
|
||||
|
||||
|
||||
func _orphans() -> int:
|
||||
return Performance.get_monitor(Performance.OBJECT_ORPHAN_NODE_COUNT) as int
|
||||
|
||||
|
||||
func orphan_nodes() -> int:
|
||||
return _orphan_count if _orphan_detection_enabled else 0
|
||||
@@ -0,0 +1 @@
|
||||
uid://cufv71udymwm5
|
||||
103
addons/gdUnit4/src/monitor/GodotGdErrorMonitor.gd
Normal file
103
addons/gdUnit4/src/monitor/GodotGdErrorMonitor.gd
Normal file
@@ -0,0 +1,103 @@
|
||||
class_name GodotGdErrorMonitor
|
||||
extends GdUnitMonitor
|
||||
|
||||
var _godot_log_file: String
|
||||
var _eof: int
|
||||
var _report_enabled := false
|
||||
var _entries: Array[ErrorLogEntry] = []
|
||||
|
||||
|
||||
func _init() -> void:
|
||||
super("GodotGdErrorMonitor")
|
||||
_godot_log_file = GdUnitSettings.get_log_path()
|
||||
_report_enabled = _is_reporting_enabled()
|
||||
|
||||
|
||||
func start() -> void:
|
||||
var file := FileAccess.open(_godot_log_file, FileAccess.READ)
|
||||
if file:
|
||||
file.seek_end(0)
|
||||
_eof = file.get_length()
|
||||
|
||||
|
||||
func stop() -> void:
|
||||
pass
|
||||
|
||||
|
||||
func to_reports() -> Array[GdUnitReport]:
|
||||
var reports_: Array[GdUnitReport] = []
|
||||
if _report_enabled:
|
||||
reports_.assign(_entries.map(_to_report))
|
||||
_entries.clear()
|
||||
return reports_
|
||||
|
||||
|
||||
static func _to_report(errorLog: ErrorLogEntry) -> GdUnitReport:
|
||||
var failure := "%s\n\t%s\n%s %s" % [
|
||||
GdAssertMessages._error("Godot Runtime Error !"),
|
||||
GdAssertMessages._colored_value(errorLog._details),
|
||||
GdAssertMessages._error("Error:"),
|
||||
GdAssertMessages._colored_value(errorLog._message)]
|
||||
return GdUnitReport.new().create(GdUnitReport.ABORT, errorLog._line, failure)
|
||||
|
||||
|
||||
func scan(force_collect_reports := false) -> Array[ErrorLogEntry]:
|
||||
await (Engine.get_main_loop() as SceneTree).process_frame
|
||||
await (Engine.get_main_loop() as SceneTree).physics_frame
|
||||
_entries.append_array(_collect_log_entries(force_collect_reports))
|
||||
return _entries
|
||||
|
||||
|
||||
func erase_log_entry(entry: ErrorLogEntry) -> void:
|
||||
_entries.erase(entry)
|
||||
|
||||
|
||||
func collect_full_logs() -> PackedStringArray:
|
||||
await (Engine.get_main_loop() as SceneTree).process_frame
|
||||
await (Engine.get_main_loop() as SceneTree).physics_frame
|
||||
|
||||
var file := FileAccess.open(_godot_log_file, FileAccess.READ)
|
||||
file.seek(_eof)
|
||||
var records := PackedStringArray()
|
||||
while not file.eof_reached():
|
||||
@warning_ignore("return_value_discarded")
|
||||
records.append(file.get_line())
|
||||
|
||||
return records
|
||||
|
||||
|
||||
func _collect_log_entries(force_collect_reports: bool) -> Array[ErrorLogEntry]:
|
||||
var file := FileAccess.open(_godot_log_file, FileAccess.READ)
|
||||
if not file:
|
||||
# Log file might not be available.
|
||||
return []
|
||||
file.seek(_eof)
|
||||
var records := PackedStringArray()
|
||||
while not file.eof_reached():
|
||||
@warning_ignore("return_value_discarded")
|
||||
records.append(file.get_line())
|
||||
file.seek_end(0)
|
||||
_eof = file.get_length()
|
||||
var log_entries: Array[ErrorLogEntry]= []
|
||||
var is_report_errors := force_collect_reports or _is_report_push_errors()
|
||||
var is_report_script_errors := force_collect_reports or _is_report_script_errors()
|
||||
for index in records.size():
|
||||
if force_collect_reports:
|
||||
log_entries.append(ErrorLogEntry.extract_push_warning(records, index))
|
||||
if is_report_errors:
|
||||
log_entries.append(ErrorLogEntry.extract_push_error(records, index))
|
||||
if is_report_script_errors:
|
||||
log_entries.append(ErrorLogEntry.extract_error(records, index))
|
||||
return log_entries.filter(func(value: ErrorLogEntry) -> bool: return value != null )
|
||||
|
||||
|
||||
func _is_reporting_enabled() -> bool:
|
||||
return _is_report_script_errors() or _is_report_push_errors()
|
||||
|
||||
|
||||
func _is_report_push_errors() -> bool:
|
||||
return GdUnitSettings.is_report_push_errors()
|
||||
|
||||
|
||||
func _is_report_script_errors() -> bool:
|
||||
return GdUnitSettings.is_report_script_errors()
|
||||
1
addons/gdUnit4/src/monitor/GodotGdErrorMonitor.gd.uid
Normal file
1
addons/gdUnit4/src/monitor/GodotGdErrorMonitor.gd.uid
Normal file
@@ -0,0 +1 @@
|
||||
uid://de86ibngfhvf5
|
||||
Reference in New Issue
Block a user