add unit tests

saveload fixes
This commit is contained in:
2025-09-27 12:17:14 +04:00
parent 3e960a955c
commit dd0c1a123c
31 changed files with 3400 additions and 282 deletions

View File

@@ -1,106 +1,110 @@
extends Node
extends SceneTree
# Test script for the DebugManager logging system
# Test script for the debug_manager logging system
# This script validates all log levels, filtering, and formatting functionality
# Usage: Add to scene or autoload temporarily to run tests
func _ready():
# Wait a frame for DebugManager to initialize
await get_tree().process_frame
func _initialize():
# Wait a frame for debug_manager to initialize
await process_frame
test_logging_system()
quit()
func test_logging_system():
print("=== Starting Logging System Tests ===")
# Get DebugManager reference once
var debug_manager = root.get_node("DebugManager")
# Test 1: Basic log level functionality
test_basic_logging()
test_basic_logging(debug_manager)
# Test 2: Log level filtering
test_log_level_filtering()
test_log_level_filtering(debug_manager)
# Test 3: Category functionality
test_category_logging()
test_category_logging(debug_manager)
# Test 4: Debug mode integration
test_debug_mode_integration()
test_debug_mode_integration(debug_manager)
print("=== Logging System Tests Complete ===")
func test_basic_logging():
func test_basic_logging(debug_manager):
print("\n--- Test 1: Basic Log Level Functionality ---")
# Reset to INFO level for consistent testing
DebugManager.set_log_level(DebugManager.LogLevel.INFO)
debug_manager.set_log_level(debug_manager.LogLevel.INFO)
DebugManager.log_trace("TRACE: This should not appear (below INFO level)")
DebugManager.log_debug("DEBUG: This should not appear (below INFO level)")
DebugManager.log_info("INFO: This message should appear")
DebugManager.log_warn("WARN: This warning should appear")
DebugManager.log_error("ERROR: This error should appear")
DebugManager.log_fatal("FATAL: This fatal error should appear")
debug_manager.log_trace("TRACE: This should not appear (below INFO level)")
debug_manager.log_debug("DEBUG: This should not appear (below INFO level)")
debug_manager.log_info("INFO: This message should appear")
debug_manager.log_warn("WARN: This warning should appear")
debug_manager.log_error("ERROR: This error should appear")
debug_manager.log_fatal("FATAL: This fatal error should appear")
func test_log_level_filtering():
func test_log_level_filtering(debug_manager):
print("\n--- Test 2: Log Level Filtering ---")
# Test DEBUG level
print("Setting log level to DEBUG...")
DebugManager.set_log_level(DebugManager.LogLevel.DEBUG)
DebugManager.log_trace("TRACE: Should not appear (below DEBUG)")
DebugManager.log_debug("DEBUG: Should appear with debug enabled")
DebugManager.log_info("INFO: Should appear")
debug_manager.set_log_level(debug_manager.LogLevel.DEBUG)
debug_manager.log_trace("TRACE: Should not appear (below DEBUG)")
debug_manager.log_debug("DEBUG: Should appear with debug enabled")
debug_manager.log_info("INFO: Should appear")
# Test ERROR level (very restrictive)
print("Setting log level to ERROR...")
DebugManager.set_log_level(DebugManager.LogLevel.ERROR)
DebugManager.log_debug("DEBUG: Should not appear (below ERROR)")
DebugManager.log_warn("WARN: Should not appear (below ERROR)")
DebugManager.log_error("ERROR: Should appear")
DebugManager.log_fatal("FATAL: Should appear")
debug_manager.set_log_level(debug_manager.LogLevel.ERROR)
debug_manager.log_debug("DEBUG: Should not appear (below ERROR)")
debug_manager.log_warn("WARN: Should not appear (below ERROR)")
debug_manager.log_error("ERROR: Should appear")
debug_manager.log_fatal("FATAL: Should appear")
# Reset to INFO for remaining tests
DebugManager.set_log_level(DebugManager.LogLevel.INFO)
debug_manager.set_log_level(debug_manager.LogLevel.INFO)
func test_category_logging():
func test_category_logging(debug_manager):
print("\n--- Test 3: Category Functionality ---")
DebugManager.log_info("Message without category")
DebugManager.log_info("Message with TEST category", "TEST")
DebugManager.log_info("Message with LOGGING category", "LOGGING")
DebugManager.log_warn("Warning with VALIDATION category", "VALIDATION")
DebugManager.log_error("Error with SYSTEM category", "SYSTEM")
debug_manager.log_info("Message without category")
debug_manager.log_info("Message with TEST category", "TEST")
debug_manager.log_info("Message with LOGGING category", "LOGGING")
debug_manager.log_warn("Warning with VALIDATION category", "VALIDATION")
debug_manager.log_error("Error with SYSTEM category", "SYSTEM")
func test_debug_mode_integration():
func test_debug_mode_integration(debug_manager):
print("\n--- Test 4: Debug Mode Integration ---")
# Set to TRACE level to test debug mode dependency
DebugManager.set_log_level(DebugManager.LogLevel.TRACE)
debug_manager.set_log_level(debug_manager.LogLevel.TRACE)
var original_debug_state = DebugManager.is_debug_enabled()
var original_debug_state = debug_manager.is_debug_enabled()
# Test with debug mode OFF
DebugManager.set_debug_enabled(false)
debug_manager.set_debug_enabled(false)
print("Debug mode OFF - TRACE and DEBUG should not appear:")
DebugManager.log_trace("TRACE: Should NOT appear (debug mode OFF)")
DebugManager.log_debug("DEBUG: Should NOT appear (debug mode OFF)")
DebugManager.log_info("INFO: Should appear regardless of debug mode")
debug_manager.log_trace("TRACE: Should NOT appear (debug mode OFF)")
debug_manager.log_debug("DEBUG: Should NOT appear (debug mode OFF)")
debug_manager.log_info("INFO: Should appear regardless of debug mode")
# Test with debug mode ON
DebugManager.set_debug_enabled(true)
debug_manager.set_debug_enabled(true)
print("Debug mode ON - TRACE and DEBUG should appear:")
DebugManager.log_trace("TRACE: Should appear (debug mode ON)")
DebugManager.log_debug("DEBUG: Should appear (debug mode ON)")
DebugManager.log_info("INFO: Should still appear")
debug_manager.log_trace("TRACE: Should appear (debug mode ON)")
debug_manager.log_debug("DEBUG: Should appear (debug mode ON)")
debug_manager.log_info("INFO: Should still appear")
# Restore original debug state
DebugManager.set_debug_enabled(original_debug_state)
DebugManager.set_log_level(DebugManager.LogLevel.INFO)
debug_manager.set_debug_enabled(original_debug_state)
debug_manager.set_log_level(debug_manager.LogLevel.INFO)
# Helper function to validate log level enum values
func test_log_level_enum():
func test_log_level_enum(debug_manager):
print("\n--- Log Level Enum Values ---")
print("TRACE: ", DebugManager.LogLevel.TRACE)
print("DEBUG: ", DebugManager.LogLevel.DEBUG)
print("INFO: ", DebugManager.LogLevel.INFO)
print("WARN: ", DebugManager.LogLevel.WARN)
print("ERROR: ", DebugManager.LogLevel.ERROR)
print("FATAL: ", DebugManager.LogLevel.FATAL)
print("TRACE: ", debug_manager.LogLevel.TRACE)
print("DEBUG: ", debug_manager.LogLevel.DEBUG)
print("INFO: ", debug_manager.LogLevel.INFO)
print("WARN: ", debug_manager.LogLevel.WARN)
print("ERROR: ", debug_manager.LogLevel.ERROR)
print("FATAL: ", debug_manager.LogLevel.FATAL)