Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Commit

Permalink
Run shfmt on all shell files in this repo
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Oct 25, 2016
1 parent 5570b0e commit b7ac59c
Show file tree
Hide file tree
Showing 10 changed files with 359 additions and 350 deletions.
5 changes: 1 addition & 4 deletions image-tag
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ set -o errexit
set -o nounset
set -o pipefail

WORKING_SUFFIX=$(if ! git diff --exit-code --quiet HEAD >&2; \
then echo "-WIP"; \
else echo ""; \
fi)
WORKING_SUFFIX=$(if ! git diff --exit-code --quiet HEAD >&2; then echo "-WIP"; else echo ""; fi)
BRANCH_PREFIX=$(git rev-parse --abbrev-ref HEAD)
echo "${BRANCH_PREFIX//\//-}-$(git rev-parse --short HEAD)$WORKING_SUFFIX"
58 changes: 32 additions & 26 deletions integration/assert.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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

Expand All @@ -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
Expand All @@ -100,26 +107,26 @@ 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"
}

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 .
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions integration/config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ N_MACHINES=${N_MACHINES:-3}
IP_PREFIX=${IP_PREFIX:-192.168.48}
IP_SUFFIX_BASE=${IP_SUFFIX_BASE:-10}

if [ -z "$HOSTS" ] ; then
if [ -z "$HOSTS" ]; then
for i in $(seq 1 $N_MACHINES); do
IP="${IP_PREFIX}.$((${IP_SUFFIX_BASE}+$i))"
IP="${IP_PREFIX}.$((${IP_SUFFIX_BASE} + $i))"
HOSTS="$HOSTS $IP"
done
fi
Expand Down Expand Up @@ -58,7 +58,7 @@ whitely() {
colourise '1;37' "$@"
}

greyly () {
greyly() {
colourise '0;37' "$@"
}

Expand Down Expand Up @@ -122,4 +122,3 @@ end_suite() {
}

WEAVE=$DIR/../weave

Loading

0 comments on commit b7ac59c

Please sign in to comment.