-
Notifications
You must be signed in to change notification settings - Fork 3
/
Test.ps1
54 lines (46 loc) · 1.93 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
<#
.SYNOPSIS
Invoke-Gherkin against a specific version in output
#>
[CmdletBinding()]
param(
# A specific folder the build is in
$OutputDirectory = $PSScriptRoot,
# 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 "Metadata$") {
$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 {
# 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 Metadata $SemVer"
$SemVer = ($SemVer -split "-")[0]
# We need to make sure we have loaded ONLY the right version of the module
Get-Module Metadata -All | Remove-Module -ErrorAction SilentlyContinue -Force
$Specs["CodeCoverage"] = Import-Module Metadata -RequiredVersion $SemVer -Passthru | Select-Object -Expand Path
Invoke-Gherkin @Specs
}
} finally {
Pop-Location -StackName BuildTestStack
}