Skip to content

Commit 18156d9

Browse files
author
quoctruong
committed
Merge pull request #28 from PowerShell/FixTestFailures
Fix test failures
2 parents c530148 + b2cdae3 commit 18156d9

File tree

51 files changed

+205
-210
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+205
-210
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+
}

Tests/Rules/AvoidUsingFilePath.tests.ps1 renamed to Tests/Disabled Rules/AvoidUsingFilePath.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Import-Module ScriptAnalyzer
1+
Import-Module PSScriptAnalyzer
22
$violationMessage = @'
33
The file path "D:\\Code" of AvoidUsingFilePath.ps1 is rooted. This should be avoided if AvoidUsingFilePath.ps1 is published online
44
'@

0 commit comments

Comments
 (0)