Skip to content

Commit

Permalink
Merge pull request #22 from andrewrdavidson/release-1.1.1
Browse files Browse the repository at this point in the history
Release 1.1.1
  • Loading branch information
andrewrdavidson authored Jan 20, 2021
2 parents cdf8e6e + 9210330 commit 072ffde
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 40 deletions.
4 changes: 2 additions & 2 deletions PSQualityCheck.Functions.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Andrew Davidson
#
# Generated on: 14/01/2021
# Generated on: 20/01/2021
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'PSQualityCheck.Functions.psm1'

# Version number of this module.
ModuleVersion = '1.1.0'
ModuleVersion = '1.1.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
4 changes: 2 additions & 2 deletions PSQualityCheck.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# Generated by: Andrew Davidson
#
# Generated on: 14/01/2021
# Generated on: 20/01/2021
#

@{
Expand All @@ -12,7 +12,7 @@
RootModule = 'PSQualityCheck.psm1'

# Version number of this module.
ModuleVersion = '1.1.0'
ModuleVersion = '1.1.1'

# Supported PSEditions
# CompatiblePSEditions = @()
Expand Down
77 changes: 60 additions & 17 deletions PSQualityCheck.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ function Invoke-PSQualityCheck {
.PARAMETER ShowCheckResults
Show a summary of the Check results at the end of processing
.PARAMETER ExportCheckResults
Exports the Check results at the end of processing to file
.PARAMETER Passthru
Returns the Check results objects back to the caller
.PARAMETER PesterConfiguration
A Pester configuration object to allow configuration of Pester
.EXAMPLE
Invoke-PSQualityCheck -Path 'C:\Scripts'
Expand Down Expand Up @@ -82,7 +91,7 @@ function Invoke-PSQualityCheck {
#>
[CmdletBinding()]
[OutputType([System.Void], [HashTable])]
[OutputType([System.Void], [HashTable], [System.Object[]])]
param (
[Parameter(Mandatory = $true, ParameterSetName = "Path")]
[String[]]$Path,
Expand All @@ -95,7 +104,14 @@ function Invoke-PSQualityCheck {
[Parameter(Mandatory = $false)]
[String]$SonarQubeRulesPath,

[switch]$ShowCheckResults
[switch]$ShowCheckResults,

[switch]$ExportCheckResults,

[switch]$Passthru,

[Parameter(Mandatory = $false)]
[System.Object]$PesterConfiguration
)

Set-StrictMode -Version Latest
Expand Down Expand Up @@ -179,13 +195,20 @@ function Invoke-PSQualityCheck {

}

# Default Pester Parameters
$configuration = [PesterConfiguration]::Default
$configuration.Run.Exit = $false
$configuration.CodeCoverage.Enabled = $false
$configuration.Output.Verbosity = 'Detailed'
$configuration.Run.PassThru = $true
$configuration.Should.ErrorAction = 'Stop'
if ($PSBoundParameters.ContainsKey('PesterConfiguration') -and $PesterConfiguration -is [PesterConfiguration]) {

# left here so that we can over-ride passed in object with values we require

}
else {
# Default Pester Parameters
$PesterConfiguration = [PesterConfiguration]::Default
$PesterConfiguration.Run.Exit = $false
$PesterConfiguration.CodeCoverage.Enabled = $false
$PesterConfiguration.Output.Verbosity = 'Detailed'
$PesterConfiguration.Run.PassThru = $true
$PesterConfiguration.Should.ErrorAction = 'Stop'
}

$moduleResults = $null
$extractionResults = $null
Expand All @@ -199,30 +222,30 @@ function Invoke-PSQualityCheck {

# Run the Module tests on all the valid module files found
$container1 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Checks\Module.Tests.ps1') -Data @{ Source = $modulesToTest }
$configuration.Run.Container = $container1
$moduleResults = Invoke-Pester -Configuration $configuration
$PesterConfiguration.Run.Container = $container1
$moduleResults = Invoke-Pester -Configuration $PesterConfiguration

# Extract all the functions from the modules into individual .ps1 files ready for testing
$container2 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Checks\Function-Extraction.Tests.ps1') -Data @{ Source = $modulesToTest; ExtractPath = $extractPath }
$configuration.Run.Container = $container2
$extractionResults = Invoke-Pester -Configuration $configuration
$PesterConfiguration.Run.Container = $container2
$extractionResults = Invoke-Pester -Configuration $PesterConfiguration

# Get a list of the 'extracted' function scripts .ps1 files
$extractedScriptsToTest = Get-ChildItem -Path $extractPath -Include '*.ps1' -Recurse

# Run the Script tests against all the extracted functions .ps1 files
$container3 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Checks\Script.Tests.ps1') -Data @{ Source = $extractedScriptsToTest; SonarQubeRules = $SonarQubeRulesPath }
$configuration.Run.Container = $container3
$extractedScriptResults = Invoke-Pester -Configuration $configuration
$PesterConfiguration.Run.Container = $container3
$extractedScriptResults = Invoke-Pester -Configuration $PesterConfiguration

}

if ($scriptsToTest.Count -ge 1) {

# Run the Script tests against all the valid script files found
$container3 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Checks\Script.Tests.ps1') -Data @{ Source = $scriptsToTest; SonarQubeRules = $SonarQubeRulesPath }
$configuration.Run.Container = $container3
$scriptResults = Invoke-Pester -Configuration $configuration
$PesterConfiguration.Run.Container = $container3
$scriptResults = Invoke-Pester -Configuration $PesterConfiguration

}

Expand Down Expand Up @@ -325,5 +348,25 @@ function Invoke-PSQualityCheck {

}

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

$moduleResults | Export-Clixml -Path "moduleResults.xml"
$extractionResults | Export-Clixml -Path "extractionResults.xml"
$scriptsToTest | Export-Clixml -Path "scriptsToTest.xml"
$extractedScriptResults | Export-Clixml -Path "extractedScriptResults.xml"

}

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

if ($PesterConfiguration.Run.PassThru.Value -eq $true) {
return $moduleResults, $extractionResults, $scriptsToTest, $extractedScriptResults
}
else {
Write-Error "Unable to pass back result objects. Passthru not enabled in Pester Configuration object"
}

}

}

2 changes: 1 addition & 1 deletion Source/Build.Properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
"HelpInfoURI": "https://github.com/andrewrdavidson/PSQualityCheck/wiki",
"LicenseUri": "https://github.com/andrewrdavidson/PSQualityCheck/blob/main/LICENSE",
"ModuleVersion": "1.1.0",
"ModuleVersion": "1.1.1",
"NestedModules": {
"PSQualityCheck": "PSQualityCheck.Functions.psd1",
"PSQualityCheck.Functions": null
Expand Down
77 changes: 60 additions & 17 deletions Source/PSQualityCheck/Invoke-PSQualityCheck.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ function Invoke-PSQualityCheck {
.PARAMETER ShowCheckResults
Show a summary of the Check results at the end of processing
.PARAMETER ExportCheckResults
Exports the Check results at the end of processing to file
.PARAMETER Passthru
Returns the Check results objects back to the caller
.PARAMETER PesterConfiguration
A Pester configuration object to allow configuration of Pester
.EXAMPLE
Invoke-PSQualityCheck -Path 'C:\Scripts'
Expand Down Expand Up @@ -82,7 +91,7 @@ function Invoke-PSQualityCheck {
#>
[CmdletBinding()]
[OutputType([System.Void], [HashTable])]
[OutputType([System.Void], [HashTable], [System.Object[]])]
param (
[Parameter(Mandatory = $true, ParameterSetName = "Path")]
[String[]]$Path,
Expand All @@ -95,7 +104,14 @@ function Invoke-PSQualityCheck {
[Parameter(Mandatory = $false)]
[String]$SonarQubeRulesPath,

[switch]$ShowCheckResults
[switch]$ShowCheckResults,

[switch]$ExportCheckResults,

[switch]$Passthru,

[Parameter(Mandatory = $false)]
[System.Object]$PesterConfiguration
)

Set-StrictMode -Version Latest
Expand Down Expand Up @@ -179,13 +195,20 @@ function Invoke-PSQualityCheck {

}

# Default Pester Parameters
$configuration = [PesterConfiguration]::Default
$configuration.Run.Exit = $false
$configuration.CodeCoverage.Enabled = $false
$configuration.Output.Verbosity = 'Detailed'
$configuration.Run.PassThru = $true
$configuration.Should.ErrorAction = 'Stop'
if ($PSBoundParameters.ContainsKey('PesterConfiguration') -and $PesterConfiguration -is [PesterConfiguration]) {

# left here so that we can over-ride passed in object with values we require

}
else {
# Default Pester Parameters
$PesterConfiguration = [PesterConfiguration]::Default
$PesterConfiguration.Run.Exit = $false
$PesterConfiguration.CodeCoverage.Enabled = $false
$PesterConfiguration.Output.Verbosity = 'Detailed'
$PesterConfiguration.Run.PassThru = $true
$PesterConfiguration.Should.ErrorAction = 'Stop'
}

$moduleResults = $null
$extractionResults = $null
Expand All @@ -199,30 +222,30 @@ function Invoke-PSQualityCheck {

# Run the Module tests on all the valid module files found
$container1 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Checks\Module.Tests.ps1') -Data @{ Source = $modulesToTest }
$configuration.Run.Container = $container1
$moduleResults = Invoke-Pester -Configuration $configuration
$PesterConfiguration.Run.Container = $container1
$moduleResults = Invoke-Pester -Configuration $PesterConfiguration

# Extract all the functions from the modules into individual .ps1 files ready for testing
$container2 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Checks\Function-Extraction.Tests.ps1') -Data @{ Source = $modulesToTest; ExtractPath = $extractPath }
$configuration.Run.Container = $container2
$extractionResults = Invoke-Pester -Configuration $configuration
$PesterConfiguration.Run.Container = $container2
$extractionResults = Invoke-Pester -Configuration $PesterConfiguration

# Get a list of the 'extracted' function scripts .ps1 files
$extractedScriptsToTest = Get-ChildItem -Path $extractPath -Include '*.ps1' -Recurse

# Run the Script tests against all the extracted functions .ps1 files
$container3 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Checks\Script.Tests.ps1') -Data @{ Source = $extractedScriptsToTest; SonarQubeRules = $SonarQubeRulesPath }
$configuration.Run.Container = $container3
$extractedScriptResults = Invoke-Pester -Configuration $configuration
$PesterConfiguration.Run.Container = $container3
$extractedScriptResults = Invoke-Pester -Configuration $PesterConfiguration

}

if ($scriptsToTest.Count -ge 1) {

# Run the Script tests against all the valid script files found
$container3 = New-PesterContainer -Path (Join-Path -Path $modulePath -ChildPath 'Checks\Script.Tests.ps1') -Data @{ Source = $scriptsToTest; SonarQubeRules = $SonarQubeRulesPath }
$configuration.Run.Container = $container3
$scriptResults = Invoke-Pester -Configuration $configuration
$PesterConfiguration.Run.Container = $container3
$scriptResults = Invoke-Pester -Configuration $PesterConfiguration

}

Expand Down Expand Up @@ -325,4 +348,24 @@ function Invoke-PSQualityCheck {

}

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

$moduleResults | Export-Clixml -Path "moduleResults.xml"
$extractionResults | Export-Clixml -Path "extractionResults.xml"
$scriptsToTest | Export-Clixml -Path "scriptsToTest.xml"
$extractedScriptResults | Export-Clixml -Path "extractedScriptResults.xml"

}

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

if ($PesterConfiguration.Run.PassThru.Value -eq $true) {
return $moduleResults, $extractionResults, $scriptsToTest, $extractedScriptResults
}
else {
Write-Error "Unable to pass back result objects. Passthru not enabled in Pester Configuration object"
}

}

}
4 changes: 3 additions & 1 deletion Source/Tests/Unit/Invoke-PSQualityCheck.Tests.ps1
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
Describe "Invoke-PSQualityCheck.Tests" {

Context "Parameter Tests" -Foreach @(
Context "Parameter Tests" -ForEach @(
@{ 'Name' = 'Path'; 'Type' = 'String[]'; 'MandatoryFlag' = $true; 'ParameterSet' = 'Path' }
@{ 'Name' = 'File'; 'Type' = 'String[]'; 'MandatoryFlag' = $true; 'ParameterSet' = 'File' }
@{ 'Name' = 'SonarQubeRulesPath'; 'Type' = 'String'; 'MandatoryFlag' = $false; 'ParameterSet' = '__AllParameterSets' }
@{ 'Name' = 'ShowCheckResults'; 'Type' = 'SwitchParameter'; 'MandatoryFlag' = $false; 'ParameterSet' = '__AllParameterSets' }
@{ 'Name' = 'ExportCheckResults'; 'Type' = 'SwitchParameter'; 'MandatoryFlag' = $false; 'ParameterSet' = '__AllParameterSets' }
@{ 'Name' = 'Passthru'; 'Type' = 'SwitchParameter'; 'MandatoryFlag' = $false; 'ParameterSet' = '__AllParameterSets' }
@{ 'Name' = 'Recurse'; 'Type' = 'SwitchParameter'; 'MandatoryFlag' = $false; 'ParameterSet' = 'Path' }
) {

Expand Down

0 comments on commit 072ffde

Please sign in to comment.