-
Notifications
You must be signed in to change notification settings - Fork 32
/
test.ps1
57 lines (48 loc) · 1.95 KB
/
test.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<#
.SYNOPSIS
Invoke-Gherkin against a specific version in output
#>
[CmdletBinding()]
param(
# A specific folder the build is in
$OutputDirectory = $PSScriptRoot,
$Module = 'PowerLine',
# The version of the output module
[Alias("ModuleVersion")]
[string]$SemVer
)
Push-Location $PSScriptRoot -StackName BuildTestStack
if (!$SemVer -and (Get-Command gitversion -ErrorAction Ignore)) {
$SemVer = gitversion -showvariable nugetversion
}
Write-Host "OutputDirectory: $OutputDirectory"
Write-Host "SemVer: $SemVer"
try {
if (Test-Path $OutputDirectory) {
# Get the part of the output path that we need to add to the PSModulePath
if ($OutputDirectory -match "$Module$") {
$OutputDirectory = Split-Path $OutputDirectory
}
if (-not (@($Env:PSModulePath.Split([IO.Path]::PathSeparator)) -contains $OutputDirectory)) {
Write-Verbose "Adding $($OutputDirectory) to PSModulePath"
$Env:PSModulePath = $OutputDirectory + [IO.Path]::PathSeparator + $Env:PSModulePath
}
}
$Specs = @{ Path = Join-Path $PSScriptRoot Specs }
# Just to make sure everything is kosher, run tests in a clean session
$PSModulePath = $Env:PSModulePath
Invoke-Command {
param($SemVer)
# We need to make sure that the PSModulePath has our output at the front
$Env:PSModulePath = $OutputDirectory + [IO.Path]::PathSeparator +
$Env:PSModulePath
Write-Host "Testing $Module $SemVer"
$SemVer = ($SemVer -split "-")[0]
# We need to make sure we have loaded ONLY the right version of the module
Get-Module $Module -All | Remove-Module -ErrorAction SilentlyContinue -Force
$Specs["CodeCoverage"] = Import-Module $Module -RequiredVersion $SemVer -Passthru | Select-Object -Expand Path
Invoke-Gherkin @Specs
} -ArgumentList @($SemVer)
} finally {
Pop-Location -StackName BuildTestStack
}