Add 'print_orphan_nodes' config key (see #1)

This commit is contained in:
JeremyStar™ 2024-03-31 14:04:53 +02:00
parent 131c61e35a
commit 897b207cac
3 changed files with 9 additions and 5 deletions

View file

@ -74,6 +74,10 @@ extends Node
# What directory should tests be located in? # What directory should tests be located in?
var test_directory: String = "res://tests" var test_directory: String = "res://tests"
# If Bessere Tests should complain about orphan nodes.
# This behaviour is reportedly broken and does not work correctly (see #1).
# Rely on Godot's debug/verbose output for this instead (use Bessere Tests' command line script).
var print_orphan_nodes: bool = false
``` ```
This is the default configuration. If you want to keep a config key to it's default simply comment it out. This is the default configuration. If you want to keep a config key to it's default simply comment it out.

View file

@ -3,10 +3,11 @@ extends Control
# Configuration for the configuration # Configuration for the configuration
var config: Node = Node.new() var config: Node = Node.new()
const config_path: String = "res://addons/besseretests_config.gd" const config_path: String = "res://addons/besseretests_config.gd"
const config_keys: Dictionary = { "test_directory": TYPE_STRING } const config_keys: Dictionary = { "test_directory": TYPE_STRING, "print_orphan_nodes": TYPE_BOOL }
# Configuration # Configuration
var config_test_directory: String = "res://tests" var config_test_directory: String = "res://tests"
var config_print_orphan_nodes: bool = false
# Statistics <3 & results # Statistics <3 & results
var results: Dictionary = {} var results: Dictionary = {}
@ -165,8 +166,6 @@ func terminate(exit_code: int = 0) -> void:
get_tree().quit(exit_code) get_tree().quit(exit_code)
# Checks # Checks
func check_children() -> void: func check_children() -> void: 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.")
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.")
func check_orphan_nodes() -> void: func check_orphan_nodes() -> void: 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.")
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.")

View file

@ -1,3 +1,4 @@
extends Node extends Node
var test_directory: String = "res://addons/besseretests/examples/" var test_directory: String = "res://addons/besseretests/examples/"
var print_orphan_nodes: bool = true