6.0 KiB
Eluna/LuaEngine Unit Test Suite
Overview
This directory contains a comprehensive unit test suite for the Eluna Lua scripting engine integration with TrinityCore. The tests validate functionality across multiple layers of the Eluna system.
Test Organization
Test Files
-
CoreLuaExecution.cpp (11 tests)
- Basic script loading and execution
- Variable assignment (integers, strings, booleans)
- Function definition and calling
- Table operations
- Error handling and recovery
- Lua state isolation
- Arithmetic operations
- String operations
- Conditional logic
- Loops (for, while)
-
DataTypeConversions.cpp (13 tests)
- LuaValue creation and type checking
- Lua to C++ conversions (integers, floats, strings, booleans, nil)
- Type coercion
- Table handling (arrays, dictionaries, nested)
-
EventSystem.cpp (8 tests)
- Event registration and handler patterns
- Event callback execution
- Event handler state persistence
- Event handler unregistration
- Event handler priority ordering
- Conditional event handling
- Error handling in event handlers
-
Integration.cpp (8 tests)
- Global Eluna instance creation
- Script lifecycle (load → execute → verify)
- Cross-script variable access
- Module pattern implementation
- Event manager pattern
- Error recovery and resilience
- Complex game script scenarios
- Lua standard library functions (table, string, math)
-
EdgeCases.cpp (13 tests)
- Empty and whitespace-only scripts
- Nil and false value handling
- Large numbers
- Special characters in strings
- Recursive functions (simple and mutual)
- Circular references
- Variable shadowing
- Operator precedence
- Table iteration edge cases
- Function return values (multiple, none)
- Metamethods
- Upvalues and closures
-
MethodBindings.cpp (11 tests - Placeholders)
- Binding availability checks
- Binding signature validation
- Return value conversion (int, string, bool, object)
- Argument conversion (int, string, bool, object)
- Null pointer handling
- Enum constants
- Method chaining
Test Fixture
LuaEngineTestFixture.h provides common utilities:
CreateGlobalElunaInstance()- Create a test Eluna instanceExecuteScript()- Execute Lua script stringGetGlobalAsString()- Retrieve global variable as stringFunctionExists()- Check if function is definedCallFunction()- Call a Lua functionGetLuaState()- Get raw Lua state pointer
Running Tests
Build Tests
cd /opt/github.com/araxiaonline/TrinityCore
mkdir build && cd build
cmake .. -DELUNA=1
make tests
Run All Tests
./bin/tests
Run Specific Test Category
# Run only core execution tests
./bin/tests "[LuaEngine][CoreExecution]"
# Run only data type tests
./bin/tests "[LuaEngine][DataTypes]"
# Run only event system tests
./bin/tests "[LuaEngine][Events]"
# Run only integration tests
./bin/tests "[LuaEngine][Integration]"
# Run only edge case tests
./bin/tests "[LuaEngine][EdgeCases]"
# Run only method binding tests
./bin/tests "[LuaEngine][MethodBindings]"
Run Specific Test
./bin/tests "Core Lua Execution - Simple Variable Assignment"
Verbose Output
./bin/tests -v
Test Statistics
- Total Tests: 64
- Core Execution: 11 tests
- Data Types: 13 tests
- Event System: 8 tests
- Integration: 8 tests
- Edge Cases: 13 tests
- Method Bindings: 11 tests (placeholders)
Test Coverage
Implemented Coverage
✅ Core Lua execution and state management ✅ Data type conversions and coercion ✅ Event handler patterns and callbacks ✅ Script lifecycle and error recovery ✅ Lua standard library functions ✅ Edge cases and error conditions
Placeholder Coverage (Requires Server Context)
⏳ C++ method bindings (requires World/Map/Creature singletons) ⏳ Server event integration (requires full server initialization) ⏳ Player/Creature/GameObject method bindings ⏳ GUID and object reference handling
Test Fixture Requirements
The test fixture requires:
sElunaMgrsingleton to be initializedsElunaConfigsingleton to be initialized- Eluna to be compiled with
ELUNAdefine
Known Limitations
- Server Context: Some tests are placeholders because they require full server initialization (World, Map, Creature objects)
- Method Bindings: Full validation of C++ method bindings requires server singletons
- Event Firing: Actual event firing requires server event system integration
Future Enhancements
- Mock Objects: Create mock World/Map/Creature for testing without full server
- Method Binding Tests: Implement actual binding validation with mocks
- Performance Tests: Add benchmarks for script execution
- Stress Tests: Test with large scripts and many concurrent handlers
- Memory Tests: Validate garbage collection and memory management
Contributing
When adding new tests:
- Follow the existing test structure and naming conventions
- Use descriptive test names and sections
- Add comments explaining complex test scenarios
- Update this README with new test categories
- Ensure tests are isolated and don't depend on execution order
- Use the LuaEngineTestFixture for common operations
Debugging Tests
Enable Verbose Output
./bin/tests -v "[LuaEngine][CoreExecution]"
Run Single Test with Debugging
gdb ./bin/tests
(gdb) run "Core Lua Execution - Simple Variable Assignment"
Check Lua Stack State
The fixture provides GetLuaState() to access the raw Lua state for debugging:
lua_State* L = fixture.GetLuaState(eluna);
// Use Lua API directly for debugging