'''
Copyright (C) 2024-2026 Mo Zhou <lumin@debian.org>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
'''
import pytest
from debgpt.cli import main

import pytest
from unittest.mock import patch
from debgpt.cli import main

@pytest.mark.parametrize('cmd', (
    '-F dryrun',
    '-F dryrun -Hf Makefile',
    '-F dryrun -Qf Makefile',
    '-F dryrun --invalid-argument-example man',
    '-F dryrun --man man',
    '-F dryrun --version',
    '-F dryrun --cmd "man man"',
))
def test_cli_system_exit(cmd: str):
    with pytest.raises(SystemExit):
        main(cmd.split())


def test_cli_backend_routing():
    with patch('debgpt.cli.subcmd_backend') as mock_subcmd:
        mock_subcmd.side_effect = SystemExit(0)
        with pytest.raises(SystemExit):
            main(['backend'])
        mock_subcmd.assert_called_once()
