New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor Invoke-Pester and validate configuration early #2317
Conversation
try { | ||
$xmlWriter.Close() | ||
} | ||
catch { |
Check warning
Code scanning / PSScriptAnalyzer
Empty catch block is used. Please use Write-Error or throw statements in catch blocks. Warning
try { | ||
$stringWriter.Close() | ||
} | ||
catch { |
Check warning
Code scanning / PSScriptAnalyzer
Empty catch block is used. Please use Write-Error or throw statements in catch blocks. Warning
$rc++ | ||
$ec = 0 | ||
if ($null -ne $r.ErrorRecord -and $r.ErrorRecord.Length -gt 0) { | ||
$err += "Result $($rc++):" | ||
$anyFailed = $true | ||
foreach ($e in $r.ErrorRecord) { | ||
$err += "Error $($ec++):" | ||
$err += "$([Environment]::NewLine)Result $rc - Error $((++$ec)):" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Previous message didn't print $ec
and $rc
(only incremented them) due to missing parantheses.
/azp run |
Azure Pipelines successfully started running 1 pipeline(s). |
src/Pester.Runtime.ps1
Outdated
@@ -1216,7 +1227,7 @@ function Invoke-PluginStep { | |||
# this is end step, we should run all steps no matter if some failed, and we should run them in opposite direction | |||
# only do this if there is more than 1, to avoid the "expensive" -like check and reverse | |||
$isEndStep = 1 -lt $pluginsWithGivenStep.Count -and $Step -like "*End" | |||
if (-not $isEndStep) { | |||
if ($isEndStep) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this did not reverse the steps before, did you see any bugs linked to that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No bugs I'm aware of. Just not behaving like comment says. We reverse on TearDown-steps as expected, but this currently reverses on everything else than *End.
Not a critical part of the PR, just testing it out while in draft. Will need to revert this or change plugin-order as it (PR-code) now runs CC and nunit-reports before writing test-report to screen. Either way it's confusing/inconsistent atm (pre-PR).
Thoughts on this @nohwnd? |
Fixes result count and error count not being printed and updates formats. Also removes the host message because it's duplicated when exception is thrown.
c7e716d
to
7520096
Compare
$err += & $SafeCommands["Out-String"] -InputObject $e | ||
$err += & $SafeCommands["Out-String"] -InputObject $e.ScriptStackTrace | ||
} | ||
} | ||
} | ||
|
||
if ($anyFailed) { | ||
$Message = $Message + ":`n$err" | ||
Write-PesterHostMessage -ForegroundColor Red $Message |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Revert this or good? Not validating configuration in plugin-step now, so PR is not affected by the duplicate error from Assert-Success
. Not sure if it's useful somewhere else
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good.
@fflaten Approved both this and your test output refactoring PRs, they seem like they might run into each other so I was not sure in which order you want them merged, please merge any way you like :) |
@nohwnd Thanks! Let's start with this. It will also cause a conflict in the last PR for container data. Can fix both later today. 🙂 |
Btw. Don't have merge rights, so up to you :) |
@fflaten you do now. |
PR Summary
The code for
Invoke-Pester
has become huge over the years and hard to read and maintain. This PR splits out parts of the code to plugin-steps and helper-functions.It also moves configuration validation to the start to avoid longs runs being lost in the end due to a typo.
Fix #2304
PR Checklist
Create Pull Request
to mark it as a draft. PR can be markedReady for review
when it's ready.