Skip to content

Commit

Permalink
Fix problems when there are no scripts in the scripts folder
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrdavidson committed May 1, 2021
1 parent bd28c4a commit b0acf02
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Source/PSQualityCheck/PSQualityCheck.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = 'PSQualityCheck.psm1'

# Version number of this module.
ModuleVersion = '2.0.0'
ModuleVersion = '2.0.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
52 changes: 52 additions & 0 deletions Source/PSQualityCheck/Public/Invoke-PSQualityCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,15 @@ function Invoke-PSQualityCheck {
}
else {
Write-Error "Project Path $ProjectPath does not exist"
$projectResults =
@{
'Count' = 0
'TotalCount' = 0
'NotRunCount' = 0
'PassedCount' = 0
'FailedCount' = 0
'SkippedCount' = 0
}
}

}
Expand Down Expand Up @@ -418,6 +427,26 @@ function Invoke-PSQualityCheck {
$extractionResults = Invoke-Pester -Configuration $PesterConfiguration

}
else {
$moduleResults =
@{
'Count' = 0
'TotalCount' = 0
'NotRunCount' = 0
'PassedCount' = 0
'FailedCount' = 0
'SkippedCount' = 0
}
$extractionResults =
@{
'Count' = 0
'TotalCount' = 0
'NotRunCount' = 0
'PassedCount' = 0
'FailedCount' = 0
'SkippedCount' = 0
}
}

if ($runScriptCheck -eq $true -and (Test-Path -Path $extractPath -ErrorAction SilentlyContinue)) {

Expand All @@ -428,6 +457,18 @@ function Invoke-PSQualityCheck {
$container3 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Data\Script.Checks.ps1') -Data @{ Source = $extractedScriptsToTest; ScriptAnalyzerRulesPath = $ScriptAnalyzerRulesPath; HelpRulesPath = $HelpRulesPath }
$PesterConfiguration.Run.Container = $container3
$extractedScriptResults = Invoke-Pester -Configuration $PesterConfiguration

}
else {
$extractedScriptResults =
@{
'Count' = 0
'TotalCount' = 0
'NotRunCount' = 0
'PassedCount' = 0
'FailedCount' = 0
'SkippedCount' = 0
}
}

# Tidy up and temporary paths that have been used
Expand All @@ -447,6 +488,17 @@ function Invoke-PSQualityCheck {
$scriptResults = Invoke-Pester -Configuration $PesterConfiguration

}
else {
$scriptResults =
@{
'Count' = 0
'TotalCount' = 0
'NotRunCount' = 0
'PassedCount' = 0
'FailedCount' = 0
'SkippedCount' = 0
}
}

# Show/Export results in the various formats

Expand Down
2 changes: 1 addition & 1 deletion Source/PSQualityCheck/data/Script.Checks.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ BeforeDiscovery {

Describe "Script Tests" -Tag "Script" {

Context "Script: <_.Name> at <_.Directory>" -Foreach $scriptFiles {
Context "Script: <_.Name> at <_.Directory>" -ForEach $scriptFiles {

BeforeAll {

Expand Down
8 changes: 0 additions & 8 deletions Tests/Invoke-UnitTest.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,6 @@ $configuration.Run.PassThru = $false
$configuration.Should.ErrorAction = 'Stop'

# Dot load all the module ready to test
Get-ChildItem -Path "..\Source\PSQualityCheck.Functions\Public" -Filter *.ps1 | ForEach-Object {
. $_.FullName
}

Get-ChildItem -Path "..\Source\PSQualityCheck.Functions\Private" -Filter *.ps1 | ForEach-Object {
. $_.FullName
}

Get-ChildItem -Path "..\Source\PSQualityCheck\Public" -Filter *.ps1 | ForEach-Object {
. $_.FullName
}
Expand Down
2 changes: 1 addition & 1 deletion build-functions.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function Install-BuiltModule {
[string]$ModuleName
)

Install-Module -Name $ModuleName -Repository "$ModuleName-local"
Install-Module -Name $ModuleName -Repository "$ModuleName-local" -Force

}

Expand Down

0 comments on commit b0acf02

Please sign in to comment.