Skip to content

🔧 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

# Windows
.\scripts\run_tests.ps1

# macOS/Linux
./scripts/run_tests.sh

CI: Release Build

# Windows
.\scripts\run_tests.ps1 -Config Release -Filter "*"

# macOS/Linux
./scripts/run_tests.sh --config Release --filter "*"

Debugging: Verbose Output

# For verbose output, use CTest directly:
cd build
ctest -C Debug --verbose --output-on-failure

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:

.\scripts\run_tests.ps1 -Filter "*unit*"

run_benchmarks.ps1:

.\scripts\run_tests.ps1 -Filter "*benchmark*"

Integration with CI

GitHub Actions:

- name: Run tests
  run: |
    ./scripts/run_tests.sh --config Release

Azure Pipelines:

- script: |
    .\scripts\run_tests.ps1 -Config Release
  displayName: 'Run Tests'

Parallel Execution

Both scripts use CTest with --verbose, which runs tests serially for clear output.

For parallel execution:

cd build
ctest -C Debug -j 4 --output-on-failure


Script Internals

run_tests.ps1 Logic

  1. Parse command-line parameters
  2. Check build directory exists
  3. Change to build directory
  4. Run ctest -C $Config -R $Filter --output-on-failure --verbose
  5. Check exit code
  6. Print success/failure message
  7. Return to original directory

run_tests.sh Logic

  1. Parse command-line options
  2. Check build directory exists
  3. Change to build directory
  4. Run ctest -C $Config -R $Filter --output-on-failure --verbose
  5. Check exit code
  6. Print success/failure message (with colors)
  7. 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


Use these scripts for consistent, cross-platform test execution! 🎧