tests/_scriptAnalyer.tests.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
$here = (Split-Path -Parent $MyInvocation.MyCommand.Path).Replace('tests', '') $scriptsModules = Get-ChildItem $here -Include *.psd1, *.psm1, *.ps1 -Exclude *.tests.ps1 -Recurse Describe 'General - Testing all scripts and modules against the Script Analyzer Rules' { Context "Checking files to test exist and Invoke-ScriptAnalyzer cmdLet is available" { It "Checking files exist to test." { $scriptsModules.count | Should Not Be 0 } It "Checking Invoke-ScriptAnalyzer exists." { { Get-Command Invoke-ScriptAnalyzer -ErrorAction Stop } | Should Not Throw } } $scriptAnalyzerRules = Get-ScriptAnalyzerRule forEach ($scriptModule in $scriptsModules) { switch -wildCard ($scriptModule) { '*.psm1' { $typeTesting = 'Module' } '*.ps1' { $typeTesting = 'Script' } '*.psd1' { $typeTesting = 'Manifest' } } Context "Checking $typeTesting – $($scriptModule) - conforms to Script Analyzer Rules" { forEach ($scriptAnalyzerRule in $scriptAnalyzerRules) { It "Script Analyzer Rule $scriptAnalyzerRule" { (Invoke-ScriptAnalyzer -Path $scriptModule -IncludeRule $scriptAnalyzerRule).count | Should Be 0 } } } } } |