From f35fc877abc7e35928f6018d2688082b4d81065e Mon Sep 17 00:00:00 2001 From: SpaghettiMaster545 <74583115+SpaghettiMaster545@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:32:34 +0100 Subject: [PATCH] Scripts: smoke.ps1 finds xcl.exe without -Xcl when started with -File Windows PowerShell 5.1 leaves $PSScriptRoot empty in the parameter defaults of a script that has [Parameter()] attributes when the script is started with `powershell -File` (or dot-sourced), so the default `-Xcl (Join-Path $PSScriptRoot ...)` failed with "Cannot bind argument to parameter 'Path' because it is an empty string" before the script did anything. Started with `&` from an open PowerShell session it works, which is why it went unnoticed. The default is now set in the script's body, where $PSScriptRoot is set in every case. scripts/smoke-default-xcl.tests.ps1 runs a copy of the script outside the repository through -File without -Xcl and checks that it looks for target\release\xcl.exe next to its own folder. It compares the child's error text without whitespace, ANSI escapes and the `|` that PowerShell 7 puts before wrapped error lines (found by fladit123 and Alpha325 on PowerShell 7.6.10 and 7.6.9 in the PR's review). Co-Authored-By: Claude Opus 5.5 --- scripts/smoke-default-xcl.tests.ps1 | 26 ++++++++++++++++++++++++++ scripts/smoke.ps1 | 5 ++++- 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 scripts/smoke-default-xcl.tests.ps1 diff --git a/scripts/smoke-default-xcl.tests.ps1 b/scripts/smoke-default-xcl.tests.ps1 new file mode 100644 index 000000000..cd1c8d770 --- /dev/null +++ b/scripts/smoke-default-xcl.tests.ps1 @@ -0,0 +1,26 @@ +# Run with powershell.exe or pwsh.exe. smoke.ps1 started with `-File` and no -Xcl looks for +# target\release\xcl.exe next to its own folder. Windows PowerShell 5.1 leaves $PSScriptRoot empty in +# the parameter defaults of a script with [Parameter()] attributes when it is started with -File, so a +# default there made Join-Path fail before the script could say anything. +$ErrorActionPreference = 'Stop' +$fixture = Join-Path ([IO.Path]::GetTempPath()) ('xcl-smoke-default-' + [guid]::NewGuid()) +$scripts = Join-Path $fixture 'scripts' +$null = New-Item -ItemType Directory -Path $scripts +try { + # a copy outside the repository: no xcl.exe is there, so the script stops before it runs anything + Copy-Item -LiteralPath (Join-Path $PSScriptRoot 'smoke.ps1') -Destination $scripts + $shell = (Get-Process -Id $PID).Path + $ErrorActionPreference = 'Continue' + $output = & $shell -NoProfile -NonInteractive -ExecutionPolicy Bypass -File (Join-Path $scripts 'smoke.ps1') -Game $fixture 2>&1 | Out-String + $ErrorActionPreference = 'Stop' + # the child's error text can be wrapped at its console width; PowerShell 7 also colours it (ANSI + # escapes) and starts each wrapped line with `|` + $flat = $output -replace '\x1b\[[0-?]*[ -/]*[@-~]', '' -replace '[\s|]', '' + $expected = ('no ' + (Join-Path $scripts '..\target\release\xcl.exe') + ' - build it first') -replace '[\s|]', '' + if (!$flat.Contains($expected)) { + throw "smoke.ps1 without -Xcl did not look for xcl.exe next to its folder; its output:`n$output" + } +} finally { + $ErrorActionPreference = 'Stop' + if (Test-Path -LiteralPath $fixture) { Remove-Item -LiteralPath $fixture -Recurse -Force } +} diff --git a/scripts/smoke.ps1 b/scripts/smoke.ps1 index db296218b..e88d57d18 100644 --- a/scripts/smoke.ps1 +++ b/scripts/smoke.ps1 @@ -12,11 +12,14 @@ param( [Parameter(Mandatory = $true)][string]$Game, [int]$Seconds = 60, - [string]$Xcl = (Join-Path $PSScriptRoot '..\target\release\xcl.exe'), + [string]$Xcl, [string]$Title, [string]$OutDir ) $ErrorActionPreference = 'Stop' +# Windows PowerShell 5.1 leaves $PSScriptRoot empty in this script's parameter defaults when it is +# started with -File, so the default is set here +if (-not $Xcl) { $Xcl = Join-Path $PSScriptRoot '..\target\release\xcl.exe' } if ($PSBoundParameters.ContainsKey('Title')) { $Title = $Title.Trim()