Skip to content

Commit

Permalink
Merge pull request #421 from dlwyatt/Inconclusive
Browse files Browse the repository at this point in the history
Adding Set-TestInconclusive
  • Loading branch information
dlwyatt committed Dec 8, 2015
2 parents 7113b4b + 79a5602 commit 292bca1
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 23 deletions.
22 changes: 22 additions & 0 deletions Functions/Assertions/Set-TestInconclusive.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
function New-InconclusiveErrorRecord ([string] $Message, [string] $File, [string] $Line, [string] $LineText) {
$exception = New-Object Exception $Message
$errorID = 'PesterTestInconclusive'
$errorCategory = [Management.Automation.ErrorCategory]::InvalidResult
# we use ErrorRecord.TargetObject to pass structured information about the error to a reporting system.
$targetObject = @{Message = $Message; File = $File; Line = $Line; LineText = $LineText}
$errorRecord = New-Object Management.Automation.ErrorRecord $exception, $errorID, $errorCategory, $targetObject
return $errorRecord
}

function Set-TestInconclusive {
param (
[string] $Message
)

Assert-DescribeInProgress -CommandName Set-TestInconclusive
$lineText = $MyInvocation.Line.TrimEnd("`n")
$line = $MyInvocation.ScriptLineNumber
$file = $MyInvocation.ScriptName

throw ( New-InconclusiveErrorRecord -Message $Message -File $file -Line $line -LineText $lineText)
}
12 changes: 12 additions & 0 deletions Functions/It.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,18 @@ function Get-PesterResult {
$line = $details.Line
$lineText = "`n$line`: $($details.LineText)"
}
elseif ($ErrorRecord.FullyQualifiedErrorId -eq 'PesterTestInconclusive')
{
# we use TargetObject to pass structured information about the error.
$details = $ErrorRecord.TargetObject

$failureMessage = $details.Message
$file = $details.File
$line = $details.Line
$lineText = "`n$line`: $($details.LineText)"

$testResult.Result = 'Inconclusive'
}
else
{
$failureMessage = $ErrorRecord.ToString()
Expand Down
58 changes: 39 additions & 19 deletions Functions/PesterState.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ function New-PesterState
$script:FailedCount = 0
$script:SkippedCount = 0
$script:PendingCount = 0
$script:InconclusiveCount = 0

function EnterDescribe([string]$Name)
{
Expand Down Expand Up @@ -121,7 +122,7 @@ function New-PesterState
{
param (
[string]$Name,
[ValidateSet("Failed","Passed","Skipped","Pending")]
[ValidateSet("Failed","Passed","Skipped","Pending","Inconclusive")]
[string]$Result,
[Nullable[TimeSpan]]$Time,
[string]$FailureMessage,
Expand Down Expand Up @@ -163,6 +164,7 @@ function New-PesterState
Failed { $script:FailedCount++; break; }
Skipped { $script:SkippedCount++; break; }
Pending { $script:PendingCount++; break; }
Inconclusive { $script:InconclusiveCount++; break; }
}

$Script:TestResult += Microsoft.PowerShell.Utility\New-Object -TypeName PsObject -Property @{
Expand Down Expand Up @@ -200,7 +202,8 @@ function New-PesterState
"PassedCount",
"FailedCount",
"SkippedCount",
"PendingCount"
"PendingCount",
"InconclusiveCount"

$ExportedFunctions = "EnterContext",
"LeaveContext",
Expand Down Expand Up @@ -292,6 +295,15 @@ function Write-PesterResult
"$margin[?] $output $humanTime" | Write-Screen -OutputType Pending
break
}
Inconclusive {
"$margin[?] $output $humanTime" | Write-Screen -OutputType Inconclusive
if ($testresult.FailureMessage) {
Write-Screen -OutputType Inconclusive $($TestResult.failureMessage -replace '(?m)^',$error_margin)
}

Write-Screen -OutputType Inconclusive $($TestResult.stackTrace -replace '(?m)^',$error_margin)
break
}
}
}
}
Expand Down Expand Up @@ -374,7 +386,12 @@ function Write-PesterReport
)

Write-Screen "Tests completed in $(Get-HumanTime $PesterState.Time.TotalSeconds)"
Write-Screen "Passed: $($PesterState.PassedCount) Failed: $($PesterState.FailedCount) Skipped: $($PesterState.SkippedCount) Pending: $($PesterState.PendingCount)"
Write-Screen ("Passed: {0} Failed: {1} Skipped: {2} Pending: {3} Inconclusive: {4}" -f
$PesterState.PassedCount,
$PesterState.FailedCount,
$PesterState.SkippedCount,
$PesterState.PendingCount,
$PesterState.InconclusiveCount)
}

function Write-Screen {
Expand All @@ -387,7 +404,7 @@ function Write-Screen {
[Object] $Separator,
#custom parameters
[Switch] $Quiet = $pester.Quiet,
[ValidateSet("Failed","Passed","Skipped","Pending","Header","Standard")]
[ValidateSet("Failed","Passed","Skipped","Pending","Inconclusive","Header","Standard")]
[String] $OutputType = "Standard"
)

Expand All @@ -414,30 +431,33 @@ function Write-Screen {
#light background
"PowerGUIScriptEditorHost" {
$ColorSet = @{
Failed = [ConsoleColor]::Red
Passed = [ConsoleColor]::DarkGreen
Skipped = [ConsoleColor]::DarkGray
Pending = [ConsoleColor]::DarkCyan
Header = [ConsoleColor]::Magenta
Failed = [ConsoleColor]::Red
Passed = [ConsoleColor]::DarkGreen
Skipped = [ConsoleColor]::DarkGray
Pending = [ConsoleColor]::DarkCyan
Inconclusive = [ConsoleColor]::DarkCyan
Header = [ConsoleColor]::Magenta
}
}
#dark background
{ "Windows PowerShell ISE Host", "ConsoleHost" -contains $_ } {
$ColorSet = @{
Failed = [ConsoleColor]::Red
Passed = [ConsoleColor]::Green
Skipped = [ConsoleColor]::Gray
Pending = [ConsoleColor]::Cyan
Header = [ConsoleColor]::Magenta
Failed = [ConsoleColor]::Red
Passed = [ConsoleColor]::Green
Skipped = [ConsoleColor]::Gray
Pending = [ConsoleColor]::Cyan
Inconclusive = [ConsoleColor]::Cyan
Header = [ConsoleColor]::Magenta
}
}
default {
$ColorSet = @{
Failed = [ConsoleColor]::Red
Passed = [ConsoleColor]::DarkGreen
Skipped = [ConsoleColor]::Gray
Pending = [ConsoleColor]::Gray
Header = [ConsoleColor]::Magenta
Failed = [ConsoleColor]::Red
Passed = [ConsoleColor]::DarkGreen
Skipped = [ConsoleColor]::Gray
Pending = [ConsoleColor]::Gray
Inconclusive = [ConsoleColor]::Gray
Header = [ConsoleColor]::Magenta
}
}

Expand Down
19 changes: 17 additions & 2 deletions Functions/TestResults.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ function Write-NUnitTestResultAttributes($PesterState, [System.Xml.XmlWriter] $X
$XmlWriter.WriteAttributeString('errors', '0')
$XmlWriter.WriteAttributeString('failures', $PesterState.FailedCount)
$XmlWriter.WriteAttributeString('not-run', '0')
$XmlWriter.WriteAttributeString('inconclusive', $PesterState.PendingCount)
$XmlWriter.WriteAttributeString('inconclusive', $PesterState.PendingCount + $PesterState.InconclusiveCount)
$XmlWriter.WriteAttributeString('ignored', $PesterState.SkippedCount)
$XmlWriter.WriteAttributeString('skipped', '0')
$XmlWriter.WriteAttributeString('invalid', '0')
Expand Down Expand Up @@ -375,12 +375,27 @@ function Write-NUnitTestCaseAttributes($TestResult, [System.Xml.XmlWriter] $XmlW
$XmlWriter.WriteAttributeString('executed', 'False')
break
}

Pending
{
$XmlWriter.WriteAttributeString('result', 'Inconclusive')
$XmlWriter.WriteAttributeString('executed', 'True')
break
}
Inconclusive
{
$XmlWriter.WriteAttributeString('result', 'Inconclusive')
$XmlWriter.WriteAttributeString('executed', 'True')

if ($TestResult.FailureMessage)
{
$XmlWriter.WriteStartElement('reason')
$xmlWriter.WriteElementString('message', $TestResult.FailureMessage)
$XmlWriter.WriteEndElement() # Close reason tag
}

break
}
Failed
{
$XmlWriter.WriteAttributeString('result', 'Failure')
Expand Down Expand Up @@ -427,6 +442,6 @@ function Get-GroupResult ($InputObject)
#TODO: Confirm this is the correct order of precedence
if ($InputObject | Where {$_.Result -eq 'Failed'}) { return 'Failure' }
if ($InputObject | Where {$_.Result -eq 'Skipped'}) { return 'Ignored' }
if ($InputObject | Where {$_.Result -eq 'Pending'}) { return 'Inconclusive' }
if ($InputObject | Where {$_.Result -eq 'Pending' -or $_.Result -eq 'Inconclusive'}) { return 'Inconclusive' }
return 'Success'
}
3 changes: 2 additions & 1 deletion Pester.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ FunctionsToExport = @(
'BeforeAll',
'AfterAll'
'Get-MockDynamicParameters',
'Set-DynamicParameterVariables'
'Set-DynamicParameterVariables',
'Set-TestInconclusive'
)

# # Cmdlets to export from this module
Expand Down
2 changes: 1 addition & 1 deletion Pester.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ if ((Test-Path -Path Variable:\psise) -and ($null -ne $psISE) -and ($PSVersionTa
Import-IseSnippet -Path $snippetsDirectoryPath
}

Export-ModuleMember Describe, Context, It, In, Mock, Assert-VerifiableMocks, Assert-MockCalled
Export-ModuleMember Describe, Context, It, In, Mock, Assert-VerifiableMocks, Assert-MockCalled, Set-TestInconclusive
Export-ModuleMember New-Fixture, Get-TestDriveItem, Should, Invoke-Pester, Setup, InModuleScope, Invoke-Mock
Export-ModuleMember BeforeEach, AfterEach, BeforeAll, AfterAll
Export-ModuleMember Get-MockDynamicParameters, Set-DynamicParameterVariables

0 comments on commit 292bca1

Please sign in to comment.