Skip to content

Commit 8485dd7

Browse files
committed
Testing improvemetns
1 parent 08ddd7d commit 8485dd7

File tree

7 files changed

+113
-14
lines changed

7 files changed

+113
-14
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ jobs:
4747
shell: pwsh
4848
run: |
4949
$exe = '${{ matrix.ps_exe }}'
50-
& $exe -NoProfile -File .\tools\ci.ps1
50+
& $exe -NoProfile -File .\tools\ci.ps1 -CurrentShellOnly

.github/workflows/publish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- name: Run Lint and Tests
3232
shell: pwsh
3333
run: |
34-
.\tools\ci.ps1
34+
.\tools\ci.ps1 -CurrentShellOnly
3535
3636
- name: Validate Module Version Against Tag
3737
if: startsWith(github.ref, 'refs/tags/v')

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,17 @@ All notable changes to this project are documented in this file.
44

55
The format is based on Keep a Changelog and the project uses Semantic Versioning.
66

7+
## [0.1.2] - 2026-02-19
8+
9+
### Added
10+
11+
- Local multi-shell test execution (`powershell` + `pwsh`) in `tools/test.ps1` with clear missing-shell errors.
12+
13+
### Fixed
14+
15+
- Stabilized long-option completion integration tests in Windows PowerShell 5.1 (`gsw`/`gco`).
16+
17+
718
## [0.1.1] - 2026-02-19
819

920
### Added

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,9 @@ Run both lint and tests:
249249
.\tools\ci.ps1
250250
```
251251

252+
By default, local test runs execute in both `powershell` (Windows PowerShell 5.1) and `pwsh` (PowerShell 7+).
253+
If one of these shells is missing, the script fails with a clear error.
254+
252255
Run only lint:
253256

254257
```powershell
@@ -261,6 +264,12 @@ Run only tests:
261264
.\tools\ci.ps1 -TestOnly
262265
```
263266

267+
Run checks only in the current shell (used by CI matrix):
268+
269+
```powershell
270+
.\tools\ci.ps1 -CurrentShellOnly
271+
```
272+
264273
## Commit hooks
265274

266275
Install local git hooks:

tests/git-aliases-extra.Integration.Tests.ps1

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,36 @@ BeforeAll {
6767
throw "Could not find blob hash prefix '$Prefix' within $MaxAttempts attempts."
6868
}
6969

70+
function Script:Get-TabCompletionResult {
71+
[CmdletBinding()]
72+
param(
73+
[Parameter(Mandatory = $true)]
74+
[string]$Line
75+
)
76+
77+
TabExpansion2 -inputScript $Line -cursorColumn $Line.Length
78+
}
79+
80+
function Script:Get-LongOptionCompletionResult {
81+
[CmdletBinding()]
82+
param(
83+
[Parameter(Mandatory = $true)]
84+
[string]$CommandName,
85+
[Parameter(Mandatory = $true)]
86+
[string]$FallbackPrefix
87+
)
88+
89+
# In Windows PowerShell 5.1, a bare "--" token is parsed in a way that
90+
# often bypasses argument completers entirely. Probe with "--" first,
91+
# then retry with a concrete prefix to validate long-option completion.
92+
$result = Get-TabCompletionResult -Line ("{0} --" -f $CommandName)
93+
if ($result.CompletionMatches.Count -gt 0 -or $PSVersionTable.PSVersion.Major -ge 6) {
94+
return $result
95+
}
96+
97+
return (Get-TabCompletionResult -Line ("{0} {1}" -f $CommandName, $FallbackPrefix))
98+
}
99+
70100
[string]$script:RepoRoot = Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '..') |
71101
Select-Object -ExpandProperty Path -First 1
72102
$script:ModuleManifest = Join-Path $script:RepoRoot 'git-aliases-extra.psd1'
@@ -301,8 +331,7 @@ Describe 'gsw integration' {
301331
It 'completes long options for gsw alias' -Skip:(-not (Get-Command git -ErrorAction SilentlyContinue)) {
302332
Push-Location $script:RepoRoot
303333
try {
304-
$line = 'gsw --'
305-
$result = TabExpansion2 -inputScript $line -cursorColumn $line.Length
334+
$result = Get-LongOptionCompletionResult -CommandName 'gsw' -FallbackPrefix '--t'
306335
} finally {
307336
Pop-Location
308337
}
@@ -315,8 +344,7 @@ Describe 'gsw integration' {
315344
It 'completes long options for gco alias from git-aliases module' -Skip:(-not (Get-Command git -ErrorAction SilentlyContinue) -or -not $script:HasGcoAlias) {
316345
Push-Location $script:RepoRoot
317346
try {
318-
$line = 'gco --'
319-
$result = TabExpansion2 -inputScript $line -cursorColumn $line.Length
347+
$result = Get-LongOptionCompletionResult -CommandName 'gco' -FallbackPrefix '--d'
320348
} finally {
321349
Pop-Location
322350
}

tools/ci.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
[CmdletBinding()]
22
param(
33
[switch]$LintOnly,
4-
[switch]$TestOnly
4+
[switch]$TestOnly,
5+
[switch]$CurrentShellOnly
56
)
67

78
$ErrorActionPreference = 'Stop'
@@ -15,7 +16,11 @@ if (-not $TestOnly) {
1516
}
1617

1718
if (-not $LintOnly) {
18-
& (Join-Path $root 'tools\test.ps1')
19+
$testArgs = @{}
20+
if ($CurrentShellOnly) {
21+
$testArgs.CurrentShellOnly = $true
22+
}
23+
& (Join-Path $root 'tools\test.ps1') @testArgs
1924
}
2025

2126
Write-Host 'CI checks completed.'

tools/test.ps1

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
[CmdletBinding()]
22
param(
3-
[string]$TestsPath = ''
3+
[string]$TestsPath = '',
4+
[switch]$CurrentShellOnly,
5+
[string[]]$Shells = @('powershell', 'pwsh')
46
)
57

68
$ErrorActionPreference = 'Stop'
79
Set-StrictMode -Version Latest
810

9-
if (-not (Get-Module -ListAvailable -Name Pester)) {
10-
throw "Pester is not installed. Run: Install-Module Pester -Scope CurrentUser -Force"
11+
function Get-UserModulePath {
12+
if ($PSVersionTable.PSEdition -eq 'Desktop') {
13+
return (Join-Path $HOME 'Documents\WindowsPowerShell\Modules')
14+
} else {
15+
return (Join-Path $HOME 'Documents\PowerShell\Modules')
16+
}
1117
}
1218

13-
Import-Module Pester -MinimumVersion 5.0 -ErrorAction Stop
19+
$userModules = Get-UserModulePath
20+
if ($env:PSModulePath -notlike "*$userModules*") {
21+
$env:PSModulePath = "$userModules;$env:PSModulePath"
22+
}
1423

1524
if (-not $TestsPath) {
1625
$TestsPath = Resolve-Path -LiteralPath (Join-Path $PSScriptRoot '..\tests') |
@@ -21,9 +30,46 @@ if (-not (Test-Path -LiteralPath $TestsPath)) {
2130
throw "Tests folder not found: $TestsPath"
2231
}
2332

24-
$result = Invoke-Pester -Path $TestsPath -CI -PassThru
33+
$runAllShells = -not $CurrentShellOnly
34+
if ($env:GITHUB_ACTIONS -eq 'true' -or $env:CI -eq 'true') {
35+
$runAllShells = $false
36+
}
37+
38+
if ($runAllShells) {
39+
$uniqueShells = @($Shells | Where-Object { -not [string]::IsNullOrWhiteSpace($_) } | Select-Object -Unique)
40+
if ($uniqueShells.Count -eq 0) {
41+
throw 'No shells specified for test execution.'
42+
}
43+
44+
$missingShells = @($uniqueShells | Where-Object { -not (Get-Command $_ -ErrorAction SilentlyContinue) })
45+
if ($missingShells.Count -gt 0) {
46+
throw ("Missing required shell executable(s): {0}. Install both Windows PowerShell 5.1 ('powershell') and PowerShell 7+ ('pwsh'), or run -CurrentShellOnly." -f ($missingShells -join ', '))
47+
}
48+
49+
foreach ($shellName in $uniqueShells) {
50+
Write-Host ("Running tests in {0}..." -f $shellName)
51+
& $shellName -NoProfile -ExecutionPolicy Bypass -File $PSCommandPath -TestsPath $TestsPath -CurrentShellOnly
52+
if ($LASTEXITCODE -ne 0) {
53+
throw ("Tests failed in shell: {0}" -f $shellName)
54+
}
55+
}
56+
57+
Write-Host ("Pester: all tests passed in shells: {0}." -f ($uniqueShells -join ', '))
58+
return
59+
}
60+
61+
if (-not (Get-Module -ListAvailable -Name Pester)) {
62+
throw "Pester is not installed in this shell. Run: Install-Module Pester -Scope CurrentUser -Force"
63+
}
64+
65+
Import-Module Pester -MinimumVersion 5.0 -ErrorAction Stop
66+
67+
$result = Invoke-Pester -Path $TestsPath -CI -PassThru -ErrorAction Stop
68+
if ($null -eq $result) {
69+
throw 'Invoke-Pester returned no result.'
70+
}
2571
if ($result.FailedCount -gt 0) {
2672
throw "Pester failed: $($result.FailedCount) test(s) failed."
2773
}
2874

29-
Write-Host "Pester: all tests passed ($($result.PassedCount) passed)."
75+
Write-Host ("Pester: all tests passed ({0} passed) in {1} {2}." -f $result.PassedCount, $PSVersionTable.PSEdition, $PSVersionTable.PSVersion)

0 commit comments

Comments
 (0)