From 774963e582ee5780f94090a000fff06674f1ec17 Mon Sep 17 00:00:00 2001 From: brycegbrazen Date: Tue, 23 Jul 2024 16:17:34 -0500 Subject: [PATCH 1/2] Add failing unit test Signed-off-by: brycegbrazen Signed-off-by: Jean-Christophe Morin --- src/rez/tests/test_shells.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/rez/tests/test_shells.py b/src/rez/tests/test_shells.py index 114497089..a05688730 100644 --- a/src/rez/tests/test_shells.py +++ b/src/rez/tests/test_shells.py @@ -607,6 +607,22 @@ def _make_alias(ex): out, _ = p.communicate() self.assertEqual(1, p.returncode) + @per_available_shell() + def test_alias_non_existent_command_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', 'a_non_existent_executable') + + r = self._create_context([]) + p = r.execute_shell(command='my_alias', + actions_callback=_make_alias, + stdout=subprocess.PIPE) + + out, _ = p.communicate() + self.assertNotEqual(0, p.returncode) + if __name__ == '__main__': unittest.main() From 9b59dd2ef39df69e07a10607d84c1d22ccad5823 Mon Sep 17 00:00:00 2001 From: brycegbrazen Date: Mon, 11 Nov 2024 20:47:58 -0600 Subject: [PATCH 2/2] Add a few more changes to get a passing unit test. Signed-off-by: brycegbrazen --- src/rezplugins/shell/_utils/powershell_base.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/rezplugins/shell/_utils/powershell_base.py b/src/rezplugins/shell/_utils/powershell_base.py index 89074efef..e9252f9bf 100644 --- a/src/rezplugins/shell/_utils/powershell_base.py +++ b/src/rezplugins/shell/_utils/powershell_base.py @@ -153,7 +153,7 @@ def _record_shell(ex, files, bind_rez=True, print_msg=False): # only the bool $? var is set. # executor.command( - "if(! $? -or $LASTEXITCODE) {\n" + "if(! $? -or $LASTEXITCODE -or $error) {\n" " if ($LASTEXITCODE) {\n" " exit $LASTEXITCODE\n" " }\n" @@ -248,7 +248,7 @@ def prependenv(self, key, value): # Be careful about ambiguous case in pwsh on Linux where pathsep is : # so that the ${ENV:VAR} form has to be used to not collide. self._addline( - 'Set-Item -Path "Env:{0}" -Value ("{1}{2}" + (Get-ChildItem -ErrorAction SilentlyContinue "Env:{0}").Value)' + 'Set-Item -Path "Env:{0}" -Value ("{1}{2}" + (Get-ChildItem -ErrorAction Ignore "Env:{0}").Value)' .format(key, value, self.pathsep) ) @@ -257,15 +257,15 @@ def appendenv(self, key, value): # Be careful about ambiguous case in pwsh on Linux where pathsep is : # so that the ${ENV:VAR} form has to be used to not collide. - # The nested Get-ChildItem call is set to SilentlyContinue to prevent + # The nested Get-ChildItem call is set to Ignore to prevent # an exception of the Environment Variable is not set already self._addline( - 'Set-Item -Path "Env:{0}" -Value ((Get-ChildItem -ErrorAction SilentlyContinue "Env:{0}").Value + "{1}{2}")' + 'Set-Item -Path "Env:{0}" -Value ((Get-ChildItem -ErrorAction Ignore "Env:{0}").Value + "{1}{2}")' .format(key, os.path.pathsep, value)) def unsetenv(self, key): self._addline( - 'Remove-Item -ErrorAction SilentlyContinue "Env:{0}"'.format(key) + 'Remove-Item -ErrorAction Ignore "Env:{0}"'.format(key) ) def resetenv(self, key, value, friends=None):