You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe 'ExitCodes' {
It 'Should catch exit codes with $? variable' {
Mock git -Verifiable -MockWith {
# This mock should call through to the real git command. Imagine it transforms some arguments.& (Get-Command-CommandType Application git) $args
}
& (Get-Command-CommandType Application git) --git-dir ~/missing/.git --work-tree ~/missing/.git/.. status
$?| Should -BeFalse # Works$LASTEXITCODE| Should -Be 128
git --git-dir ~/missing/.git --work-tree ~/missing/.git/.. status
$?| Should -BeFalse # Breaks$LASTEXITCODE| Should -Be 128
}
}
How can we have the second example, which uses the mock, to work as expected? So that the $? is false.
Pester 5.7.1 and PowerShell 7.4.6
Edit:
It does work if a cmdlet is used instead of the mock like this:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Given this code:
How can we have the second example, which uses the mock, to work as expected? So that the
$?
is false.Pester 5.7.1 and PowerShell 7.4.6
Edit:
It does work if a cmdlet is used instead of the mock like this:
Beta Was this translation helpful? Give feedback.
All reactions