From ec1699f3c7bf6406fae0acc4d1e4c501850017df Mon Sep 17 00:00:00 2001 From: JeremyStarTM Date: Sat, 6 Apr 2024 13:47:48 +0200 Subject: [PATCH] Prevent any further code execution after crash --- addons/besseretests/src/runtimescene.gd | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/addons/besseretests/src/runtimescene.gd b/addons/besseretests/src/runtimescene.gd index 29e157e..9aff373 100644 --- a/addons/besseretests/src/runtimescene.gd +++ b/addons/besseretests/src/runtimescene.gd @@ -19,6 +19,9 @@ var stats_skip: int = 0 var stats_forgot: int = 0 var stats_unknown: int = 0 +# To stop any still running test +var crashed: bool = false + func _ready() -> void: await get_tree().process_frame @@ -48,7 +51,11 @@ func _ready() -> void: if !DirAccess.dir_exists_absolute(config_test_directory): await lcrash("Testing directory \"" + config_test_directory + "\" does not exist") # Run test suites - for suite in DirAccess.get_files_at(config_test_directory): await run_suite(suite.replace(".gd", "")) + for suite in DirAccess.get_files_at(config_test_directory): + if crashed: return + await run_suite(suite.replace(".gd", "")) + + if crashed: return # Print test results lresu("") @@ -106,6 +113,7 @@ func run_suite(suite: String) -> void: # Execute before_all() suite_node.lfunc = "before_all" await suite_node.before_all() + if crashed: return # Iterate over all functions for test_method in suite_node.get_method_list(): @@ -122,12 +130,15 @@ func run_suite(suite: String) -> void: # Execute before_each() suite_node.lfunc = "before_each" await suite_node.before_each() + if crashed: return # Execute test function suite_node.lfunc = test_method["name"].replace("test_", "") await suite_node.call(test_method["name"]) + if crashed: return # Execute after_each() suite_node.lfunc = "after_each" await suite_node.after_each() + if crashed: return # Merge result into result dictionary results.merge({ suite + ":" + test_method["name"].replace("test_", ""): { "status": suite_node.test_status, "message": lsanitize(suite_node.test_message) if suite_node.test_message != "" else "[i]No message has been set.[/i]" } }) @@ -135,6 +146,7 @@ func run_suite(suite: String) -> void: # Execute after_all() suite_node.lfunc = "after_all" await suite_node.after_all() + if crashed: return # Remove suite node get_tree().root.remove_child(suite_node) @@ -148,6 +160,7 @@ func linfo(message: String, origin: String = "Bessere Tests") -> void: print_ric func lwarn(message: String, origin: String = "Bessere Tests") -> void: print_rich("[color=yellow]WARN " + origin + ": " + message + "[/color]") func lerror(message: String, origin: String = "Bessere Tests") -> void: print_rich("[color=red]ERR! " + origin + ": " + message + "[/color]") func lcrash(message: String, origin: String = "Bessere Tests") -> void: + crashed = true print_rich("[color=red][b]CRSH " + origin + ": " + message + "[/b][/color]") await terminate(69) @@ -167,12 +180,14 @@ func terminate(exit_code: int = 0) -> void: # Checks func check_children() -> void: + if crashed: return if get_tree().root.get_child_count() != 1: lwarn("There are still '" + str(get_tree().root.get_child_count()-1) + "' children active in the scene tree. Please make sure to call 'remove_child' on them in your tests.") lwarn("Here's a tree of /root:") get_tree().root.print_tree_pretty() func check_orphan_nodes() -> void: + if crashed: return if config_print_orphan_nodes: if Performance.get_monitor(Performance.OBJECT_ORPHAN_NODE_COUNT) != 4: lwarn("There are still '" + str(Performance.get_monitor(Performance.OBJECT_ORPHAN_NODE_COUNT)-4) + "' orphan nodes loaded. Please make sure to call 'queue_free' or 'free' on them in your tests.")