From ffe0a250a90e522adfc872b88632ba8a9a074b28 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 19 Jul 2016 16:22:59 -0700 Subject: [PATCH 1/7] Changed Find-Package test to 'SLOW' --- test/powershell/Modules/PackageManagement/Nuget.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/Modules/PackageManagement/Nuget.Tests.ps1 b/test/powershell/Modules/PackageManagement/Nuget.Tests.ps1 index 7c3712a1d..54dd7df37 100644 --- a/test/powershell/Modules/PackageManagement/Nuget.Tests.ps1 +++ b/test/powershell/Modules/PackageManagement/Nuget.Tests.ps1 @@ -281,7 +281,7 @@ Describe "Event Test" -Tags @('BVT', 'DRT') { } } -Describe "Find-Package" -Tags @('BVT', 'DRT'){ +Describe "Find-Package" -Tags @('CI','SLOW'){ it "EXPECTED: Find a package with a location created via new-psdrive" -Skip:(-not $IsWindows) { $Error.Clear() New-PSDrive -Name xx -PSProvider FileSystem -Root $TestDrive -warningaction:silentlycontinue -ea silentlycontinue > $null; find-package -name "fooobarrr" -provider nuget -source xx:\ -warningaction:silentlycontinue -ea silentlycontinue From c69104a7505118741cb67314c8b282f7634ec8ed Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Tue, 19 Jul 2016 16:47:48 -0700 Subject: [PATCH 2/7] Made appveyor exclude 'slow' tests --- appveyor.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index c33a35031..7b9e368cb 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -34,14 +34,15 @@ test_script: $env:CoreOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -Publish)) Write-Host -Foreground Green 'Run CoreCLR tests' $testResultsFile = "$pwd\TestsResults.xml" - & ("$env:CoreOutput\powershell.exe") -noprofile -noninteractive -c "Invoke-Pester test/powershell -OutputFormat NUnitXml -OutputFile $testResultsFile" + & ("$env:CoreOutput\powershell.exe") -noprofile -noninteractive -c "Invoke-Pester test/powershell -ExcludeTag 'Slow' -OutputFormat NUnitXml -OutputFile $testResultsFile" + (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFile)) # # FullCLR $env:FullOutput = Split-Path -Parent (Get-PSOutput -Options (New-PSOptions -FullCLR)) Write-Host -Foreground Green 'Run FullCLR tests' $testResultsFileFullCLR = "$pwd\TestsResults.FullCLR.xml" - Start-DevPowerShell -NoNewWindow -ArgumentList '-noprofile', '-noninteractive' -Command "Invoke-Pester test/fullCLR -OutputFormat NUnitXml -OutputFile $testResultsFileFullCLR" + Start-DevPowerShell -NoNewWindow -ArgumentList '-noprofile', '-noninteractive' -Command "Invoke-Pester test/fullCLR -ExcludeTag 'Slow' -OutputFormat NUnitXml -OutputFile $testResultsFileFullCLR" (New-Object 'System.Net.WebClient').UploadFile("https://ci.appveyor.com/api/testresults/nunit/$($env:APPVEYOR_JOB_ID)", (Resolve-Path $testResultsFileFullCLR)) # # Fail the build, if tests failed From 7f97e4b9cfab6c100530be47423f3566d65da24a Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 20 Jul 2016 14:46:54 -0700 Subject: [PATCH 3/7] Added CI Tag to sample --- docs/cmdlet-example/SendGreeting.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cmdlet-example/SendGreeting.Tests.ps1 b/docs/cmdlet-example/SendGreeting.Tests.ps1 index c4390fbe2..039be41eb 100644 --- a/docs/cmdlet-example/SendGreeting.Tests.ps1 +++ b/docs/cmdlet-example/SendGreeting.Tests.ps1 @@ -1,4 +1,4 @@ -Describe "Send-Greeting cmdlet" -Tag 'Slow' { +Describe "Send-Greeting cmdlet" -Tag 'Slow','CI' { It "Should be able build the cmdlet" { Remove-Item -Recurse -Force bin -ErrorAction SilentlyContinue dotnet restore --verbosity Error | Should BeNullOrEmpty From 441b105fd82be6eef314907c952b6bf9fb5edf92 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 20 Jul 2016 14:47:58 -0700 Subject: [PATCH 4/7] Made the test run in new powershell Ran the test with the same filter Imported the result cleaned up the test run --- test/powershell/SDK/CmdletExample.Tests.ps1 | 78 +++++++++++++++++++-- 1 file changed, 71 insertions(+), 7 deletions(-) diff --git a/test/powershell/SDK/CmdletExample.Tests.ps1 b/test/powershell/SDK/CmdletExample.Tests.ps1 index 517d7a51a..25f64e715 100644 --- a/test/powershell/SDK/CmdletExample.Tests.ps1 +++ b/test/powershell/SDK/CmdletExample.Tests.ps1 @@ -1,9 +1,73 @@ -try { - $enlistmentRoot = git rev-parse --show-toplevel +# Looking at pester internal to get tag filter and ExcludeTagFilter +# This seems like the most stable way to do this +# other options like testing for tags seems more likely to break + +InModuleScope Pester { + Describe 'Getting Tag Filters' -Tag CI { + $global:__PesterTags = $pester.TagFilter + $global:__PesterExcludeTags = $pester.ExcludeTagFilter + } +} +Describe 'SDK Send Greeting Sample Tests' -Tag CI { + + try { + $enlistmentRoot = git rev-parse --show-toplevel + $docLocation = Join-Path -Path $enlistmentRoot -ChildPath '\docs\cmdlet-example' + $testResultPath = Join-Path $TestDrive 'sendgreetingresults.xml' + $sampleCopy = Join-Path $TestDrive 'sendgreeting' + $fullSampleCopyPath = Join-Path $sampleCopy 'cmdlet-example' + if(!(Test-Path $sampleCopy)) + { + New-Item -ItemType Directory -Path $sampleCopy + } + + Copy-Item -Recurse -Path $docLocation -Destination $sampleCopy -Force + dir -Recurse $sampleCopy | %{ Write-Verbose "sc: $($_.FullName)"} + +$pesterCommand = "Invoke-Pester $sampleCopy -PassThru" +if($global:__PesterTags) +{ + $pesterCommand += " -Tag $(@($global:__PesterTags) -join ',')" +} + +if($global:__PesterExcludeTags) +{ + $pesterCommand += " -ExcludeTag $(@($global:__PesterExcludeTags) -join ',')" +} + + $command = @" +Push-Location -Path $fullSampleCopyPath +Import-module $(Join-path $env:PSModulePath pester) +$pesterCommand | Export-Clixml -Path $testResultPath +"@ + + Write-Verbose -Message "command: '$command'" -Verbose + $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) + $encodedCommand = [Convert]::ToBase64String($bytes) + &"$PSHOME/Powershell.exe" -encodedCommand $encodedCommand + + it "Should have test results file" { + $testResultPath | should exist + $script:results = Import-Clixml $testResultPath + } + #$host.EnterNestedPrompt(); + it "Should have test results" { + $script:results | should not be BeNullOrEmpty + $script:results.TotalCount | should not BeNullOrEmpty + $script:results.TestResult.Count | should not BeNullOrEmpty + } + + foreach($testResult in $script:results.TestResult){ + it "Test $($testResult.Name) should not fail" { + $testResult.FailureMessage + $testResult.StackTrace | should BeNullOrEmpty + $testResult.ErrorRecord | should BeNullOrEmpty + Write-Verbose "Result: $($testResult.Result)" + $testResult.Result | should not be Failed + } + } + + } finally { + Pop-Location + } - $docLocation = [io.path]::Combine($enlistmentRoot, "docs","cmdlet-example") - Push-Location $docLocation - ./SendGreeting.Tests.ps1 -} finally { - Pop-Location } From a51618aa4cb738fb0c5953428802270cde85254a Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 20 Jul 2016 14:48:36 -0700 Subject: [PATCH 5/7] Removed test for appveyor.yml --- appveyor.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 7b9e368cb..a63c3cd45 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -58,12 +58,6 @@ test_script: { throw "$($x.'test-results'.failures) tests in test/fullCLR failed" } - # - # Portable module test - Write-Host -Foreground Green 'Test use of cross-platform binary module' - Import-Module ./docs/cmdlet-example/bin/Debug/netstandard1.3/SendGreeting.dll - Send-Greeting -Name World - on_finish: - ps: | From 6fea33379d642a67ec1f9f3ccc6f3905c666d773 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 20 Jul 2016 15:10:39 -0700 Subject: [PATCH 6/7] made powershell invoke compatible with linux --- test/powershell/SDK/CmdletExample.Tests.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/powershell/SDK/CmdletExample.Tests.ps1 b/test/powershell/SDK/CmdletExample.Tests.ps1 index 25f64e715..287ea3950 100644 --- a/test/powershell/SDK/CmdletExample.Tests.ps1 +++ b/test/powershell/SDK/CmdletExample.Tests.ps1 @@ -44,7 +44,7 @@ $pesterCommand | Export-Clixml -Path $testResultPath Write-Verbose -Message "command: '$command'" -Verbose $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $encodedCommand = [Convert]::ToBase64String($bytes) - &"$PSHOME/Powershell.exe" -encodedCommand $encodedCommand + &"$PSHOME/powershell" -encodedCommand $encodedCommand it "Should have test results file" { $testResultPath | should exist From cd9ddb156ddc072752b15850279e530aedd22947 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 20 Jul 2016 16:16:21 -0700 Subject: [PATCH 7/7] Used method from PR comments to find powershell replaced dir with get-childitem used appropriate path when importing pester verified failure count was 0 split test case verification into individual it's so we get all the info. --- test/powershell/SDK/CmdletExample.Tests.ps1 | 58 ++++++++++++++------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/test/powershell/SDK/CmdletExample.Tests.ps1 b/test/powershell/SDK/CmdletExample.Tests.ps1 index 287ea3950..4b41f314b 100644 --- a/test/powershell/SDK/CmdletExample.Tests.ps1 +++ b/test/powershell/SDK/CmdletExample.Tests.ps1 @@ -16,53 +16,73 @@ Describe 'SDK Send Greeting Sample Tests' -Tag CI { $testResultPath = Join-Path $TestDrive 'sendgreetingresults.xml' $sampleCopy = Join-Path $TestDrive 'sendgreeting' $fullSampleCopyPath = Join-Path $sampleCopy 'cmdlet-example' + $powershell = (Get-Process -id $PID).MainModule.FileName if(!(Test-Path $sampleCopy)) { New-Item -ItemType Directory -Path $sampleCopy } Copy-Item -Recurse -Path $docLocation -Destination $sampleCopy -Force - dir -Recurse $sampleCopy | %{ Write-Verbose "sc: $($_.FullName)"} + Get-ChildItem -Recurse $sampleCopy | %{ Write-Verbose "sc: $($_.FullName)"} -$pesterCommand = "Invoke-Pester $sampleCopy -PassThru" -if($global:__PesterTags) -{ - $pesterCommand += " -Tag $(@($global:__PesterTags) -join ',')" -} + $pesterCommand = "Invoke-Pester $sampleCopy -PassThru" + if($global:__PesterTags) + { + $pesterCommand += " -Tag $(@($global:__PesterTags) -join ',')" + } -if($global:__PesterExcludeTags) -{ - $pesterCommand += " -ExcludeTag $(@($global:__PesterExcludeTags) -join ',')" -} + if($global:__PesterExcludeTags) + { + $pesterCommand += " -ExcludeTag $(@($global:__PesterExcludeTags) -join ',')" + } + + $importPesterCommand = 'Import-module Pester' + if($isCore) + { + $importPesterCommand = "Import-Module $(Join-Path -path $PSHOME -child '/Modules/Pester')" + } $command = @" Push-Location -Path $fullSampleCopyPath -Import-module $(Join-path $env:PSModulePath pester) +$importPesterCommand $pesterCommand | Export-Clixml -Path $testResultPath "@ - Write-Verbose -Message "command: '$command'" -Verbose + Write-Verbose -Message "command: '$command'" $bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $encodedCommand = [Convert]::ToBase64String($bytes) - &"$PSHOME/powershell" -encodedCommand $encodedCommand + &$powershell -encodedCommand $encodedCommand it "Should have test results file" { $testResultPath | should exist $script:results = Import-Clixml $testResultPath } - #$host.EnterNestedPrompt(); + it "Should have test results" { $script:results | should not be BeNullOrEmpty $script:results.TotalCount | should not BeNullOrEmpty $script:results.TestResult.Count | should not BeNullOrEmpty } + it "Should have no failures" { + $script:results.FailedCount | should be 0 + } + foreach($testResult in $script:results.TestResult){ - it "Test $($testResult.Name) should not fail" { - $testResult.FailureMessage + $testResult.StackTrace | should BeNullOrEmpty - $testResult.ErrorRecord | should BeNullOrEmpty - Write-Verbose "Result: $($testResult.Result)" - $testResult.Result | should not be Failed + Context "Test $($testResult.Name)" { + it "should have no failure message" { + $testResult.FailureMessage | should BeNullOrEmpty + } + it "should have no stack trace" { + $testResult.StackTrace | should BeNullOrEmpty + } + it "should have no error record" { + $testResult.ErrorRecord | should BeNullOrEmpty + } + it "should have not failed" { + Write-Verbose "Result: $($testResult.Result)" + $testResult.Result | should not be Failed + } } }