Skip to content

Commit

Permalink
Allow VersionedOutputDirectory for PSModuleTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaykul committed Jan 14, 2024
1 parent 4482be1 commit ddf2069
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions PSModuleTest.Task.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ Add-BuildTask PSModuleTest @{
$PesterFilter ??= if ($BuildSystem -ne "None") { @{ "ExcludeTag" = 'NoCI' } }


$Version = $GitVersion.$PSModuleName.MajorMinorPatch

# Write-Information "Build-Module -SourcePath $PSModuleSourcePath -Destination $PSModuleOutputPath -SemVer $SemVer"
# $Module = Build-Module -SourcePath $PSModuleSourcePath -Destination $PSModuleOutputPath -SemVer $SemVer -Verbose:$Verbose -Debug:$Debug -Passthru

# For PowerShell Modules with classes to work in tests:
# 1. The $OutputRoot directory must be first on Env:PSModulePath
# 2. The $PSModuleName directory must be in $OutputRoot directory
# 3. The $PSModuleName.psd1 file must be in the $PSModuleName directory
if (-not (Test-Path "$OutputRoot${/}$PSModuleName${/}$PSModuleName.psd1")) {
throw "Cannot test module if it's not in $OutputRoot${/}$PSModuleName${/}$PSModuleName.psd1"
if (-not ((Test-Path "$OutputRoot${/}$PSModuleName${/}$PSModuleName.psd1", "$OutputRoot${/}$PSModuleName${/}$Version${/}$PSModuleName.psd1") -contains $true)) {
throw "Cannot test module if it's not in $OutputRoot${/}$PSModuleName"
} else {
$TestModulePath = @($OutputRoot) + @($Env:PSModulePath -split [IO.Path]::PathSeparator -ne $OutputRoot) -join [IO.Path]::PathSeparator
$Env:PSModulePath, $OldModulePath = $TestModulePath, $Env:PSModulePath
Expand Down

0 comments on commit ddf2069

Please sign in to comment.