"wrappers/python/vscode:/vscode.git/clone" did not exist on "2031d4e673a48ae7c2528375d369a6643eb8bc3f"
Commit 53452dce authored by Matthew Brett's avatar Matthew Brett
Browse files

Refactor suppress function to error with set -e

Previous version was using a sub-shell to execute, and therefore not
catching errors during execution of the functions that had errors, but
did not return non-0 exit codes.

Add tests.
parent e8ef7c3a
......@@ -96,11 +96,14 @@ function gh-clone {
}
function suppress {
# Suppress the output of a bash command unless it fails
out=$( ( $@ ) 2>&1 )
# https://unix.stackexchange.com/questions/256120/how-can-i-suppress-output-only-if-the-command-succeeds#256122
tmp=$(mktemp) || return
echo "Running $@"
"$@" > "$tmp" 2>&1
ret=$?
[ "$ret" -eq 0 ] || >&2 echo "$out" # if $? (the return of the last run command) is not zero, cat the temp file
return "$ret" # return the exit status of the command
[ "$ret" -eq 0 ] || cat "$tmp"
rm -f "$tmp"
return "$ret"
}
function rm_mkdir {
......
......@@ -34,5 +34,32 @@ rm_mkdir tmp_dir
[ -e tmp_dir/afile ] && ingest "tmp_dir/afile should have been deleted"
rmdir tmp_dir
# Test suppress command
function bad_cmd {
echo bad
return 1
}
function bad_mid_cmd {
echo ok for now
false
echo should be bad now
return 0
}
function good_cmd {
echo good
return 0
}
# Check state of set -e, disable if set
# https://stackoverflow.com/questions/14564746/in-bash-how-to-get-the-current-status-of-set-x?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
using_e=${-//[^e]/}
set +e
[ "$(suppress bad_cmd)" == "$(printf "Running bad_cmd\nbad")" ] || ingest "suppress bad_cmd"
[ "$(suppress good_cmd)" == "Running good_cmd" ] || ingest "suppress good_cmd"
[ "$(suppress bad_mid_cmd)" == "Running bad_mid_cmd" ] || ingest "suppress bad_mid_cmd"
if [ -n "$using_e" ]; then set -e; fi
# On Linux docker containers in travis, can only be x86_64 or i686
[ "$(get_platform)" == x86_64 ] || [ "$(get_platform)" == i686 ] || exit 1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment