Skip to content

Commit

Permalink
Make Powershell correctly return exit codes for aliases (#1778)
Browse files Browse the repository at this point in the history
Fixes issue where powershell plugins were not correctly capturing exit codes when aliased commands failed (#1778)

---------

Signed-off-by: brycegbrazen <[email protected]>
Co-authored-by: Jean-Christophe Morin <[email protected]>
  • Loading branch information
brycegbrazen and JeanChristopheMorinPerso authored Sep 22, 2024
1 parent f0e40fd commit 63326f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/rez/tests/test_shells.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,22 @@ def _make_alias(ex):
out, _ = p.communicate()
self.assertEqual(0, p.returncode)

@per_available_shell()
def test_alias_return_code(self, shell):
"""Ensure return codes are correct while using aliases."""
config.override("default_shell", shell)

def _make_alias(ex):
ex.alias('my_alias', 'hello_world -r 1')

r = self._create_context(["hello_world"])
p = r.execute_shell(command='my_alias',
actions_callback=_make_alias,
stdout=subprocess.PIPE)

out, _ = p.communicate()
self.assertEqual(1, p.returncode)


if __name__ == '__main__':
unittest.main()
2 changes: 1 addition & 1 deletion src/rezplugins/shell/_utils/powershell_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def _record_shell(ex, files, bind_rez=True, print_msg=False):
# only the bool $? var is set.
#
executor.command(
"if(! $?) {\n"
"if(! $? -or $LASTEXITCODE) {\n"
" if ($LASTEXITCODE) {\n"
" exit $LASTEXITCODE\n"
" }\n"
Expand Down

0 comments on commit 63326f2

Please sign in to comment.