1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
|
# AzerothCore Test Framework
This is the centralized test framework for all AzerothCore bash scripts. It provides a unified way to write, run, and manage tests across all modules.
## Structure
```
apps/test-framework/
├── run-tests.sh # Universal test runner (single entry point)
├── README.md # This documentation
├── bats_libs/ # Custom BATS libraries
│ ├── acore-support.bash # Test setup and helpers
│ └── acore-assert.bash # Custom assertions
└── helpers/ # Test utilities
└── test_common.sh # Common test functions and setup
```
## Quick Start
### From any module directory:
```bash
# Run tests for current module
../test-framework/run-tests.sh --dir .
```
### From test-framework directory:
```bash
# Run all tests in all modules
./run-tests.sh --all
# Run tests for specific module
./run-tests.sh startup-scripts
# List available modules
./run-tests.sh --list
# Run tests with debug info
./run-tests.sh --all --debug
```
### From project root:
```bash
# Run all tests
apps/test-framework/run-tests.sh --all
# Run specific module
apps/test-framework/run-tests.sh startup-scripts
# Run with verbose output
apps/test-framework/run-tests.sh startup-scripts --verbose
```
## Usage
### Basic Commands
```bash
# Run all tests
./run-tests.sh --all
# Run tests for specific module
./run-tests.sh startup-scripts
# Run tests matching pattern
./run-tests.sh --filter starter
# Run tests in specific directory
./run-tests.sh --dir apps/docker
# Show available modules
./run-tests.sh --list
# Show test count
./run-tests.sh --count
```
### Output Formats
```bash
# Pretty output (default)
./run-tests.sh --pretty
# TAP output for CI/CD
./run-tests.sh --tap
# Verbose output with debug info
./run-tests.sh --verbose --debug
```
## Writing Tests
### Basic Test Structure
```bash
#!/usr/bin/env bats
# Load the AzerothCore test framework
load '../../test-framework/bats_libs/acore-support'
load '../../test-framework/bats_libs/acore-assert'
setup() {
acore_test_setup # Standard setup
# or
startup_scripts_setup # For startup scripts
# or
compiler_setup # For compiler tests
# or
docker_setup # For docker tests
}
teardown() {
acore_test_teardown
}
@test "my test description" {
run my_command
assert_success
assert_output "expected output"
}
```
### Available Setup Functions
- `acore_test_setup` - Basic setup for all tests
- `startup_scripts_setup` - Setup for startup script tests
- `compiler_setup` - Setup for compiler tests
- `docker_setup` - Setup for docker tests
- `extractor_setup` - Setup for extractor tests
### Custom Assertions
```bash
# Assert binary exists and is executable
assert_binary_exists "$TEST_DIR/bin/authserver"
# Assert server started correctly
assert_acore_server_started "$output" "authserver"
# Assert config was loaded
assert_config_loaded "$output" "authserver.conf"
# Assert build success
assert_build_success "$output"
# Assert timeout occurred (for long-running processes)
assert_timeout "$status"
# Assert log contains content
assert_log_contains "$log_file" "Server started"
```
### Test Environment Variables
When using the framework, these variables are automatically set:
- `$TEST_DIR` - Temporary test directory
- `$AC_TEST_ROOT` - Project root directory
- `$AC_TEST_APPS` - Apps directory
- `$BUILDPATH` - Build directory path
- `$SRCPATH` - Source directory path
- `$BINPATH` - Binary directory path
- `$LOGS_PATH` - Logs directory path
### Helper Functions
```bash
# Create test binary
create_test_binary "authserver" 0 2 "Server started"
# Create test config
create_test_config "authserver.conf" "Database.Info = \"127.0.0.1;3306;root;pass;db\""
# Create AzerothCore specific binaries and configs
create_acore_binaries
create_acore_configs
# Run command with timeout
run_with_timeout 5s my_command
# Wait for condition
wait_for_condition "test -f $TEST_DIR/ready" 10 1
# Debug test failure
debug_on_failure
```
## Module Integration
### Adding Tests to a New Module
1. Create a `test/` directory in your module:
```bash
mkdir apps/my-module/test
```
2. Create test files (ending in `.bats`):
```bash
touch apps/my-module/test/test_my_feature.bats
```
3. Write your tests using the framework (see examples above)
### Running Tests
From your module directory:
```bash
../test-framework/run-tests.sh --dir .
```
From the test framework:
```bash
./run-tests.sh my-module
```
From project root:
```bash
apps/test-framework/run-tests.sh my-module
```
## CI/CD Integration
For continuous integration, use TAP output:
```bash
# In your CI script
cd apps/test-framework
./run-tests.sh --all --tap > test-results.tap
# Or from project root
apps/test-framework/run-tests.sh --all --tap > test-results.tap
```
## Available Commands
All functionality is available through the single `run-tests.sh` script:
### Basic Test Execution
- `./run-tests.sh --all` - Run all tests in all modules
- `./run-tests.sh <module>` - Run tests for specific module
- `./run-tests.sh --dir <path>` - Run tests in specific directory
- `./run-tests.sh --list` - List available modules
- `./run-tests.sh --count` - Show test count
### Output Control
- `./run-tests.sh --verbose` - Verbose output with debug info
- `./run-tests.sh --tap` - TAP output for CI/CD
- `./run-tests.sh --debug` - Debug mode with failure details
- `./run-tests.sh --pretty` - Pretty output (default)
### Test Filtering
- `./run-tests.sh --filter <pattern>` - Run tests matching pattern
- `./run-tests.sh <module> --filter <pattern>` - Filter within module
### Utility Functions
- `./run-tests.sh --help` - Show help message
- Install BATS: Use your system package manager (`apt install bats`, `brew install bats-core`, etc.)
### Direct Script Usage
## Examples
### Running Specific Tests
```bash
# Run only starter-related tests
./run-tests.sh --filter starter
# Run only tests in startup-scripts module
./run-tests.sh startup-scripts
# Run all tests with verbose output
./run-tests.sh --all --verbose
# Run tests in specific directory with debug
./run-tests.sh --dir apps/docker --debug
```
### Development Workflow
```bash
# While developing, run tests frequently from module directory
cd apps/my-module
../test-framework/run-tests.sh --dir .
# Debug failing tests
../test-framework/run-tests.sh --dir . --debug --verbose
# Run specific test pattern
../test-framework/run-tests.sh --dir . --filter my-feature
# From project root - run all tests
apps/test-framework/run-tests.sh --all
# Quick test count check
apps/test-framework/run-tests.sh --count
```
## Benefits
1. **No Boilerplate**: Minimal setup required for new test modules
2. **Consistent Environment**: All tests use the same setup/teardown
3. **Reusable Utilities**: Common functions available across all tests
4. **Centralized Management**: Single place to update test infrastructure
5. **Flexible Execution**: Run tests for one module, multiple modules, or all modules
6. **CI/CD Ready**: TAP output format supported
7. **Easy Debugging**: Built-in debug helpers and verbose output
## Dependencies
- [BATS (Bash Automated Testing System)](https://github.com/bats-core/bats-core)
- Standard Unix utilities (find, grep, timeout, etc.)
Install BATS with your system package manager:
```bash
# Ubuntu/Debian
sudo apt update && sudo apt install bats
# Fedora/RHEL
sudo dnf install bats
# macOS
brew install bats-core
# Arch Linux
sudo pacman -S bats
```
## Contributing
When adding new test utilities:
1. Add common functions to `helpers/test_common.sh`
2. Add BATS-specific helpers to `bats_libs/acore-support.bash`
3. Add custom assertions to `bats_libs/acore-assert.bash`
4. Update this README with new functionality
|