Skip to content

Commit 7354892

Browse files
bergmeisterChristoph Bergmeister
and
Christoph Bergmeister
authored
Pester v5 (#1444)
* Replace usage of $MyInvocation.MyCommand.Pat with $PSScriptRoot and cleanup tests * Fix 2 small mistakes, test should now be green again * Adapt build.psm1 * Engine tests migration to Pester v5 * use pester v5 in ci and always upload test results * Upgrade Rule tests to Pester v5 using BeforeAll block and addressing some -Skip problems already * -AllowPrerelease * try bootstrap in wmf4 * fix invoke-pester call in CI * fix CorrectionExtent.tests.ps1 * fix Helper.tests.ps1 * Fix remaining tests with BeforeAll/AfterAll (discovery works now) * fix UseUsingScopeModifierInNewRunspaces.tests.ps1 * make test cases more readable * cleanup UseUsingScopeModifierInNewRunspaces.tests.ps1 * Fix UseShouldProcessForStateChangingFunctions.tests.ps1 * cleanup UseShouldProcessForStateChangingFunctions.tests.ps1 * Fix PSCompatibilityCollector/Tests/UtilityApi.Tests.ps1 * Fix InvokeScriptAnalyzer.tests.ps1 * Format InvokeScriptAnalyzer.tests.ps1 * Fix ModuleHelp.Tests.ps1 and cleanup * Fix RuleSuppression.tests.ps1 * Fix Settings.tests.ps1 * format Settings.tests.ps1 * Fix Tests/Engine/TextEdit.tests.ps1 and format * Fix AllCompatibilityRules.Tests.ps1 * Fix AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 * Format AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 to fix indentation * Fix AvoidUsingPlainTextForPassword.tests.ps1 * fix place*brace tests * Format brace tests and fix PSCredentialType.tests.ps1 * Fix UseCompatibleCommands.Tests.ps1 * Fix UseCompatibleSyntax.Tests.ps1 * Fix UseCompatibleTypes.Tests.ps1 * Fix UseCompatibleCmdlets.tests.ps1 * Fix variable clash between compatibility tests that were not in BeforeEach block and remove unused variables * Fix LibraryUsage.tests.ps1 teardown syntax * Fix LibraryUsage.tests.ps1 * rc3 for wmf4 * Properly execute library tests and cleanup CustomizedRule.tests.ps1 * tidy up * cleanup module imports and only import once at the root * Fix 5 of 6 v4 tests and add logging to better understand modulehelp failure * remove test-psversion functions and fix v3 or v4 checks * Fix ModuleHelp.Tests.ps1 for v4 and cleanup * Really fix ModuleHelp.Tests.ps1 on v4 and cleanup invoke-pester calls * add debugging as to why there is no TestResults.xml on Ubuntu * fix yaml * fix test file upload on Ubuntu (casing) and ensure test file always gets uploaded on appveyor * move appveyor upload back * move appveyor into finally * fix merge error to make install pester v5 again * Pester rc4 * Update to rc5 * cleanup ci run * rc6 * rc7 * rc8 * Update appveyor.psm1 * don't use -CI switch for local build and disable code coverage in CI * import pester module before running tests to import types * fix property name * actually use configuration object (doh) * config object * fix output verbosity * fix type casting of [string[]] of pester paths * pester 5 GA * Pester 5.0.2 * move testcases declaration before test * remove left-over comments * remove unnecessary [bool] in if condition * simplify version check to not require [version] type and patch version * fix missing whitespace in test that made test invalid * empty commit since Azure Pipelines did not trigger * empty commit since Azure Pipelines did not trigger again * empty commit since Azure Pipelines did not trigger again Co-authored-by: Christoph Bergmeister <christoph.bergmeister@bjss.com>
1 parent 67805a1 commit 7354892

File tree

87 files changed

+2403
-2134
lines changed

Some content is hidden

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

87 files changed

+2403
-2134
lines changed

.azure-pipelines-ci/templates/test-powershell.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ steps:
1515
- task: PublishTestResults@2
1616
inputs:
1717
testRunner: NUnit
18-
testResultsFiles: 'TestResults.xml'
18+
testResultsFiles: 'testResults.xml'
1919
condition: succeededOrFailed()

PSCompatibilityCollector/Tests/UtilityApi.Tests.ps1

+108-129
Large diffs are not rendered by default.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Note: the PSScriptAnalyzer Chocolatey package is provided and supported by the c
108108
#### Requirements
109109

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

Tests/DisabledRules/UseTypeAtVariableAssignment.tests.ps1

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Import-Module -Verbose PSScriptAnalyzer
2-
$violationMessage = [regex]::Escape('Specify type at the assignment of variable $test')
1+
$violationMessage = [regex]::Escape('Specify type at the assignment of variable $test')
32
$violationName = "PSUseTypeAtVariableAssignment"
43
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
54
$violations = Invoke-ScriptAnalyzer $directory\UseTypeAtVariableAssignment.ps1 | Where-Object {$_.RuleName -eq $violationName}

Tests/Engine/CorrectionExtent.tests.ps1

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
Describe "Correction Extent" {
2-
$type = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.CorrectionExtent]
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
33

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

810
$correctionExtent.StartLineNumber | Should -Be 1

Tests/Engine/CustomizedRule.tests.ps1

+47-46
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,27 @@
1-
if (-not $IsCoreCLR)
2-
{
3-
# Force Get-Help not to prompt for interactive input to download help using Update-Help
4-
# By adding this registry key we turn off Get-Help interactivity logic during ScriptRule parsing
5-
$null,"Wow6432Node" | ForEach-Object {
6-
try
7-
{
8-
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue
9-
}
10-
catch
11-
{
12-
# Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
BeforeAll {
5+
if (-not $IsCoreCLR)
6+
{
7+
# Force Get-Help not to prompt for interactive input to download help using Update-Help
8+
# By adding this registry key we turn off Get-Help interactivity logic during ScriptRule parsing
9+
$null,"Wow6432Node" | ForEach-Object {
10+
try
11+
{
12+
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -ErrorAction SilentlyContinue
13+
}
14+
catch
15+
{
16+
# Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
17+
}
1318
}
1419
}
20+
$message = "this is help"
21+
$measure = "Measure-RequiresRunAsAdministrator"
1522
}
1623

1724

18-
$message = "this is help"
19-
$measure = "Measure-RequiresRunAsAdministrator"
20-
2125
Describe "Test importing customized rules with null return results" {
2226
Context "Test Get-ScriptAnalyzer with customized rules" {
2327
It "will not terminate the engine" {
@@ -38,40 +42,38 @@ Describe "Test importing customized rules with null return results" {
3842

3943
Describe "Test importing correct customized rules" {
4044

41-
if(-not $IsCoreCLR)
42-
{
43-
Context "Test Get-Help functionality in ScriptRule parsing logic" {
44-
It "ScriptRule help section must be correctly processed when Get-Help is called for the first time" {
45-
46-
# Force Get-Help to prompt for interactive input to download help using Update-Help
47-
# By removing this registry key we force to turn on Get-Help interactivity logic during ScriptRule parsing
48-
$null,"Wow6432Node" | ForEach-Object {
49-
try
50-
{
51-
Remove-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -ErrorAction Stop
52-
} catch {
53-
#Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
54-
}
45+
Context "Test Get-Help functionality in ScriptRule parsing logic" -Skip:$IsCoreCLR {
46+
It "ScriptRule help section must be correctly processed when Get-Help is called for the first time" {
47+
48+
# Force Get-Help to prompt for interactive input to download help using Update-Help
49+
# By removing this registry key we force to turn on Get-Help interactivity logic during ScriptRule parsing
50+
$null,"Wow6432Node" | ForEach-Object {
51+
try
52+
{
53+
Remove-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -ErrorAction Stop
54+
} catch {
55+
#Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
5556
}
57+
}
5658

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

60-
# Force Get-Help not to prompt for interactive input to download help using Update-Help
61-
# By adding this registry key we turn off Get-Help interactivity logic during ScriptRule parsing
62-
$null,"Wow6432Node" | ForEach-Object {
63-
try
64-
{
65-
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -EA SilentlyContinue
66-
}
67-
catch
68-
{
69-
# Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
70-
}
62+
# Force Get-Help not to prompt for interactive input to download help using Update-Help
63+
# By adding this registry key we turn off Get-Help interactivity logic during ScriptRule parsing
64+
$null,"Wow6432Node" | ForEach-Object {
65+
try
66+
{
67+
Set-ItemProperty -Name "DisablePromptToUpdateHelp" -Path "HKLM:\SOFTWARE\$($_)\Microsoft\PowerShell" -Value 1 -Force -EA SilentlyContinue
68+
}
69+
catch
70+
{
71+
# Ignore for cases when tests are running in non-elevated more or registry key does not exist or not accessible
7172
}
7273
}
7374
}
7475
}
76+
# }
7577

7678
Context "Test Get-ScriptAnalyzer with customized rules" {
7779
It "will show the custom rule" {
@@ -197,8 +199,7 @@ Describe "Test importing correct customized rules" {
197199
$violations[0].RuleSuppressionID | Should -Be "MyRuleSuppressionID"
198200
}
199201

200-
if (!$testingLibraryUsage)
201-
{
202+
Context "Test Invoke-ScriptAnalyzer with customized rules - Advanced test cases" -Skip:$testingLibraryUsage {
202203
It "will show the custom rule in the results when given a rule folder path with trailing backslash" {
203204
# needs fixing for Linux
204205
if (!$IsLinux -and !$IsMacOS)
@@ -243,15 +244,15 @@ Describe "Test importing correct customized rules" {
243244
$customizedRulePath.Count | Should -Be 1
244245
}
245246

246-
It "loads custom rules that contain version in their path" -Skip:($PSVersionTable.PSVersion -lt [Version]'5.0.0') {
247+
It "loads custom rules that contain version in their path" -Skip:($PSVersionTable.PSVersion -lt '5.0') {
247248
$customizedRulePath = Invoke-ScriptAnalyzer $PSScriptRoot\TestScript.ps1 -CustomRulePath $PSScriptRoot\VersionedSampleRule\SampleRuleWithVersion
248249
$customizedRulePath.Count | Should -Be 1
249250

250251
$customizedRulePath = Get-ScriptAnalyzerRule -CustomRulePath $PSScriptRoot\VersionedSampleRule\SampleRuleWithVersion
251252
$customizedRulePath.Count | Should -Be 1
252253
}
253254

254-
It "loads custom rules that contain version in their path with the RecurseCustomRule switch" -Skip:($PSVersionTable.PSVersion -lt [Version]'5.0.0') {
255+
It "loads custom rules that contain version in their path with the RecurseCustomRule switch" -Skip:($PSVersionTable.PSVersion -lt '5.0') {
255256
$customizedRulePath = Invoke-ScriptAnalyzer $PSScriptRoot\TestScript.ps1 -CustomRulePath $PSScriptRoot\VersionedSampleRule -RecurseCustomRulePath
256257
$customizedRulePath.Count | Should -Be 1
257258

Tests/Engine/EditableText.tests.ps1

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
$testRootDirectory = Split-Path -Parent $PSScriptRoot
2-
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
3-
$editableTextType = "Microsoft.Windows.PowerShell.ScriptAnalyzer.EditableText"
4-
$textEditType = "Microsoft.Windows.PowerShell.ScriptAnalyzer.TextEdit"
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
BeforeAll {
5+
$testRootDirectory = Split-Path -Parent $PSScriptRoot
6+
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
7+
$editableTextType = "Microsoft.Windows.PowerShell.ScriptAnalyzer.EditableText"
8+
$textEditType = "Microsoft.Windows.PowerShell.ScriptAnalyzer.TextEdit"
9+
}
510

611
Describe "EditableText class" {
712
Context "When a single edit is given for application" {

Tests/Engine/Extensions.tests.ps1

+30-24
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,36 @@
1-
$testRootDirectory = Split-Path -Parent $PSScriptRoot
2-
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
3-
4-
function Get-Extent {
5-
param($line, $startLineNum, $startColumnNum, $endLineNum, $endColumnNum)
6-
$scriptPositionType = 'System.Management.Automation.Language.ScriptPosition'
7-
$scriptExtentType = 'System.Management.Automation.Language.ScriptExtent'
8-
$extentStartPos = New-Object -TypeName $scriptPositionType -ArgumentList $null, $startLineNum, $startColumnNum, $line
9-
$extentEndPos = New-Object -TypeName $scriptPositionType -ArgumentList $null, $endLineNum, $endColumnNum, $line
10-
New-Object -TypeName $scriptExtentType -ArgumentList $extentStartPos, $extentEndPos
11-
}
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
BeforeAll {
5+
$testRootDirectory = Split-Path -Parent $PSScriptRoot
6+
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
7+
8+
function Get-Extent {
9+
param($line, $startLineNum, $startColumnNum, $endLineNum, $endColumnNum)
10+
$scriptPositionType = 'System.Management.Automation.Language.ScriptPosition'
11+
$scriptExtentType = 'System.Management.Automation.Language.ScriptExtent'
12+
$extentStartPos = New-Object -TypeName $scriptPositionType -ArgumentList $null, $startLineNum, $startColumnNum, $line
13+
$extentEndPos = New-Object -TypeName $scriptPositionType -ArgumentList $null, $endLineNum, $endColumnNum, $line
14+
New-Object -TypeName $scriptExtentType -ArgumentList $extentStartPos, $extentEndPos
15+
}
16+
17+
function Test-Extent {
18+
param(
19+
$translatedExtent,
20+
$expectedStartLineNumber,
21+
$expectedStartColumnNumber,
22+
$expectedEndLineNumber,
23+
$expectedEndColumnNumber)
24+
25+
$translatedExtent.StartLineNumber | Should -Be $expectedStartLineNumber
26+
$translatedExtent.StartColumnNumber | Should -Be $expectedStartColumnNumber
27+
$translatedExtent.EndLineNumber | Should -Be $expectedEndLineNumber
28+
$translatedExtent.EndColumnNumber | Should -Be $expectedEndColumnNumber
29+
}
1230

13-
function Test-Extent {
14-
param(
15-
$translatedExtent,
16-
$expectedStartLineNumber,
17-
$expectedStartColumnNumber,
18-
$expectedEndLineNumber,
19-
$expectedEndColumnNumber)
20-
21-
$translatedExtent.StartLineNumber | Should -Be $expectedStartLineNumber
22-
$translatedExtent.StartColumnNumber | Should -Be $expectedStartColumnNumber
23-
$translatedExtent.EndLineNumber | Should -Be $expectedEndLineNumber
24-
$translatedExtent.EndColumnNumber | Should -Be $expectedEndColumnNumber
31+
$extNamespace = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]
2532
}
2633

27-
$extNamespace = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Extensions.Extensions]
2834

2935
Describe "String extension methods" {
3036
Context "When a text is given to GetLines" {

Tests/Engine/GetScriptAnalyzerRule.tests.ps1

+24-18
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
$testRootDirectory = Split-Path -Parent $PSScriptRoot
2-
Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1')
3-
$sa = Get-Command Get-ScriptAnalyzerRule
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
43

5-
$singularNouns = "PSUseSingularNouns" # this rule does not exist for coreclr version
6-
$approvedVerbs = "PSUseApprovedVerbs"
7-
$cmdletAliases = "PSAvoidUsingCmdletAliases"
8-
$dscIdentical = "PSDSCUseIdenticalParametersForDSC"
4+
BeforeAll {
5+
$sa = Get-Command Get-ScriptAnalyzerRule
6+
7+
$singularNouns = "PSUseSingularNouns" # this rule does not exist for coreclr version
8+
$approvedVerbs = "PSUseApprovedVerbs"
9+
$cmdletAliases = "PSAvoidUsingCmdletAliases"
10+
$dscIdentical = "PSDSCUseIdenticalParametersForDSC"
11+
}
912

1013
Describe "Test available parameters" {
11-
$params = $sa.Parameters
14+
BeforeAll {
15+
$params = $sa.Parameters
16+
}
17+
1218
Context "Name parameter" {
1319
It "has a RuleName parameter" {
1420
$params.ContainsKey("Name") | Should -BeTrue
@@ -32,7 +38,6 @@ Describe "Test available parameters" {
3238
$params.CustomRulePath.Aliases.Contains("CustomizedRulePath") | Should -BeTrue
3339
}
3440
}
35-
3641
}
3742

3843
Describe "Test Name parameters" {
@@ -59,7 +64,7 @@ Describe "Test Name parameters" {
5964
It "get Rules with no parameters supplied" {
6065
$defaultRules = Get-ScriptAnalyzerRule
6166
$expectedNumRules = 64
62-
if ((Test-PSEditionCoreClr) -or (Test-PSVersionV3) -or (Test-PSVersionV4))
67+
if ($IsCoreCLR -or ($PSVersionTable.PSVersion.Major -eq 3) -or ($PSVersionTable.PSVersion.Major -eq 4))
6368
{
6469
# for PSv3 PSAvoidGlobalAliases is not shipped because
6570
# it uses StaticParameterBinder.BindCommand which is
@@ -94,15 +99,16 @@ Describe "Test Name parameters" {
9499
}
95100

96101
Describe "Test RuleExtension" {
97-
$community = "CommunityAnalyzerRules"
98-
$measureRequired = "Measure-RequiresModules"
99102
Context "When used correctly" {
100-
101-
$expectedNumCommunityRules = 10
102-
if ($PSVersionTable.PSVersion -ge [Version]'4.0.0')
103-
{
104-
$expectedNumCommunityRules = 12
105-
}
103+
BeforeAll {
104+
$community = "CommunityAnalyzerRules"
105+
$measureRequired = "Measure-RequiresModules"
106+
$expectedNumCommunityRules = 10
107+
if ($PSVersionTable.PSVersion -ge [Version]'4.0.0')
108+
{
109+
$expectedNumCommunityRules = 12
110+
}
111+
}
106112
It "with the module folder path" {
107113
$ruleExtension = Get-ScriptAnalyzerRule -CustomizedRulePath $PSScriptRoot\CommunityAnalyzerRules | Where-Object {$_.SourceName -eq $community}
108114
$ruleExtension.Count | Should -Be $expectedNumCommunityRules

Tests/Engine/GlobalSuppression.test.ps1

+8-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
# Check if PSScriptAnalyzer is already loaded so we don't
2-
# overwrite a test version of Invoke-ScriptAnalyzer by
3-
# accident
4-
if (!(Get-Module PSScriptAnalyzer) -and !$testingLibraryUsage)
5-
{
6-
Import-Module -Verbose PSScriptAnalyzer
7-
}
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
83

9-
$violations = Invoke-ScriptAnalyzer "$PSScriptRoot\GlobalSuppression.ps1"
10-
$violationsUsingScriptDefinition = Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw "$PSScriptRoot\GlobalSuppression.ps1")
11-
$suppression = Invoke-ScriptAnalyzer "$PSScriptRoot\GlobalSuppression.ps1" -Profile "$PSScriptRoot\Profile.ps1"
12-
$suppressionUsingScriptDefinition = Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw "$PSScriptRoot\GlobalSuppression.ps1") -Profile "$PSScriptRoot\Profile.ps1"
4+
BeforeAll {
5+
$violations = Invoke-ScriptAnalyzer "$PSScriptRoot\GlobalSuppression.ps1"
6+
$violationsUsingScriptDefinition = Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw "$PSScriptRoot\GlobalSuppression.ps1")
7+
$suppression = Invoke-ScriptAnalyzer "$PSScriptRoot\GlobalSuppression.ps1" -Profile "$PSScriptRoot\Profile.ps1"
8+
$suppressionUsingScriptDefinition = Invoke-ScriptAnalyzer -ScriptDefinition (Get-Content -Raw "$PSScriptRoot\GlobalSuppression.ps1") -Profile "$PSScriptRoot\Profile.ps1"
9+
}
1310

1411
Describe "GlobalSuppression" {
1512
Context "Exclude Rule" {

Tests/Engine/Helper.tests.ps1

+14-9
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
14
Describe "Test Directed Graph" {
25
Context "When a graph is created" {
3-
$digraph = New-Object -TypeName 'Microsoft.Windows.PowerShell.ScriptAnalyzer.DiGraph[string]'
4-
$digraph.AddVertex('v1');
5-
$digraph.AddVertex('v2');
6-
$digraph.AddVertex('v3');
7-
$digraph.AddVertex('v4');
8-
$digraph.AddVertex('v5');
6+
BeforeAll {
7+
$digraph = New-Object -TypeName 'Microsoft.Windows.PowerShell.ScriptAnalyzer.DiGraph[string]'
8+
$digraph.AddVertex('v1');
9+
$digraph.AddVertex('v2');
10+
$digraph.AddVertex('v3');
11+
$digraph.AddVertex('v4');
12+
$digraph.AddVertex('v5');
913

10-
$digraph.AddEdge('v1', 'v2');
11-
$digraph.AddEdge('v1', 'v5');
12-
$digraph.AddEdge('v2', 'v4');
14+
$digraph.AddEdge('v1', 'v2');
15+
$digraph.AddEdge('v1', 'v5');
16+
$digraph.AddEdge('v2', 'v4');
17+
}
1318

1419
It "correctly adds the vertices" {
1520
$digraph.NumVertices | Should -Be 5

Tests/Engine/InvokeFormatter.tests.ps1

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
$testRootDirectory = Split-Path -Parent $PSScriptRoot
2-
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
4+
BeforeAll {
5+
$testRootDirectory = Split-Path -Parent $PSScriptRoot
6+
Import-Module (Join-Path $testRootDirectory "PSScriptAnalyzerTestHelper.psm1")
7+
}
38

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

0 commit comments

Comments
 (0)