Skip to content

Commit 41096d5

Browse files
committed
further slim Invoke-SharedPesterTest.ps1
1 parent 6d07b8c commit 41096d5

1 file changed

Lines changed: 13 additions & 30 deletions

File tree

tools/Invoke-SharedPesterTests.ps1

Lines changed: 13 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,6 @@ $repoRoot = [System.IO.Path]::GetFullPath((Join-Path $PSScriptRoot ".."))
1515
$originalSystemRoot = $env:SystemRoot
1616
$originalTemp = $env:TEMP
1717

18-
function Assert-PesterEnvironment {
19-
if ($PSVersionTable.PSEdition -eq "Core" -and -not $IsWindows) {
20-
$referenceAssembliesPath = Join-Path $PSHOME "ref"
21-
if (-not (Test-Path -Path $referenceAssembliesPath)) {
22-
throw "Pester 3.4.3 on macOS requires a compatible pwsh installation with reference assemblies under '$referenceAssembliesPath'. This runner is intentionally lean and does not patch Pester at runtime."
23-
}
24-
}
25-
}
26-
2718
function Get-PesterModulePath {
2819
$packagesFolder = Join-Path $repoRoot "packages"
2920
$localPesterPaths = @(
@@ -50,24 +41,6 @@ function Get-PesterModulePath {
5041
throw "Pester 3.4.3 was not found in the repository packages folder or installed modules."
5142
}
5243

53-
function Import-Pester {
54-
$pesterModulePath = Get-PesterModulePath
55-
Import-Module -Name $pesterModulePath -RequiredVersion 3.4.3 -ErrorAction Stop
56-
}
57-
58-
function Get-TestFiles {
59-
$discoveredFiles = Get-ChildItem -Path $testRootPath -Filter "*.tests.ps1" -Recurse
60-
if ([string]::IsNullOrWhiteSpace($Filter) -or $Filter -eq "*") {
61-
return @($discoveredFiles)
62-
}
63-
64-
return @(
65-
$discoveredFiles | Where-Object {
66-
$_.Name -like $Filter -or $_.FullName -like $Filter
67-
}
68-
)
69-
}
70-
7144
function Invoke-SelectedTests {
7245
param(
7346
[Parameter(Mandatory = $true)]
@@ -103,14 +76,24 @@ try {
10376
& $BeforeRun
10477
}
10578

106-
$testFiles = @(Get-TestFiles)
79+
$testFiles = @(Get-ChildItem -Path $testRootPath -Filter "*.tests.ps1" -Recurse)
80+
if (-not [string]::IsNullOrWhiteSpace($Filter) -and $Filter -ne "*") {
81+
$testFiles = @($testFiles | Where-Object { $_.Name -like $Filter -or $_.FullName -like $Filter })
82+
}
83+
10784
if ($testFiles.Count -eq 0) {
10885
Write-Host "No matching test files found under $testRootPath for filter '$Filter'."
10986
return
11087
}
11188

112-
Assert-PesterEnvironment
113-
Import-Pester
89+
if ($PSVersionTable.PSEdition -eq "Core" -and -not $IsWindows) {
90+
$referenceAssembliesPath = Join-Path $PSHOME "ref"
91+
if (-not (Test-Path -Path $referenceAssembliesPath)) {
92+
throw "Pester 3.4.3 on macOS requires a compatible pwsh installation with reference assemblies under '$referenceAssembliesPath'. This runner is intentionally lean and does not patch Pester at runtime."
93+
}
94+
}
95+
96+
Import-Module -Name (Get-PesterModulePath) -RequiredVersion 3.4.3 -ErrorAction Stop
11497
Invoke-SelectedTests -TestFiles $testFiles
11598
} finally {
11699
$env:SystemRoot = $originalSystemRoot

0 commit comments

Comments
 (0)