extends SceneTree var test_scripts: Array[String] = [] var test_index: int = 0 var total_passed: int = 0 var total_failed: int = 0 func _init(): print("\n=== GODOT TEST RUNNER ===\n") _discover_tests() if test_scripts.is_empty(): print("[ERROR] No test scripts found in res://tests/") print("[RESULT] FAIL") quit(1) return print("Found %d test(s): %s\n" % [test_scripts.size(), str(test_scripts)]) await _run_next_test() print("\n=== TEST SUMMARY ===") print("Total passed: %d" % total_passed) print("Total failed: %d" % total_failed) if total_failed == 0: print("[OVERALL_RESULT] PASS") quit(0) else: print("[OVERALL_RESULT] FAIL") quit(1) func _discover_tests() -> void: var dir = DirAccess.open("res://tests") if dir: dir.list_dir_begin() var file_name = dir.get_next() while file_name != "": if file_name.ends_with(".gd") and file_name.begins_with("test_") and \ file_name != "test_runner.gd" and file_name != "test_utils.gd": test_scripts.append("res://tests/%s" % file_name) file_name = dir.get_next() dir.list_dir_end() test_scripts.sort() func _run_next_test() -> void: if test_index >= test_scripts.size(): return var test_script = test_scripts[test_index] print("--- Running test %d/%d: %s ---" % [test_index + 1, test_scripts.size(), test_script]) print("") # Load and run test var test_instance = load(test_script).new() get_root().add_child(test_instance) # Check if test has run() method (new pattern) or uses _ready() (old pattern) if test_instance.has_method("run"): await test_instance.run() # Clean up test instance test_instance.queue_free() else: # For old pattern, wait a bit for _ready() to complete await create_timer(0.2).timeout # Clean up test instance test_instance.queue_free() # Get results if available if test_instance.has_method("get_passed"): total_passed += test_instance.get_passed() total_failed += test_instance.get_failed() # Wait for cleanup await create_timer(0.1).timeout print("") test_index += 1 await _run_next_test()