File: cscli-wrapper

package info (click to toggle)
crowdsec 1.4.6-10.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,500 kB
  • sloc: sh: 2,870; makefile: 386; python: 74
file content (40 lines) | stat: -rwxr-xr-x 1,334 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash

set -eu

#
# Delegate operations to an instrumented binary and collects coverage data.
#

#shellcheck disable=SC1007
THIS_DIR=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
# no need to change directory, and doing it here would break hub tests
# shellcheck disable=SC1091
. "${THIS_DIR}/../.environment.sh"

set -o pipefail  # don't let sed hide the statuscode
mkdir -p "${LOCAL_DIR}/var/lib/coverage"

# we collect rc and output by hand, because setting -o pipefail would trigger a
# SIGPIPE.
set +e

# Arguments to cscli are passed through a temporary, newline-delimited
# file courtesy of github.com/confluentinc/bincover. Coverage data will be
# merged at the end of the test run.
# The '=' between flags and values is required.
output=$("${BIN_DIR}/cscli.cover" \
    -test.run="^TestBincoverRunMain$" \
    -test.coverprofile="${LOCAL_DIR}/var/lib/coverage/cscli-$(date +'%s')-$$-${RANDOM}.out" \
    -args-file=<(for i; do echo "${i}"; done))
rc=$?

# If there is bincover metadata, we take the status code from there. Otherwise,
# we keep the status from the above command.
if [[ ${output} =~ (.*)(START_BINCOVER_METADATA[[:space:]]*)(.*)([[:space:]]END_BINCOVER_METADATA) ]]; then
    echo -n "${BASH_REMATCH[1]}"
    exit "$(jq '.exit_code' <<< "${BASH_REMATCH[3]}")"
fi

echo -n "${output}"
exit "${rc}"