$ErrorActionPreference = 'Stop' $workspacePath = (Resolve-Path (Join-Path $PSScriptRoot '..\..')).Path $compiler = Get-Command gcc.exe -ErrorAction SilentlyContinue if ($null -eq $compiler) { throw 'gcc.exe was not found; PLSR host tests cannot run.' } $outputPath = Join-Path $workspacePath 'tmp\test_plc_device.exe' $outputDirectory = Split-Path -Parent $outputPath if (-not (Test-Path -LiteralPath $outputDirectory)) { New-Item -ItemType Directory -Path $outputDirectory | Out-Null } $arguments = @( '-std=c11', '-Wall', '-Wextra', '-Werror', '-DPLSR_HOST_TEST', "-I$workspacePath\PLSR\Inc", "$workspacePath\PLSR\Src\plc_device.c", "$workspacePath\PLSR\Src\plsr_persistence.c", "$workspacePath\PLSR\Test\test_plc_device.c", '-o', $outputPath ) try { & $compiler.Source @arguments if ($LASTEXITCODE -ne 0) { throw "PLSR host-test compilation failed with exit code $LASTEXITCODE." } & $outputPath if ($LASTEXITCODE -ne 0) { throw "PLSR host tests failed with exit code $LASTEXITCODE." } } finally { if (Test-Path -LiteralPath $outputPath) { Remove-Item -LiteralPath $outputPath -Force } }