From cd9ddb156ddc072752b15850279e530aedd22947 Mon Sep 17 00:00:00 2001 From: Travis Plunk Date: Wed, 20 Jul 2016 16:16:21 -0700 Subject: [PATCH] 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 287ea3950b..4b41f314be 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 + } } }