Skip to content

Errors reported from Describe and Context blocks#168

Merged
dlwyatt merged 3 commits intopester:Betafrom
dlwyatt:DescribeAndCheckoutFailureReport
Aug 4, 2014
Merged

Errors reported from Describe and Context blocks#168
dlwyatt merged 3 commits intopester:Betafrom
dlwyatt:DescribeAndCheckoutFailureReport

Conversation

@dlwyatt
Copy link
Copy Markdown
Member

@dlwyatt dlwyatt commented Jul 31, 2014

Quick update to make terminating errors that occur in a Describe or Context block cause a failed "test" to appear in the output.

Because we're just piggybacking onto the existing PesterState.AddTestResult and Write-PesterResult code, the output looks as though it came from an It statement, though the name is always "Error occurred in Context block" or "Error occurred in Describe block". If this style of output is undesirable, a more extensive code update would be required.

Do we need to handle nonterminating errors in this fashion as well, or leave that up to the person writing the test script? (For instance, they can set -ErrorAction Stop, if they like.)

This is intended to fix issue #79

@dlwyatt
Copy link
Copy Markdown
Member Author

dlwyatt commented Jul 31, 2014

Quick note: I don't think this PR will be merged as-is. I just put it up as a starting point for us to discuss in issue 79's thread. Expect more commits to be added here as we figure out what the behavior should be.

dlwyatt added 3 commits August 3, 2014 23:20
Quick update to make terminating errors that occur in a Describe or Context block cause a failed "test" to appear in the output.

Because we're just piggybacking onto the existing PesterState.AddTestResult and Write-PesterResult code, the output looks as though it came from an It statement, though the name is always "Error occurred in Context block" or "Error occurred in Describe block".  If this style of output is undesirable, a more extensive code update would be required.
This is along the same lines as the original commit in this branch, but addresses issue pester#91.

Also moved the calls to Add-SetupAndTeardown into the Try blocks of Describe and Context.
@dlwyatt
Copy link
Copy Markdown
Member Author

dlwyatt commented Aug 4, 2014

This branch produces failed tests when a test script contains a syntax error, or when terminating errors are produced from inside Describe or Context blocks (but not inside an It block.) These failed tests become part of the output via the console, NUnit XML file, exit code and PassThru features, allowing a CI solution to detect the error condition not to treat the test suite as "passed".

dlwyatt added a commit that referenced this pull request Aug 4, 2014
Errors reported from Describe and Context blocks
@dlwyatt dlwyatt merged commit 6c3efb0 into pester:Beta Aug 4, 2014
@dlwyatt dlwyatt deleted the DescribeAndCheckoutFailureReport branch August 4, 2014 12:54
@dlwyatt
Copy link
Copy Markdown
Member Author

dlwyatt commented Aug 4, 2014

In addition to issue 79, this also takes care of #91.

@mzs-github
Copy link
Copy Markdown

Do we need to handle nonterminating errors in this fashion as well, or leave that up to the person writing the test script? (For instance, they can set -ErrorAction Stop, if they like.)

It's funny you should mention that - the error I was thinking about when I commented earlier was actually a nonterminating error and I'd forgotten to set $ErrorActionPreference in my test script. I wonder if it would make sense to add $ErrorActionPreference = 'Stop' and maybe a strict mode setting to the top of the generated fixtures and/or the examples in the Wiki.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants