Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/bats-core/bats-assert.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJason Karns <jason@karns.name>2019-01-29 17:56:10 +0300
committerJason Karns <jason@karns.name>2019-01-29 17:59:01 +0300
commit40aad9873658efe96b9d54658d843a47d250f3b6 (patch)
tree25edaa4094f1aeee75d1c6fd33dcc8e4f7167907 /src
parent68f112c2fa0409a6386fcd779a1e54243309b03b (diff)
Reformat with vim
Diffstat (limited to 'src')
-rw-r--r--src/assert_equal.bash8
-rw-r--r--src/assert_failure.bash15
-rw-r--r--src/assert_line.bash116
-rw-r--r--src/assert_output.bash46
-rw-r--r--src/assert_success.bash5
-rw-r--r--src/refute_line.bash129
-rw-r--r--src/refute_output.bash46
7 files changed, 167 insertions, 198 deletions
diff --git a/src/assert_equal.bash b/src/assert_equal.bash
index 0aff69a..3f0aa80 100644
--- a/src/assert_equal.bash
+++ b/src/assert_equal.bash
@@ -14,9 +14,9 @@
assert_equal() {
if [[ $1 != "$2" ]]; then
batslib_print_kv_single_or_multi 8 \
- 'expected' "$2" \
- 'actual' "$1" \
- | batslib_decorate 'values do not equal' \
- | fail
+ 'expected' "$2" \
+ 'actual' "$1" \
+ | batslib_decorate 'values do not equal' \
+ | fail
fi
}
diff --git a/src/assert_failure.bash b/src/assert_failure.bash
index 45742bd..1a797f4 100644
--- a/src/assert_failure.bash
+++ b/src/assert_failure.bash
@@ -19,16 +19,17 @@ assert_failure() {
(( $# > 0 )) && local -r expected="$1"
if (( status == 0 )); then
batslib_print_kv_single_or_multi 6 'output' "$output" \
- | batslib_decorate 'command succeeded, but it was expected to fail' \
- | fail
+ | batslib_decorate 'command succeeded, but it was expected to fail' \
+ | fail
elif (( $# > 0 )) && (( status != expected )); then
{ local -ir width=8
batslib_print_kv_single "$width" \
- 'expected' "$expected" \
- 'actual' "$status"
+ 'expected' "$expected" \
+ 'actual' "$status"
batslib_print_kv_single_or_multi "$width" \
- 'output' "$output"
- } | batslib_decorate 'command failed as expected, but status differs' \
- | fail
+ 'output' "$output"
+ } \
+ | batslib_decorate 'command failed as expected, but status differs' \
+ | fail
fi
}
diff --git a/src/assert_line.bash b/src/assert_line.bash
index 5b44101..2ab427a 100644
--- a/src/assert_line.bash
+++ b/src/assert_line.bash
@@ -51,28 +51,28 @@ assert_line() {
# Handle options.
while (( $# > 0 )); do
case "$1" in
- -n|--index)
- if (( $# < 2 )) || ! [[ $2 =~ ^([0-9]|[1-9][0-9]+)$ ]]; then
- echo "\`--index' requires an integer argument: \`$2'" \
- | batslib_decorate 'ERROR: assert_line' \
- | fail
- return $?
- fi
- is_match_line=1
- local -ri idx="$2"
- shift 2
- ;;
- -p|--partial) is_mode_partial=1; shift ;;
- -e|--regexp) is_mode_regexp=1; shift ;;
- --) shift; break ;;
- *) break ;;
+ -n|--index)
+ if (( $# < 2 )) || ! [[ $2 =~ ^([0-9]|[1-9][0-9]+)$ ]]; then
+ echo "\`--index' requires an integer argument: \`$2'" \
+ | batslib_decorate 'ERROR: assert_line' \
+ | fail
+ return $?
+ fi
+ is_match_line=1
+ local -ri idx="$2"
+ shift 2
+ ;;
+ -p|--partial) is_mode_partial=1; shift ;;
+ -e|--regexp) is_mode_regexp=1; shift ;;
+ --) shift; break ;;
+ *) break ;;
esac
done
if (( is_mode_partial )) && (( is_mode_regexp )); then
echo "\`--partial' and \`--regexp' are mutually exclusive" \
- | batslib_decorate 'ERROR: assert_line' \
- | fail
+ | batslib_decorate 'ERROR: assert_line' \
+ | fail
return $?
fi
@@ -81,8 +81,8 @@ assert_line() {
if (( is_mode_regexp == 1 )) && [[ '' =~ $expected ]] || (( $? == 2 )); then
echo "Invalid extended regular expression: \`$expected'" \
- | batslib_decorate 'ERROR: assert_line' \
- | fail
+ | batslib_decorate 'ERROR: assert_line' \
+ | fail
return $?
fi
@@ -92,29 +92,29 @@ assert_line() {
if (( is_mode_regexp )); then
if ! [[ ${lines[$idx]} =~ $expected ]]; then
batslib_print_kv_single 6 \
- 'index' "$idx" \
- 'regexp' "$expected" \
- 'line' "${lines[$idx]}" \
- | batslib_decorate 'regular expression does not match line' \
- | fail
+ 'index' "$idx" \
+ 'regexp' "$expected" \
+ 'line' "${lines[$idx]}" \
+ | batslib_decorate 'regular expression does not match line' \
+ | fail
fi
elif (( is_mode_partial )); then
if [[ ${lines[$idx]} != *"$expected"* ]]; then
batslib_print_kv_single 9 \
- 'index' "$idx" \
- 'substring' "$expected" \
- 'line' "${lines[$idx]}" \
- | batslib_decorate 'line does not contain substring' \
- | fail
+ 'index' "$idx" \
+ 'substring' "$expected" \
+ 'line' "${lines[$idx]}" \
+ | batslib_decorate 'line does not contain substring' \
+ | fail
fi
else
if [[ ${lines[$idx]} != "$expected" ]]; then
batslib_print_kv_single 8 \
- 'index' "$idx" \
- 'expected' "$expected" \
- 'actual' "${lines[$idx]}" \
- | batslib_decorate 'line differs' \
- | fail
+ 'index' "$idx" \
+ 'expected' "$expected" \
+ 'actual' "${lines[$idx]}" \
+ | batslib_decorate 'line differs' \
+ | fail
fi
fi
else
@@ -124,52 +124,40 @@ assert_line() {
for (( idx = 0; idx < ${#lines[@]}; ++idx )); do
[[ ${lines[$idx]} =~ $expected ]] && return 0
done
- { local -ar single=(
- 'regexp' "$expected"
- )
- local -ar may_be_multi=(
- 'output' "$output"
- )
- local -ir width="$( batslib_get_max_single_line_key_width \
- "${single[@]}" "${may_be_multi[@]}" )"
+ { local -ar single=( 'regexp' "$expected" )
+ local -ar may_be_multi=( 'output' "$output" )
+ local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )"
batslib_print_kv_single "$width" "${single[@]}"
batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}"
- } | batslib_decorate 'no output line matches regular expression' \
- | fail
+ } \
+ | batslib_decorate 'no output line matches regular expression' \
+ | fail
elif (( is_mode_partial )); then
local -i idx
for (( idx = 0; idx < ${#lines[@]}; ++idx )); do
[[ ${lines[$idx]} == *"$expected"* ]] && return 0
done
- { local -ar single=(
- 'substring' "$expected"
- )
- local -ar may_be_multi=(
- 'output' "$output"
- )
- local -ir width="$( batslib_get_max_single_line_key_width \
- "${single[@]}" "${may_be_multi[@]}" )"
+ { local -ar single=( 'substring' "$expected" )
+ local -ar may_be_multi=( 'output' "$output" )
+ local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )"
batslib_print_kv_single "$width" "${single[@]}"
batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}"
- } | batslib_decorate 'no output line contains substring' \
- | fail
+ } \
+ | batslib_decorate 'no output line contains substring' \
+ | fail
else
local -i idx
for (( idx = 0; idx < ${#lines[@]}; ++idx )); do
[[ ${lines[$idx]} == "$expected" ]] && return 0
done
- { local -ar single=(
- 'line' "$expected"
- )
- local -ar may_be_multi=(
- 'output' "$output"
- )
- local -ir width="$( batslib_get_max_single_line_key_width \
- "${single[@]}" "${may_be_multi[@]}" )"
+ { local -ar single=( 'line' "$expected" )
+ local -ar may_be_multi=( 'output' "$output" )
+ local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )"
batslib_print_kv_single "$width" "${single[@]}"
batslib_print_kv_single_or_multi "$width" "${may_be_multi[@]}"
- } | batslib_decorate 'output does not contain line' \
- | fail
+ } \
+ | batslib_decorate 'output does not contain line' \
+ | fail
fi
fi
}
diff --git a/src/assert_output.bash b/src/assert_output.bash
index 146bbd5..ec10547 100644
--- a/src/assert_output.bash
+++ b/src/assert_output.bash
@@ -44,18 +44,18 @@ assert_output() {
while (( $# > 0 )); do
case "$1" in
- -p|--partial) is_mode_partial=1; shift ;;
- -e|--regexp) is_mode_regexp=1; shift ;;
- -|--stdin) use_stdin=1; shift ;;
- --) shift; break ;;
- *) break ;;
+ -p|--partial) is_mode_partial=1; shift ;;
+ -e|--regexp) is_mode_regexp=1; shift ;;
+ -|--stdin) use_stdin=1; shift ;;
+ --) shift; break ;;
+ *) break ;;
esac
done
if (( is_mode_partial )) && (( is_mode_regexp )); then
echo "\`--partial' and \`--regexp' are mutually exclusive" \
- | batslib_decorate 'ERROR: assert_output' \
- | fail
+ | batslib_decorate 'ERROR: assert_output' \
+ | fail
return $?
fi
@@ -71,36 +71,36 @@ assert_output() {
if (( is_mode_nonempty )); then
if [ -z "$output" ]; then
echo 'expected non-empty output, but output was empty' \
- | batslib_decorate 'no output' \
- | fail
+ | batslib_decorate 'no output' \
+ | fail
fi
elif (( is_mode_regexp )); then
if [[ '' =~ $expected ]] || (( $? == 2 )); then
echo "Invalid extended regular expression: \`$expected'" \
- | batslib_decorate 'ERROR: assert_output' \
- | fail
+ | batslib_decorate 'ERROR: assert_output' \
+ | fail
elif ! [[ $output =~ $expected ]]; then
batslib_print_kv_single_or_multi 6 \
- 'regexp' "$expected" \
- 'output' "$output" \
- | batslib_decorate 'regular expression does not match output' \
- | fail
+ 'regexp' "$expected" \
+ 'output' "$output" \
+ | batslib_decorate 'regular expression does not match output' \
+ | fail
fi
elif (( is_mode_partial )); then
if [[ $output != *"$expected"* ]]; then
batslib_print_kv_single_or_multi 9 \
- 'substring' "$expected" \
- 'output' "$output" \
- | batslib_decorate 'output does not contain substring' \
- | fail
+ 'substring' "$expected" \
+ 'output' "$output" \
+ | batslib_decorate 'output does not contain substring' \
+ | fail
fi
else
if [[ $output != "$expected" ]]; then
batslib_print_kv_single_or_multi 8 \
- 'expected' "$expected" \
- 'actual' "$output" \
- | batslib_decorate 'output differs' \
- | fail
+ 'expected' "$expected" \
+ 'actual' "$output" \
+ | batslib_decorate 'output differs' \
+ | fail
fi
fi
}
diff --git a/src/assert_success.bash b/src/assert_success.bash
index 342850d..e7d285b 100644
--- a/src/assert_success.bash
+++ b/src/assert_success.bash
@@ -16,7 +16,8 @@ assert_success() {
{ local -ir width=6
batslib_print_kv_single "$width" 'status' "$status"
batslib_print_kv_single_or_multi "$width" 'output' "$output"
- } | batslib_decorate 'command failed' \
- | fail
+ } \
+ | batslib_decorate 'command failed' \
+ | fail
fi
}
diff --git a/src/refute_line.bash b/src/refute_line.bash
index 80b2467..332c384 100644
--- a/src/refute_line.bash
+++ b/src/refute_line.bash
@@ -55,28 +55,28 @@ refute_line() {
# Handle options.
while (( $# > 0 )); do
case "$1" in
- -n|--index)
- if (( $# < 2 )) || ! [[ $2 =~ ^([0-9]|[1-9][0-9]+)$ ]]; then
- echo "\`--index' requires an integer argument: \`$2'" \
- | batslib_decorate 'ERROR: refute_line' \
- | fail
- return $?
- fi
- is_match_line=1
- local -ri idx="$2"
- shift 2
- ;;
- -p|--partial) is_mode_partial=1; shift ;;
- -e|--regexp) is_mode_regexp=1; shift ;;
- --) shift; break ;;
- *) break ;;
+ -n|--index)
+ if (( $# < 2 )) || ! [[ $2 =~ ^([0-9]|[1-9][0-9]+)$ ]]; then
+ echo "\`--index' requires an integer argument: \`$2'" \
+ | batslib_decorate 'ERROR: refute_line' \
+ | fail
+ return $?
+ fi
+ is_match_line=1
+ local -ri idx="$2"
+ shift 2
+ ;;
+ -p|--partial) is_mode_partial=1; shift ;;
+ -e|--regexp) is_mode_regexp=1; shift ;;
+ --) shift; break ;;
+ *) break ;;
esac
done
if (( is_mode_partial )) && (( is_mode_regexp )); then
echo "\`--partial' and \`--regexp' are mutually exclusive" \
- | batslib_decorate 'ERROR: refute_line' \
- | fail
+ | batslib_decorate 'ERROR: refute_line' \
+ | fail
return $?
fi
@@ -85,8 +85,8 @@ refute_line() {
if (( is_mode_regexp == 1 )) && [[ '' =~ $unexpected ]] || (( $? == 2 )); then
echo "Invalid extended regular expression: \`$unexpected'" \
- | batslib_decorate 'ERROR: refute_line' \
- | fail
+ | batslib_decorate 'ERROR: refute_line' \
+ | fail
return $?
fi
@@ -96,28 +96,28 @@ refute_line() {
if (( is_mode_regexp )); then
if [[ ${lines[$idx]} =~ $unexpected ]] || (( $? == 0 )); then
batslib_print_kv_single 6 \
- 'index' "$idx" \
- 'regexp' "$unexpected" \
- 'line' "${lines[$idx]}" \
- | batslib_decorate 'regular expression should not match line' \
- | fail
+ 'index' "$idx" \
+ 'regexp' "$unexpected" \
+ 'line' "${lines[$idx]}" \
+ | batslib_decorate 'regular expression should not match line' \
+ | fail
fi
elif (( is_mode_partial )); then
if [[ ${lines[$idx]} == *"$unexpected"* ]]; then
batslib_print_kv_single 9 \
- 'index' "$idx" \
- 'substring' "$unexpected" \
- 'line' "${lines[$idx]}" \
- | batslib_decorate 'line should not contain substring' \
- | fail
+ 'index' "$idx" \
+ 'substring' "$unexpected" \
+ 'line' "${lines[$idx]}" \
+ | batslib_decorate 'line should not contain substring' \
+ | fail
fi
else
if [[ ${lines[$idx]} == "$unexpected" ]]; then
batslib_print_kv_single 5 \
- 'index' "$idx" \
- 'line' "${lines[$idx]}" \
- | batslib_decorate 'line should differ' \
- | fail
+ 'index' "$idx" \
+ 'line' "${lines[$idx]}" \
+ | batslib_decorate 'line should differ' \
+ | fail
fi
fi
else
@@ -126,26 +126,19 @@ refute_line() {
local -i idx
for (( idx = 0; idx < ${#lines[@]}; ++idx )); do
if [[ ${lines[$idx]} =~ $unexpected ]]; then
- { local -ar single=(
- 'regexp' "$unexpected"
- 'index' "$idx"
- )
- local -a may_be_multi=(
- 'output' "$output"
- )
- local -ir width="$( batslib_get_max_single_line_key_width \
- "${single[@]}" "${may_be_multi[@]}" )"
+ { local -ar single=( 'regexp' "$unexpected" 'index' "$idx" )
+ local -a may_be_multi=( 'output' "$output" )
+ local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )"
batslib_print_kv_single "$width" "${single[@]}"
if batslib_is_single_line "${may_be_multi[1]}"; then
batslib_print_kv_single "$width" "${may_be_multi[@]}"
else
- may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" \
- | batslib_prefix \
- | batslib_mark '>' "$idx" )"
+ may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" | batslib_prefix | batslib_mark '>' "$idx" )"
batslib_print_kv_multi "${may_be_multi[@]}"
fi
- } | batslib_decorate 'no line should match the regular expression' \
- | fail
+ } \
+ | batslib_decorate 'no line should match the regular expression' \
+ | fail
return $?
fi
done
@@ -153,26 +146,19 @@ refute_line() {
local -i idx
for (( idx = 0; idx < ${#lines[@]}; ++idx )); do
if [[ ${lines[$idx]} == *"$unexpected"* ]]; then
- { local -ar single=(
- 'substring' "$unexpected"
- 'index' "$idx"
- )
- local -a may_be_multi=(
- 'output' "$output"
- )
- local -ir width="$( batslib_get_max_single_line_key_width \
- "${single[@]}" "${may_be_multi[@]}" )"
+ { local -ar single=( 'substring' "$unexpected" 'index' "$idx" )
+ local -a may_be_multi=( 'output' "$output" )
+ local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )"
batslib_print_kv_single "$width" "${single[@]}"
if batslib_is_single_line "${may_be_multi[1]}"; then
batslib_print_kv_single "$width" "${may_be_multi[@]}"
else
- may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" \
- | batslib_prefix \
- | batslib_mark '>' "$idx" )"
+ may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" | batslib_prefix | batslib_mark '>' "$idx" )"
batslib_print_kv_multi "${may_be_multi[@]}"
fi
- } | batslib_decorate 'no line should contain substring' \
- | fail
+ } \
+ | batslib_decorate 'no line should contain substring' \
+ | fail
return $?
fi
done
@@ -180,26 +166,19 @@ refute_line() {
local -i idx
for (( idx = 0; idx < ${#lines[@]}; ++idx )); do
if [[ ${lines[$idx]} == "$unexpected" ]]; then
- { local -ar single=(
- 'line' "$unexpected"
- 'index' "$idx"
- )
- local -a may_be_multi=(
- 'output' "$output"
- )
- local -ir width="$( batslib_get_max_single_line_key_width \
- "${single[@]}" "${may_be_multi[@]}" )"
+ { local -ar single=( 'line' "$unexpected" 'index' "$idx" )
+ local -a may_be_multi=( 'output' "$output" )
+ local -ir width="$( batslib_get_max_single_line_key_width "${single[@]}" "${may_be_multi[@]}" )"
batslib_print_kv_single "$width" "${single[@]}"
if batslib_is_single_line "${may_be_multi[1]}"; then
batslib_print_kv_single "$width" "${may_be_multi[@]}"
else
- may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" \
- | batslib_prefix \
- | batslib_mark '>' "$idx" )"
+ may_be_multi[1]="$( printf '%s' "${may_be_multi[1]}" | batslib_prefix | batslib_mark '>' "$idx" )"
batslib_print_kv_multi "${may_be_multi[@]}"
fi
- } | batslib_decorate 'line should not be in output' \
- | fail
+ } \
+ | batslib_decorate 'line should not be in output' \
+ | fail
return $?
fi
done
diff --git a/src/refute_output.bash b/src/refute_output.bash
index 02b38a1..93298f6 100644
--- a/src/refute_output.bash
+++ b/src/refute_output.bash
@@ -46,18 +46,18 @@ refute_output() {
while (( $# > 0 )); do
case "$1" in
- -p|--partial) is_mode_partial=1; shift ;;
- -e|--regexp) is_mode_regexp=1; shift ;;
- -|--stdin) use_stdin=1; shift ;;
- --) shift; break ;;
- *) break ;;
+ -p|--partial) is_mode_partial=1; shift ;;
+ -e|--regexp) is_mode_regexp=1; shift ;;
+ -|--stdin) use_stdin=1; shift ;;
+ --) shift; break ;;
+ *) break ;;
esac
done
if (( is_mode_partial )) && (( is_mode_regexp )); then
echo "\`--partial' and \`--regexp' are mutually exclusive" \
- | batslib_decorate 'ERROR: refute_output' \
- | fail
+ | batslib_decorate 'ERROR: refute_output' \
+ | fail
return $?
fi
@@ -71,8 +71,8 @@ refute_output() {
if (( is_mode_regexp == 1 )) && [[ '' =~ $unexpected ]] || (( $? == 2 )); then
echo "Invalid extended regular expression: \`$unexpected'" \
- | batslib_decorate 'ERROR: refute_output' \
- | fail
+ | batslib_decorate 'ERROR: refute_output' \
+ | fail
return $?
fi
@@ -80,32 +80,32 @@ refute_output() {
if (( is_mode_empty )); then
if [ -n "$output" ]; then
batslib_print_kv_single_or_multi 6 \
- 'output' "$output" \
- | batslib_decorate 'output non-empty, but expected no output' \
- | fail
+ 'output' "$output" \
+ | batslib_decorate 'output non-empty, but expected no output' \
+ | fail
fi
elif (( is_mode_regexp )); then
if [[ $output =~ $unexpected ]] || (( $? == 0 )); then
batslib_print_kv_single_or_multi 6 \
- 'regexp' "$unexpected" \
- 'output' "$output" \
- | batslib_decorate 'regular expression should not match output' \
- | fail
+ 'regexp' "$unexpected" \
+ 'output' "$output" \
+ | batslib_decorate 'regular expression should not match output' \
+ | fail
fi
elif (( is_mode_partial )); then
if [[ $output == *"$unexpected"* ]]; then
batslib_print_kv_single_or_multi 9 \
- 'substring' "$unexpected" \
- 'output' "$output" \
- | batslib_decorate 'output should not contain substring' \
- | fail
+ 'substring' "$unexpected" \
+ 'output' "$output" \
+ | batslib_decorate 'output should not contain substring' \
+ | fail
fi
else
if [[ $output == "$unexpected" ]]; then
batslib_print_kv_single_or_multi 6 \
- 'output' "$output" \
- | batslib_decorate 'output equals, but it was expected to differ' \
- | fail
+ 'output' "$output" \
+ | batslib_decorate 'output equals, but it was expected to differ' \
+ | fail
fi
fi
}