Skip to content

Commit 22c062c

Browse files
bergmeisterJamesWTruher
authored andcommitted
Fix regressions introduced by PR 882 (#891)
* Fix regressions introduced by PR 882: - $IsWindows returns false on Windows PowerShell because this automatic variable was only introduced in PowerShell Core - some reverts of test code that did not fail due to the above. * fix wmf4 build with steps to only execute when skip is not true * fix appveyor test upload script (build was not red due to that)
1 parent 8f20c98 commit 22c062c

5 files changed

+19
-21
lines changed

Tests/Engine/CustomizedRule.tests.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Describe "Test importing correct customized rules" {
9797
$customizedRulePath.Count | Should Be 1
9898
}
9999

100-
It "will show the custom rule when given a rule folder path with trailing backslash" -skip:(!$IsWindows){
100+
It "will show the custom rule when given a rule folder path with trailing backslash" -skip:$($IsLinux -or $IsMacOS) {
101101
# needs fixing for linux
102102
$customizedRulePath = Get-ScriptAnalyzerRule -CustomizedRulePath $directory/samplerule/ | Where-Object {$_.RuleName -eq $measure}
103103
$customizedRulePath.Count | Should Be 1
@@ -106,7 +106,7 @@ Describe "Test importing correct customized rules" {
106106
It "will show the custom rules when given a glob" {
107107
# needs fixing for Linux
108108
$expectedNumRules = 4
109-
if (!$IsWindows)
109+
if ($IsLinux -or $IsMacOS)
110110
{
111111
$expectedNumRules = 3
112112
}
@@ -122,7 +122,7 @@ Describe "Test importing correct customized rules" {
122122
It "will show the custom rules when given glob with recurse switch" {
123123
# needs fixing for Linux
124124
$expectedNumRules = 5
125-
if (!$IsWindows)
125+
if ($IsLinux -or $IsMacOS)
126126
{
127127
$expectedNumRules = 4
128128
}
@@ -162,7 +162,7 @@ Describe "Test importing correct customized rules" {
162162
{
163163
It "will show the custom rule in the results when given a rule folder path with trailing backslash" {
164164
# needs fixing for Linux
165-
if ($IsWindows)
165+
if (!$IsLinux -and !$IsMacOS)
166166
{
167167
$customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomizedRulePath $directory\samplerule\ | Where-Object {$_.Message -eq $message}
168168
$customizedRulePath.Count | Should Be 1

Tests/Engine/ModuleDependencyHandler.tests.ps1

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1+
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
2+
13
Describe "Resolve DSC Resource Dependency" {
24
BeforeAll {
35
$skipTest = $false
4-
if ( -not $IsWindows -or $testingLibararyUsage -or ($PSversionTable.PSVersion -lt [Version]'5.0.0'))
6+
if ($IsLinux -or $IsMacOS -or $testingLibararyUsage -or ($PSversionTable.PSVersion -lt [Version]'5.0.0'))
57
{
68
$skipTest = $true
79
return
810
}
911
$SavedPSModulePath = $env:PSModulePath
1012
$violationFileName = 'MissingDSCResource.ps1'
1113
$violationFilePath = Join-Path $directory $violationFileName
12-
13-
$directory = Split-Path -Parent $MyInvocation.MyCommand.Path
1414
$testRootDirectory = Split-Path -Parent $directory
1515
Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1')
1616

@@ -166,15 +166,6 @@ Describe "Resolve DSC Resource Dependency" {
166166
Copy-Item -Recurse -Path $modulePath -Destination $tempModulePath
167167
}
168168

169-
AfterAll {
170-
if ( $skipTest ) { return }
171-
#restore environment variables and clean up temporary location
172-
$env:LOCALAPPDATA = $oldLocalAppDataPath
173-
$env:TEMP = $oldTempPath
174-
Remove-Item -Recurse -Path $tempModulePath -Force
175-
Remove-Item -Recurse -Path $tempPath -Force
176-
}
177-
178169
It "Doesn't have parse errors" -skip:$skipTest {
179170
# invoke script analyzer
180171
$dr = Invoke-ScriptAnalyzer -Path $violationFilePath -ErrorVariable parseErrors -ErrorAction SilentlyContinue
@@ -186,6 +177,14 @@ Describe "Resolve DSC Resource Dependency" {
186177
$env:PSModulePath | Should Be $oldPSModulePath
187178
}
188179

180+
if (!$skipTest)
181+
{
182+
$env:LOCALAPPDATA = $oldLocalAppDataPath
183+
$env:TEMP = $oldTempPath
184+
Remove-Item -Recurse -Path $tempModulePath -Force
185+
Remove-Item -Recurse -Path $tempPath -Force
186+
}
187+
189188
It "Keeps the environment variables unchanged" -skip:$skipTest {
190189
Test-EnvironmentVariables($oldEnvVars)
191190
}

Tests/Engine/RuleSuppression.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ function SuppressPwdParam()
106106
}
107107

108108
Context "Rule suppression within DSC Configuration definition" {
109-
It "Suppresses rule" -skip:((!$IsWindows) -or ($PSVersionTable.PSVersion.Major -lt 5)) {
109+
It "Suppresses rule" -skip:($IsLinux -or $IsMacOS -or ($PSVersionTable.PSVersion.Major -lt 5)) {
110110
$suppressedRule = Invoke-ScriptAnalyzer -ScriptDefinition $ruleSuppressionInConfiguration -SuppressedOnly
111111
$suppressedRule.Count | Should Be 1
112112
}

Tests/Rules/AlignAssignmentStatement.tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ $x = @{ }
6666
}
6767

6868
Context "When assignment statements are in DSC Configuration" {
69-
It "Should find violations when assignment statements are not aligned" -skip:(!$IsWindows) {
69+
It "Should find violations when assignment statements are not aligned" -skip:($IsLinux -or $IsMacOS) {
7070
$def = @'
7171
Configuration MyDscConfiguration {
7272

appveyor.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,11 @@ test_script:
5959
- ps: |
6060
copy-item "C:\projects\psscriptanalyzer\out\PSScriptAnalyzer" "$Env:ProgramFiles\WindowsPowerShell\Modules\" -Recurse -Force
6161
$testResultsFile = ".\TestResults.xml"
62-
$ruleTestResultsFile = ".\RuleTestResults.xml"
6362
$testScripts = "C:\projects\psscriptanalyzer\Tests\Engine","C:\projects\psscriptanalyzer\Tests\Rules"
6463
$testResults = Invoke-Pester -Script $testScripts -OutputFormat NUnitXml -OutputFile $testResultsFile -PassThru
6564
(New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile))
66-
if ($engineTestResults.FailedCount -gt 0) {
67-
throw "$($engineTestResults.FailedCount) tests failed."
65+
if ($testResults.FailedCount -gt 0) {
66+
throw "$($testResults.FailedCount) tests failed."
6867
}
6968
7069
# Upload the project along with TestResults as a zip archive

0 commit comments

Comments
 (0)