| 1 | #!/usr/bin/env bash |
| 2 | |
| 3 | set -eu |
| 4 | |
| 5 | # |
| 6 | # Delegate operations to an instrumented binary and collects coverage data. |
| 7 | # |
| 8 | |
| 9 | #shellcheck disable=SC1007 |
| 10 | THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd) |
| 11 | # no need to change directory, and doing it here would break hub tests |
| 12 | # shellcheck disable=SC1091 |
| 13 | . "${THIS_DIR}/../.environment.sh" |
| 14 | |
| 15 | set -o pipefail # don't let sed hide the statuscode |
| 16 | mkdir -p "${LOCAL_DIR}/var/lib/coverage" |
| 17 | |
| 18 | # we collect rc and output by hand, because setting -o pipefail would trigger a |
| 19 | # SIGPIPE. |
| 20 | set +e |
| 21 | |
| 22 | # Arguments to cscli are passed through a temporary, newline-delimited |
| 23 | # file courtesy of github.com/confluentinc/bincover. Coverage data will be |
| 24 | # merged at the end of the test run. |
| 25 | # The '=' between flags and values is required. |
| 26 | output=$("${BIN_DIR}/cscli.cover" \ |
| 27 | -test.run="^TestBincoverRunMain$" \ |
| 28 | -test.coverprofile="${LOCAL_DIR}/var/lib/coverage/cscli-$(date +'%s')-$$-${RANDOM}.out" \ |
| 29 | -args-file=<(for i; do echo "${i}"; done)) |
| 30 | rc=$? |
| 31 | |
| 32 | # If there is bincover metadata, we take the status code from there. Otherwise, |
| 33 | # we keep the status from the above command. |
| 34 | if [[ ${output} =~ (.*)(START_BINCOVER_METADATA[[:space:]]*)(.*)([[:space:]]END_BINCOVER_METADATA) ]]; then |
| 35 | echo -n "${BASH_REMATCH[1]}" |
| 36 | exit "$(jq '.exit_code' <<< "${BASH_REMATCH[3]}")" |
| 37 | fi |
| 38 | |
| 39 | echo -n "${output}" |
| 40 | exit "${rc}" |