extends SceneTree ## Runs suites one after another in this process. SUITES (environment) lists ## them in order; workers started with the same CLAIMS folder share the list, ## each suite going to whichever worker claims it first. ## Output per suite: "SUITE name", the suite's output, then ## "DONE name ". tools/run_tests.sh reads it. ## After a script error, a suite that awaited the crashed function never ends: ## it is abandoned this many frames later. const FRAMES_AFTER_ERROR := 30 ## Notices script errors, which don't reach the suite's own checks. class ErrorWatch extends Logger: var script_errors := 0 func _log_error(_function: String, _file: String, _line: int, _code: String, _rationale: String, _editor_notify: bool, error_type: int, _backtraces: Array[ScriptBacktrace]) -> void: if error_type == ERROR_TYPE_SCRIPT: script_errors += 1 var _errors := ErrorWatch.new() var _original_children: Array[Node] = [] func _init() -> void: OS.add_logger(_errors) await process_frame _original_children = root.get_children() var claims := OS.get_environment("CLAIMS") var failed := false for suite in OS.get_environment("SUITES").split(",", false): # Making a folder is atomic, so only one worker gets each suite. if claims == "" or DirAccess.make_dir_absolute(claims.path_join(suite)) == OK: failed = await _run_suite(suite) > 0 or failed quit(1 if failed else 0) func _run_suite(suite_name: String) -> int: print("SUITE ", suite_name) var started := Time.get_ticks_msec() _errors.script_errors = 0 var failures := 1 var script: GDScript = load("res://tests/%s.gd" % suite_name) if script != null and script.can_instantiate(): var suite: TestBase = script.new() root.add_child(suite) suite.run() var frames_left := FRAMES_AFTER_ERROR while not suite.done and frames_left > 0: await process_frame if _errors.script_errors > 0: frames_left -= 1 failures = suite.failures + _errors.script_errors suite.clean_up() await _reset_tree() print("DONE %s %d %d" % [suite_name, Time.get_ticks_msec() - started, failures]) return failures ## Frees whatever the suite left under root and resets the window. func _reset_tree() -> void: paused = false Engine.time_scale = 1.0 root.gui_release_focus() for child in root.get_children(): if child not in _original_children: child.queue_free() await process_frame