Skip to content

Commit b2cdae3

Browse files
author
quoctruong
committed
Put test cases for disabled rule in a separate folder
1 parent cb5680a commit b2cdae3

22 files changed

+134
-127
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Import-Module PSScriptAnalyzer
2+
$oneCharMessage = "The cmdlet name O only has one character."
3+
$oneCharName = "PSOneChar"
4+
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
5+
$invoke = Invoke-ScriptAnalyzer $directory\AvoidUsingReservedCharOneCharNames.ps1 | Where-Object {$_.RuleName -eq $oneCharName}
6+
$noViolations = Invoke-ScriptAnalyzer $directory\GoodCmdlet.ps1 | Where-Object {$_.RuleName -eq $oneCharName}
7+
8+
Describe "Avoid Using One Char" {
9+
Context "When there are violations" {
10+
It "has 1 One Char Violation" {
11+
$oneCharViolations.Count | Should Be 1
12+
}
13+
14+
It "has the correct description message" {
15+
$oneCharViolations[0].Message | Should Match $oneCharMessage
16+
}
17+
}
18+
19+
Context "When there are no violations" {
20+
It "has no violations" {
21+
$noReservedCharViolations.Count | Should Be 0
22+
}
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Import-Module PSScriptAnalyzer
2+
$unloadableMessage = [regex]::Escape("Cannot load the module TestBadModule that the file TestBadModule.psd1 is in.")
3+
$unloadableName = "PSAvoidUnloadableModule"
4+
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
5+
$violations = Invoke-ScriptAnalyzer $directory\TestBadModule\TestBadModule.psd1 | Where-Object {$_.RuleName -eq $unloadableName}
6+
$noViolations = Invoke-ScriptAnalyzer $directory\TestGoodModule\TestGoodModule.psd1 | Where-Object {$_.RuleName -eq $unloadableName}
7+
8+
Describe "AvoidUnloadableModule" {
9+
Context "When there are violations" {
10+
It "has 1 unloadable module violation" {
11+
$violations.Count | Should Be 1
12+
}
13+
14+
It "has the correct description message" {
15+
$violations.Message | Should Match $unloadableMessage
16+
}
17+
}
18+
19+
Context "When there are no violations" {
20+
It "returns no violations" {
21+
$noViolations.Count | Should Be 0
22+
}
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Import-Module PSScriptAnalyzer
2+
Set-Alias ctss ConvertTo-SecureString
3+
$clearHostMessage = "File 'AvoidUsingClearHostWriteHost.ps1' uses Clear-Host. This is not recommended because it may not work in some hosts or there may even be no hosts at all."
4+
$clearHostName = "PSAvoidUsingClearHost"
5+
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
6+
$violations = Invoke-ScriptAnalyzer $directory\AvoidUsingClearHost.ps1 | Where-Object {$_.RuleName -eq $clearHostName}
7+
$noViolations = Invoke-ScriptAnalyzer $directory\AvoidUsingClearHostNoViolations.ps1 | Where-Object {$_.RuleName -eq $writeHostName}
8+
9+
Describe "AvoidUsingClearHost" {
10+
Context "When there are violations" {
11+
It "has 3 Clear-Host violations" {
12+
$violations.Count | Should Be 3
13+
}
14+
15+
It "has the correct description message for Clear-Host" {
16+
$violations[0].Message | Should Match $clearHostMessage
17+
}
18+
}
19+
20+
Context "When there are no violations" {
21+
It "returns no violations" {
22+
$noViolations.Count | Should Be 0
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)