mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2025-12-15 17:43:51 +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
|
||||||
USEMODULE += shell_democommands
|
USEMODULE += shell_democommands
|
||||||
|
USEMODULE += shell_builtin_cmd_help_json # for automated testing
|
||||||
USEMODULE += ztimer_msec
|
USEMODULE += ztimer_msec
|
||||||
|
|
||||||
FEATURES_REQUIRED += rust_target
|
FEATURES_REQUIRED += rust_target
|
||||||
|
|||||||
@ -7,34 +7,25 @@
|
|||||||
# General Public License v2.1. See the file LICENSE in the top level
|
# General Public License v2.1. See the file LICENSE in the top level
|
||||||
# directory for more details.
|
# directory for more details.
|
||||||
|
|
||||||
|
import json
|
||||||
import sys
|
import sys
|
||||||
from testrunner import run
|
from testrunner import run
|
||||||
|
|
||||||
|
|
||||||
EXPECTED_HELP = (
|
EXPECTED_CMDS = {
|
||||||
'Command Description',
|
'bufsize': 'Get the shell\'s buffer size',
|
||||||
'---------------------------------------',
|
'start_test': 'starts a test',
|
||||||
'bufsize Get the shell\'s buffer size',
|
'end_test': 'ends a test',
|
||||||
'start_test starts a test',
|
'echo': 'prints the input command',
|
||||||
'end_test ends a test',
|
'empty': 'print nothing on command',
|
||||||
'echo prints the input command',
|
'periodic': 'periodically print command',
|
||||||
'empty print nothing on command',
|
'hello_world': 'Print a greeting',
|
||||||
'hello_world Print a greeting',
|
'xfa_test1': 'xfa test command 1',
|
||||||
'xfa_test1 xfa test command 1',
|
'xfa_test2': 'xfa test command 2',
|
||||||
'xfa_test2 xfa test command 2',
|
}
|
||||||
)
|
|
||||||
|
|
||||||
PROMPT = '> '
|
PROMPT = '> '
|
||||||
|
|
||||||
CMDS = (
|
|
||||||
('start_test', '[TEST_START]'),
|
|
||||||
|
|
||||||
# test default commands
|
|
||||||
('help', EXPECTED_HELP),
|
|
||||||
|
|
||||||
('end_test', '[TEST_END]'),
|
|
||||||
)
|
|
||||||
|
|
||||||
CMDS_REGEX = {'ps.rs'}
|
CMDS_REGEX = {'ps.rs'}
|
||||||
|
|
||||||
|
|
||||||
@ -49,10 +40,26 @@ def check_cmd(child, cmd, expected):
|
|||||||
child.expect_exact(line)
|
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):
|
def testfunc(child):
|
||||||
# loop other defined commands and expected output
|
# loop other defined commands and expected output
|
||||||
for cmd, expected in CMDS:
|
check_cmd(child, 'start_test', '[TEST_START]')
|
||||||
check_cmd(child, cmd, expected)
|
check_cmd_list(child)
|
||||||
|
check_cmd(child, 'end_test', '[TEST_END]')
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user