Skip to content

Commit

Permalink
Fix Python selftests on macOS by using portable shell commands only (r…
Browse files Browse the repository at this point in the history
…ed-hat-data-services#1672)

* /bin/true and /bin/false don't exist as executable binaries on disk, need to use `true` and `false` shell builtin commands
* echo -e is a nonstandard extension and there are differing implementations, using printf is more reliable
  • Loading branch information
jiridanek authored Aug 1, 2024
1 parent 8e6b7a0 commit d81b1ae
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions ods_ci/selftests/utils/scripts/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def test_failed_to_run(self):
assert "No such file or directory" in util.execute_command("/this-file-does-not-exist", print_stdout=False)

def test_success(self):
assert util.execute_command("/bin/true") == ""
assert util.execute_command("true") == ""

def test_fail(self):
assert util.execute_command("/bin/false") == ""
assert util.execute_command("false") == ""

def test_stdout(self):
assert util.execute_command("echo stdout") == "stdout\n"
Expand All @@ -77,8 +77,9 @@ def test_output_printing_spaces(self):

def test_output_printing_tab(self):
with contextlib.redirect_stdout(io.StringIO()) as output:
# use echo binary, not the shell builtin, because some shells (e.g. /bin/sh on Ubuntu) don't support -e
assert util.execute_command("/usr/bin/echo -e 'hello\tworld'") == "hello\tworld\n"
# use printf, not the shell builtin, nor echo binary, because some shells (e.g. /bin/sh on Ubuntu) don't support -e
# and the echo binary on macOS also does not support -e
assert util.execute_command("printf '%b\n' 'hello\tworld'") == "hello\tworld\n"
assert output.getvalue() == ">: hello world\n"

def test_string_cmd(self):
Expand Down

0 comments on commit d81b1ae

Please sign in to comment.