aboutsummaryrefslogtreecommitdiff
path: root/verif/tests/test_tosa_run_tests_runshcmd.py
blob: a7654139abbadf750eb7459048bd79781351301a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""Tests for tosa_verif_run_tests.py."""
# Copyright (c) 2021-2022, ARM Limited.
# SPDX-License-Identifier: Apache-2.0
from runner.run_command import run_sh_command
from runner.run_command import RunShCommandError


def test_run_command_success():
    """Run successful command."""
    cmd = ["echo", "Hello Space Cadets"]
    try:
        run_sh_command(cmd)
        ok = True
    except RunShCommandError:
        ok = False
    assert ok


def test_run_command_fail():
    """Run unsuccessful command."""
    cmd = ["cat", "non-existant-file-432342.txt"]
    try:
        run_sh_command(cmd)
        ok = True
    except RunShCommandError as e:
        assert e.return_code == 1
        ok = False
    assert not ok


def test_run_command_fail_with_stderr():
    """Run unsuccessful command capturing output."""
    cmd = ["ls", "--unknown-option"]
    try:
        stdout, stderr = run_sh_command(cmd, capture_output=True)
        ok = True
    except RunShCommandError as e:
        assert e.return_code == 2
        assert e.stderr
        ok = False
    assert not ok


def test_run_command_success_verbose_with_stdout():
    """Run successful command capturing output."""
    output = "There is no Planet B"
    cmd = ["echo", output]
    try:
        stdout, stderr = run_sh_command(cmd, verbose=True, capture_output=True)
        assert stdout == f"{output}\n"
        ok = True
    except RunShCommandError:
        ok = False
    assert ok