🔧 Test Runner Scripts¶
Automated test execution for AudioLab
Overview¶
This directory contains cross-platform scripts for running AudioLab tests.
Available Scripts: - run_tests.ps1 - Windows PowerShell test runner - run_tests.sh - Unix/macOS Bash test runner
Both scripts provide: - ✅ Colored output - ✅ Automatic build directory detection - ✅ Configuration selection (Debug/Release) - ✅ Test filtering - ✅ Error handling
run_tests.ps1 (Windows)¶
Basic Usage¶
# Run all tests (Debug)
.\scripts\run_tests.ps1
# Run with Release configuration
.\scripts\run_tests.ps1 -Config Release
# Run specific tests
.\scripts\run_tests.ps1 -Filter "test_example*"
# Use custom build directory
.\scripts\run_tests.ps1 -BuildDir "my_build"
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
-BuildDir |
string | "build" |
Build directory path |
-Config |
string | "Debug" |
Build configuration |
-Filter |
string | "*" |
CTest test filter regex |
Examples¶
# Quick unit tests only
.\scripts\run_tests.ps1 -Filter "test_infrastructure"
# Run integration tests in Release
.\scripts\run_tests.ps1 -Config Release -Filter "*integration*"
# Custom build directory
.\scripts\run_tests.ps1 -BuildDir "build-vs2022"
Exit Codes¶
- 0 - All tests passed
- 1 - Build directory not found or tests failed
run_tests.sh (Unix/macOS)¶
Basic Usage¶
# Run all tests (Debug)
./scripts/run_tests.sh
# Run with Release configuration
./scripts/run_tests.sh --config Release
# Run specific tests
./scripts/run_tests.sh --filter "test_example*"
# Use custom build directory
./scripts/run_tests.sh --build-dir my_build
Options¶
| Option | Type | Default | Description |
|---|---|---|---|
--build-dir <dir> |
string | build |
Build directory path |
--config <cfg> |
string | Debug |
Build configuration |
--filter <regex> |
string | * |
CTest test filter regex |
--help |
flag | - | Show help message |
Examples¶
# Quick unit tests only
./scripts/run_tests.sh --filter "test_infrastructure"
# Run integration tests in Release
./scripts/run_tests.sh --config Release --filter "*integration*"
# Custom build directory
./scripts/run_tests.sh --build-dir build-clang
Exit Codes¶
- 0 - All tests passed
- 1 - Build directory not found or tests failed
Common Workflows¶
Development: Quick Feedback¶
# Windows - Run only changed tests
.\scripts\run_tests.ps1 -Filter "test_my_feature"
# macOS/Linux
./scripts/run_tests.sh --filter "test_my_feature"
Pre-Commit: All Tests¶
CI: Release Build¶
# Windows
.\scripts\run_tests.ps1 -Config Release -Filter "*"
# macOS/Linux
./scripts/run_tests.sh --config Release --filter "*"
Debugging: Verbose Output¶
Troubleshooting¶
❌ "Build directory not found"¶
Problem: Script can't find build directory
Solution:
# Verify build directory exists
ls build
# Specify custom path
.\scripts\run_tests.ps1 -BuildDir "path\to\build"
# Or build first
cmake -S . -B build
cmake --build build
❌ "No tests found"¶
Problem: CTest finds no tests
Solution:
# Check if tests were built
ls build/tests
# Rebuild tests
cmake --build build --target all
# Verify CTest configuration
cd build
ctest -N # List all tests
❌ "Tests fail in script but pass manually"¶
Problem: Environment differences
Solution:
# Run CTest manually to compare
cd build
ctest -C Debug --output-on-failure
# Check PATH and environment
echo $env:PATH # PowerShell
echo $PATH # Bash
# Ensure all DLLs are available (Windows)
$env:PATH += ";C:\vcpkg\installed\x64-windows\bin"
Advanced Usage¶
Custom Test Categories¶
Create wrapper scripts for specific test categories:
run_unit_tests.ps1:
run_benchmarks.ps1:
Integration with CI¶
GitHub Actions:
Azure Pipelines:
Parallel Execution¶
Both scripts use CTest with --verbose, which runs tests serially for clear output.
For parallel execution:
Script Internals¶
run_tests.ps1 Logic¶
- Parse command-line parameters
- Check build directory exists
- Change to build directory
- Run
ctest -C $Config -R $Filter --output-on-failure --verbose - Check exit code
- Print success/failure message
- Return to original directory
run_tests.sh Logic¶
- Parse command-line options
- Check build directory exists
- Change to build directory
- Run
ctest -C $Config -R $Filter --output-on-failure --verbose - Check exit code
- Print success/failure message (with colors)
- Return to original directory
Creating Custom Runners¶
Template for Custom Script¶
# custom_test.ps1
param(
[string]$BuildDir = "build",
[string]$Config = "Debug"
)
$ErrorActionPreference = "Stop"
Write-Host "Running Custom Tests" -ForegroundColor Cyan
Push-Location $BuildDir
try {
# Your custom test logic here
ctest -C $Config -R "my_pattern" --output-on-failure
if ($LASTEXITCODE -eq 0) {
Write-Host "✅ Tests passed" -ForegroundColor Green
} else {
Write-Host "❌ Tests failed" -ForegroundColor Red
exit $LASTEXITCODE
}
} finally {
Pop-Location
}
Resources¶
- TEST_CHEAT_SHEET.md - All testing commands
- QUICK_START.md - Getting started guide
- CTest Documentation - Official CTest docs
Use these scripts for consistent, cross-platform test execution! 🎧