Skip to content

Commit

Permalink
Merge pull request #3 from andrewrdavidson/release-1.0.2
Browse files Browse the repository at this point in the history
Move showing check results code
  • Loading branch information
andrewrdavidson authored Dec 20, 2020
2 parents b3230e5 + 6b869ba commit 665cd7c
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 148 deletions.
1 change: 0 additions & 1 deletion PSQualityCheck.Functions.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
'Get-Token',
'Get-TokenComponent',
'Get-TokenMarker',
'Show-CheckResultsOutput',
'Test-HelpForRequiredTokens',
'Test-HelpForUnspecifiedTokens',
'Test-HelpTokensCountIsValid',
Expand Down
138 changes: 0 additions & 138 deletions PSQualityCheck.Functions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -1181,141 +1181,3 @@ function Test-ParameterVariablesHaveType {
}

}

function Show-CheckResultsOutput {
<#
.SYNOPSIS
Show the summary output of all checks
.DESCRIPTION
Shows the summary output of all the checks performed and a total
.PARAMETER ModulesToTestCount
Integer value of the number of modules tested
.PARAMETER ExtractedScriptsToTestCount
Integer value of the number of script files extracted from modules tested
.PARAMETER ScriptsToTestCount
Integer value of the number of script files tested
.PARAMETER ModuleResults
Pester result object from the Module tests
.PARAMETER ExtractionResults
Pester result object from the Function Extractions tests
.PARAMETER ExtractedScriptResults
Pester result object from the Scripts tests on the extracted files
.PARAMETER ScriptResults
Pester result object from the Script tests
.EXAMPLE
Show-CheckResultsOutput -ModulesToTestCount $modulesToTestCount -ModuleResults $moduleResults -ExtractionResults $extractionResults -ExtractedScriptsToTestCount $extractedScriptsToTestCount -ExtractedScriptResults $extractedScriptResults -ScriptsToTestCount $scriptsToTestCount -ScriptResults $scriptResults
#>
[CmdletBinding()]
[OutputType([HashTable])]
param
(
[int]$ModulesToTestCount,
[int]$extractedScriptsToTestCount,
[int]$scriptsToTestCount,
[System.Object]$moduleResults,
[System.Object]$extractionResults,
[System.Object]$extractedScriptResults,
[System.Object]$scriptResults
)

$qualityCheckResults = @()
$filesTested = $total = $passed = $failed = $skipped = 0

if ($null -ne $moduleResults) {
$qualityCheckResults +=
@{
'Test' = 'Module Tests'
'Files Tested' = $ModulesToTestCount
'Total' = $moduleResults.TotalCount
'Passed' = $moduleResults.PassedCount
'Failed' = $moduleResults.FailedCount
'Skipped' = $moduleResults.SkippedCount
}
$filesTested += $ModulesToTestCount
$total += $moduleResults.TotalCount
$passed += $moduleResults.PassedCount
$failed += $moduleResults.FailedCount
$skipped += $moduleResults.SkippedCount
}
if ($null -ne $extractionResults) {
$qualityCheckResults +=
@{
'Test' = 'Extracting functions'
'Files Tested' = $ModulesToTestCount
'Total' = $extractionResults.TotalCount
'Passed' = $extractionResults.PassedCount
'Failed' = $extractionResults.FailedCount
'Skipped' = $extractionResults.SkippedCount
}
$total += $extractionResults.TotalCount
$passed += $extractionResults.PassedCount
$failed += $extractionResults.FailedCount
$skipped += $extractionResults.SkippedCount
}
if ($null -ne $extractedScriptResults) {
$qualityCheckResults +=
@{
'Test' = 'Extracted function script tests'
'Files Tested' = $extractedScriptsToTestCount
'Total' = $extractedScriptResults.TotalCount
'Passed' = $extractedScriptResults.PassedCount
'Failed' = $extractedScriptResults.FailedCount
'Skipped' = $extractedScriptResults.SkippedCount
}
$filesTested += $extractedScriptsToTestCount
$total += $extractedScriptResults.TotalCount
$passed += $extractedScriptResults.PassedCount
$failed += $extractedScriptResults.FailedCount
$skipped += $extractedScriptResults.SkippedCount
}
if ($null -ne $scriptResults) {
$qualityCheckResults +=
@{
'Test' = "Script Tests"
'Files Tested' = $scriptsToTestCount
'Total' = $scriptResults.TotalCount
'Passed' = $scriptResults.PassedCount
'Failed' = $scriptResults.FailedCount
'Skipped' = $scriptResults.SkippedCount
}
$filesTested += $scriptsToTestCount
$total += $scriptResults.TotalCount
$passed += $scriptResults.PassedCount
$failed += $scriptResults.FailedCount
$skipped += $scriptResults.SkippedCount
}
$qualityCheckResults +=
@{
'Test' = "Total"
'Files Tested' = $filesTested
'Total' = $total
'Passed' = $passed
'Failed' = $failed
'Skipped' = $skipped
}

# This works on PS5
$qualityCheckResults | ForEach-Object {
[PSCustomObject]@{
'Test' = $_.Test
'Files Tested' = $_.'Files Tested'
'Total' = $_.total
'Passed' = $_.passed
'Failed' = $_.failed
'Skipped' = $_.skipped
} } | Format-Table -AutoSize

# This works on PS7 not on PS5
# $qualityCheckResults | Select-Object Name, 'Files Tested', Total, Passed, Failed, Skipped | Format-Table -AutoSize

}
96 changes: 87 additions & 9 deletions PSQualityCheck.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,95 @@ function Invoke-PSQualityCheck {

if ($PSBoundParameters.ContainsKey('ShowCheckResults')) {

$showCheckResultsOutputSplat = @{
'ModulesToTestCount' = $modulesToTest.Count
'ExtractedScriptsToTestCount' = $extractedScriptsToTest.Count
'ScriptsToTestCount' = $scriptsToTest.Count
'ModuleResults' = $moduleResults
'ExtractionResults' = $extractionResults
'ExtractedScriptResults' = $extractedScriptResults
'ScriptResults' = $scriptResults
$qualityCheckResults = @()
$filesTested = $total = $passed = $failed = $skipped = 0

if ($null -ne $moduleResults) {
$qualityCheckResults +=
@{
'Test' = 'Module Tests'
'Files Tested' = $ModulesToTestCount
'Total' = $moduleResults.TotalCount
'Passed' = $moduleResults.PassedCount
'Failed' = $moduleResults.FailedCount
'Skipped' = $moduleResults.SkippedCount
}
$filesTested += $ModulesToTestCount
$total += $moduleResults.TotalCount
$passed += $moduleResults.PassedCount
$failed += $moduleResults.FailedCount
$skipped += $moduleResults.SkippedCount
}
if ($null -ne $extractionResults) {
$qualityCheckResults +=
@{
'Test' = 'Extracting functions'
'Files Tested' = $ModulesToTestCount
'Total' = $extractionResults.TotalCount
'Passed' = $extractionResults.PassedCount
'Failed' = $extractionResults.FailedCount
'Skipped' = $extractionResults.SkippedCount
}
$total += $extractionResults.TotalCount
$passed += $extractionResults.PassedCount
$failed += $extractionResults.FailedCount
$skipped += $extractionResults.SkippedCount
}
if ($null -ne $extractedScriptResults) {
$qualityCheckResults +=
@{
'Test' = 'Extracted function script tests'
'Files Tested' = $extractedScriptsToTestCount
'Total' = $extractedScriptResults.TotalCount
'Passed' = $extractedScriptResults.PassedCount
'Failed' = $extractedScriptResults.FailedCount
'Skipped' = $extractedScriptResults.SkippedCount
}
$filesTested += $extractedScriptsToTestCount
$total += $extractedScriptResults.TotalCount
$passed += $extractedScriptResults.PassedCount
$failed += $extractedScriptResults.FailedCount
$skipped += $extractedScriptResults.SkippedCount
}
if ($null -ne $scriptResults) {
$qualityCheckResults +=
@{
'Test' = "Script Tests"
'Files Tested' = $scriptsToTestCount
'Total' = $scriptResults.TotalCount
'Passed' = $scriptResults.PassedCount
'Failed' = $scriptResults.FailedCount
'Skipped' = $scriptResults.SkippedCount
}
$filesTested += $scriptsToTestCount
$total += $scriptResults.TotalCount
$passed += $scriptResults.PassedCount
$failed += $scriptResults.FailedCount
$skipped += $scriptResults.SkippedCount
}
$qualityCheckResults +=
@{
'Test' = "Total"
'Files Tested' = $filesTested
'Total' = $total
'Passed' = $passed
'Failed' = $failed
'Skipped' = $skipped
}

Show-CheckResultsOutput @showCheckResultsOutputSplat
# This works on PS5
$qualityCheckResults | ForEach-Object {
[PSCustomObject]@{
'Test' = $_.Test
'Files Tested' = $_.'Files Tested'
'Total' = $_.total
'Passed' = $_.passed
'Failed' = $_.failed
'Skipped' = $_.skipped
} } | Format-Table -AutoSize

# This works on PS7 not on PS5
# $qualityCheckResults | Select-Object Name, 'Files Tested', Total, Passed, Failed, Skipped | Format-Table -AutoSize

}

Expand Down

0 comments on commit 665cd7c

Please sign in to comment.