diff --git a/Tests/Engine/CustomizedRule.tests.ps1 b/Tests/Engine/CustomizedRule.tests.ps1 index 609c8f3ae..0be3cfb80 100644 --- a/Tests/Engine/CustomizedRule.tests.ps1 +++ b/Tests/Engine/CustomizedRule.tests.ps1 @@ -97,7 +97,7 @@ Describe "Test importing correct customized rules" { $customizedRulePath.Count | Should Be 1 } - It "will show the custom rule when given a rule folder path with trailing backslash" -skip:(!$IsWindows){ + It "will show the custom rule when given a rule folder path with trailing backslash" -skip:$($IsLinux -or $IsMacOS) { # needs fixing for linux $customizedRulePath = Get-ScriptAnalyzerRule -CustomizedRulePath $directory/samplerule/ | Where-Object {$_.RuleName -eq $measure} $customizedRulePath.Count | Should Be 1 @@ -106,7 +106,7 @@ Describe "Test importing correct customized rules" { It "will show the custom rules when given a glob" { # needs fixing for Linux $expectedNumRules = 4 - if (!$IsWindows) + if ($IsLinux -or $IsMacOS) { $expectedNumRules = 3 } @@ -122,7 +122,7 @@ Describe "Test importing correct customized rules" { It "will show the custom rules when given glob with recurse switch" { # needs fixing for Linux $expectedNumRules = 5 - if (!$IsWindows) + if ($IsLinux -or $IsMacOS) { $expectedNumRules = 4 } @@ -162,7 +162,7 @@ Describe "Test importing correct customized rules" { { It "will show the custom rule in the results when given a rule folder path with trailing backslash" { # needs fixing for Linux - if ($IsWindows) + if (!$IsLinux -and !$IsMacOS) { $customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomizedRulePath $directory\samplerule\ | Where-Object {$_.Message -eq $message} $customizedRulePath.Count | Should Be 1 diff --git a/Tests/Engine/ModuleDependencyHandler.tests.ps1 b/Tests/Engine/ModuleDependencyHandler.tests.ps1 index c8bf52e6c..3d73bdbcc 100644 --- a/Tests/Engine/ModuleDependencyHandler.tests.ps1 +++ b/Tests/Engine/ModuleDependencyHandler.tests.ps1 @@ -1,7 +1,9 @@ +$directory = Split-Path -Parent $MyInvocation.MyCommand.Path + Describe "Resolve DSC Resource Dependency" { BeforeAll { $skipTest = $false - if ( -not $IsWindows -or $testingLibararyUsage -or ($PSversionTable.PSVersion -lt [Version]'5.0.0')) + if ($IsLinux -or $IsMacOS -or $testingLibararyUsage -or ($PSversionTable.PSVersion -lt [Version]'5.0.0')) { $skipTest = $true return @@ -9,8 +11,6 @@ Describe "Resolve DSC Resource Dependency" { $SavedPSModulePath = $env:PSModulePath $violationFileName = 'MissingDSCResource.ps1' $violationFilePath = Join-Path $directory $violationFileName - - $directory = Split-Path -Parent $MyInvocation.MyCommand.Path $testRootDirectory = Split-Path -Parent $directory Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1') @@ -166,15 +166,6 @@ Describe "Resolve DSC Resource Dependency" { Copy-Item -Recurse -Path $modulePath -Destination $tempModulePath } - AfterAll { - if ( $skipTest ) { return } - #restore environment variables and clean up temporary location - $env:LOCALAPPDATA = $oldLocalAppDataPath - $env:TEMP = $oldTempPath - Remove-Item -Recurse -Path $tempModulePath -Force - Remove-Item -Recurse -Path $tempPath -Force - } - It "Doesn't have parse errors" -skip:$skipTest { # invoke script analyzer $dr = Invoke-ScriptAnalyzer -Path $violationFilePath -ErrorVariable parseErrors -ErrorAction SilentlyContinue @@ -186,6 +177,14 @@ Describe "Resolve DSC Resource Dependency" { $env:PSModulePath | Should Be $oldPSModulePath } + if (!$skipTest) + { + $env:LOCALAPPDATA = $oldLocalAppDataPath + $env:TEMP = $oldTempPath + Remove-Item -Recurse -Path $tempModulePath -Force + Remove-Item -Recurse -Path $tempPath -Force + } + It "Keeps the environment variables unchanged" -skip:$skipTest { Test-EnvironmentVariables($oldEnvVars) } diff --git a/Tests/Engine/RuleSuppression.tests.ps1 b/Tests/Engine/RuleSuppression.tests.ps1 index 3127a3ae5..7ab02d79e 100644 --- a/Tests/Engine/RuleSuppression.tests.ps1 +++ b/Tests/Engine/RuleSuppression.tests.ps1 @@ -106,7 +106,7 @@ function SuppressPwdParam() } Context "Rule suppression within DSC Configuration definition" { - It "Suppresses rule" -skip:((!$IsWindows) -or ($PSVersionTable.PSVersion.Major -lt 5)) { + It "Suppresses rule" -skip:($IsLinux -or $IsMacOS -or ($PSVersionTable.PSVersion.Major -lt 5)) { $suppressedRule = Invoke-ScriptAnalyzer -ScriptDefinition $ruleSuppressionInConfiguration -SuppressedOnly $suppressedRule.Count | Should Be 1 } diff --git a/Tests/Rules/AlignAssignmentStatement.tests.ps1 b/Tests/Rules/AlignAssignmentStatement.tests.ps1 index 0854045b8..5d076dc95 100644 --- a/Tests/Rules/AlignAssignmentStatement.tests.ps1 +++ b/Tests/Rules/AlignAssignmentStatement.tests.ps1 @@ -66,7 +66,7 @@ $x = @{ } } Context "When assignment statements are in DSC Configuration" { - It "Should find violations when assignment statements are not aligned" -skip:(!$IsWindows) { + It "Should find violations when assignment statements are not aligned" -skip:($IsLinux -or $IsMacOS) { $def = @' Configuration MyDscConfiguration { diff --git a/appveyor.yml b/appveyor.yml index c28bf8b54..55ae23912 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -59,12 +59,11 @@ test_script: - ps: | copy-item "C:\projects\psscriptanalyzer\out\PSScriptAnalyzer" "$Env:ProgramFiles\WindowsPowerShell\Modules\" -Recurse -Force $testResultsFile = ".\TestResults.xml" - $ruleTestResultsFile = ".\RuleTestResults.xml" $testScripts = "C:\projects\psscriptanalyzer\Tests\Engine","C:\projects\psscriptanalyzer\Tests\Rules" $testResults = Invoke-Pester -Script $testScripts -OutputFormat NUnitXml -OutputFile $testResultsFile -PassThru (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile)) - if ($engineTestResults.FailedCount -gt 0) { - throw "$($engineTestResults.FailedCount) tests failed." + if ($testResults.FailedCount -gt 0) { + throw "$($testResults.FailedCount) tests failed." } # Upload the project along with TestResults as a zip archive