forked from MicrosoftDocs/PowerShell-Docs
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPowerShellDocsTests.psm1
58 lines (51 loc) · 1.7 KB
/
PowerShellDocsTests.psm1
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
function Invoke-Test
{
[CmdletBinding()]
param()
$path = Join-Path $PSScriptRoot 'Pester'
$logFilePath = Join-Path $PSScriptRoot 'TestResults.xml'
Invoke-Pester $path -OutputFile $logFilePath -OutputFormat NUnitXml
Test-PSPesterResults -TestResultsFile $logFilePath
}
function Test-PSPesterResults
{
param(
[string]$TestResultsFile = "pester-tests.xml"
)
if(!(Test-Path $TestResultsFile))
{
throw "Test result file '$testResultsFile' not found."
}
$x = [xml](Get-Content -raw $testResultsFile)
if ([int]$x.'test-results'.failures -gt 0)
{
logerror "TEST FAILURES"
# switch between methods, SelectNode is not available on dotnet core
if ( "System.Xml.XmlDocumentXPathExtensions" -as [Type] ) {
$failures = [System.Xml.XmlDocumentXPathExtensions]::SelectNodes($x."test-results",'.//test-case[@result = "Failure"]')
}
else {
$failures = $x.SelectNodes('.//test-case[@result = "Failure"]')
}
foreach ( $testfail in $failures )
{
Show-PSPesterError $testfail
}
throw "$($x.'test-results'.failures)"
}
}
function Show-PSPesterError
{
param ( [Xml.XmlElement]$testFailure )
logerror ("Description: " + $testFailure.description)
logerror ("Name: " + $testFailure.name)
logerror "message:"
logerror $testFailure.failure.message
logerror "stack-trace:"
logerror $testFailure.failure."stack-trace"
}
function script:logerror([string]$message) {
Write-Host -Foreground Red $message
#reset colors for older package to at return to default after error message on a compilation error
[console]::ResetColor()
}