-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.ps1
70 lines (53 loc) · 1.83 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
58
59
60
61
62
63
64
65
66
67
68
69
70
[CmdletBinding()]
param (
[ValidateSet('None','Normal','Detailed','Diagnostic')]
[String]
$Output = 'Normal',
[switch]
$Local
)
$ErrorActionPreference = 'Stop'
# 4>$null elimates the requires errors for testing
Import-Module .\PS-Tools\PS-Tools.psd1 -Force -DisableNameChecking 4>$null
if (-not [boolean](Get-Module -Name Pester)) {
Install-Module -Name Pester -Force -SkipPublisherCheck | Out-Null
}
$Pester = Import-Module Pester -Force -PassThru
Write-InformationPlus "Pester Version: $($Pester.Version)`n"
$Config = [PesterConfiguration]::Default
$Config.Output.Verbosity = $Output
$Config.Run.PassThru = $true
$Config.Run.Path = "$PSScriptRoot\PS-Tools\tests"
if (-not $Local) {
$Config.TestResult.Enabled = $true
}
if ($PSEdition -eq 'Core' -and $IsLinux) {
$Config.Filter.ExcludeTag = @('PS5Only','WindowsOnly')
}
elseif ($PSEdition -eq 'Core' -and $IsWindows) {
$Config.Filter.ExcludeTag = @('PS5Only')
}
else {
$Config.Filter.ExcludeTag = @('PS6Only')
}
Write-InformationPlus "OS is Windows : $IsWindows"
Write-InformationPlus "OS is Linux : $IsLinux`n"
Write-InformationPlus "PowerShell Version : $($PSVersionTable.PSVersion)"
Write-InformationPlus "PowerShell Edition : $($PSVersionTable.PSEdition)"
Write-InformationPlus "`nPester Parameters:"
Write-Output $PesterParams
# For Code Coverage
#$Functions = (Get-ChildItem -Path .\PS-Tools\ -Recurse -Include *.ps1 -Exclude *.tests.ps1,images.ps1).FullName
$TestResults = Invoke-Pester -Configuration $Config
if ($TestResults.FailedCount -gt 0) {
# Throw "Unit tests failed."
}
$Version = "v$((Test-ModuleManifest ./PS-Tools/PS-Tools.psd1).version.ToString())"
git rev-parse -q --verify refs/tags/$version
if ($LASTEXITCODE -eq 0) {
throw "Tag $Version already exists"
}
else {
Write-InformationPlus "Commit will be tagged $Version"
exit 0
}