Skip to content
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

Pester v5 #1444

Merged
merged 85 commits into from Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
85 commits
Select commit Hold shift + click to select a range
2811ab7
Replace usage of $MyInvocation.MyCommand.Pat with $PSScriptRoot and c…
Apr 12, 2020
d4f54f5
Fix 2 small mistakes, test should now be green again
Apr 12, 2020
eeb251f
Adapt build.psm1
Apr 12, 2020
36d213a
Engine tests migration to Pester v5
Apr 12, 2020
b25714d
use pester v5 in ci and always upload test results
Apr 12, 2020
a498236
Upgrade Rule tests to Pester v5 using BeforeAll block and addressing …
Apr 12, 2020
765aad3
-AllowPrerelease
Apr 12, 2020
7a67f0e
try bootstrap in wmf4
Apr 12, 2020
9d17571
fix invoke-pester call in CI
Apr 12, 2020
2de4c20
fix CorrectionExtent.tests.ps1
Apr 12, 2020
a10983e
fix Helper.tests.ps1
Apr 12, 2020
c6dd640
Fix remaining tests with BeforeAll/AfterAll (discovery works now)
Apr 13, 2020
35ed07c
fix UseUsingScopeModifierInNewRunspaces.tests.ps1
Apr 13, 2020
a350f2b
make test cases more readable
Apr 13, 2020
5350e87
cleanup UseUsingScopeModifierInNewRunspaces.tests.ps1
Apr 13, 2020
f2e37f3
Fix UseShouldProcessForStateChangingFunctions.tests.ps1
Apr 13, 2020
2a9fa9f
cleanup UseShouldProcessForStateChangingFunctions.tests.ps1
Apr 13, 2020
a5df593
Fix PSCompatibilityCollector/Tests/UtilityApi.Tests.ps1
Apr 13, 2020
b6e6fda
Fix InvokeScriptAnalyzer.tests.ps1
Apr 13, 2020
bce0a88
Format InvokeScriptAnalyzer.tests.ps1
Apr 13, 2020
afb1b98
Fix ModuleHelp.Tests.ps1 and cleanup
Apr 13, 2020
3413419
Fix RuleSuppression.tests.ps1
Apr 13, 2020
350f840
Fix Settings.tests.ps1
Apr 13, 2020
6bdf977
format Settings.tests.ps1
Apr 13, 2020
f5ef381
Fix Tests/Engine/TextEdit.tests.ps1 and format
Apr 13, 2020
184081f
Fix AllCompatibilityRules.Tests.ps1
Apr 13, 2020
8c43725
Fix AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1
Apr 13, 2020
be4b0a2
Format AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps…
Apr 13, 2020
51a9fa9
Fix AvoidUsingPlainTextForPassword.tests.ps1
Apr 13, 2020
78ff1ab
fix place*brace tests
Apr 13, 2020
d7f3f9a
Format brace tests and fix PSCredentialType.tests.ps1
Apr 13, 2020
23de9a7
Fix UseCompatibleCommands.Tests.ps1
Apr 13, 2020
b571e31
Fix UseCompatibleSyntax.Tests.ps1
Apr 13, 2020
355658f
Fix UseCompatibleTypes.Tests.ps1
Apr 13, 2020
6314002
Fix UseCompatibleCmdlets.tests.ps1
Apr 13, 2020
0346659
Fix variable clash between compatibility tests that were not in Befor…
Apr 13, 2020
28e77e8
Fix LibraryUsage.tests.ps1 teardown syntax
Apr 13, 2020
d86a32b
Fix LibraryUsage.tests.ps1
Apr 14, 2020
9cd193d
rc3 for wmf4
Apr 14, 2020
6831297
Properly execute library tests and cleanup CustomizedRule.tests.ps1
Apr 15, 2020
9adf595
tidy up
Apr 15, 2020
75da17e
cleanup module imports and only import once at the root
Apr 15, 2020
2ca286d
Fix 5 of 6 v4 tests and add logging to better understand modulehelp f…
Apr 16, 2020
c6f6ab0
remove test-psversion functions and fix v3 or v4 checks
Apr 16, 2020
391c015
Fix ModuleHelp.Tests.ps1 for v4 and cleanup
Apr 16, 2020
a42bba2
Really fix ModuleHelp.Tests.ps1 on v4 and cleanup invoke-pester calls
Apr 16, 2020
eabcb6c
add debugging as to why there is no TestResults.xml on Ubuntu
Apr 16, 2020
4deff83
fix yaml
Apr 16, 2020
1fde869
fix test file upload on Ubuntu (casing) and ensure test file always g…
Apr 16, 2020
d23ed36
Merge branch 'master' of https://github.com/powershell/psscriptanalyz…
Apr 16, 2020
30f9ed9
Merge branch 'master' of https://github.com/powershell/psscriptanalyz…
Apr 16, 2020
1e9d3cb
move appveyor upload back
Apr 16, 2020
adf4c1e
move appveyor into finally
Apr 16, 2020
738e528
Merge branch 'master' of https://github.com/powershell/psscriptanalyz…
Apr 17, 2020
54dcafd
fix merge error to make install pester v5 again
Apr 17, 2020
2b852f2
Merge branch 'master' of https://github.com/powershell/psscriptanalyz…
Apr 18, 2020
af25ec0
Pester rc4
Apr 20, 2020
a331b5d
Update to rc5
bergmeister Apr 24, 2020
7cc976c
Pull in changes from master and resolve trivial merge conflict
Apr 24, 2020
314e7d0
Merge branch 'pesterv5PoC' of https://github.com/bergmeister/psscript…
Apr 24, 2020
0c3af3b
cleanup ci run
Apr 25, 2020
c3dd5a1
Merge branch 'master' of https://github.com/powershell/psscriptanalyz…
Apr 30, 2020
ea721fe
rc6
bergmeister May 4, 2020
4fd600f
rc7
bergmeister May 12, 2020
de8889b
rc8
bergmeister May 14, 2020
53f1f0b
Update appveyor.psm1
bergmeister May 16, 2020
98fdaf5
Merge branch 'master' of https://github.com/powershell/PSScriptAnalyz…
May 16, 2020
4b4a976
don't use -CI switch for local build and disable code coverage in CI
May 16, 2020
e6d1497
import pester module before running tests to import types
May 16, 2020
1dff12d
fix property name
May 16, 2020
1bd9e96
actually use configuration object (doh)
May 16, 2020
b683115
config object
May 16, 2020
edfbd10
fix output verbosity
May 16, 2020
570d287
fix type casting of [string[]] of pester paths
May 16, 2020
8baab13
pester 5 GA
May 27, 2020
752307e
Merge branch 'master' of https://github.com/powershell/psscriptanalyz…
May 27, 2020
b4eb871
Pester 5.0.2
bergmeister Jun 2, 2020
932ca10
move testcases declaration before test
Jun 7, 2020
b540737
remove left-over comments
Jun 7, 2020
ea23a46
remove unnecessary [bool] in if condition
Jun 7, 2020
6a44a18
simplify version check to not require [version] type and patch version
Jun 7, 2020
5ee8a38
fix missing whitespace in test that made test invalid
Jun 7, 2020
1619ad8
empty commit since Azure Pipelines did not trigger
Jun 7, 2020
6a13f04
empty commit since Azure Pipelines did not trigger again
Jun 7, 2020
3b21278
empty commit since Azure Pipelines did not trigger again
Jun 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .azure-pipelines-ci/templates/test-powershell.yaml
Expand Up @@ -15,5 +15,5 @@ steps:
- task: PublishTestResults@2
inputs:
testRunner: NUnit
testResultsFiles: 'TestResults.xml'
testResultsFiles: 'testResults.xml'
condition: succeededOrFailed()
247 changes: 113 additions & 134 deletions PSCompatibilityCollector/Tests/UtilityApi.Tests.ps1

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -108,7 +108,7 @@ Note: the PSScriptAnalyzer Chocolatey package is provided and supported by the c
#### Requirements

* [.NET Core 3.1.102 SDK](https://www.microsoft.com/net/download/dotnet-core/3.1#sdk-3.1.102) or newer patch release
* [Pester v4 PowerShell module, available on PowerShell Gallery](https://github.com/pester/Pester)
* [Pester v5 PowerShell module, available on PowerShell Gallery](https://github.com/pester/Pester)
* [PlatyPS PowerShell module, available on PowerShell Gallery](https://github.com/PowerShell/platyPS/releases)
* Optionally but recommended for development: [Visual Studio 2017/2019](https://www.visualstudio.com/downloads/)

Expand Down
3 changes: 1 addition & 2 deletions Tests/DisabledRules/UseTypeAtVariableAssignment.tests.ps1
@@ -1,5 +1,4 @@
Import-Module -Verbose PSScriptAnalyzer
$violationMessage = [regex]::Escape('Specify type at the assignment of variable $test')
$violationMessage = [regex]::Escape('Specify type at the assignment of variable $test')
$violationName = "PSUseTypeAtVariableAssignment"
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
$violations = Invoke-ScriptAnalyzer $directory\UseTypeAtVariableAssignment.ps1 | Where-Object {$_.RuleName -eq $violationName}
Expand Down
6 changes: 4 additions & 2 deletions Tests/Engine/CorrectionExtent.tests.ps1
@@ -1,8 +1,10 @@
Describe "Correction Extent" {
$type = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "Correction Extent" {
Context "Object construction" {
It "creates the object with correct properties" {
$type = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]
$correctionExtent = $obj = New-Object -TypeName $type -ArgumentList 1, 1, 1, 3, "get-childitem", "newfile", "cool description"

$correctionExtent.StartLineNumber | Should -Be 1
Expand Down
93 changes: 49 additions & 44 deletions Tests/Engine/CustomizedRule.tests.ps1
@@ -1,23 +1,27 @@
if (-not $IsCoreCLR)
{
# Force Get-Help not to prompt for interactive input to download help using Update-Help
# By adding this registry key we turn off Get-Help interactivity logic during ScriptRule parsing
$null,"Wow6432Node" | ForEach-Object {
try
{
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue
}
catch
{
# Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

BeforeAll {
if (-not $IsCoreCLR)
{
# Force Get-Help not to prompt for interactive input to download help using Update-Help
# By adding this registry key we turn off Get-Help interactivity logic during ScriptRule parsing
$null,"Wow6432Node" | ForEach-Object {
try
{
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue
}
catch
{
# Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
}
}
}
$message = "this is help"
$measure = "Measure-RequiresRunAsAdministrator"
}


$message = "this is help"
$measure = "Measure-RequiresRunAsAdministrator"

Describe "Test importing customized rules with null return results" {
Context "Test Get-ScriptAnalyzer with customized rules" {
It "will not terminate the engine" {
Expand All @@ -38,40 +42,40 @@ Describe "Test importing customized rules with null return results" {

Describe "Test importing correct customized rules" {

if(-not $IsCoreCLR)
{
Context "Test Get-Help functionality in ScriptRule parsing logic" {
It "ScriptRule help section must be correctly processed when Get-Help is called for the first time" {

# Force Get-Help to prompt for interactive input to download help using Update-Help
# By removing this registry key we force to turn on Get-Help interactivity logic during ScriptRule parsing
$null,"Wow6432Node" | ForEach-Object {
try
{
Remove-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -ErrorAction Stop
} catch {
#Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
}
# if(-not ([bool] $IsCoreCLR))
# {
bergmeister marked this conversation as resolved.
Show resolved Hide resolved
Context "Test Get-Help functionality in ScriptRule parsing logic" -Skip:$IsCoreCLR {
It "ScriptRule help section must be correctly processed when Get-Help is called for the first time" {

# Force Get-Help to prompt for interactive input to download help using Update-Help
# By removing this registry key we force to turn on Get-Help interactivity logic during ScriptRule parsing
$null,"Wow6432Node" | ForEach-Object {
try
{
Remove-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -ErrorAction Stop
} catch {
#Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
}
}

$customizedRulePath = Invoke-ScriptAnalyzer $PSScriptRoot\TestScript.ps1 -CustomizedRulePath $PSScriptRoot\samplerule\samplerule.psm1 | Where-Object {$_.Message -eq $message}
$customizedRulePath.Count | Should -Be 1
$customizedRulePath = Invoke-ScriptAnalyzer $PSScriptRoot\TestScript.ps1 -CustomizedRulePath $PSScriptRoot\samplerule\samplerule.psm1 | Where-Object {$_.Message -eq $message}
$customizedRulePath.Count | Should -Be 1

# Force Get-Help not to prompt for interactive input to download help using Update-Help
# By adding this registry key we turn off Get-Help interactivity logic during ScriptRule parsing
$null,"Wow6432Node" | ForEach-Object {
try
{
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -EA SilentlyContinue
}
catch
{
# Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
}
# Force Get-Help not to prompt for interactive input to download help using Update-Help
# By adding this registry key we turn off Get-Help interactivity logic during ScriptRule parsing
$null,"Wow6432Node" | ForEach-Object {
try
{
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -EA SilentlyContinue
}
catch
{
# Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
}
}
}
}
# }

Context "Test Get-ScriptAnalyzer with customized rules" {
It "will show the custom rule" {
Expand Down Expand Up @@ -197,8 +201,9 @@ Describe "Test importing correct customized rules" {
$violations[0].RuleSuppressionID | Should -Be "MyRuleSuppressionID"
}

if (!$testingLibraryUsage)
{
# if (!$testingLibraryUsage)
# {
bergmeister marked this conversation as resolved.
Show resolved Hide resolved
Context "Test Invoke-ScriptAnalyzer with customized rules - Advanced test cases" -Skip:$testingLibraryUsage {
It "will show the custom rule in the results when given a rule folder path with trailing backslash" {
# needs fixing for Linux
if (!$IsLinux -and !$IsMacOS)
Expand Down
13 changes: 9 additions & 4 deletions Tests/Engine/EditableText.tests.ps1
@@ -1,7 +1,12 @@
$testRootDirectory = Split-Path -Parent $PSScriptRoot
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
$editableTextType = "Microsoft.Windows.PowerShell.ScriptAnalyzer.EditableText"
$textEditType = "Microsoft.Windows.PowerShell.ScriptAnalyzer.TextEdit"
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

BeforeAll {
$testRootDirectory = Split-Path -Parent $PSScriptRoot
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
$editableTextType = "Microsoft.Windows.PowerShell.ScriptAnalyzer.EditableText"
$textEditType = "Microsoft.Windows.PowerShell.ScriptAnalyzer.TextEdit"
}

Describe "EditableText class" {
Context "When a single edit is given for application" {
Expand Down
54 changes: 30 additions & 24 deletions Tests/Engine/Extensions.tests.ps1
@@ -1,30 +1,36 @@
$testRootDirectory = Split-Path -Parent $PSScriptRoot
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")

function Get-Extent {
param($line, $startLineNum, $startColumnNum, $endLineNum, $endColumnNum)
$scriptPositionType = 'System.Management.Automation.Language.ScriptPosition'
$scriptExtentType = 'System.Management.Automation.Language.ScriptExtent'
$extentStartPos = New-Object -TypeName $scriptPositionType -ArgumentList $null, $startLineNum, $startColumnNum, $line
$extentEndPos = New-Object -TypeName $scriptPositionType -ArgumentList $null, $endLineNum, $endColumnNum, $line
New-Object -TypeName $scriptExtentType -ArgumentList $extentStartPos, $extentEndPos
}
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

BeforeAll {
$testRootDirectory = Split-Path -Parent $PSScriptRoot
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")

function Get-Extent {
param($line, $startLineNum, $startColumnNum, $endLineNum, $endColumnNum)
$scriptPositionType = 'System.Management.Automation.Language.ScriptPosition'
$scriptExtentType = 'System.Management.Automation.Language.ScriptExtent'
$extentStartPos = New-Object -TypeName $scriptPositionType -ArgumentList $null, $startLineNum, $startColumnNum, $line
$extentEndPos = New-Object -TypeName $scriptPositionType -ArgumentList $null, $endLineNum, $endColumnNum, $line
New-Object -TypeName $scriptExtentType -ArgumentList $extentStartPos, $extentEndPos
}

function Test-Extent {
param(
$translatedExtent,
$expectedStartLineNumber,
$expectedStartColumnNumber,
$expectedEndLineNumber,
$expectedEndColumnNumber)

$translatedExtent.StartLineNumber | Should -Be $expectedStartLineNumber
$translatedExtent.StartColumnNumber | Should -Be $expectedStartColumnNumber
$translatedExtent.EndLineNumber | Should -Be $expectedEndLineNumber
$translatedExtent.EndColumnNumber | Should -Be $expectedEndColumnNumber
}

function Test-Extent {
param(
$translatedExtent,
$expectedStartLineNumber,
$expectedStartColumnNumber,
$expectedEndLineNumber,
$expectedEndColumnNumber)

$translatedExtent.StartLineNumber | Should -Be $expectedStartLineNumber
$translatedExtent.StartColumnNumber | Should -Be $expectedStartColumnNumber
$translatedExtent.EndLineNumber | Should -Be $expectedEndLineNumber
$translatedExtent.EndColumnNumber | Should -Be $expectedEndColumnNumber
$extNamespace = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]
}

$extNamespace = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]

Describe "String extension methods" {
Context "When a text is given to GetLines" {
Expand Down
42 changes: 24 additions & 18 deletions Tests/Engine/GetScriptAnalyzerRule.tests.ps1
@@ -1,14 +1,20 @@
$testRootDirectory = Split-Path -Parent $PSScriptRoot
Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1')
$sa = Get-Command Get-ScriptAnalyzerRule
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

$singularNouns = "PSUseSingularNouns" # this rule does not exist for coreclr version
$approvedVerbs = "PSUseApprovedVerbs"
$cmdletAliases = "PSAvoidUsingCmdletAliases"
$dscIdentical = "PSDSCUseIdenticalParametersForDSC"
BeforeAll {
$sa = Get-Command Get-ScriptAnalyzerRule

$singularNouns = "PSUseSingularNouns" # this rule does not exist for coreclr version
$approvedVerbs = "PSUseApprovedVerbs"
$cmdletAliases = "PSAvoidUsingCmdletAliases"
$dscIdentical = "PSDSCUseIdenticalParametersForDSC"
}

Describe "Test available parameters" {
$params = $sa.Parameters
BeforeAll {
$params = $sa.Parameters
}

Context "Name parameter" {
It "has a RuleName parameter" {
$params.ContainsKey("Name") | Should -BeTrue
Expand All @@ -32,7 +38,6 @@ Describe "Test available parameters" {
$params.CustomRulePath.Aliases.Contains("CustomizedRulePath") | Should -BeTrue
}
}

}

Describe "Test Name parameters" {
Expand All @@ -59,7 +64,7 @@ Describe "Test Name parameters" {
It "get Rules with no parameters supplied" {
$defaultRules = Get-ScriptAnalyzerRule
$expectedNumRules = 64
if ((Test-PSEditionCoreClr) -or (Test-PSVersionV3) -or (Test-PSVersionV4))
if ($IsCoreCLR -or ($PSVersionTable.PSVersion.Major -eq 3) -or ($PSVersionTable.PSVersion.Major -eq 4))
{
# for PSv3 PSAvoidGlobalAliases is not shipped because
# it uses StaticParameterBinder.BindCommand which is
Expand Down Expand Up @@ -94,15 +99,16 @@ Describe "Test Name parameters" {
}

Describe "Test RuleExtension" {
$community = "CommunityAnalyzerRules"
$measureRequired = "Measure-RequiresModules"
Context "When used correctly" {

$expectedNumCommunityRules = 10
if ($PSVersionTable.PSVersion -ge [Version]'4.0.0')
{
$expectedNumCommunityRules = 12
}
BeforeAll {
$community = "CommunityAnalyzerRules"
$measureRequired = "Measure-RequiresModules"
$expectedNumCommunityRules = 10
if ($PSVersionTable.PSVersion -ge [Version]'4.0.0')
{
$expectedNumCommunityRules = 12
}
}
It "with the module folder path" {
$ruleExtension = Get-ScriptAnalyzerRule -CustomizedRulePath $PSScriptRoot\CommunityAnalyzerRules | Where-Object {$_.SourceName -eq $community}
$ruleExtension.Count | Should -Be $expectedNumCommunityRules
Expand Down
19 changes: 8 additions & 11 deletions Tests/Engine/GlobalSuppression.test.ps1
@@ -1,15 +1,12 @@
# Check if PSScriptAnalyzer is already loaded so we don't
# overwrite a test version of Invoke-ScriptAnalyzer by
# accident
if (!(Get-Module PSScriptAnalyzer) -and !$testingLibraryUsage)
{
Import-Module -Verbose PSScriptAnalyzer
}
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

$violations = Invoke-ScriptAnalyzer "$PSScriptRoot\GlobalSuppression.ps1"
$violationsUsingScriptDefinition = Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw "$PSScriptRoot\GlobalSuppression.ps1")
$suppression = Invoke-ScriptAnalyzer "$PSScriptRoot\GlobalSuppression.ps1" -Profile "$PSScriptRoot\Profile.ps1"
$suppressionUsingScriptDefinition = Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw "$PSScriptRoot\GlobalSuppression.ps1") -Profile "$PSScriptRoot\Profile.ps1"
BeforeAll {
$violations = Invoke-ScriptAnalyzer "$PSScriptRoot\GlobalSuppression.ps1"
$violationsUsingScriptDefinition = Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw "$PSScriptRoot\GlobalSuppression.ps1")
$suppression = Invoke-ScriptAnalyzer "$PSScriptRoot\GlobalSuppression.ps1" -Profile "$PSScriptRoot\Profile.ps1"
$suppressionUsingScriptDefinition = Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw "$PSScriptRoot\GlobalSuppression.ps1") -Profile "$PSScriptRoot\Profile.ps1"
}

Describe "GlobalSuppression" {
Context "Exclude Rule" {
Expand Down
23 changes: 14 additions & 9 deletions Tests/Engine/Helper.tests.ps1
@@ -1,15 +1,20 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

Describe "Test Directed Graph" {
Context "When a graph is created" {
$digraph = New-Object -TypeName 'Microsoft.Windows.PowerShell.ScriptAnalyzer.DiGraph[string]'
$digraph.AddVertex('v1');
$digraph.AddVertex('v2');
$digraph.AddVertex('v3');
$digraph.AddVertex('v4');
$digraph.AddVertex('v5');
BeforeAll {
$digraph = New-Object -TypeName 'Microsoft.Windows.PowerShell.ScriptAnalyzer.DiGraph[string]'
$digraph.AddVertex('v1');
$digraph.AddVertex('v2');
$digraph.AddVertex('v3');
$digraph.AddVertex('v4');
$digraph.AddVertex('v5');

$digraph.AddEdge('v1', 'v2');
$digraph.AddEdge('v1', 'v5');
$digraph.AddEdge('v2', 'v4');
$digraph.AddEdge('v1', 'v2');
$digraph.AddEdge('v1', 'v5');
$digraph.AddEdge('v2', 'v4');
}

It "correctly adds the vertices" {
$digraph.NumVertices | Should -Be 5
Expand Down
9 changes: 7 additions & 2 deletions Tests/Engine/InvokeFormatter.tests.ps1
@@ -1,5 +1,10 @@
$testRootDirectory = Split-Path -Parent $PSScriptRoot
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License.

BeforeAll {
$testRootDirectory = Split-Path -Parent $PSScriptRoot
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
}

Describe "Invoke-Formatter Cmdlet" {
Context "Cmdlet cleans up and has no knock on effect" {
Expand Down