Non-existent testresults file causes CO build failure

9 views
Skip to first unread message

Jamie Thomson

unread,
Sep 1, 2014, 7:15:10 AM9/1/14
to pes...@googlegroups.com
I've been discussing an issue with Dave Wyatt where errors created by Pester in the Powershell error stream cause my CI build to fail even though the tests pass (see thread Error: "Cannot find a variable with the name 'TestDrive'"). Now I've discovered a similar problem regarding the file specified in the -OutputXml parameter of Invoke-Pester. If the file specified therein does not exist then my tests still pass but I get an error in the error stream that causes my CI build to fail. That error is:
Cannot find path '<path to intended test results file>' because it does not exist.

I tracked the error down to GetFullPath in TestResults.ps1. That function is defined as:
function GetFullPath ([string]$Path) {
    $fullpath
= Resolve-Path -Path $Path -ErrorAction SilentlyContinue -ErrorVariable Error
   
if ($fullpath)
   
{
        $fullpath
   
}
   
else
   
{
        $error
[0].TargetObject
   
}
}
(Its the call to Resolve-Path that causes the error).

I hacked away and ended up with:
function GetFullPath ([string]$Path) {
 
if (Test-Path $Path)
 
{
   
Resolve-Path -Path $Path
 
}
 
else
 
{
   
(Split-Path -parent -Path $path | Resolve-Path).ToString() + "\" + (Split-Path -Path $path -Leaf)
 }
}

which gets me past the immediate problem but is clearly bad because I've changed the behaviour of GetFullPath and only actually works if the parent folder exists.

I'm writing this to report the problem and hopefully prompt a discussion regarding the correct course of action.

regards
Jamie

Jamie Thomson

unread,
Sep 1, 2014, 7:16:08 AM9/1/14
to pes...@googlegroups.com
Typo in subject. Should be "CI" not "CO"

Dave Wyatt

unread,
Sep 1, 2014, 9:24:10 AM9/1/14
to pes...@googlegroups.com
That's another instance of the same sort of problem.  Error suppressed by -ErrorAction SilentlyContinue still get added to the $error variable, which is what I assume is causing your CI process to fail at this point.  The same goes for errors handled by try/catch or trap; they are added to $error _before_ the trap or catch blocks are evaluated.  This is rather annoying.

There is an 'Ignore' option for -ErrorAction in PowerShell 3.0 and later which addresses this behavior for non-terminating errors, but the same behavior still exists for try/catch and trap.


On Monday, September 1, 2014 7:16:08 AM UTC-4, Jamie Thomson wrote:
Reply all
Reply to author
Forward
0 new messages