mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-27 17:21:34 +00:00
Merge commit 'c03f7d50ff6bc14d17b0c25201e6570dd84e5211' into shfmt
This commit is contained in:
@@ -25,14 +25,15 @@ export CONTINUE=${CONTINUE:-}
|
||||
|
||||
args="$(getopt -n "$0" -l \
|
||||
verbose,help,stop,discover,invariant,continue vhxdic "$@")" \
|
||||
|| exit -1
|
||||
|| exit -1
|
||||
for arg in $args; do
|
||||
case "$arg" in
|
||||
-h)
|
||||
echo "$0 [-vxidc]" \
|
||||
"[--verbose] [--stop] [--invariant] [--discover] [--continue]"
|
||||
echo "$(sed 's/./ /g' <<< "$0") [-h] [--help]"
|
||||
exit 0;;
|
||||
echo "$(sed 's/./ /g' <<<"$0") [-h] [--help]"
|
||||
exit 0
|
||||
;;
|
||||
--help)
|
||||
cat <<EOF
|
||||
Usage: $0 [options]
|
||||
@@ -47,17 +48,23 @@ Options:
|
||||
-h show brief usage information and exit
|
||||
--help show this help message and exit
|
||||
EOF
|
||||
exit 0;;
|
||||
-v|--verbose)
|
||||
DEBUG=1;;
|
||||
-x|--stop)
|
||||
STOP=1;;
|
||||
-i|--invariant)
|
||||
INVARIANT=1;;
|
||||
-d|--discover)
|
||||
DISCOVERONLY=1;;
|
||||
-c|--continue)
|
||||
CONTINUE=1;;
|
||||
exit 0
|
||||
;;
|
||||
-v | --verbose)
|
||||
DEBUG=1
|
||||
;;
|
||||
-x | --stop)
|
||||
STOP=1
|
||||
;;
|
||||
-i | --invariant)
|
||||
INVARIANT=1
|
||||
;;
|
||||
-d | --discover)
|
||||
DISCOVERONLY=1
|
||||
;;
|
||||
-c | --continue)
|
||||
CONTINUE=1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
@@ -74,9 +81,9 @@ assert_end() {
|
||||
# assert_end [suite ..]
|
||||
tests_endtime="$(date +%s%N)"
|
||||
# required visible decimal place for seconds (leading zeros if needed)
|
||||
tests_time="$( \
|
||||
printf "%010d" "$(( ${tests_endtime/%N/000000000}
|
||||
- ${tests_starttime/%N/000000000} ))")" # in ns
|
||||
tests_time="$(
|
||||
printf "%010d" "$((${tests_endtime/%N/000000000} - ${tests_starttime/%N/000000000}))"
|
||||
)" # in ns
|
||||
tests="$tests_ran ${*:+$* }tests"
|
||||
[[ -n "$DISCOVERONLY" ]] && echo "collected $tests." && _assert_reset && return
|
||||
[[ -n "$DEBUG" ]] && echo
|
||||
@@ -100,15 +107,15 @@ assert_end() {
|
||||
|
||||
assert() {
|
||||
# assert <command> <expected stdout> [stdin]
|
||||
(( tests_ran++ )) || :
|
||||
((tests_ran++)) || :
|
||||
[[ -z "$DISCOVERONLY" ]] || return
|
||||
expected=$(echo -ne "${2:-}")
|
||||
result="$(eval 2>/dev/null "$1" <<< "${3:-}")" || true
|
||||
result="$(eval "$1" 2>/dev/null <<<"${3:-}")" || true
|
||||
if [[ "$result" == "$expected" ]]; then
|
||||
[[ -z "$DEBUG" ]] || echo -n .
|
||||
return
|
||||
fi
|
||||
result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<< "$result")"
|
||||
result="$(sed -e :a -e '$!N;s/\n/\\n/;ta' <<<"$result")"
|
||||
[[ -z "$result" ]] && result="nothing" || result="\"$result\""
|
||||
[[ -z "$2" ]] && expected="nothing" || expected="\"$2\""
|
||||
_assert_fail "expected $expected${_indent}got $result" "$1" "$3"
|
||||
@@ -116,10 +123,10 @@ assert() {
|
||||
|
||||
assert_raises() {
|
||||
# assert_raises <command> <expected code> [stdin]
|
||||
(( tests_ran++ )) || :
|
||||
((tests_ran++)) || :
|
||||
[[ -z "$DISCOVERONLY" ]] || return
|
||||
status=0
|
||||
(eval "$1" <<< "${3:-}") > /dev/null 2>&1 || status=$?
|
||||
(eval "$1" <<<"${3:-}") >/dev/null 2>&1 || status=$?
|
||||
expected=${2:-0}
|
||||
if [[ "$status" -eq "$expected" ]]; then
|
||||
[[ -z "$DEBUG" ]] || echo -n .
|
||||
@@ -138,12 +145,12 @@ _assert_fail() {
|
||||
exit 1
|
||||
fi
|
||||
tests_errors[$tests_failed]="$report"
|
||||
(( tests_failed++ )) || :
|
||||
((tests_failed++)) || :
|
||||
}
|
||||
|
||||
skip_if() {
|
||||
# skip_if <command ..>
|
||||
(eval "$@") > /dev/null 2>&1 && status=0 || status=$?
|
||||
(eval "$@") >/dev/null 2>&1 && status=0 || status=$?
|
||||
[[ "$status" -eq 0 ]] || return
|
||||
skip
|
||||
}
|
||||
@@ -175,9 +182,8 @@ _skip() {
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
_assert_reset
|
||||
: ${tests_suite_status:=0} # remember if any of the tests failed so far
|
||||
: ${tests_suite_status:=0} # remember if any of the tests failed so far
|
||||
_assert_cleanup() {
|
||||
local status=$?
|
||||
# modify exit code if it's not already non-zero
|
||||
|
||||
Reference in New Issue
Block a user