mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 00:29:46 +01:00
tests/rust_libs: use shell_builtin_cmd_help_json
This increases the robustness of the test by not relying on the order shell commands are printed in. At least for XFA based shell commands, there is no guarantee in which order they will be shown in the help.
This commit is contained in:
parent
f0a88dcf56
commit
b60534796a
@ -2,6 +2,7 @@ include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += shell
|
||||
USEMODULE += shell_democommands
|
||||
USEMODULE += shell_builtin_cmd_help_json # for automated testing
|
||||
USEMODULE += ztimer_msec
|
||||
|
||||
FEATURES_REQUIRED += rust_target
|
||||
|
@ -7,34 +7,25 @@
|
||||
# General Public License v2.1. See the file LICENSE in the top level
|
||||
# directory for more details.
|
||||
|
||||
import json
|
||||
import sys
|
||||
from testrunner import run
|
||||
|
||||
|
||||
EXPECTED_HELP = (
|
||||
'Command Description',
|
||||
'---------------------------------------',
|
||||
'bufsize Get the shell\'s buffer size',
|
||||
'start_test starts a test',
|
||||
'end_test ends a test',
|
||||
'echo prints the input command',
|
||||
'empty print nothing on command',
|
||||
'hello_world Print a greeting',
|
||||
'xfa_test1 xfa test command 1',
|
||||
'xfa_test2 xfa test command 2',
|
||||
)
|
||||
EXPECTED_CMDS = {
|
||||
'bufsize': 'Get the shell\'s buffer size',
|
||||
'start_test': 'starts a test',
|
||||
'end_test': 'ends a test',
|
||||
'echo': 'prints the input command',
|
||||
'empty': 'print nothing on command',
|
||||
'periodic': 'periodically print command',
|
||||
'hello_world': 'Print a greeting',
|
||||
'xfa_test1': 'xfa test command 1',
|
||||
'xfa_test2': 'xfa test command 2',
|
||||
}
|
||||
|
||||
PROMPT = '> '
|
||||
|
||||
CMDS = (
|
||||
('start_test', '[TEST_START]'),
|
||||
|
||||
# test default commands
|
||||
('help', EXPECTED_HELP),
|
||||
|
||||
('end_test', '[TEST_END]'),
|
||||
)
|
||||
|
||||
CMDS_REGEX = {'ps.rs'}
|
||||
|
||||
|
||||
@ -49,10 +40,26 @@ def check_cmd(child, cmd, expected):
|
||||
child.expect_exact(line)
|
||||
|
||||
|
||||
def check_cmd_list(child):
|
||||
child.expect(PROMPT)
|
||||
child.sendline('help_json')
|
||||
child.expect(r"(\{[^\n\r]*\})\r\n")
|
||||
cmdlist = json.loads(child.match.group(1))["cmds"]
|
||||
cmds = set(EXPECTED_CMDS)
|
||||
for item in cmdlist:
|
||||
assert item['cmd'] in EXPECTED_CMDS, f"command {item['cmd']} not expected"
|
||||
assert item['cmd'] in cmds, f"command {item['cmd']} listed twice"
|
||||
assert item['desc'] == EXPECTED_CMDS[item['cmd']], f"description of {item['cmd']} not expected"
|
||||
cmds.remove(item['cmd'])
|
||||
|
||||
assert len(cmds) == 0, f"commands {cmds} missing"
|
||||
|
||||
|
||||
def testfunc(child):
|
||||
# loop other defined commands and expected output
|
||||
for cmd, expected in CMDS:
|
||||
check_cmd(child, cmd, expected)
|
||||
check_cmd(child, 'start_test', '[TEST_START]')
|
||||
check_cmd_list(child)
|
||||
check_cmd(child, 'end_test', '[TEST_END]')
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user