Skip to content

Add Tests for UseShouldProcessForStateChangingFunctions #35

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 2 commits into from
Apr 16, 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
11 changes: 11 additions & 0 deletions Tests/Rules/UseShouldProcessForStateChangingFunctions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
function Get-Service
{
param ([string]$c)
}

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

}

25 changes: 25 additions & 0 deletions Tests/Rules/UseShouldProcessForStateChangingFunctions.tests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Import-Module PSScriptAnalyzer
$violationMessage = "Function ’Get-Service’ 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 "" {
Context "When there are violations" {
It "has 2 violations where ShouldProcess is not supported" {
$violations.Count | Should Be 3
}

It "has the correct description message" {
$violations[0].Message | Should Match $violationMessage
}
}

Context "When there are no violations" {
It "returns no violations" {
$noViolations.Count | Should Be 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
function Get-Service
{
[CmdletBinding(SupportShouldSuppress= $false)]
param ([string]$c)
}

function Test-GetMyObject{

param([string]$c, [int]$d)

}