diff --git a/src/rez/tests/test_shells.py b/src/rez/tests/test_shells.py index 35f7de76e..114497089 100644 --- a/src/rez/tests/test_shells.py +++ b/src/rez/tests/test_shells.py @@ -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() diff --git a/src/rezplugins/shell/_utils/powershell_base.py b/src/rezplugins/shell/_utils/powershell_base.py index f059bb248..bf9d3014d 100644 --- a/src/rezplugins/shell/_utils/powershell_base.py +++ b/src/rezplugins/shell/_utils/powershell_base.py @@ -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"