1# Copyright (c) 2015-2016, NVIDIA CORPORATION. All rights reserved.
2#
3# SPDX-License-Identifier: GPL-2.0
4
5# Test basic shell functionality, such as commands separate by semi-colons.
6
7def test_shell_execute(u_boot_console):
8    """Test any shell command."""
9
10    response = u_boot_console.run_command('echo hello')
11    assert response.strip() == 'hello'
12
13def test_shell_semicolon_two(u_boot_console):
14    """Test two shell commands separate by a semi-colon."""
15
16    cmd = 'echo hello; echo world'
17    response = u_boot_console.run_command(cmd)
18    # This validation method ignores the exact whitespace between the strings
19    assert response.index('hello') < response.index('world')
20
21def test_shell_semicolon_three(u_boot_console):
22    """Test three shell commands separate by a semi-colon, with variable
23    expansion dependencies between them."""
24
25    cmd = 'setenv list 1; setenv list ${list}2; setenv list ${list}3; ' + \
26        'echo ${list}'
27    response = u_boot_console.run_command(cmd)
28    assert response.strip() == '123'
29    u_boot_console.run_command('setenv list')
30
31def test_shell_run(u_boot_console):
32    """Test the "run" shell command."""
33
34    u_boot_console.run_command('setenv foo "setenv monty 1; setenv python 2"')
35    u_boot_console.run_command('run foo')
36    response = u_boot_console.run_command('echo $monty')
37    assert response.strip() == '1'
38    response = u_boot_console.run_command('echo $python')
39    assert response.strip() == '2'
40    u_boot_console.run_command('setenv foo')
41    u_boot_console.run_command('setenv monty')
42    u_boot_console.run_command('setenv python')
43