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.
This commit is contained in:
Travis Plunk committed 2016-07-20 16:28:33 -07:00
1 parent 6fea33379d
commit cd9ddb156d
1 file changed
+39 -19
+39 -19
View File
@@ -16,53 +16,73 @@ Describe 'SDK Send Greeting Sample Tests' -Tag CI {
$testResultPath = Join-Path $TestDrive 'sendgreetingresults.xml' $testResultPath = Join-Path $TestDrive 'sendgreetingresults.xml'
$sampleCopy = Join-Path $TestDrive 'sendgreeting' $sampleCopy = Join-Path $TestDrive 'sendgreeting'
$fullSampleCopyPath = Join-Path $sampleCopy 'cmdlet-example' $fullSampleCopyPath = Join-Path $sampleCopy 'cmdlet-example'
$powershell = (Get-Process -id $PID).MainModule.FileName
if(!(Test-Path $sampleCopy)) if(!(Test-Path $sampleCopy))
{ {
New-Item -ItemType Directory -Path $sampleCopy New-Item -ItemType Directory -Path $sampleCopy
} }
Copy-Item -Recurse -Path $docLocation -Destination $sampleCopy -Force 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" $pesterCommand = "Invoke-Pester $sampleCopy -PassThru"
if($global:__PesterTags) if($global:__PesterTags)
{ {
$pesterCommand += " -Tag $(@($global:__PesterTags) -join ',')" $pesterCommand += " -Tag $(@($global:__PesterTags) -join ',')"
} }
if($global:__PesterExcludeTags) if($global:__PesterExcludeTags)
{ {
$pesterCommand += " -ExcludeTag $(@($global:__PesterExcludeTags) -join ',')" $pesterCommand += " -ExcludeTag $(@($global:__PesterExcludeTags) -join ',')"
} }
$importPesterCommand = 'Import-module Pester'
if($isCore)
{
$importPesterCommand = "Import-Module $(Join-Path -path $PSHOME -child '/Modules/Pester')"
}
$command = @" $command = @"
Push-Location -Path $fullSampleCopyPath Push-Location -Path $fullSampleCopyPath
Import-module $(Join-path $env:PSModulePath pester) $importPesterCommand
$pesterCommand | Export-Clixml -Path $testResultPath $pesterCommand | Export-Clixml -Path $testResultPath
"@ "@
Write-Verbose -Message "command: '$command'" -Verbose Write-Verbose -Message "command: '$command'"
$bytes = [System.Text.Encoding]::Unicode.GetBytes($command) $bytes = [System.Text.Encoding]::Unicode.GetBytes($command)
$encodedCommand = [Convert]::ToBase64String($bytes) $encodedCommand = [Convert]::ToBase64String($bytes)
&"$PSHOME/powershell" -encodedCommand $encodedCommand &$powershell -encodedCommand $encodedCommand
it "Should have test results file" { it "Should have test results file" {
$testResultPath | should exist $testResultPath | should exist
$script:results = Import-Clixml $testResultPath $script:results = Import-Clixml $testResultPath
} }
#$host.EnterNestedPrompt();
it "Should have test results" { it "Should have test results" {
$script:results | should not be BeNullOrEmpty $script:results | should not be BeNullOrEmpty
$script:results.TotalCount | should not BeNullOrEmpty $script:results.TotalCount | should not BeNullOrEmpty
$script:results.TestResult.Count | 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){ foreach($testResult in $script:results.TestResult){
it "Test $($testResult.Name) should not fail" { Context "Test $($testResult.Name)" {
$testResult.FailureMessage + $testResult.StackTrace | should BeNullOrEmpty it "should have no failure message" {
$testResult.ErrorRecord | should BeNullOrEmpty $testResult.FailureMessage | should BeNullOrEmpty
Write-Verbose "Result: $($testResult.Result)" }
$testResult.Result | should not be Failed 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
}
} }
} }