Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It is not an assert <em>function</em> that you use, it is an assert <em>script block</em> used as a “member function”. But it is still a script block.</p> <p>According to this reported issue: <a href="https://connect.microsoft.com/PowerShell/feedback/details/531086/depending-on-how-you-invoke-a-script-block-the-invocation-details-may-not-be-available-from-inside-the-script-block#" rel="nofollow noreferrer">https://connect.microsoft.com/PowerShell/feedback/details/531086/depending-on-how-you-invoke-a-script-block-the-invocation-details-may-not-be-available-from-inside-the-script-block#</a></p> <p>there is something wrong with calling <code>Get-PSCallStack</code> from script blocks. So, the answer to your question is probably: yes, it is a PowerShell issue.</p> <p>Well, I would recommend you to use functions. I re-factored your scripts to use functions (dirty version, bad names, etc.) and they work as expected:</p> <pre><code>#File 1 (Tester.ps1) #Creates the tester object function AssertTrue { param($expression); $stackFrame = (Get-PSCallStack)[1] try{ $result = . $expression; if($result -eq $true){ LogPass }else{ LogFailure ("Evaluation Failed expected ""$true"" got ""$false""") $stackFrame } }catch [Exception]{ LogFailure "Unexpected exception encountered" $stackFrame } } function LogPass { #Do nothing } function LogFailure { param($message, $stackFrame); "Failure Encounterd"; "Command: $($stackFrame.Command)" "Location: $($stackFrame.Location)"; "Message: $message"; } </code></pre> <p>And</p> <pre><code>#File 2 (TestCase.ps1) #Runs the tests using the tester object . (Resolve-Path "Tester.ps1"); function TestFailure { $expression = {$false}; AssertTrue $expression } TestFailure </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload