From 88d19fc6002f24aa4246b65e57f8e999d9c5b1d8 Mon Sep 17 00:00:00 2001 From: James Truher Date: Fri, 9 Feb 2018 16:41:39 -0800 Subject: [PATCH 1/2] Change logic for test execution to handle running on Mac Mark some tests as pending that weren't actually doing anything Skip DSC tests on Mac/Linux --- Tests/Engine/CustomizedRule.tests.ps1 | 15 +- Tests/Engine/InvokeScriptAnalyzer.tests.ps1 | 27 +-- .../Engine/ModuleDependencyHandler.tests.ps1 | 179 +++++++++--------- Tests/Engine/ModuleHelp.Tests.ps1 | 6 +- Tests/Engine/RuleSuppression.tests.ps1 | 4 +- Tests/PSScriptAnalyzerTestHelper.psm1 | 8 +- .../Rules/AlignAssignmentStatement.tests.ps1 | 4 +- ...OrMissingRequiredFieldInManifest.tests.ps1 | 2 +- Tests/Rules/AvoidUsingAlias.tests.ps1 | 4 +- ...enticalMandatoryParametersForDSC.tests.ps1 | 6 +- .../UseToExportFieldsInManifest.tests.ps1 | 2 +- 11 files changed, 124 insertions(+), 133 deletions(-) diff --git a/Tests/Engine/CustomizedRule.tests.ps1 b/Tests/Engine/CustomizedRule.tests.ps1 index 714c089be..195726585 100644 --- a/Tests/Engine/CustomizedRule.tests.ps1 +++ b/Tests/Engine/CustomizedRule.tests.ps1 @@ -97,19 +97,16 @@ 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" { + It "will show the custom rule when given a rule folder path with trailing backslash" -skip:(!$IsWindows){ # needs fixing for linux - if (-not (Test-PSEditionCoreCLRLinux)) - { - $customizedRulePath = Get-ScriptAnalyzerRule -CustomizedRulePath $directory/samplerule/ | Where-Object {$_.RuleName -eq $measure} - $customizedRulePath.Count | Should Be 1 - } + $customizedRulePath = Get-ScriptAnalyzerRule -CustomizedRulePath $directory/samplerule/ | Where-Object {$_.RuleName -eq $measure} + $customizedRulePath.Count | Should Be 1 } It "will show the custom rules when given a glob" { # needs fixing for Linux $expectedNumRules = 4 - if (Test-PSEditionCoreCLRLinux) + if ( ! $IsWindows ) { $expectedNumRules = 3 } @@ -125,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 (Test-PSEditionCoreCLRLinux) + if (! $IsWindows ) { $expectedNumRules = 4 } @@ -165,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 (-not (Test-PSEditionCoreCLRLinux)) + if ($IsWindows) { $customizedRulePath = Invoke-ScriptAnalyzer $directory\TestScript.ps1 -CustomizedRulePath $directory\samplerule\ | Where-Object {$_.Message -eq $message} $customizedRulePath.Count | Should Be 1 diff --git a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 index 50f2e8a2f..9db3839a2 100644 --- a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 +++ b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 @@ -468,33 +468,34 @@ Describe "Test CustomizedRulePath" { Describe "Test -Fix Switch" { - BeforeEach { - $initialTestScript = Get-Content $directory\TestScriptWithFixableWarnings.ps1 -Raw + BeforeAll { + $scriptName = "TestScriptWithFixableWarnings.ps1" + $testSource = join-path $PSScriptRoot ${scriptName} + $fixedScript = join-path $PSScriptRoot TestScriptWithFixableWarnings_AfterFix.ps1 + $expectedScriptContent = Get-Content $fixedScript -raw + $testScript = Join-Path $TESTDRIVE $scriptName } - AfterEach { - if ($null -ne $initialTestScript) - { - [System.IO.File]::WriteAllText("$($directory)\TestScriptWithFixableWarnings.ps1", $initialTestScript) # Set-Content -NoNewline was only introduced in PS v5 and would therefore not work in CI - } + BeforeEach { + Copy-Item $testSource $TESTDRIVE } It "Fixes warnings" { # we expect the script to contain warnings - $warningsBeforeFix = Invoke-ScriptAnalyzer $directory\TestScriptWithFixableWarnings.ps1 + $warningsBeforeFix = Invoke-ScriptAnalyzer $testScript $warningsBeforeFix.Count | Should Be 5 # fix the warnings and expect that it should not return the fixed warnings - $warningsWithFixSwitch = Invoke-ScriptAnalyzer $directory\TestScriptWithFixableWarnings.ps1 -Fix + $warningsWithFixSwitch = Invoke-ScriptAnalyzer $testScript -Fix $warningsWithFixSwitch.Count | Should Be 0 # double check that the warnings are really fixed - $warningsAfterFix = Invoke-ScriptAnalyzer $directory\TestScriptWithFixableWarnings.ps1 + $warningsAfterFix = Invoke-ScriptAnalyzer $testScript $warningsAfterFix.Count | Should Be 0 - $expectedScriptContentAfterFix = Get-Content $directory\TestScriptWithFixableWarnings_AfterFix.ps1 -Raw - $actualScriptContentAfterFix = Get-Content $directory\TestScriptWithFixableWarnings.ps1 -Raw - $actualScriptContentAfterFix | Should Be $expectedScriptContentAfterFix + # check content to ensure we have what we expect + $actualScriptContentAfterFix = Get-Content $testScript -Raw + $actualScriptContentAfterFix | Should Be $expectedScriptContent } } diff --git a/Tests/Engine/ModuleDependencyHandler.tests.ps1 b/Tests/Engine/ModuleDependencyHandler.tests.ps1 index 166bd01e4..c8bf52e6c 100644 --- a/Tests/Engine/ModuleDependencyHandler.tests.ps1 +++ b/Tests/Engine/ModuleDependencyHandler.tests.ps1 @@ -1,51 +1,43 @@ -if (!(Get-Module PSScriptAnalyzer) -and !$testingLibraryUsage) -{ - Import-Module PSScriptAnalyzer -} - -if ($testingLibraryUsage) -{ - return -} - -$directory = Split-Path -Parent $MyInvocation.MyCommand.Path -$testRootDirectory = Split-Path -Parent $directory -Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1') - -# needs fixing -# right now we do not support module dependency handing on Linux -if ((Test-PSEditionCoreCLRLinux)) -{ - return -} - -# DSC Module saving is not supported in versions less than PSv5 -if (($PSVersionTable.PSVersion -lt [Version]'5.0.0')) -{ - return -} - -$violationFileName = 'MissingDSCResource.ps1' -$violationFilePath = Join-Path $directory $violationFileName - Describe "Resolve DSC Resource Dependency" { + BeforeAll { + $skipTest = $false + if ( -not $IsWindows -or $testingLibararyUsage -or ($PSversionTable.PSVersion -lt [Version]'5.0.0')) + { + $skipTest = $true + return + } + $SavedPSModulePath = $env:PSModulePath + $violationFileName = 'MissingDSCResource.ps1' + $violationFilePath = Join-Path $directory $violationFileName - Function Test-EnvironmentVariables($oldEnv) - { - $newEnv = Get-Item Env:\* | Sort-Object -Property Key - $newEnv.Count | Should Be $oldEnv.Count - foreach ($index in 1..$newEnv.Count) + $directory = Split-Path -Parent $MyInvocation.MyCommand.Path + $testRootDirectory = Split-Path -Parent $directory + Import-Module (Join-Path $testRootDirectory 'PSScriptAnalyzerTestHelper.psm1') + + Function Test-EnvironmentVariables($oldEnv) { - $newEnv[$index].Key | Should Be $oldEnv[$index].Key - $newEnv[$index].Value | Should Be $oldEnv[$index].Value + $newEnv = Get-Item Env:\* | Sort-Object -Property Key + $newEnv.Count | Should Be $oldEnv.Count + foreach ($index in 1..$newEnv.Count) + { + $newEnv[$index].Key | Should Be $oldEnv[$index].Key + $newEnv[$index].Value | Should Be $oldEnv[$index].Value + } } } + AfterAll { + if ( $skipTest ) { return } + $env:PSModulePath = $SavedPSModulePath + } Context "Module handler class" { - $moduleHandlerType = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.ModuleDependencyHandler] - $oldEnvVars = Get-Item Env:\* | Sort-Object -Property Key - $oldPSModulePath = $env:PSModulePath - It "Sets defaults correctly" { + BeforeAll { + if ( $skipTest ) { return } + $moduleHandlerType = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.ModuleDependencyHandler] + $oldEnvVars = Get-Item Env:\* | Sort-Object -Property Key + $oldPSModulePath = $env:PSModulePath + } + It "Sets defaults correctly" -skip:$skipTest { $rsp = [runspacefactory]::CreateRunspace() $rsp.Open() $depHandler = $moduleHandlerType::new($rsp) @@ -69,21 +61,21 @@ Describe "Resolve DSC Resource Dependency" { $rsp.Dispose() } - It "Keeps the environment variables unchanged" { + It "Keeps the environment variables unchanged" -skip:$skipTest { Test-EnvironmentVariables($oldEnvVars) } - It "Throws if runspace is null" { + It "Throws if runspace is null" -skip:$skipTest { {$moduleHandlerType::new($null)} | Should Throw } - It "Throws if runspace is not opened" { + It "Throws if runspace is not opened" -skip:$skipTest { $rsp = [runspacefactory]::CreateRunspace() {$moduleHandlerType::new($rsp)} | Should Throw $rsp.Dispose() } - It "Extracts 1 module name" { + It "Extracts 1 module name" -skip:$skipTest { $sb = @" {Configuration SomeConfiguration { @@ -97,7 +89,7 @@ Describe "Resolve DSC Resource Dependency" { $resultModuleNames[0] | Should Be 'SomeDscModule1' } - It "Extracts more than 1 module names" { + It "Extracts more than 1 module names" -skip:$skipTest { $sb = @" {Configuration SomeConfiguration { @@ -114,7 +106,7 @@ Describe "Resolve DSC Resource Dependency" { } - It "Extracts module names when ModuleName parameter is not the first named parameter" { + It "Extracts module names when ModuleName parameter is not the first named parameter" -skip:$skipTest { $sb = @" {Configuration SomeConfiguration { @@ -130,64 +122,71 @@ Describe "Resolve DSC Resource Dependency" { } Context "Invoke-ScriptAnalyzer without switch" { - It "Has parse errors" { + It "Has parse errors" -skip:$skipTest { $dr = Invoke-ScriptAnalyzer -Path $violationFilePath -ErrorVariable parseErrors -ErrorAction SilentlyContinue $parseErrors.Count | Should Be 1 } } Context "Invoke-ScriptAnalyzer without switch but with module in temp path" { - $oldEnvVars = Get-Item Env:\* | Sort-Object -Property Key - $moduleName = "MyDscResource" - $modulePath = "$(Split-Path $directory)\Rules\DSCResourceModule\DSCResources\$moduleName" - - # Save the current environment variables - $oldLocalAppDataPath = $env:LOCALAPPDATA - $oldTempPath = $env:TEMP - $oldPSModulePath = $env:PSModulePath - - # set the environment variables - $tempPath = Join-Path $oldTempPath ([guid]::NewGUID()).ToString() - $newLocalAppDataPath = Join-Path $tempPath "LocalAppData" - $newTempPath = Join-Path $tempPath "Temp" - $env:LOCALAPPDATA = $newLocalAppDataPath - $env:TEMP = $newTempPath - - # create the temporary directories - New-Item -Type Directory -Path $newLocalAppDataPath - New-Item -Type Directory -Path $newTempPath - - # create and dispose module dependency handler object - # to setup the temporary module - $rsp = [runspacefactory]::CreateRunspace() - $rsp.Open() - $depHandler = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.ModuleDependencyHandler]::new($rsp) - $pssaAppDataPath = $depHandler.PSSAAppDataPath - $tempModulePath = $depHandler.TempModulePath - $rsp.Dispose() - $depHandler.Dispose() - - # copy myresource module to the temporary location - # we could let the module dependency handler download it from psgallery - Copy-Item -Recurse -Path $modulePath -Destination $tempModulePath - - It "Doesn't have parse errors" { + BeforeAll { + if ( $skipTest ) { return } + $oldEnvVars = Get-Item Env:\* | Sort-Object -Property Key + $moduleName = "MyDscResource" + $modulePath = "$(Split-Path $directory)\Rules\DSCResourceModule\DSCResources\$moduleName" + + # Save the current environment variables + $oldLocalAppDataPath = $env:LOCALAPPDATA + $oldTempPath = $env:TEMP + $oldPSModulePath = $env:PSModulePath + + # set the environment variables + $tempPath = Join-Path $oldTempPath ([guid]::NewGUID()).ToString() + $newLocalAppDataPath = Join-Path $tempPath "LocalAppData" + $newTempPath = Join-Path $tempPath "Temp" + $env:LOCALAPPDATA = $newLocalAppDataPath + $env:TEMP = $newTempPath + + # create the temporary directories + New-Item -Type Directory -Path $newLocalAppDataPath + New-Item -Type Directory -Path $newTempPath + + # create and dispose module dependency handler object + # to setup the temporary module + $rsp = [runspacefactory]::CreateRunspace() + $rsp.Open() + $depHandler = [Microsoft.Windows.PowerShell.ScriptAnalyzer.Generic.ModuleDependencyHandler]::new($rsp) + $pssaAppDataPath = $depHandler.PSSAAppDataPath + $tempModulePath = $depHandler.TempModulePath + $rsp.Dispose() + $depHandler.Dispose() + + # copy myresource module to the temporary location + # we could let the module dependency handler download it from psgallery + 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 $dr.Count | Should Be 0 } - It "Keeps PSModulePath unchanged before and after invocation" { + It "Keeps PSModulePath unchanged before and after invocation" -skip:$skipTest { $dr = Invoke-ScriptAnalyzer -Path $violationFilePath -ErrorVariable parseErrors -ErrorAction SilentlyContinue $env:PSModulePath | Should Be $oldPSModulePath } - #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 "Keeps the environment variables unchanged" { + It "Keeps the environment variables unchanged" -skip:$skipTest { Test-EnvironmentVariables($oldEnvVars) } } diff --git a/Tests/Engine/ModuleHelp.Tests.ps1 b/Tests/Engine/ModuleHelp.Tests.ps1 index b4dd7e94a..7337193eb 100644 --- a/Tests/Engine/ModuleHelp.Tests.ps1 +++ b/Tests/Engine/ModuleHelp.Tests.ps1 @@ -33,8 +33,8 @@ Enter the version of the module to test. This parameter is optional. If you omit it, the test runs on the latest version of the module in $env:PSModulePath. .EXAMPLE -.\Module.Help.Tests.ps1 -ModuleName Pester -RequiredVersion 3.4.0 -This command runs the tests on the commands in Pester 3.4.0. +.\Module.Help.Tests.ps1 -ModuleName Pester -RequiredVersion 4.1.1 +This command runs the tests on the commands in Pester 4.1.1. .EXAMPLE .\Module.Help.Tests.ps1 -ModuleName Pester @@ -63,7 +63,7 @@ Param $RequiredVersion ) -# #Requires -Module @{ModuleName = 'Pester'; ModuleVersion = '3.4.0'} +# #Requires -Module @{ModuleName = 'Pester'; ModuleVersion = '4.1.1'} <# .SYNOPSIS diff --git a/Tests/Engine/RuleSuppression.tests.ps1 b/Tests/Engine/RuleSuppression.tests.ps1 index ee145826f..b8ba1a87a 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:((Test-PSEditionCoreCLRLinux) -or ($PSVersionTable.PSVersion -lt [Version]'5.0.0')) { + It "Suppresses rule" -skip:((!$IsWindows) -or ($PSVersionTable.PSVersion -lt [Version]'5.0.0')) { $suppressedRule = Invoke-ScriptAnalyzer -ScriptDefinition $ruleSuppressionInConfiguration -SuppressedOnly $suppressedRule.Count | Should Be 1 } @@ -215,4 +215,4 @@ Describe "RuleSuppressionWithScope" { $suppressed.Count | Should Be 1 } } - } \ No newline at end of file + } diff --git a/Tests/PSScriptAnalyzerTestHelper.psm1 b/Tests/PSScriptAnalyzerTestHelper.psm1 index 7dc83713c..81a79cc2f 100644 --- a/Tests/PSScriptAnalyzerTestHelper.psm1 +++ b/Tests/PSScriptAnalyzerTestHelper.psm1 @@ -56,11 +56,6 @@ Function Test-PSEditionCoreCLR [bool]$IsCoreCLR } -Function Test-PSEditionCoreCLRLinux -{ - (Test-PSEditionCoreCLR) -and $IsLinux -} - Function Test-PSVersionV3 { $PSVersionTable.PSVersion.Major -eq 3 @@ -82,7 +77,6 @@ Export-ModuleMember -Function Get-ExtentText Export-ModuleMember -Function Test-CorrectionExtent Export-ModuleMember -Function Test-CorrectionExtentFromContent Export-ModuleMember -Function Test-PSEditionCoreCLR -Export-ModuleMember -Function Test-PSEditionCoreCLRLinux Export-ModuleMember -Function Test-PSVersionV3 Export-ModuleMember -Function Test-PSVersionV4 -Export-ModuleMember -Function Get-Count \ No newline at end of file +Export-ModuleMember -Function Get-Count diff --git a/Tests/Rules/AlignAssignmentStatement.tests.ps1 b/Tests/Rules/AlignAssignmentStatement.tests.ps1 index 6dd22304b..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" { + It "Should find violations when assignment statements are not aligned" -skip:($IsLinux -or $IsMacOS) { $def = @' Configuration MyDscConfiguration { @@ -91,7 +91,7 @@ Configuration MyDscConfiguration { if ($PSVersionTable.PSVersion.Major -ge 5) { Context "When assignment statements are in DSC Configuration that has parse errors" { - It "Should find violations when assignment statements are not aligned" { + It "Should find violations when assignment statements are not aligned" -skip:($IsLinux -or $IsMacOS) { $def = @' Configuration Sample_ChangeDescriptionAndPermissions { diff --git a/Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 b/Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 index 9355f4625..951d9ee7c 100644 --- a/Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 +++ b/Tests/Rules/AvoidUnloadableModuleOrMissingRequiredFieldInManifest.tests.ps1 @@ -34,7 +34,7 @@ Describe "MissingRequiredFieldModuleManifest" { } # On Linux, mismatch in line endings cause this to fail - It "has the right suggested correction" -Skip:(Test-PSEditionCoreCLRLinux) { + It "has the right suggested correction" -Skip:($IsLinux) { $expectedText = @' # Version number of this module. ModuleVersion = '1.0.0.0' diff --git a/Tests/Rules/AvoidUsingAlias.tests.ps1 b/Tests/Rules/AvoidUsingAlias.tests.ps1 index ebdbb0d80..9a8f89dc2 100644 --- a/Tests/Rules/AvoidUsingAlias.tests.ps1 +++ b/Tests/Rules/AvoidUsingAlias.tests.ps1 @@ -43,7 +43,7 @@ gci -Path C:\ $noViolations.Count | Should Be 0 } - It "should return no violation for assignment statement-like command in dsc configuration" { + It "should return no violation for assignment statement-like command in dsc configuration" -skip:($IsLinux -or $IsMacOS) { $target = @' Configuration MyDscConfiguration { Node "NodeA" { @@ -96,4 +96,4 @@ Configuration MyDscConfiguration { $violations.Count | Should Be 0 } } -} \ No newline at end of file +} diff --git a/Tests/Rules/UseIdenticalMandatoryParametersForDSC.tests.ps1 b/Tests/Rules/UseIdenticalMandatoryParametersForDSC.tests.ps1 index d815f9467..e8e82a11b 100644 --- a/Tests/Rules/UseIdenticalMandatoryParametersForDSC.tests.ps1 +++ b/Tests/Rules/UseIdenticalMandatoryParametersForDSC.tests.ps1 @@ -14,11 +14,11 @@ Describe "UseIdenticalMandatoryParametersForDSC" { $violations = Invoke-ScriptAnalyzer -Path $badResourceFilepath -IncludeRule $ruleName } - It "Should find a violations" { + It "Should find a violations" -skip:($IsLinux -or $IsMacOS) { $violations.Count | Should Be 5 } - It "Should mark only the function name" { + It "Should mark only the function name" -skip:($IsLinux -or $IsMacOS) { $violations[0].Extent.Text | Should Be 'Get-TargetResource' } } @@ -29,7 +29,7 @@ Describe "UseIdenticalMandatoryParametersForDSC" { } # todo add a test to check one violation per function - It "Should find a violations" { + It "Should find a violations" -pending { $violations.Count | Should Be 0 } } diff --git a/Tests/Rules/UseToExportFieldsInManifest.tests.ps1 b/Tests/Rules/UseToExportFieldsInManifest.tests.ps1 index 18b285f08..e7a00a770 100644 --- a/Tests/Rules/UseToExportFieldsInManifest.tests.ps1 +++ b/Tests/Rules/UseToExportFieldsInManifest.tests.ps1 @@ -83,7 +83,7 @@ Describe "UseManifestExportFields" { $results[0].Extent.Text | Should be "'*'" } - It "suggests corrections for AliasesToExport with wildcard" { + It "suggests corrections for AliasesToExport with wildcard" -pending:($IsLinux -or $IsMacOS) { $violations = Run-PSScriptAnalyzerRule $testManifestBadAliasesWildcardPath $violationFilepath = Join-path $testManifestPath $testManifestBadAliasesWildcardPath Test-CorrectionExtent $violationFilepath $violations[0] 1 "'*'" "@('gbar', 'gfoo')" From ad17fe8b9f1c2d3cf6504178f76ba7cd1441dabc Mon Sep 17 00:00:00 2001 From: James Truher Date: Fri, 9 Feb 2018 16:43:26 -0800 Subject: [PATCH 2/2] Reduce verbosity of build script Update to use Pester version 4.1.1 Change logic in appveyor to invoke pester only once --- README.md | 2 +- Tests/Engine/CustomizedRule.tests.ps1 | 4 ++-- Tests/Engine/InvokeScriptAnalyzer.tests.ps1 | 2 +- Tests/Engine/RuleSuppression.tests.ps1 | 2 +- .../Rules/AlignAssignmentStatement.tests.ps1 | 2 +- appveyor.yml | 18 +++++++--------- build.ps1 | 4 ++-- buildCoreClr.ps1 | 21 ++++++++++++------- 8 files changed, 29 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index 69e268659..e1bee75aa 100644 --- a/README.md +++ b/README.md @@ -129,7 +129,7 @@ For adding/removing resource strings in the `*.resx` files, it is recommended to #### Tests Pester-based ScriptAnalyzer Tests are located in `path/to/PSScriptAnalyzer/Tests` folder. -* Ensure Pester 3.4 is installed on the machine +* Ensure Pester 4.1.1 is installed on the machine * Copy `path/to/PSScriptAnalyzer/out/PSScriptAnalyzer` to a folder in `PSModulePath` * Go the Tests folder in your local repository * Run Engine Tests: diff --git a/Tests/Engine/CustomizedRule.tests.ps1 b/Tests/Engine/CustomizedRule.tests.ps1 index 195726585..609c8f3ae 100644 --- a/Tests/Engine/CustomizedRule.tests.ps1 +++ b/Tests/Engine/CustomizedRule.tests.ps1 @@ -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 (!$IsWindows) { $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 (!$IsWindows) { $expectedNumRules = 4 } diff --git a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 index 9db3839a2..12fa34d22 100644 --- a/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 +++ b/Tests/Engine/InvokeScriptAnalyzer.tests.ps1 @@ -470,7 +470,7 @@ Describe "Test -Fix Switch" { BeforeAll { $scriptName = "TestScriptWithFixableWarnings.ps1" - $testSource = join-path $PSScriptRoot ${scriptName} + $testSource = join-path $PSScriptRoot $scriptName $fixedScript = join-path $PSScriptRoot TestScriptWithFixableWarnings_AfterFix.ps1 $expectedScriptContent = Get-Content $fixedScript -raw $testScript = Join-Path $TESTDRIVE $scriptName diff --git a/Tests/Engine/RuleSuppression.tests.ps1 b/Tests/Engine/RuleSuppression.tests.ps1 index b8ba1a87a..3127a3ae5 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 -lt [Version]'5.0.0')) { + It "Suppresses rule" -skip:((!$IsWindows) -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 5d076dc95..0854045b8 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:($IsLinux -or $IsMacOS) { + It "Should find violations when assignment statements are not aligned" -skip:(!$IsWindows) { $def = @' Configuration MyDscConfiguration { diff --git a/appveyor.yml b/appveyor.yml index 9b394a26b..c28bf8b54 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -19,12 +19,12 @@ cache: install: - ps: nuget install platyPS -Version 0.9.0 -source https://www.powershellgallery.com/api/v2 -outputDirectory "$Env:ProgramFiles\WindowsPowerShell\Modules\." -ExcludeVersion - ps: | - $requiredPesterVersion = '3.4.0' + $requiredPesterVersion = '4.1.1' $pester = Get-Module Pester -ListAvailable | Where-Object { $_.Version -eq $requiredPesterVersion } $pester if ($null -eq $pester) # WMF 4 build does not have pester { - cinst -y pester --version $requiredPesterVersion + nuget install Pester -Version 4.1.1 -source https://www.powershellgallery.com/api/v2 -outputDirectory "$Env:ProgramFiles\WindowsPowerShell\Modules\." -ExcludeVersion } - ps: | # the legacy WMF4 image only has the old preview SDKs of dotnet @@ -57,19 +57,15 @@ branches: test_script: - SET PATH=c:\Program Files\WindowsPowerShell\Modules\;%PATH%; - ps: | - copy "C:\projects\psscriptanalyzer\out\PSScriptAnalyzer" "$Env:ProgramFiles\WindowsPowerShell\Modules\" -Recurse -Force - $engineTestResultsFile = ".\EngineTestResults.xml" + copy-item "C:\projects\psscriptanalyzer\out\PSScriptAnalyzer" "$Env:ProgramFiles\WindowsPowerShell\Modules\" -Recurse -Force + $testResultsFile = ".\TestResults.xml" $ruleTestResultsFile = ".\RuleTestResults.xml" - $engineTestResults = Invoke-Pester -Script "C:\projects\psscriptanalyzer\Tests\Engine" -OutputFormat NUnitXml -OutputFile $engineTestResultsFile -PassThru - (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $engineTestResultsFile)) + $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." } - $ruleTestResults = Invoke-Pester -Script "C:\projects\psscriptanalyzer\Tests\Rules" -OutputFormat NUnitXml -OutputFile $ruleTestResultsFile -PassThru - (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $ruleTestResultsFile)) - if ($ruleTestResults.FailedCount -gt 0) { - throw "$($ruleTestResults.FailedCount) tests failed." - } # Upload the project along with TestResults as a zip archive on_finish: diff --git a/build.ps1 b/build.ps1 index 71979ae4f..40e9c02d6 100644 --- a/build.ps1 +++ b/build.ps1 @@ -132,7 +132,7 @@ if ($Install) if ($Test) { - Import-Module -Name Pester -MinimumVersion 3.4.0 -ErrorAction Stop + Import-Module -Name Pester -MinimumVersion 4.1.1 -ErrorAction Stop Function GetTestRunnerScriptContent($testPath) { $x = @" @@ -202,4 +202,4 @@ if ($Test) if ($Uninstall) { Remove-Item -Path $modulePSSAPath -Force -Verbose:$verbosity -Recurse -} \ No newline at end of file +} diff --git a/buildCoreClr.ps1 b/buildCoreClr.ps1 index 86a28a1c5..9daf3f756 100644 --- a/buildCoreClr.ps1 +++ b/buildCoreClr.ps1 @@ -31,6 +31,7 @@ function Invoke-RestoreSolution dotnet restore (Join-Path $PSScriptRoot .\PSScriptAnalyzer.sln) } +Write-Progress "Building ScriptAnalyzer" $solutionDir = Split-Path $MyInvocation.InvocationName if (-not (Test-Path "$solutionDir/global.json")) { @@ -63,6 +64,7 @@ if ($Restore.IsPresent) if ($build) { + Write-Progress "Building Engine" if (-not (Test-DotNetRestore((Join-Path $solutionDir Engine)))) { Invoke-RestoreSolution @@ -76,6 +78,7 @@ if ($build) { Invoke-RestoreSolution } + Write-Progress "Building for framework $Framework, configuration $Configuration" Push-Location Rules\ dotnet build Rules.csproj --framework $Framework --configuration $Configuration Pop-Location @@ -84,23 +87,26 @@ if ($build) { if (-not (Test-Path $destination)) { - New-Item -ItemType Directory $destination -Force + $null = New-Item -ItemType Directory $destination -Force } foreach ($file in $itemsToCopy) { - Copy-Item -Path $file -Destination (Join-Path $destination (Split-Path $file -Leaf)) -Verbose -Force + Copy-Item -Path $file -Destination (Join-Path $destination (Split-Path $file -Leaf)) -Force } } + + + Write-Progress "Copying files to $destinationDir" CopyToDestinationDir $itemsToCopyCommon $destinationDir CopyToDestinationDir $itemsToCopyBinaries $destinationDirBinaries # Copy Settings File - Copy-Item -Path "$solutionDir\Engine\Settings" -Destination $destinationDir -Force -Recurse -Verbose + Copy-Item -Path "$solutionDir\Engine\Settings" -Destination $destinationDir -Force -Recurse # copy newtonsoft dll if net451 framework if ($Framework -eq "net451") { - copy-item -path "$solutionDir\Rules\bin\$Configuration\$Framework\Newtonsoft.Json.dll" -Destination $destinationDirBinaries -Verbose + copy-item -path "$solutionDir\Rules\bin\$Configuration\$Framework\Newtonsoft.Json.dll" -Destination $destinationDirBinaries } } @@ -112,11 +118,12 @@ if ($uninstall) { if ((Test-Path $pssaModulePath)) { - Remove-Item -Recurse $pssaModulePath -Verbose + Remove-Item -Recurse $pssaModulePath } } if ($install) { - Copy-Item -Recurse -Path "$destinationDir" -Destination "$modulePath\." -Verbose -Force -} \ No newline at end of file + Write-Progress "Installing to $modulePath" + Copy-Item -Recurse -Path "$destinationDir" -Destination "$modulePath\." -Force +}