test_build.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # Copyright (c) 2018 Nordic Semiconductor ASA
  2. #
  3. # SPDX-License-Identifier: Apache-2.0
  4. from argparse import Namespace
  5. from build import Build
  6. import pytest
  7. TEST_CASES = [
  8. {'r': [],
  9. 's': None, 'c': None},
  10. {'r': ['source_dir'],
  11. 's': 'source_dir', 'c': None},
  12. {'r': ['source_dir', '--'],
  13. 's': 'source_dir', 'c': None},
  14. {'r': ['source_dir', '--', 'cmake_opt'],
  15. 's': 'source_dir', 'c': ['cmake_opt']},
  16. {'r': ['source_dir', '--', 'cmake_opt', 'cmake_opt2'],
  17. 's': 'source_dir', 'c': ['cmake_opt', 'cmake_opt2']},
  18. {'r': ['thing_one', 'thing_two'],
  19. 's': 'thing_one', 'c': ['thing_two']},
  20. {'r': ['thing_one', 'thing_two', 'thing_three'],
  21. 's': 'thing_one', 'c': ['thing_two', 'thing_three']},
  22. {'r': ['--'],
  23. 's': None, 'c': None},
  24. {'r': ['--', '--'],
  25. 's': None, 'c': ['--']},
  26. {'r': ['--', 'cmake_opt'],
  27. 's': None, 'c': ['cmake_opt']},
  28. {'r': ['--', 'cmake_opt', 'cmake_opt2'],
  29. 's': None, 'c': ['cmake_opt', 'cmake_opt2']},
  30. {'r': ['--', 'cmake_opt', 'cmake_opt2', '--'],
  31. 's': None, 'c': ['cmake_opt', 'cmake_opt2', '--']},
  32. {'r': ['--', 'cmake_opt', 'cmake_opt2', '--', 'tool_opt'],
  33. 's': None, 'c': ['cmake_opt', 'cmake_opt2', '--', 'tool_opt']},
  34. {'r': ['--', 'cmake_opt', 'cmake_opt2', '--', 'tool_opt', 'tool_opt2'],
  35. 's': None, 'c': ['cmake_opt', 'cmake_opt2', '--', 'tool_opt',
  36. 'tool_opt2']},
  37. {'r': ['--', 'cmake_opt', 'cmake_opt2', '--', 'tool_opt', 'tool_opt2',
  38. '--'],
  39. 's': None, 'c': ['cmake_opt', 'cmake_opt2', '--', 'tool_opt', 'tool_opt2',
  40. '--']},
  41. ]
  42. ARGS = Namespace(board=None, build_dir=None, cmake=False, command='build',
  43. force=False, help=None, target=None, verbose=3, version=False,
  44. zephyr_base=None)
  45. @pytest.mark.parametrize('test_case', TEST_CASES)
  46. def test_parse_remainder(test_case):
  47. b = Build()
  48. b.args = Namespace()
  49. b._parse_remainder(test_case['r'])
  50. assert b.args.source_dir == test_case['s']
  51. assert b.args.cmake_opts == test_case['c']