diff --git a/PSQualityCheck.Functions.psd1 b/PSQualityCheck.Functions.psd1 index 7373004..a7df1a0 100644 --- a/PSQualityCheck.Functions.psd1 +++ b/PSQualityCheck.Functions.psd1 @@ -3,7 +3,7 @@ # # Generated by: Andrew Davidson # -# Generated on: 11/01/2021 +# Generated on: 14/01/2021 # @{ @@ -12,7 +12,7 @@ RootModule = 'PSQualityCheck.Functions.psm1' # Version number of this module. -ModuleVersion = '1.0.10' +ModuleVersion = '1.1.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -102,7 +102,7 @@ PrivateData = @{ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. - Tags = 'powershell', 'powershell-module', 'tests', 'quality', 'quality-check', + Tags = 'powershell', 'powershell-module', 'quality', 'quality-check', 'tests', 'pester', 'pester-tests' # A URL to the license for this module. diff --git a/PSQualityCheck.Functions.psm1 b/PSQualityCheck.Functions.psm1 index d754615..50de042 100644 --- a/PSQualityCheck.Functions.psm1 +++ b/PSQualityCheck.Functions.psm1 @@ -400,8 +400,14 @@ function Get-FileList { .PARAMETER Extension A string containing the extension + .PARAMETER Recurse + A switch specifying whether or not to recursively search the path specified + .EXAMPLE $files = Get-FileList -Path 'c:\folder' -Extension ".ps1" + + .EXAMPLE + $files = Get-FileList -Path 'c:\folder' -Extension ".ps1" -Recurse #> [CmdletBinding()] [OutputType([System.Object[]])] @@ -409,7 +415,9 @@ function Get-FileList { [parameter(Mandatory = $true)] [string]$Path, [parameter(Mandatory = $true)] - [string]$Extension + [string]$Extension, + [parameter(Mandatory = $false)] + [switch]$Recurse ) $Extension = $Extension @@ -418,8 +426,16 @@ function Get-FileList { if (Test-Path -Path $Path) { + $gciSplat = @{ + 'Path' = $Path + 'Exclude' = "*.Tests.*" + } + if ($PSBoundParameters.ContainsKey('Recurse')) { + $gciSplat.Add('Recurse', $true) + } + # Get the list of files - $SelectedFilesArray = Get-ChildItem -Path $Path -Recurse -Exclude "*.Tests.*" | Where-Object { $_.Extension -eq $Extension } | Select-Object -Property FullName + $SelectedFilesArray = Get-ChildItem @gciSplat | Where-Object { $_.Extension -eq $Extension } | Select-Object -Property FullName # Convert to a string array of filenames $SelectedFilesArray | ForEach-Object { $FileNameArray += [string]$_.FullName } diff --git a/PSQualityCheck.psd1 b/PSQualityCheck.psd1 index 3a18c91..e735340 100644 --- a/PSQualityCheck.psd1 +++ b/PSQualityCheck.psd1 @@ -3,7 +3,7 @@ # # Generated by: Andrew Davidson # -# Generated on: 11/01/2021 +# Generated on: 14/01/2021 # @{ @@ -12,7 +12,7 @@ RootModule = 'PSQualityCheck.psm1' # Version number of this module. -ModuleVersion = '1.0.10' +ModuleVersion = '1.1.0' # Supported PSEditions # CompatiblePSEditions = @() @@ -95,7 +95,7 @@ PrivateData = @{ PSData = @{ # Tags applied to this module. These help with module discovery in online galleries. - Tags = 'powershell', 'powershell-module', 'tests', 'quality', 'quality-check', + Tags = 'powershell', 'powershell-module', 'quality', 'quality-check', 'tests', 'pester', 'pester-tests' # A URL to the license for this module. diff --git a/PSQualityCheck.psm1 b/PSQualityCheck.psm1 index 52e30d2..d1dc263 100644 --- a/PSQualityCheck.psm1 +++ b/PSQualityCheck.psm1 @@ -12,6 +12,9 @@ function Invoke-PSQualityCheck { .PARAMETER File A string array containing testable files + .PARAMETER Recurse + A switch specifying whether or not to recursively search the path specified + .PARAMETER SonarQubeRulesPath A path the the external PSScriptAnalyzer rules for SonarQube @@ -23,6 +26,11 @@ function Invoke-PSQualityCheck { This will call the quality checks on single path + .EXAMPLE + Invoke-PSQualityCheck -Path 'C:\Scripts' -Recurse + + This will call the quality checks on single path and sub folders + .EXAMPLE Invoke-PSQualityCheck -Path @('C:\Scripts', 'C:\MoreScripts') @@ -81,6 +89,9 @@ function Invoke-PSQualityCheck { [Parameter(Mandatory = $true, ParameterSetName = "File")] [String[]]$File, + [Parameter(Mandatory = $false, ParameterSetName = "Path")] + [switch]$Recurse, + [Parameter(Mandatory = $false)] [String]$SonarQubeRulesPath, @@ -111,8 +122,15 @@ function Invoke-PSQualityCheck { # Test whether the item is a directory (also tells us if it exists) if (Test-Path -Path $item -PathType Container) { - $scriptsToTest += Get-FileList -Path $item -Extension '.ps1' - $modulesToTest += Get-FileList -Path $item -Extension '.psm1' + $getFileListSplat = @{ + 'Path' = $item + } + if ($PSBoundParameters.ContainsKey('Recurse')) { + $getFileListSplat.Add('Recurse', $true) + } + + $scriptsToTest += Get-FileList @getFileListSplat -Extension '.ps1' + $modulesToTest += Get-FileList @getFileListSplat -Extension '.psm1' } else { diff --git a/Source/Build.Properties.json b/Source/Build.Properties.json index 8c25c5e..9e0a847 100644 --- a/Source/Build.Properties.json +++ b/Source/Build.Properties.json @@ -18,7 +18,7 @@ }, "HelpInfoURI": "https://github.com/andrewrdavidson/PSQualityCheck/wiki", "LicenseUri": "https://github.com/andrewrdavidson/PSQualityCheck/blob/main/LICENSE", - "ModuleVersion": "1.0.10", + "ModuleVersion": "1.1.0", "NestedModules": { "PSQualityCheck": "PSQualityCheck.Functions.psd1", "PSQualityCheck.Functions": null diff --git a/Source/PSQualityCheck.Functions/Get-FileList.ps1 b/Source/PSQualityCheck.Functions/Get-FileList.ps1 index d1e89e1..cc9722e 100644 --- a/Source/PSQualityCheck.Functions/Get-FileList.ps1 +++ b/Source/PSQualityCheck.Functions/Get-FileList.ps1 @@ -12,8 +12,14 @@ function Get-FileList { .PARAMETER Extension A string containing the extension + .PARAMETER Recurse + A switch specifying whether or not to recursively search the path specified + .EXAMPLE $files = Get-FileList -Path 'c:\folder' -Extension ".ps1" + + .EXAMPLE + $files = Get-FileList -Path 'c:\folder' -Extension ".ps1" -Recurse #> [CmdletBinding()] [OutputType([System.Object[]])] @@ -21,7 +27,9 @@ function Get-FileList { [parameter(Mandatory = $true)] [string]$Path, [parameter(Mandatory = $true)] - [string]$Extension + [string]$Extension, + [parameter(Mandatory = $false)] + [switch]$Recurse ) $Extension = $Extension @@ -30,8 +38,16 @@ function Get-FileList { if (Test-Path -Path $Path) { + $gciSplat = @{ + 'Path' = $Path + 'Exclude' = "*.Tests.*" + } + if ($PSBoundParameters.ContainsKey('Recurse')) { + $gciSplat.Add('Recurse', $true) + } + # Get the list of files - $SelectedFilesArray = Get-ChildItem -Path $Path -Recurse -Exclude "*.Tests.*" | Where-Object { $_.Extension -eq $Extension } | Select-Object -Property FullName + $SelectedFilesArray = Get-ChildItem @gciSplat | Where-Object { $_.Extension -eq $Extension } | Select-Object -Property FullName # Convert to a string array of filenames $SelectedFilesArray | ForEach-Object { $FileNameArray += [string]$_.FullName } diff --git a/Source/PSQualityCheck/Invoke-PSQualityCheck.ps1 b/Source/PSQualityCheck/Invoke-PSQualityCheck.ps1 index 7abde27..232a6e7 100644 --- a/Source/PSQualityCheck/Invoke-PSQualityCheck.ps1 +++ b/Source/PSQualityCheck/Invoke-PSQualityCheck.ps1 @@ -12,6 +12,9 @@ function Invoke-PSQualityCheck { .PARAMETER File A string array containing testable files + .PARAMETER Recurse + A switch specifying whether or not to recursively search the path specified + .PARAMETER SonarQubeRulesPath A path the the external PSScriptAnalyzer rules for SonarQube @@ -23,6 +26,11 @@ function Invoke-PSQualityCheck { This will call the quality checks on single path + .EXAMPLE + Invoke-PSQualityCheck -Path 'C:\Scripts' -Recurse + + This will call the quality checks on single path and sub folders + .EXAMPLE Invoke-PSQualityCheck -Path @('C:\Scripts', 'C:\MoreScripts') @@ -81,6 +89,9 @@ function Invoke-PSQualityCheck { [Parameter(Mandatory = $true, ParameterSetName = "File")] [String[]]$File, + [Parameter(Mandatory = $false, ParameterSetName = "Path")] + [switch]$Recurse, + [Parameter(Mandatory = $false)] [String]$SonarQubeRulesPath, @@ -111,8 +122,15 @@ function Invoke-PSQualityCheck { # Test whether the item is a directory (also tells us if it exists) if (Test-Path -Path $item -PathType Container) { - $scriptsToTest += Get-FileList -Path $item -Extension '.ps1' - $modulesToTest += Get-FileList -Path $item -Extension '.psm1' + $getFileListSplat = @{ + 'Path' = $item + } + if ($PSBoundParameters.ContainsKey('Recurse')) { + $getFileListSplat.Add('Recurse', $true) + } + + $scriptsToTest += Get-FileList @getFileListSplat -Extension '.ps1' + $modulesToTest += Get-FileList @getFileListSplat -Extension '.psm1' } else { diff --git a/Source/Tests/Unit/Convert-Help.Tests.ps1 b/Source/Tests/Unit/Convert-Help.Tests.ps1 index bcbbbdc..41bda3e 100644 --- a/Source/Tests/Unit/Convert-Help.Tests.ps1 +++ b/Source/Tests/Unit/Convert-Help.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Convert-Help.Tests" { - Context "Parameter Tests" -Foreach @( + Context "Parameter Tests" -ForEach @( @{ 'Name' = 'Help'; 'Type' = 'String' } ) { @@ -63,7 +63,7 @@ Describe "Convert-Help.Tests" { } - It "should find in help" -ForEach @( + It "should find in help" -Foreach @( @{ 'Token' = '.SYNOPSIS' } @{ 'Token' = '.DESCRIPTION' } @{ 'Token' = '.PARAMETER' } diff --git a/Source/Tests/Unit/Export-FunctionsFromModule.Tests.ps1 b/Source/Tests/Unit/Export-FunctionsFromModule.Tests.ps1 index 84d895b..34a4167 100644 --- a/Source/Tests/Unit/Export-FunctionsFromModule.Tests.ps1 +++ b/Source/Tests/Unit/Export-FunctionsFromModule.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Export-FunctionsFromModule.Tests" { - Context "Parameter Tests" -Foreach @( + Context "Parameter Tests" -ForEach @( @{ 'Name' = 'Path'; 'Type' = 'String' } @{ 'Name' = 'ExtractPath'; 'Type' = 'String' } ) { diff --git a/Source/Tests/Unit/Get-FileContent.Tests.ps1 b/Source/Tests/Unit/Get-FileContent.Tests.ps1 index 93339c4..bf6ece6 100644 --- a/Source/Tests/Unit/Get-FileContent.Tests.ps1 +++ b/Source/Tests/Unit/Get-FileContent.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Get-FileContent.Tests" { - Context "Parameter Tests" -Foreach @( + Context "Parameter Tests" -ForEach @( @{ 'Name' = 'Path'; 'Type' = 'String' } ) { diff --git a/Source/Tests/Unit/Get-FileList.Tests.ps1 b/Source/Tests/Unit/Get-FileList.Tests.ps1 index 9395b59..96f96bc 100644 --- a/Source/Tests/Unit/Get-FileList.Tests.ps1 +++ b/Source/Tests/Unit/Get-FileList.Tests.ps1 @@ -1,8 +1,9 @@ Describe "Get-FileList.Tests" { Context "Parameter Tests" -ForEach @( - @{ 'Name' = 'Path'; 'Type' = 'String' } - @{ 'Name' = 'Extension'; 'Type' = 'String' } + @{ 'Name' = 'Path'; 'Type' = 'String'; 'MandatoryFlag' = $true } + @{ 'Name' = 'Extension'; 'Type' = 'String'; 'MandatoryFlag' = $true } + @{ 'Name' = 'Recurse'; 'Type' = 'SwitchParameter'; 'MandatoryFlag' = $false } ) { BeforeAll { @@ -12,7 +13,7 @@ Describe "Get-FileList.Tests" { It "should have $Name as a mandatory parameter" { (Get-Command -Name $commandletUnderTest).Parameters[$Name].Name | Should -BeExactly $Name - (Get-Command -Name $commandletUnderTest).Parameters[$Name].Attributes.Mandatory | Should -BeTrue + (Get-Command -Name $commandletUnderTest).Parameters[$Name].Attributes.Mandatory | Should -BeExactly $MandatoryFlag } diff --git a/Source/Tests/Unit/Get-FunctionCount.Tests.ps1 b/Source/Tests/Unit/Get-FunctionCount.Tests.ps1 index c3e44f1..869d512 100644 --- a/Source/Tests/Unit/Get-FunctionCount.Tests.ps1 +++ b/Source/Tests/Unit/Get-FunctionCount.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Get-FunctionCount.Tests" { - Context "Parameter Tests" -ForEach @( + Context "Parameter Tests" -Foreach @( @{ 'Name' = 'ModulePath'; 'Type' = 'String' } @{ 'Name' = 'ManifestPath'; 'Type' = 'String' } ) { diff --git a/Source/Tests/Unit/Get-ParsedContent.Tests.ps1 b/Source/Tests/Unit/Get-ParsedContent.Tests.ps1 index 083704a..36d3400 100644 --- a/Source/Tests/Unit/Get-ParsedContent.Tests.ps1 +++ b/Source/Tests/Unit/Get-ParsedContent.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Get-ParsedContent.Tests" { - Context "Parameter Tests" -Foreach @( + Context "Parameter Tests" -ForEach @( @{ 'Name' = 'Content'; 'Type' = 'String' } ) { diff --git a/Source/Tests/Unit/Get-ParsedFile.Tests.ps1 b/Source/Tests/Unit/Get-ParsedFile.Tests.ps1 index 8c2cd1f..bb5d750 100644 --- a/Source/Tests/Unit/Get-ParsedFile.Tests.ps1 +++ b/Source/Tests/Unit/Get-ParsedFile.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Get-ParsedFile.Tests" { - Context "Parameter Tests" -Foreach @( + Context "Parameter Tests" -ForEach @( @{ 'Name' = 'Path'; 'Type' = 'String' } ) { diff --git a/Source/Tests/Unit/Get-ScriptParameter.Tests.ps1 b/Source/Tests/Unit/Get-ScriptParameter.Tests.ps1 index 177a482..7e5f93a 100644 --- a/Source/Tests/Unit/Get-ScriptParameter.Tests.ps1 +++ b/Source/Tests/Unit/Get-ScriptParameter.Tests.ps1 @@ -1,11 +1,11 @@ -Describe "Get-ScriptParameters.Tests" { +Describe "Get-ScriptParameter.Tests" { Context "Parameter Tests" -Foreach @( @{ 'Name' = 'Content'; 'Type' = 'String' } ) { BeforeAll { - $commandletUnderTest = "Get-ScriptParameters" + $commandletUnderTest = "Get-ScriptParameter" } It "should have $Name as a mandatory parameter" { diff --git a/Source/Tests/Unit/Get-TokenComponent.Tests.ps1 b/Source/Tests/Unit/Get-TokenComponent.Tests.ps1 index d41a94b..4c5f9a3 100644 --- a/Source/Tests/Unit/Get-TokenComponent.Tests.ps1 +++ b/Source/Tests/Unit/Get-TokenComponent.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Get-TokenComponent.Tests" { - Context "Parameter Tests" -ForEach @( + Context "Parameter Tests" -Foreach @( @{ 'Name' = 'ParsedContent'; 'Type' = 'Object[]' } @{ 'Name' = 'StartLine'; 'Type' = 'Int32' } ) { diff --git a/Source/Tests/Unit/Get-TokenMarker.Tests.ps1 b/Source/Tests/Unit/Get-TokenMarker.Tests.ps1 index dfd1032..04d90f6 100644 --- a/Source/Tests/Unit/Get-TokenMarker.Tests.ps1 +++ b/Source/Tests/Unit/Get-TokenMarker.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Get-TokenMarker.Tests" { - Context "Parameter Tests" -Foreach @( + Context "Parameter Tests" -ForEach @( @{ 'Name' = 'ParsedContent'; 'Type' = 'Object[]' } @{ 'Name' = 'Type'; 'Type' = 'String' } @{ 'Name' = 'Content'; 'Type' = 'String' } diff --git a/Source/Tests/Unit/Invoke-PSQualityCheck.Tests.ps1 b/Source/Tests/Unit/Invoke-PSQualityCheck.Tests.ps1 index cc7c7d1..5257106 100644 --- a/Source/Tests/Unit/Invoke-PSQualityCheck.Tests.ps1 +++ b/Source/Tests/Unit/Invoke-PSQualityCheck.Tests.ps1 @@ -5,6 +5,7 @@ Describe "Invoke-PSQualityCheck.Tests" { @{ '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' = 'Recurse'; 'Type' = 'SwitchParameter'; 'MandatoryFlag' = $false; 'ParameterSet' = 'Path' } ) { BeforeAll { @@ -18,7 +19,7 @@ Describe "Invoke-PSQualityCheck.Tests" { } - It "should $Name not belong to a parameter set" { + It "should $Name belong to a $ParameterSet parameter set" { (Get-Command -Name $commandletUnderTest).Parameters[$Name].ParameterSets.Keys | Should -Be $ParameterSet diff --git a/Source/Tests/Unit/Test-HelpTokensCountIsValid.Tests.ps1 b/Source/Tests/Unit/Test-HelpTokensCountIsValid.Tests.ps1 index 0ec609e..c8c152c 100644 --- a/Source/Tests/Unit/Test-HelpTokensCountIsValid.Tests.ps1 +++ b/Source/Tests/Unit/Test-HelpTokensCountIsValid.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Test-HelpTokensCountIsValid.Tests" { - Context "Parameter Tests" -Foreach @( + Context "Parameter Tests" -ForEach @( @{ 'Name' = 'HelpTokens'; 'Type' = 'HashTable' } ) { diff --git a/Source/Tests/Unit/Test-HelpTokensParamsMatch.Tests.ps1 b/Source/Tests/Unit/Test-HelpTokensParamsMatch.Tests.ps1 index 091e39d..ee3ae36 100644 --- a/Source/Tests/Unit/Test-HelpTokensParamsMatch.Tests.ps1 +++ b/Source/Tests/Unit/Test-HelpTokensParamsMatch.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Test-HelpTokensParamsMatch.Tests" { - Context "Parameter Tests" -ForEach @( + Context "Parameter Tests" -Foreach @( @{ 'Name' = 'HelpTokens'; 'Type' = 'HashTable' } @{ 'Name' = 'ParameterVariables'; 'Type' = 'PSObject' } ) { diff --git a/Source/Tests/Unit/Test-HelpTokensTextIsValid.Tests.ps1 b/Source/Tests/Unit/Test-HelpTokensTextIsValid.Tests.ps1 index 79f0d00..77bdf2e 100644 --- a/Source/Tests/Unit/Test-HelpTokensTextIsValid.Tests.ps1 +++ b/Source/Tests/Unit/Test-HelpTokensTextIsValid.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Test-HelpTokensTextIsValid.Tests" { - Context "Parameter Tests" -Foreach @( + Context "Parameter Tests" -ForEach @( @{ 'Name' = 'HelpTokens'; 'Type' = 'HashTable' } ) { diff --git a/Source/Tests/Unit/Test-ImportModuleIsValid.Tests.ps1 b/Source/Tests/Unit/Test-ImportModuleIsValid.Tests.ps1 index 699f001..44a9f5a 100644 --- a/Source/Tests/Unit/Test-ImportModuleIsValid.Tests.ps1 +++ b/Source/Tests/Unit/Test-ImportModuleIsValid.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Test-ImportModuleIsValid.Tests" { - Context "Parameter Tests" -Foreach @( + Context "Parameter Tests" -ForEach @( @{ 'Name' = 'ParsedContent'; 'Type' = 'Object[]' } @{ 'Name' = 'ImportModuleTokens'; 'Type' = 'Object[]' } ) { diff --git a/Source/Tests/Unit/Test-ParameterVariablesHaveType.Tests.ps1 b/Source/Tests/Unit/Test-ParameterVariablesHaveType.Tests.ps1 index d342363..37e5690 100644 --- a/Source/Tests/Unit/Test-ParameterVariablesHaveType.Tests.ps1 +++ b/Source/Tests/Unit/Test-ParameterVariablesHaveType.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Test-ParameterVariablesHaveType.Tests" { - Context "Parameter Tests" -Foreach @( + Context "Parameter Tests" -ForEach @( @{ 'Name' = 'ParameterVariables'; 'Type' = 'HashTable' } ) { diff --git a/Source/Tests/Unit/Test-RequiredToken.Tests.ps1 b/Source/Tests/Unit/Test-RequiredToken.Tests.ps1 index 7e3f691..98a6836 100644 --- a/Source/Tests/Unit/Test-RequiredToken.Tests.ps1 +++ b/Source/Tests/Unit/Test-RequiredToken.Tests.ps1 @@ -1,6 +1,6 @@ Describe "Test-RequiredToken.Tests" { - Context "Parameter Tests" -ForEach @( + Context "Parameter Tests" -Foreach @( @{ 'Name' = 'HelpTokens'; 'Type' = 'HashTable' } ) { diff --git a/Source/Tests/Unit/Test-UnspecifiedToken.Tests.ps1 b/Source/Tests/Unit/Test-UnspecifiedToken.Tests.ps1 index 38280db..3191139 100644 --- a/Source/Tests/Unit/Test-UnspecifiedToken.Tests.ps1 +++ b/Source/Tests/Unit/Test-UnspecifiedToken.Tests.ps1 @@ -1,11 +1,11 @@ Describe "Test-UnspecifiedToken.Tests" { - Context "Parameter Tests" -ForEach @( + Context "Parameter Tests" -Foreach @( @{ 'Name' = 'HelpTokens'; 'Type' = 'HashTable' } ) { BeforeAll { - $commandletUnderTest = "Test-HelpForUnspecifiedTokens" + $commandletUnderTest = "Test-UnspecifiedToken" } It "should have $Name as a mandatory parameter" {