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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
|
# 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/
├── test-main.sh # Unified test framework entry point
├── run-bash-tests.sh # Bash test runner for BATS tests
├── run-core-tests.sh # AzerothCore unit test runner
├── 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
### Using acore.sh (Recommended):
```bash
# Run the unified test framework (interactive menu)
./acore.sh test
# Run bash tests directly
./acore.sh test bash --all
# Run AzerothCore unit tests
./acore.sh test core
```
### From any module directory:
```bash
# Run tests for current module
../test-framework/run-bash-tests.sh --dir .
```
### From test-framework directory:
```bash
# Run all tests in all modules
./run-bash-tests.sh --all
# Run tests for specific module
./run-bash-tests.sh startup-scripts
# List available modules
./run-bash-tests.sh --list
# Run tests with debug info
./run-bash-tests.sh --all --debug
```
### From project root:
```bash
# Run all tests
apps/test-framework/run-bash-tests.sh --all
# Run specific module
apps/test-framework/run-bash-tests.sh startup-scripts
# Run with verbose output
apps/test-framework/run-bash-tests.sh startup-scripts --verbose
```
## Test Types
The framework now supports two types of tests:
1. **Bash Tests** - BATS-based tests for bash scripts and functionality
2. **Core Tests** - AzerothCore C++ unit tests
### Unified Test Framework
The test framework provides a unified entry point through `test-main.sh` which presents an interactive menu:
- **bash**: Run BATS-based bash script tests
- **core**: Run AzerothCore C++ unit tests
- **quit**: Exit the test framework
```bash
# Interactive test menu
./acore.sh test
# Direct test execution
./acore.sh test bash --all # Run all bash tests
./acore.sh test core # Run core unit tests
```
## Usage
### Basic Commands
```bash
# Run all tests
./run-bash-tests.sh --all
# Run tests for specific module
./run-bash-tests.sh startup-scripts
# Run tests matching pattern
./run-bash-tests.sh --filter starter
# Run tests in specific directory
./run-bash-tests.sh --dir apps/docker
# Show available modules
./run-bash-tests.sh --list
# Show test count
./run-bash-tests.sh --count
```
### Output Formats
```bash
# Pretty output (default)
./run-bash-tests.sh --pretty
# TAP output for CI/CD
./run-bash-tests.sh --tap
# Verbose output with debug info
./run-bash-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-bash-tests.sh --dir .
```
From the test framework:
```bash
./run-bash-tests.sh my-module
```
From project root:
```bash
apps/test-framework/run-bash-tests.sh my-module
```
## CI/CD Integration
For continuous integration, use TAP output:
```bash
# Recommended: Use acore.sh integration
./acore.sh test bash --tap --all > test-results.tap
# Direct script usage
cd apps/test-framework
./run-bash-tests.sh --all --tap > test-results.tap
# Or from project root
apps/test-framework/run-bash-tests.sh --all --tap > test-results.tap
# Run core unit tests in CI
./acore.sh test core
```
## Core Tests
The framework now includes support for AzerothCore's C++ unit tests through `run-core-tests.sh`:
```bash
# Run core unit tests
./acore.sh test core
# Direct script usage
apps/test-framework/run-core-tests.sh
```
**Prerequisites for Core Tests:**
- Project must be built with unit tests enabled (`CBUILD_TESTING="ON"` inside `conf/config.sh` that works with the acore.sh compiler)
- Unit test binary should be available at `$BUILDPATH/src/test/unit_tests`
The core test runner will:
1. Check if the unit test binary exists
2. Execute the AzerothCore unit tests
3. Return appropriate exit codes for CI/CD integration
## Available Commands
### Unified Test Framework Commands
Recommended usage through `acore.sh`:
- `./acore.sh test` - Interactive test framework menu
- `./acore.sh test bash [options]` - Run bash tests with options
- `./acore.sh test core` - Run AzerothCore unit tests
### Bash Test Commands
All bash test functionality is available through the `run-bash-tests.sh` script:
### Basic Test Execution
- `./run-bash-tests.sh --all` - Run all tests in all modules
- `./run-bash-tests.sh <module>` - Run tests for specific module
- `./run-bash-tests.sh --dir <path>` - Run tests in specific directory
- `./run-bash-tests.sh --list` - List available modules
- `./run-bash-tests.sh --count` - Show test count
### Output Control
- `./run-bash-tests.sh --verbose` - Verbose output with debug info
- `./run-bash-tests.sh --tap` - TAP output for CI/CD
- `./run-bash-tests.sh --debug` - Debug mode with failure details
- `./run-bash-tests.sh --pretty` - Pretty output (default)
### Test Filtering
- `./run-bash-tests.sh --filter <pattern>` - Run tests matching pattern
- `./run-bash-tests.sh <module> --filter <pattern>` - Filter within module
### Utility Functions
- `./run-bash-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-bash-tests.sh --filter starter
# Run only tests in startup-scripts module
./run-bash-tests.sh startup-scripts
# Run all tests with verbose output
./run-bash-tests.sh --all --verbose
# Run tests in specific directory with debug
./run-bash-tests.sh --dir apps/docker --debug
```
### Development Workflow
```bash
# Recommended: Use acore.sh for unified testing
./acore.sh test # Interactive menu
./acore.sh test bash --all # All bash tests
./acore.sh test core # Core unit tests
# While developing, run tests frequently from module directory
cd apps/my-module
../test-framework/run-bash-tests.sh --dir .
# Debug failing tests
../test-framework/run-bash-tests.sh --dir . --debug --verbose
# Run specific test pattern
../test-framework/run-bash-tests.sh --dir . --filter my-feature
# From project root - run all tests
./acore.sh test bash --all # Recommended
apps/test-framework/run-bash-tests.sh --all # Direct
# Quick test count check
./acore.sh test bash --count # Recommended
apps/test-framework/run-bash-tests.sh --count # Direct
```
## 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
|