-
-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathTest-PSBuildScriptAnalysis.tests.ps1
More file actions
57 lines (48 loc) · 1.97 KB
/
Test-PSBuildScriptAnalysis.tests.ps1
File metadata and controls
57 lines (48 loc) · 1.97 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
Describe 'Test-PSBuildScriptAnalysis' {
BeforeAll {
Set-StrictMode -Version Latest
. (Join-Path -Path $PSScriptRoot -ChildPath '../PowerShellBuild/Public/Test-PSBuildScriptAnalysis.ps1')
$script:LocalizedData = @{
SeverityThresholdSetTo = 'Severity threshold set to {0}'
PSScriptAnalyzerResults = 'PSScriptAnalyzer results'
ScriptAnalyzerErrors = 'ScriptAnalyzer errors found'
ScriptAnalyzerWarnings = 'ScriptAnalyzer warnings found'
ScriptAnalyzerIssues = 'ScriptAnalyzer issues found'
}
}
It 'calls Invoke-ScriptAnalyzer with the provided settings path' {
Mock -CommandName Invoke-ScriptAnalyzer -MockWith {
@()
}
Test-PSBuildScriptAnalysis -Path 'function Test-Me { "ok" }' -SeverityThreshold Error -SettingsPath 'tests/ScriptAnalyzerSettings.psd1'
Should -Invoke -CommandName Invoke-ScriptAnalyzer -Times 1 -Exactly -ParameterFilter {
$Path -eq 'function Test-Me { "ok" }' -and
$Settings -eq 'tests/ScriptAnalyzerSettings.psd1' -and
$Recurse
}
}
It 'passes when no results are returned at Error threshold' {
Mock -CommandName Invoke-ScriptAnalyzer -MockWith {
@()
}
{
Test-PSBuildScriptAnalysis -Path 'function Test-Me { "ok" }' -SeverityThreshold Error
} | Should -Not -Throw
}
It 'fails when an error is returned at Error threshold' {
Mock -CommandName Invoke-ScriptAnalyzer -MockWith {
@(
[pscustomobject]@{
Severity = 'Error'
RuleName = 'TestRule'
ScriptName = 'inline.ps1'
Message = 'Boom'
Line = 1
}
)
}
{
Test-PSBuildScriptAnalysis -Path 'function Test-Me { "ok" }' -SeverityThreshold Error
} | Should -Throw
}
}