-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
$projectRoot = Resolve-Path "$PSScriptRoot\.." | ||
$moduleName = Split-Path $projectRoot -Leaf | ||
$moduleRoot = Split-Path (Resolve-Path "$projectRoot\$moduleName\*.psm1") | ||
|
||
Describe "General project validation: $moduleName" { | ||
|
||
$scripts = Get-ChildItem $projectRoot -Include *.ps1,*.psm1,*.psd1 -Recurse | ||
|
||
# TestCases are splatted to the script so we need hashtables | ||
$testCase = $scripts | Foreach-Object{@{file=$_}} | ||
It "Script <file> should be valid powershell" -TestCases $testCase { | ||
param($file) | ||
|
||
$file.fullname | Should Exist | ||
|
||
$contents = Get-Content -Path $file.fullname -ErrorAction Stop | ||
$errors = $null | ||
$null = [System.Management.Automation.PSParser]::Tokenize($contents, [ref]$errors) | ||
$errors.Count | Should Be 0 | ||
} | ||
|
||
It "Module '$moduleName' can import cleanly" { | ||
{Import-Module (Join-Path $moduleRoot "$moduleName.psd1") -force } | Should Not Throw | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
$projectRoot = Resolve-Path "$PSScriptRoot\.." | ||
$scripts = Get-ChildItem $projectRoot -Include *.ps1,*.psm1,*.psd1 -Recurse | ||
Describe 'Testing against PSSA rules' { | ||
|
||
Context "Checking all files against Powershell ScriptAnalyzer"{ | ||
It "Checking files exists" { | ||
$script.count | Should Not Be 0 | ||
} | ||
It "Checking if Invoke-ScriptAnalyzer exists" { | ||
{ Get-Command Invoke-ScriptAnalyzer -ErrorAction Stop } | Should Not Throw | ||
} | ||
} | ||
|
||
$scriptAnalyzerRules = Get-ScriptAnalyzerRule | Where-Object {$_.RuleName -ne "PSAvoidGlobalVars" -and $_.RuleName -ne "PSAvoidDefaultValueSwitchParameter"} | ||
|
||
foreach($script in $scripts){ | ||
Context "PSSA Standard Rules - $($script.name)" { | ||
forEach ($rule in $scriptAnalyzerRules) { | ||
It "$script Should pass $($rule.RuleName)" { | ||
(Invoke-ScriptAnalyzer -Path $script -IncludeRule $rule).Count | Should Be 0 | ||
} | ||
} | ||
} | ||
} | ||
} |