Skip to content

Commit e10ff30

Browse files
committed
Merge pull request #57 from PowerShell/TestFix
Fix test failure issue
2 parents 1bf5b9c + bdaa53d commit e10ff30

5 files changed

+15
-14
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PSScriptAnalyzer is shipped with a collection of built-in rules that checks vari
88
PSScriptAnalyzer cmdlets
99
======================
1010
```
11-
Get-ScriptAnalyzerRule [-CustomizedRulePath <string[]>] [-Name <string[]>] [<CommonParameters>]
11+
Get-ScriptAnalyzerRule [-CustomizedRulePath <string[]>] [-Name <string[]>] [<CommonParameters>] [-Severity <string[]>]
1212
1313
Invoke-ScriptAnalyzer [-Path] <string> [-CustomizedRulePath <string[]>] [-ExcludeRule <string[]>] [-IncludeRule <string[]>] [-Severity <string[]>] [-Recurse] [<CommonParameters>]
1414
```
@@ -46,6 +46,7 @@ Pester-based ScriptAnalyzer Tests are located in ```<branch>/PSScriptAnalyzer/Te
4646
.\InvokeScriptAnalyzer.tests.ps1
4747
* Run Tests for Built-in rules:
4848
.\*.ps1 (Example - .\ AvoidConvertToSecureStringWithPlainText.ps1)
49+
*You can also run all tests under \Engine or \Rules by calling Invoke-Pester in the Engine/Rules directory.
4950

5051

5152
Contributing to ScriptAnalyzer

Rules/AvoidUsingInternalURLs.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,12 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
113113
}
114114
if (!firstPartURL.Contains("."))
115115
{
116+
isInternalURL = true;
116117
//Add a check to exclude potential SDDL format. Check if a string have four components separated by ":"
117118
var count = firstPartURL.Count(x => x == ':');
118119
if (count == 3 || count == 4 )
119120
{
120-
isInternalURL = true;
121+
isInternalURL = false;
121122
}
122123
}
123124
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
function Get-Service
2-
{
3-
param ([string]$c)
4-
}
5-
6-
function Get-MyObject{
1+
function Set-MyObject{
72
[CmdletBinding(SupportsShouldProcess = $false)]
83
param([string]$c, [int]$d)
94

105
}
116

7+
function Set-MyObject{
8+
[CmdletBinding()]
9+
param([string]$c, [int]$d)
10+
11+
}

Tests/Rules/UseShouldProcessForStateChangingFunctions.tests.ps1

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
Import-Module PSScriptAnalyzer
2-
$violationMessage = "Function ’Get-Service’ has verb that could change system state. Therefore, the function has to support 'ShouldProcess'"
2+
$violationMessage = "Function ’Set-MyObject’ has verb that could change system state. Therefore, the function has to support 'ShouldProcess'"
33
$violationName = "PSUseShouldProcessForStateChangingFunctions"
4-
$violationName = "PS.UseShouldProcessForStateChangingFunctions"
54
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
65
$violations = Invoke-ScriptAnalyzer $directory\UseShouldProcessForStateChangingFunctions.ps1 | Where-Object {$_.RuleName -eq $violationName}
76
$noViolations = Invoke-ScriptAnalyzer $directory\UseShouldProcessForStateChangingFunctionsNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}
87

9-
Describe "" {
8+
Describe "It checks UseShouldProcess is enabled when there are state changing verbs in the function names" {
109
Context "When there are violations" {
1110
It "has 2 violations where ShouldProcess is not supported" {
12-
$violations.Count | Should Be 3
11+
$violations.Count | Should Be 2
1312
}
1413

1514
It "has the correct description message" {

Tests/Rules/UseShouldProcessForStateChangingFunctionsNoViolations.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
function Get-Service
1+
function Set-Service
22
{
3-
[CmdletBinding(SupportShouldSuppress= $false)]
3+
[CmdletBinding(SupportsShouldProcess = $true)]
44
param ([string]$c)
55
}
66

0 commit comments

Comments
 (0)