Tests/cMDTBuildLab.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
#region Variables
$Rules = Get-ScriptAnalyzerRule | Where-Object RuleName -NotIn @('PSUseShouldProcessForStateChangingFunctions','PSAvoidUsingWMICmdlet')
#endregion

$modules = Get-ChildItem -Path $PSScriptRoot\.. -Include 'cMDTBuildLab*'
$modules += Get-ChildItem -Path $PSScriptRoot\..\Deploy -Recurse -Include @('*.ps1','*.psd1')
$modules += Get-ChildItem -Path $PSScriptRoot\..\Examples -Recurse -Include @('*.ps1','*.psd1')
$modules += Get-ChildItem -Path $PSScriptRoot\..\Sources -Recurse -Include @('*.ps1','*.psd1')
$modules += Get-ChildItem -Path $PSScriptRoot\..\Tests -Recurse -Include @('*.ps1','*.psd1')

Describe 'Script analyzer rule: ' {
    foreach ($module in $modules) {
        foreach ($rule in $rules) {
            It "$($module.Name) Passes the `"$($rule.CommonName)`" validation" {
                $output = $null
                $results = Invoke-ScriptAnalyzer -Path $module.FullName -IncludeRule $Rule.RuleName
                if ($results.count -eq 1) {
                    $output = "$($results.Message) at line $($results.Line)"
                }
                elseif ($results.count -gt 1) {
                    foreach ($result in $results) {
                        $output += "$($result.Message) at line $($result.Line)`r`n"
                    }
                }
                $output | should be $null
            }
        }
    }
}