diff --git a/PSQualityCheck.Functions.psd1 b/PSQualityCheck.Functions.psd1 index a034392..0357ab4 100644 --- a/PSQualityCheck.Functions.psd1 +++ b/PSQualityCheck.Functions.psd1 @@ -4,7 +4,7 @@ RootModule = 'PSQualityCheck.Functions.psm1' # Version number of this module. - ModuleVersion = '1.0.3' + ModuleVersion = '1.0.4' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/PSQualityCheck.Functions.psm1 b/PSQualityCheck.Functions.psm1 index 860b0f3..bd6cd70 100644 --- a/PSQualityCheck.Functions.psm1 +++ b/PSQualityCheck.Functions.psm1 @@ -457,16 +457,18 @@ function Get-ParsedContent { ($ParsedModule, $ParserErrorCount) = Get-ParsedContent -Content $fileContent #> [CmdletBinding()] - [OutputType([System.Object[]])] + [OutputType([System.Object[]], [System.Void])] param ( [parameter(Mandatory = $true)] [string]$Content ) - $ParserErrors = $null - $ParsedModule = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ParserErrors) + if (-not ([string]::IsNullOrEmpty($Content))) { + $ParserErrors = $null + $ParsedModule = [System.Management.Automation.PSParser]::Tokenize($Content, [ref]$ParserErrors) - return $ParsedModule, ($ParserErrors.Count) + return $ParsedModule, ($ParserErrors.Count) + } } diff --git a/PSQualityCheck.psd1 b/PSQualityCheck.psd1 index ab2eff0..c6d4c9e 100644 --- a/PSQualityCheck.psd1 +++ b/PSQualityCheck.psd1 @@ -4,7 +4,7 @@ RootModule = 'PSQualityCheck.psm1' # Version number of this module. - ModuleVersion = '1.0.3' + ModuleVersion = '1.0.4' # Supported PSEditions # CompatiblePSEditions = @() diff --git a/PSQualityCheck.psm1 b/PSQualityCheck.psm1 index a8e5c6e..d946e0d 100644 --- a/PSQualityCheck.psm1 +++ b/PSQualityCheck.psm1 @@ -217,13 +217,13 @@ function Invoke-PSQualityCheck { $qualityCheckResults += @{ 'Test' = 'Module Tests' - 'Files Tested' = $ModulesToTestCount + 'Files Tested' = $ModulesToTest.Count 'Total' = $moduleResults.TotalCount 'Passed' = $moduleResults.PassedCount 'Failed' = $moduleResults.FailedCount 'Skipped' = $moduleResults.SkippedCount } - $filesTested += $ModulesToTestCount + $filesTested += $ModulesToTest.Count $total += $moduleResults.TotalCount $passed += $moduleResults.PassedCount $failed += $moduleResults.FailedCount @@ -233,7 +233,7 @@ function Invoke-PSQualityCheck { $qualityCheckResults += @{ 'Test' = 'Extracting functions' - 'Files Tested' = $ModulesToTestCount + 'Files Tested' = $ModulesToTest.Count 'Total' = $extractionResults.TotalCount 'Passed' = $extractionResults.PassedCount 'Failed' = $extractionResults.FailedCount @@ -248,13 +248,13 @@ function Invoke-PSQualityCheck { $qualityCheckResults += @{ 'Test' = 'Extracted function script tests' - 'Files Tested' = $extractedScriptsToTestCount + 'Files Tested' = $extractedScriptsToTest.Count 'Total' = $extractedScriptResults.TotalCount 'Passed' = $extractedScriptResults.PassedCount 'Failed' = $extractedScriptResults.FailedCount 'Skipped' = $extractedScriptResults.SkippedCount } - $filesTested += $extractedScriptsToTestCount + $filesTested += $extractedScriptsToTest.Count $total += $extractedScriptResults.TotalCount $passed += $extractedScriptResults.PassedCount $failed += $extractedScriptResults.FailedCount @@ -264,13 +264,13 @@ function Invoke-PSQualityCheck { $qualityCheckResults += @{ 'Test' = "Script Tests" - 'Files Tested' = $scriptsToTestCount + 'Files Tested' = $scriptsToTest.Count 'Total' = $scriptResults.TotalCount 'Passed' = $scriptResults.PassedCount 'Failed' = $scriptResults.FailedCount 'Skipped' = $scriptResults.SkippedCount } - $filesTested += $scriptsToTestCount + $filesTested += $scriptsToTest.Count $total += $scriptResults.TotalCount $passed += $scriptResults.PassedCount $failed += $scriptResults.FailedCount @@ -295,7 +295,8 @@ function Invoke-PSQualityCheck { 'Passed' = $_.passed 'Failed' = $_.failed 'Skipped' = $_.skipped - } } | Format-Table -AutoSize + } + } | Format-Table -AutoSize # This works on PS7 not on PS5 # $qualityCheckResults | Select-Object Name, 'Files Tested', Total, Passed, Failed, Skipped | Format-Table -AutoSize diff --git a/Tests/Script.Tests.ps1 b/Tests/Script.Tests.ps1 index 6509e30..799e600 100644 --- a/Tests/Script.Tests.ps1 +++ b/Tests/Script.Tests.ps1 @@ -17,7 +17,14 @@ Describe "Script Tests" { # This needs to get the content of the file or the content of the function inside the file $fileContent = Get-FileContent -File $scriptFile - ($ParsedFile, $ErrorCount) = Get-ParsedContent -Content $fileContent + if (-not([string]::IsNullOrEmpty($fileContent))) { + ($ParsedFile, $ErrorCount) = Get-ParsedContent -Content $fileContent + } + else { + Write-Warning "File is empty" + $ParsedFile = $null + $ErrorCount = 1 + } It "check script has valid PowerShell syntax" -TestCases @{ 'ErrorCount' = $ErrorCount } {