Skip to content

Fix test failure issue #57

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PSScriptAnalyzer is shipped with a collection of built-in rules that checks vari
PSScriptAnalyzer cmdlets
======================
```
Get-ScriptAnalyzerRule [-CustomizedRulePath <string[]>] [-Name <string[]>] [<CommonParameters>]
Get-ScriptAnalyzerRule [-CustomizedRulePath <string[]>] [-Name <string[]>] [<CommonParameters>] [-Severity <string[]>]

Invoke-ScriptAnalyzer [-Path] <string> [-CustomizedRulePath <string[]>] [-ExcludeRule <string[]>] [-IncludeRule <string[]>] [-Severity <string[]>] [-Recurse] [<CommonParameters>]
```
Expand Down Expand Up @@ -46,6 +46,7 @@ Pester-based ScriptAnalyzer Tests are located in ```<branch>/PSScriptAnalyzer/Te
.\InvokeScriptAnalyzer.tests.ps1
* Run Tests for Built-in rules:
.\*.ps1 (Example - .\ AvoidConvertToSecureStringWithPlainText.ps1)
*You can also run all tests under \Engine or \Rules by calling Invoke-Pester in the Engine/Rules directory.


Contributing to ScriptAnalyzer
Expand Down
3 changes: 2 additions & 1 deletion Rules/AvoidUsingInternalURLs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,12 @@ public IEnumerable<DiagnosticRecord> AnalyzeScript(Ast ast, string fileName)
}
if (!firstPartURL.Contains("."))
{
isInternalURL = true;
//Add a check to exclude potential SDDL format. Check if a string have four components separated by ":"
var count = firstPartURL.Count(x => x == ':');
if (count == 3 || count == 4 )
{
isInternalURL = true;
isInternalURL = false;
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions Tests/Rules/UseShouldProcessForStateChangingFunctions.ps1
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
function Get-Service
{
param ([string]$c)
}

function Get-MyObject{
function Set-MyObject{
[CmdletBinding(SupportsShouldProcess = $false)]
param([string]$c, [int]$d)

}

function Set-MyObject{
[CmdletBinding()]
param([string]$c, [int]$d)

}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
Import-Module PSScriptAnalyzer
$violationMessage = "Function ’Get-Service’ has verb that could change system state. Therefore, the function has to support 'ShouldProcess'"
$violationMessage = "Function ’Set-MyObject’ has verb that could change system state. Therefore, the function has to support 'ShouldProcess'"
$violationName = "PSUseShouldProcessForStateChangingFunctions"
$violationName = "PS.UseShouldProcessForStateChangingFunctions"
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
$violations = Invoke-ScriptAnalyzer $directory\UseShouldProcessForStateChangingFunctions.ps1 | Where-Object {$_.RuleName -eq $violationName}
$noViolations = Invoke-ScriptAnalyzer $directory\UseShouldProcessForStateChangingFunctionsNoViolations.ps1 | Where-Object {$_.RuleName -eq $violationName}

Describe "" {
Describe "It checks UseShouldProcess is enabled when there are state changing verbs in the function names" {
Context "When there are violations" {
It "has 2 violations where ShouldProcess is not supported" {
$violations.Count | Should Be 3
$violations.Count | Should Be 2
}

It "has the correct description message" {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function Get-Service
function Set-Service
{
[CmdletBinding(SupportShouldSuppress= $false)]
[CmdletBinding(SupportsShouldProcess = $true)]
param ([string]$c)
}

Expand Down