55import tempfile
66
77import pytest
8+ from pexpect .exceptions import TIMEOUT
89
910import riotctrl .ctrl
1011import riotctrl .shell
@@ -20,13 +21,14 @@ def fixture_app_pidfile_env():
2021 yield {'PIDFILE' : tmpfile .name }
2122
2223
23- def init_ctrl (app_pidfile_env , skip_first_prompt = False ):
24+ def init_ctrl (app_pidfile_env , skip_first_prompt = False , prompt = "> " ):
2425 """Initializes RIOTCtrl for ShellInteraction tests"""
2526 env = {
2627 'QUIET' : '1' , # pipe > in command interferes with test
2728 'BOARD' : 'board' ,
2829 'APPLICATION' : './shell.py' +
29- (' 1' if skip_first_prompt else '' ),
30+ (' 1' if skip_first_prompt else ' 0' ) +
31+ " --prompt=\" {}\" " .format (prompt ),
3032 }
3133 env .update (app_pidfile_env )
3234
@@ -57,6 +59,31 @@ def test_shell_interaction_cmd_first_prompt_missing(app_pidfile_env):
5759 assert 'snafoo' in res
5860
5961
62+ def test_shell_interaction_cmd_different_prompt (app_pidfile_env ):
63+ """Test basic functionalities with the 'shell' application when the prompt
64+ is not default."""
65+ prompt = "my_prompt "
66+ ctrl = init_ctrl (app_pidfile_env , prompt = prompt )
67+ with ctrl .run_term (logfile = sys .stdout , reset = False ):
68+ shell = riotctrl .shell .ShellInteraction (ctrl , prompt = prompt )
69+ res = shell .cmd ('foobar' )
70+ assert 'foobar' in res
71+
72+
73+ def test_shell_interaction_cmd_prompt_timeout (app_pidfile_env ):
74+ """Test basic functionalities with the 'shell' application when the
75+ prompt timeout is changed."""
76+ prompt = "my_prompt "
77+ ctrl = init_ctrl (app_pidfile_env , prompt = prompt )
78+ with ctrl .run_term (logfile = sys .stdout , reset = False ):
79+ riotctrl .shell .ShellInteraction .PROMPT_TIMEOUT = 0
80+ shell = riotctrl .shell .ShellInteraction (ctrl )
81+ with pytest .raises (TIMEOUT ):
82+ # Fast systems may occasionally reply in 0 secs
83+ for _ in range (5 ):
84+ shell .cmd ('foobar' )
85+
86+
6087def test_shell_interaction_cmd_reset_term (app_pidfile_env ):
6188 """Test basic functionalities with the 'shell' application."""
6289 ctrl = init_ctrl (app_pidfile_env )
0 commit comments