Skip to content

Include more statements in code coverage#2554

Merged
nohwnd merged 6 commits into
pester:mainfrom
fflaten:cc-statements
Dec 13, 2024
Merged

Include more statements in code coverage#2554
nohwnd merged 6 commits into
pester:mainfrom
fflaten:cc-statements

Conversation

@fflaten
Copy link
Copy Markdown
Collaborator

@fflaten fflaten commented Aug 3, 2024

PR Summary

Extends code coverage to include break, continue, exit and throw statements.
return is not included due to inconsistent behavior (though return 123 is already covered as a command expression)

Adds sort after Group-Object to save future headaches with inconsistent report/output order in Windows PowerShell vs PowerShell 6.1 which sorts by default.

Fix #1465

PR Checklist

  • PR has meaningful title
  • Summary describes changes
  • PR is ready to be merged
    • If not, use the arrow next to Create Pull Request to mark it as a draft. PR can be marked Ready for review when it's ready.
  • Tests are added/update (if required)
  • Documentation is updated/added (if required)

@fflaten
Copy link
Copy Markdown
Collaborator Author

fflaten commented Aug 3, 2024

Draft PR due to merge conflict with #2553 and #2298. Need to merge one, fix next + repeat due to hardcoded reports.

Comment thread src/functions/Coverage.ps1
Comment on lines 293 to 301
$predicate = {
$args[0] -is [System.Management.Automation.Language.DynamicKeywordStatementAst] -or
$args[0] -is [System.Management.Automation.Language.CommandBaseAst]
$args[0] -is [System.Management.Automation.Language.CommandBaseAst] -or
$args[0] -is [System.Management.Automation.Language.BreakStatementAst] -or
$args[0] -is [System.Management.Automation.Language.ContinueStatementAst] -or
$args[0] -is [System.Management.Automation.Language.ExitStatementAst] -or
$args[0] -is [System.Management.Automation.Language.ThrowStatementAst]
}
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only updated PSv5+ predicate as we might remove the redundant predicate for v6.
A potential backport would need to extend both predicates.

@fflaten fflaten marked this pull request as ready for review October 31, 2024 17:42
Comment thread src/functions/TestResults.NUnit25.ps1
@nohwnd nohwnd merged commit 422ef99 into pester:main Dec 13, 2024
@nohwnd
Copy link
Copy Markdown
Member

nohwnd commented Dec 13, 2024

👍👍👍

@fflaten fflaten deleted the cc-statements branch December 13, 2024 19:33
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.

Code coverage not listing all missed commands

2 participants