3
0
Fork 0
mirror of https://github.com/Z3Prover/z3 synced 2025-04-06 17:44:08 +00:00
z3/contrib/ci/scripts/run_quiet.sh
Dan Liew ecadef6e48 [TravisCI] Try to fix case in run_quiet where the script would fail
with.

```
-ne: unary operator expected
```
2017-10-16 08:56:17 +01:00

42 lines
1.1 KiB
Bash

# Simple wrapper function that runs a command suppressing
# it's output. However it's output will be shown in the
# case that `NO_SUPPRESS_OUTPUT` is set to `1` or the command
# fails.
#
# The use case for this trying to avoid large logs on TravisCI
function run_quiet() {
if [ "X${NO_SUPPRESS_OUTPUT}" = "X1" ]; then
"${@}"
else
OLD_SETTINGS="$-"
set +x
set +e
TMP_DIR="${TMP_DIR:-/tmp/}"
STDOUT="${TMP_DIR}/$$.stdout"
STDERR="${TMP_DIR}/$$.stderr"
"${@}" > "${STDOUT}" 2> "${STDERR}"
EXIT_STATUS="$?"
if [ "${EXIT_STATUS}" -ne 0 ]; then
echo "Command \"$@\" failed"
echo "EXIT CODE: ${EXIT_STATUS}"
echo "STDOUT"
echo ""
echo "\`\`\`"
cat ${STDOUT}
echo "\`\`\`"
echo ""
echo "STDERR"
echo ""
echo "\`\`\`"
cat ${STDERR}
echo "\`\`\`"
echo ""
fi
# Clean up
rm "${STDOUT}" "${STDERR}"
[ "$( echo "${OLD_SETTINGS}" | grep -c 'e')" != "0" ] && set -e
[ "$( echo "${OLD_SETTINGS}" | grep -c 'x')" != "0" ] && set -x
return ${EXIT_STATUS}
fi
}