From f03c144f971e50688fe9827320339a513959b497 Mon Sep 17 00:00:00 2001 From: Aamir Abdul Azeez <165933255+aamir-azeez@users.noreply.github.com> Date: Fri, 25 Sep 2026 17:54:47 -0400 Subject: [PATCH] Return commander exit status --- pyocd/subcommands/commander_cmd.py | 5 ++--- test/unit/test_cmdline.py | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/pyocd/subcommands/commander_cmd.py b/pyocd/subcommands/commander_cmd.py index 5714eebef..7e5ee8214 100644 --- a/pyocd/subcommands/commander_cmd.py +++ b/pyocd/subcommands/commander_cmd.py @@ -1,5 +1,6 @@ # pyOCD debugger # Copyright (c) 2021 Chris Reed +# Copyright (c) 2026 Aamir Abdul Azeez # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -72,8 +73,6 @@ def invoke(self) -> int: cmds = None # Enter REPL. - PyOCDCommander(self._args, cmds).run() - - return 0 + return PyOCDCommander(self._args, cmds).run() diff --git a/test/unit/test_cmdline.py b/test/unit/test_cmdline.py index 15d16a7d0..b89c1279e 100644 --- a/test/unit/test_cmdline.py +++ b/test/unit/test_cmdline.py @@ -1,6 +1,7 @@ # pyOCD debugger # Copyright (c) 2015,2018-2019,2026 Arm Limited # Copyright (c) 2022 Chris Reed +# Copyright (c) 2026 Aamir Abdul Azeez # SPDX-License-Identifier: Apache-2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,6 +16,9 @@ # See the License for the specific language governing permissions and # limitations under the License. +import argparse +from unittest.mock import Mock + import pytest from pyocd.utility.compatibility import to_bytes_safe @@ -26,6 +30,20 @@ ) from pyocd.core.target import Target from pyocd.target import normalise_target_type_name +from pyocd.subcommands.commander_cmd import CommanderSubcommand + + +class TestCommanderSubcommand: + @pytest.mark.parametrize("exit_code", [0, 1, 2, 3, 4]) + def test_exit_code(self, monkeypatch, exit_code): + args = argparse.Namespace(commands=None) + commander = Mock() + commander.return_value.run.return_value = exit_code + monkeypatch.setattr("pyocd.subcommands.commander_cmd.PyOCDCommander", commander) + + assert CommanderSubcommand(args).invoke() == exit_code + commander.assert_called_once_with(args, None) + commander.return_value.run.assert_called_once_with() class TestSplitCommandLine(object): def test_split(self):