diff options
author | Bryan Drewery <bryan@shatow.net> | 2019-02-28 02:48:06 +0300 |
---|---|---|
committer | Bryan Drewery <bryan@shatow.net> | 2019-02-28 03:46:36 +0300 |
commit | 67405d2dcc4a1e6815443f2884a1d52dcd4ef8d4 (patch) | |
tree | a45361e38ad1a78e0f2d9982c926147efacb5678 /test | |
parent | de1f42c284dfcb5d7e668f5051476575b2dec234 (diff) |
Add basic tests for prefix functions.
Currently prefix_stderr_quick expectedly fails due to pipefail issues.
Diffstat (limited to 'test')
-rw-r--r-- | test/Makefile | 1 | ||||
-rw-r--r-- | test/prefix_output.sh | 239 |
2 files changed, 240 insertions, 0 deletions
diff --git a/test/Makefile b/test/Makefile index 45aff85f..da21d431 100644 --- a/test/Makefile +++ b/test/Makefile @@ -8,6 +8,7 @@ TESTS=\ locks_critical_section_nested.sh \ mapfile.sh \ port_var_fetch.sh \ + prefix_output.sh \ read_file.sh \ relpath.sh \ relpath_common.sh \ diff --git a/test/prefix_output.sh b/test/prefix_output.sh new file mode 100644 index 00000000..98c01b7d --- /dev/null +++ b/test/prefix_output.sh @@ -0,0 +1,239 @@ +#! /bin/sh + +. common.sh +. ${SCRIPTPREFIX}/include/hash.sh +. ${SCRIPTPREFIX}/include/parallel.sh +. ${SCRIPTPREFIX}/include/util.sh + +# Override common.sh msg_warn +msg_warn() { + echo "$@" >&2 +} + +test_output() { + local ret="$1" + + echo "test stdout 1" + echo "test stderr 1" >&2 + echo "test stdout 2" + echo "test stderr 2" >&2 + return "${ret}" +} + +OUTPUT=$(mktemp -ut poudriere) +ret=0 +# Basic output test with prefix_stderr_quick +( + prefix_stderr_quick "STDERR" test_output 0 \ + > "${OUTPUT}" 2> "${OUTPUT}.stderr" + assert 0 $? "prefix_stderr_quick test_output 0 wrong exit status" + + cat > "${OUTPUT}.expected" <<-EOF + test stdout 1 + test stdout 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}" + assert 0 $? "prefix_stderr_quick stdout output should match" + + cat > "${OUTPUT}.expected" <<-EOF + STDERR: test stderr 1 + STDERR: test stderr 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}.stderr" + assert 0 $? "prefix_stderr_quick stderr output should match" +) || ret=1 + +# Basic output test with prefix_stdout +( + prefix_stdout "STDOUT" test_output 0 \ + > "${OUTPUT}" 2> "${OUTPUT}.stderr" + assert 0 $? "prefix_stdout test_output 0 wrong exit status" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] STDOUT: test stdout 1 + [00:00:00] STDOUT: test stdout 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}" + assert 0 $? "prefix_stdout stdout output should match" + + cat > "${OUTPUT}.expected" <<-EOF + test stderr 1 + test stderr 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}.stderr" + assert 0 $? "prefix_stdout stderr output should match" +) || ret=2 + +# Basic output test with prefix_stderr +( + prefix_stderr "STDERR" test_output 0 \ + > "${OUTPUT}" 2> "${OUTPUT}.stderr" + assert 0 $? "prefix_stderr test_output 0 wrong exit status" + + cat > "${OUTPUT}.expected" <<-EOF + test stdout 1 + test stdout 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}" + assert 0 $? "prefix_stderr stdout output should match" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] STDERR: test stderr 1 + [00:00:00] STDERR: test stderr 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}.stderr" + assert 0 $? "prefix_stderr stderr output should match" +) || ret=3 + +# Basic output test with prefix_output +( + prefix_output "OUTPUT" test_output 0 \ + > "${OUTPUT}" 2> "${OUTPUT}.stderr" + assert 0 $? "prefix_output test_output 0 wrong exit status" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] OUTPUT: test stdout 1 + [00:00:00] OUTPUT: test stdout 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}" + assert 0 $? "prefix_output stdout output should match" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] OUTPUT: test stderr 1 + [00:00:00] OUTPUT: test stderr 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}.stderr" + assert 0 $? "prefix_output stderr output should match" +) || ret=4 + +# Basic output test with chaining prefix_stderr and prefix_stdout +( + prefix_stderr "STDERR" prefix_stdout "STDOUT" test_output 0 \ + > "${OUTPUT}" 2> "${OUTPUT}.stderr" + assert 0 $? "prefix_stderr+prefix_stdout test_output 0 wrong exit status" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] STDOUT: test stdout 1 + [00:00:00] STDOUT: test stdout 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}" + assert 0 $? "prefix_stderr+prefix_stdout stdout output should match" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] STDERR: test stderr 1 + [00:00:00] STDERR: test stderr 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}.stderr" + assert 0 $? "prefix_stderr+prefix_stdout stderr output should match" +) || ret=5 + +# Now test exit statuses (pipefail and such) + +# Pipefail test with prefix_stderr_quick +( + echo "SKIP: pipefail issues" >&2 + prefix_stderr_quick "STDERR" test_output 5 \ + > "${OUTPUT}" 2> "${OUTPUT}.stderr" + assert 5 $? "prefix_stderr_quick test_output 5 wrong exit status" + + cat > "${OUTPUT}.expected" <<-EOF + test stdout 1 + test stdout 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}" + assert 0 $? "prefix_stderr_quick/5 stdout output should match" + + cat > "${OUTPUT}.expected" <<-EOF + STDERR: test stderr 1 + STDERR: test stderr 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}.stderr" + assert 0 $? "prefix_stderr_quick/5 stderr output should match" +) || ret=6 + +# pipefail test with prefix_stdout +( + prefix_stdout "STDOUT" test_output 5 \ + > "${OUTPUT}" 2> "${OUTPUT}.stderr" + assert 5 $? "prefix_stdout test_output 5 wrong exit status" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] STDOUT: test stdout 1 + [00:00:00] STDOUT: test stdout 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}" + assert 0 $? "prefix_stdout/5 stdout output should match" + + cat > "${OUTPUT}.expected" <<-EOF + test stderr 1 + test stderr 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}.stderr" + assert 0 $? "prefix_stdout/5 stderr output should match" +) || ret=7 + +# pipefail test with prefix_stderr +( + prefix_stderr "STDERR" test_output 5 \ + > "${OUTPUT}" 2> "${OUTPUT}.stderr" + assert 5 $? "prefix_stderr test_output 5 wrong exit status" + + cat > "${OUTPUT}.expected" <<-EOF + test stdout 1 + test stdout 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}" + assert 0 $? "prefix_stderr/5 stdout output should match" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] STDERR: test stderr 1 + [00:00:00] STDERR: test stderr 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}.stderr" + assert 0 $? "prefix_stderr/5 stderr output should match" +) || ret=8 + +# pipefail test with prefix_output +( + prefix_output "OUTPUT" test_output 5 \ + > "${OUTPUT}" 2> "${OUTPUT}.stderr" + assert 5 $? "prefix_output test_output 5 wrong exit status" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] OUTPUT: test stdout 1 + [00:00:00] OUTPUT: test stdout 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}" + assert 0 $? "prefix_output/5 stdout output should match" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] OUTPUT: test stderr 1 + [00:00:00] OUTPUT: test stderr 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}.stderr" + assert 0 $? "prefix_output/5 stderr output should match" +) || ret=9 + +# pipefail test with chaining prefix_stderr and prefix_stdout +( + prefix_stderr "STDERR" prefix_stdout "STDOUT" test_output 5 \ + > "${OUTPUT}" 2> "${OUTPUT}.stderr" + assert 5 $? "prefix_stderr+prefix_stdout test_output 5 wrong exit status" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] STDOUT: test stdout 1 + [00:00:00] STDOUT: test stdout 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}" + assert 0 $? "prefix_stderr+prefix_stdout/5 stdout output should match" + + cat > "${OUTPUT}.expected" <<-EOF + [00:00:00] STDERR: test stderr 1 + [00:00:00] STDERR: test stderr 2 + EOF + diff -u "${OUTPUT}.expected" "${OUTPUT}.stderr" + assert 0 $? "prefix_stderr+prefix_stdout/5 stderr output should match" +) || ret=10 + +rm "${OUTPUT}" "${OUTPUT}.stderr" "${OUTPUT}.expected" +exit "${ret}" |