diff --git a/scripts/test-native-stderr.tests.ps1 b/scripts/test-native-stderr.tests.ps1 new file mode 100644 index 0000000..b57de4a --- /dev/null +++ b/scripts/test-native-stderr.tests.ps1 @@ -0,0 +1,39 @@ +# Run with powershell.exe or pwsh.exe. The fixture writes stderr through a native process. +$ErrorActionPreference = 'Stop' +$runner = Join-Path $PSScriptRoot 'test.ps1' +$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-native-stderr-' + [guid]::NewGuid()) +$null = New-Item -ItemType Directory -Path $fixture +$cargo = Join-Path $fixture 'cargo.cmd' +$log = Join-Path $fixture 'runner.log' +$oldPath = $env:PATH +Push-Location +try { + @' +@echo off +if "%1"=="build" ( + >&2 echo synthetic build progress + exit /b 0 +) +if "%1"=="test" ( + >&2 echo SKIPPED native_stderr: synthetic reason + exit /b 0 +) +exit /b 127 +'@ | Set-Content -LiteralPath $cargo -Encoding Ascii + $env:PATH = $fixture + if ((Get-Command cargo).Path -ne $cargo) { throw 'The native Cargo fixture was not selected.' } + + & $runner *> $log + if ($LASTEXITCODE -ne 0) { throw "Runner exited $LASTEXITCODE on a successful build." } + $output = Get-Content -LiteralPath $log -Raw + if (!$output.Contains('synthetic build progress') -or + !$output.Contains('GPU tests skipped on this adapter: 1 (synthetic reason)')) { + throw 'Expected native build output and the GPU skip summary in the redirected log.' + } +} finally { + Pop-Location + $env:PATH = $oldPath + foreach ($path in $cargo, $log, $fixture) { + if (Test-Path -LiteralPath $path) { Remove-Item -LiteralPath $path } + } +} diff --git a/scripts/test.ps1 b/scripts/test.ps1 index 901c6af..b65997c 100644 --- a/scripts/test.ps1 +++ b/scripts/test.ps1 @@ -4,11 +4,13 @@ Set-Location (Join-Path $PSScriptRoot '..') # tests on game data pass without running anything when their variable is not set $missing = 'XCL_SAMPLE_RPF', 'XCL_SAMPLE_DLLS', 'XCL_SAMPLE_TTPF', 'XCL_SAMPLE_BK2', 'XCL_SAMPLE_BVH4', 'XCL_SAMPLE_AWC', 'XCL_SAMPLE_XG', 'XCL_SAMPLE_DXC' | Where-Object { -not (Test-Path "env:$_") } if ($missing) { Write-Host "not set, their tests are skipped: $($missing -join ', ')" } +# Windows PowerShell 5.1 treats redirected native stderr as an error even when Cargo succeeds. +$null = Get-Command cargo -ErrorAction Stop +$ErrorActionPreference = 'Continue' cargo build --workspace if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } # GPU tests that cannot run on this adapter pass too: each prints "SKIPPED : " # to stderr (XCL_REQUIRE_GPU=wave64 / =mesh makes them fail); counted at the end -$ErrorActionPreference = 'Continue' $skipped = @() cargo test --workspace -- --test-threads=4 2>&1 | ForEach-Object { $line = "$_"