1# Copyright (c) 2023 Google Inc
2#
3# SPDX-License-Identifier: Apache-2.0
4
5import argparse
6from argparse import Namespace
7
8import pytest
9from twister_cmd import Twister
10
11TEST_CASES = [
12    {
13        "r": [],
14        "c": False,
15        "test_only": False,
16    },
17    {
18        "r": ["-c", "-T tests/ztest/base"],
19        "c": True,
20        "T": [" tests/ztest/base"],
21        "test_only": False,
22    },
23    {
24        "r": ["--test-only"],
25        "c": False,
26        "test_only": True,
27    },
28]
29
30ARGS = Namespace(
31    help=None,
32    zephyr_base=None,
33    verbose=0,
34    command="twister",
35)
36
37
38@pytest.mark.parametrize("test_case", TEST_CASES)
39def test_parse_remainder(test_case):
40    twister = Twister()
41    parser = argparse.ArgumentParser(
42        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter,
43        allow_abbrev=False
44    )
45    sub_p = parser.add_subparsers()
46
47    twister.parser = twister.do_add_parser(sub_p)
48    options = twister._parse_arguments(args=test_case["r"], options=None)
49
50    assert options.clobber_output == test_case["c"]
51    assert options.test_only == test_case["test_only"]
52    if "T" in test_case:
53        assert options.testsuite_root == test_case["T"]
54