2020-01-15 08:55:21 +08:00
|
|
|
# Copyright (c) 2020, Nordic Semiconductor ASA
|
|
|
|
|
2019-11-06 04:02:40 +08:00
|
|
|
import itertools
|
2019-02-18 07:48:40 +08:00
|
|
|
|
2019-11-16 07:42:04 +08:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
2020-01-21 23:31:26 +08:00
|
|
|
from west.app.main import BUILTIN_COMMAND_GROUPS
|
2019-02-18 07:48:40 +08:00
|
|
|
from conftest import cmd
|
|
|
|
|
2019-09-06 23:02:36 +08:00
|
|
|
def test_builtin_help_and_dash_h(west_init_tmpdir):
|
|
|
|
# Test "west help" and "west -h" are the same for built-in
|
|
|
|
# functionality.
|
2019-02-18 07:48:40 +08:00
|
|
|
|
|
|
|
h1out = cmd('help')
|
|
|
|
h2out = cmd('-h')
|
2019-09-06 22:59:13 +08:00
|
|
|
assert h1out == h2out
|
2019-02-18 07:48:40 +08:00
|
|
|
|
2019-11-06 04:02:40 +08:00
|
|
|
for cls in itertools.chain(*BUILTIN_COMMAND_GROUPS.values()):
|
|
|
|
c = cls()
|
2020-01-15 08:59:33 +08:00
|
|
|
h1out = cmd(f'help {c.name}')
|
|
|
|
h2out = cmd(f'{c.name} -h')
|
2019-09-06 22:59:13 +08:00
|
|
|
assert h1out == h2out
|
2019-09-06 23:02:36 +08:00
|
|
|
|
|
|
|
def test_extension_help_and_dash_h(west_init_tmpdir):
|
|
|
|
# Test "west help <command>" and "west <command> -h" for extension
|
|
|
|
# commands (west_init_tmpdir has a command with one).
|
|
|
|
|
|
|
|
cmd('update')
|
|
|
|
ext1out = cmd('help test-extension')
|
|
|
|
ext2out = cmd('test-extension -h')
|
2019-11-16 07:42:04 +08:00
|
|
|
|
|
|
|
expected = EXTENSION_EXPECTED
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
# Manage gratuitous incompatibilities:
|
|
|
|
#
|
|
|
|
# - multiline python strings are \n separated even on windows
|
|
|
|
# - the windows command help output gets an extra newline
|
|
|
|
expected = os.linesep.join(expected.splitlines()) + os.linesep
|
|
|
|
|
2019-09-06 23:02:36 +08:00
|
|
|
assert ext1out == ext2out
|
2019-11-16 07:42:04 +08:00
|
|
|
assert ext1out == expected
|
2019-09-06 23:02:36 +08:00
|
|
|
|
|
|
|
|
|
|
|
EXTENSION_EXPECTED = '''\
|
|
|
|
usage: west test-extension [-h]
|
|
|
|
|
|
|
|
optional arguments:
|
|
|
|
-h, --help show this help message and exit
|
|
|
|
'''
|