Add an in-repo test runner that discovers test/**/test_*.gd and runs under --headless. It uses Godot's Logger API, so engine and script errors during a test fail that test. make test runs the suite, and make test-selfcheck runs deliberately failing fixtures to prove each kind of failure is detected. Closes #4 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
37 lines
1002 B
GDScript
37 lines
1002 B
GDScript
## Records engine and script errors so the runner can fail the test that caused them.
|
|
## Godot may call a Logger from any thread, so all state is guarded by a mutex, and
|
|
## nothing here prints (printing from a logger callback would recurse).
|
|
class_name TestLogger
|
|
extends Logger
|
|
|
|
var _mutex: Mutex = Mutex.new()
|
|
var _errors: Array[String] = []
|
|
|
|
|
|
func _log_error(
|
|
function: String,
|
|
file: String,
|
|
line: int,
|
|
code: String,
|
|
rationale: String,
|
|
_editor_notify: bool,
|
|
error_type: int,
|
|
_script_backtrace: Array[ScriptBacktrace],
|
|
) -> void:
|
|
if error_type == Logger.ERROR_TYPE_WARNING:
|
|
return
|
|
var what: String = rationale if not rationale.is_empty() else code
|
|
var entry: String = "%s (at %s:%d in %s)" % [what, file, line, function]
|
|
_mutex.lock()
|
|
_errors.append(entry)
|
|
_mutex.unlock()
|
|
|
|
|
|
## Returns every error recorded since the last call, and clears the record.
|
|
func take_errors() -> Array[String]:
|
|
_mutex.lock()
|
|
var taken: Array[String] = _errors
|
|
_errors = []
|
|
_mutex.unlock()
|
|
return taken
|