Skip to content

Commit

Permalink
Added defensive coding and warning - fixes pester#33
Browse files Browse the repository at this point in the history
  • Loading branch information
kilasuit committed Jun 10, 2020
1 parent a44ff1d commit ed5a1ac
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Extension/PesterTask/PesterV9/Pester.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ if ($TargetPesterVersion -match '^5') {
Write-Host "##vso[task.logissue type=error]This version of the task does not support Pester V5, please use task version 10 or higher."
exit 1
}
if ($TargetPesterVersion -match 'latest') {
Write-Host "##vso[task.logissue type=warning]Task version not properly set so defaulting to enforcing it to be the latest possible v4 that we will support in this version of the task - v4.99.99"
$TargetPesterVersion = '4.99.99'
}
Write-Host "scriptFolder $scriptFolder"
Write-Host "resultsFile $resultsFile"
Write-Host "run32Bit $run32Bit"
Expand All @@ -58,7 +62,13 @@ Write-Host "CodeCoverageFolder $CodeCoverageFolder"
Write-Host "ScriptBlock $ScriptBlock"

Import-Module -Name (Join-Path $PSScriptRoot "HelperModule.psm1") -Force
Import-Pester -Version $TargetPesterVersion
If ($TargetPesterVersion -eq '4.99.99') {
Import-Pester -MaximumVersion $TargetPesterVersion
}
else {
Import-Pester -Version $TargetPesterVersion
}


if ($run32Bit -eq $true -and $env:Processor_Architecture -ne "x86") {
# Get the command parameters
Expand All @@ -74,7 +84,7 @@ if ($run32Bit -eq $true -and $env:Processor_Architecture -ne "x86") {
}

}
write-warning "Re-launching in x86 PowerShell with $($args -join ' ')"
Write-Warning "Re-launching in x86 PowerShell with $($args -join ' ')"
&"$env:windir\syswow64\windowspowershell\v1.0\powershell.exe" -noprofile -executionpolicy bypass -file $myinvocation.Mycommand.path $args
exit
}
Expand All @@ -87,13 +97,12 @@ if ($PSBoundParameters.ContainsKey('additionalModulePath')) {


$Parameters = @{
PassThru = $True
OutputFile = $resultsFile
PassThru = $True
OutputFile = $resultsFile
OutputFormat = 'NUnitXml'
}

if (test-path -path $scriptFolder)
{
if (Test-Path -path $scriptFolder) {
Write-Host "Running Pester from the folder [$scriptFolder] output sent to [$resultsFile]"
$Parameters.Add("Script", $scriptFolder)
}
Expand All @@ -119,7 +128,7 @@ if ($CodeCoverageOutputFile -and (Get-Module Pester).Version -ge [Version]::Pars
$CodeCoverageFolder = $scriptFolder
}
$Files = Get-ChildItem -Path $CodeCoverageFolder -include *.ps1, *.psm1 -Exclude *.Tests.ps1 -Recurse |
Select-object -ExpandProperty Fullname
Select-Object -ExpandProperty Fullname

if ($Files) {
$Parameters.Add('CodeCoverage', $Files)
Expand Down

0 comments on commit ed5a1ac

Please sign in to comment.