Skip to content

Commit

Permalink
Make Powershell correctly return exit codes for aliases (AcademySoftw…
Browse files Browse the repository at this point in the history
…areFoundation#1778)

Fixes issue where powershell plugins were not correctly capturing exit codes when aliased commands failed (AcademySoftwareFoundation#1778)

---------

Signed-off-by: brycegbrazen <bryce.gattis@brazenanimation.com>
Co-authored-by: Jean-Christophe Morin <38703886+JeanChristopheMorinPerso@users.noreply.github.com>
  • Loading branch information
Pixel-Minions and JeanChristopheMorinPerso committed Sep 26, 2024
1 parent 0d73bfa commit 8113ffd
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 8113ffd

Please sign in to comment.