Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 32 additions & 29 deletions Functions/Describe.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,26 +140,44 @@ function DescribeImpl {
$testDriveAdded = $false
try
{
if (-not $NoTestDrive)
try
{
if (-not (Test-Path TestDrive:\))
if (-not $NoTestDrive)
{
New-TestDrive
$testDriveAdded = $true
if (-not (Test-Path TestDrive:\))
{
New-TestDrive
$testDriveAdded = $true
}
else
{
$TestDriveContent = Get-TestDriveChildItem
}
}
else
{
$TestDriveContent = Get-TestDriveChildItem
}
}

Add-SetupAndTeardown -ScriptBlock $Fixture
Invoke-TestGroupSetupBlocks
Add-SetupAndTeardown -ScriptBlock $Fixture
Invoke-TestGroupSetupBlocks

do
do
{
$null = & $Fixture
} until ($true)
}
finally
{
$null = & $Fixture
} until ($true)
Invoke-TestGroupTeardownBlocks
if (-not $NoTestDrive)
{
if ($testDriveAdded)
{
Remove-TestDrive
}
else
{
Clear-TestDrive -Exclude ($TestDriveContent | & $SafeCommands['Select-Object'] -ExpandProperty FullName)
}
}
}
}
catch
{
Expand All @@ -170,21 +188,6 @@ function DescribeImpl {
& $TestOutputBlock $Pester.TestResult[-1]
}
}
finally
{
Invoke-TestGroupTeardownBlocks
if (-not $NoTestDrive)
{
if ($testDriveAdded)
{
Remove-TestDrive
}
else
{
Clear-TestDrive -Exclude ($TestDriveContent | & $SafeCommands['Select-Object'] -ExpandProperty FullName)
}
}
}

Exit-MockScope

Expand Down
30 changes: 30 additions & 0 deletions Functions/TestsRunningInCleanRunspace.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,34 @@ Describe 'Guarantee It fail on setup or teardown fail (running in clean runspace
$result.FailedCount | Should Be 1
$result.TestResult[0].FailureMessage | Should Be "test exception"
}

Context 'Teardown fails' {
It "Failed teardown does not let exception propagate outside of the scope of Describe/Context in which it failed" {
$testSuite = {
$teardownFailure = $null

try {
Context 'This is a test context' {
AfterAll {
throw 'I throw in Afterall'
}
}
}
catch {
$teardownFailure = $_
}
It "Failed teardown does not let exception propagate outside of the scope of Describe/Context in which it failed" {
# issue #584, #662
$teardownFailure | Should -BeNullOrEmpty
}
}
$result = Invoke-PesterInJob -ScriptBlock $testSuite

# the second test should pass because correctly the exception does not propagate
$result.PassedCount | Should -Be 1

# the first test should fail because after all throws
$result.FailedCount | Should -Be 1
}
}
}