Skip to content
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
8 changes: 4 additions & 4 deletions Tests/Engine/CustomizedRule.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the $ is unneeded

# needs fixing for linux
$customizedRulePath = Get-ScriptAnalyzerRule -CustomizedRulePath $directory/samplerule/ | Where-Object {$_.RuleName -eq $measure}
$customizedRulePath.Count | Should Be 1
Expand All @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
23 changes: 11 additions & 12 deletions Tests/Engine/ModuleDependencyHandler.tests.ps1
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
$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
}
$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')

Expand Down Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Engine/RuleSuppression.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion Tests/Rules/AlignAssignmentStatement.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
5 changes: 2 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down