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
|
#!/usr/bin/env pwsh
# Unit tests runner - runs all compiled unit test executables
# Runs all tests inline in the same console for visible output
$ErrorActionPreference = "Stop"
# Source common test functions
. (Join-Path $PSScriptRoot "testfuncs.ps1")
$script:RootDir = Split-Path -Parent $PSScriptRoot
# Find the directory containing test executables
$testDirs = @(
(Join-Path $script:RootDir "x64\Release"),
(Join-Path $script:RootDir "x64\Debug"),
(Join-Path $script:RootDir "Win32\Release"),
(Join-Path $script:RootDir "Win32\Debug"),
(Join-Path $script:RootDir "ARM64\Release"),
(Join-Path $script:RootDir "ARM64\Debug"),
(Split-Path -Parent $PARBINARY)
)
$testExeDir = $null
foreach ($dir in $testDirs) {
if (Test-Path $dir) {
$testExeDir = $dir
break
}
}
if (-not $testExeDir) {
Write-Host "ERROR: Could not find test executable directory" -ForegroundColor Red
exit 1
}
Write-Host "Looking for unit tests in: $testExeDir" -ForegroundColor Cyan
Write-Host ""
$unitTestExes = @(
"letype_test.exe",
"crc_test.exe",
"md5_test.exe",
"diskfile_test.exe",
"libpar2_test.exe",
"commandline_test.exe",
"descriptionpacket_test.exe",
"criticalpacket_test.exe",
"reedsolomon_test.exe",
"galois_test.exe",
"utf8_test.exe"
)
$passed = 0
$failed = 0
$skipped = 0
$failedTests = @()
foreach ($testExe in $unitTestExes) {
$testPath = Join-Path $testExeDir $testExe
if (Test-Path $testPath) {
Write-Host "------------------------------------------------------"
Write-Host "Running unit tests from file $testExe"
Write-Host "------------------------------------------------------"
$startTime = Get-Date
try {
# Run the executable inline using the call operator
# This keeps output visible in the same console
& $testPath
$exitCode = $LASTEXITCODE
$duration = (Get-Date) - $startTime
if ($exitCode -eq 0) {
Write-Host "------------------------------------------------------"
Write-Host "PASSED: $testExe (duration: $($duration.TotalSeconds.ToString('F2'))s)" -ForegroundColor Green
Write-Host "------------------------------------------------------"
$passed++
} else {
Write-Host "------------------------------------------------------"
Write-Host "FAILED: $testExe (exit code: $exitCode, duration: $($duration.TotalSeconds.ToString('F2'))s)" -ForegroundColor Red
Write-Host "------------------------------------------------------"
$failed++
$failedTests += $testExe
}
}
catch {
$duration = (Get-Date) - $startTime
Write-Host "------------------------------------------------------"
Write-Host "FAILED: $testExe - $_ (duration: $($duration.TotalSeconds.ToString('F2'))s)" -ForegroundColor Red
Write-Host "------------------------------------------------------"
$failed++
$failedTests += $testExe
}
Write-Host ""
} else {
Write-Host "SKIPPED: $testExe not found at $testPath" -ForegroundColor Yellow
$skipped++
}
}
Write-Host ""
Write-Host "======================================================"
Write-Host "Unit Test Summary"
Write-Host "======================================================"
Write-Host "Passed: $passed" -ForegroundColor Green
Write-Host "Failed: $failed" -ForegroundColor $(if ($failed -gt 0) { "Red" } else { "Green" })
Write-Host "Skipped: $skipped" -ForegroundColor Yellow
Write-Host ""
if ($failed -gt 0) {
Write-Host "Failed tests:" -ForegroundColor Red
foreach ($failedTest in $failedTests) {
Write-Host " - $failedTest" -ForegroundColor Red
}
Write-Host ""
exit 1
}
exit 0
|