diff options
author | Jason Karns <jason.karns@gmail.com> | 2019-01-30 04:58:42 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-30 04:58:42 +0300 |
commit | 8f177a699e31bbc47b6487c894f25385ae6fcd3d (patch) | |
tree | 0884778ec55365a1fe21d50b25075b235a4e441f | |
parent | e1b1378a7a1bc6501d932cb4fe70de1fdf15e9e0 (diff) | |
parent | 55547e5713ed9a76881ac247184cdaf85ad5e93c (diff) |
Merge pull request #21 from jasonkarns/shellcheck
Adds shellcheck linting
-rw-r--r-- | load.bash | 1 | ||||
-rw-r--r-- | src/assert_failure.bash | 3 | ||||
-rw-r--r-- | src/assert_line.bash | 1 | ||||
-rw-r--r-- | src/assert_output.bash | 1 | ||||
-rw-r--r-- | src/assert_success.bash | 3 | ||||
-rw-r--r-- | src/refute_line.bash | 3 | ||||
-rw-r--r-- | src/refute_output.bash | 3 | ||||
-rw-r--r-- | test/test_helper.bash | 38 |
8 files changed, 33 insertions, 20 deletions
@@ -18,6 +18,7 @@ # All output is formatted for readability using the functions of # `output.bash' and sent to the standard error. +# shellcheck disable=1090 source "$(dirname "${BASH_SOURCE[0]}")/src/assert.bash" source "$(dirname "${BASH_SOURCE[0]}")/src/refute.bash" source "$(dirname "${BASH_SOURCE[0]}")/src/assert_equal.bash" diff --git a/src/assert_failure.bash b/src/assert_failure.bash index 1a797f4..9d5cf57 100644 --- a/src/assert_failure.bash +++ b/src/assert_failure.bash @@ -16,6 +16,9 @@ # Outputs: # STDERR - details, on failure assert_failure() { + : "${output?}" + : "${status?}" + (( $# > 0 )) && local -r expected="$1" if (( status == 0 )); then batslib_print_kv_single_or_multi 6 'output' "$output" \ diff --git a/src/assert_line.bash b/src/assert_line.bash index 2ab427a..011f08e 100644 --- a/src/assert_line.bash +++ b/src/assert_line.bash @@ -47,6 +47,7 @@ assert_line() { local -i is_match_line=0 local -i is_mode_partial=0 local -i is_mode_regexp=0 + : "${lines?}" # Handle options. while (( $# > 0 )); do diff --git a/src/assert_output.bash b/src/assert_output.bash index ec10547..bead6c5 100644 --- a/src/assert_output.bash +++ b/src/assert_output.bash @@ -36,6 +36,7 @@ assert_output() { local -i is_mode_regexp=0 local -i is_mode_nonempty=0 local -i use_stdin=0 + : "${output?}" # Handle options. if (( $# == 0 )); then diff --git a/src/assert_success.bash b/src/assert_success.bash index e7d285b..0f36272 100644 --- a/src/assert_success.bash +++ b/src/assert_success.bash @@ -12,6 +12,9 @@ # Outputs: # STDERR - details, on failure assert_success() { + : "${output?}" + : "${status?}" + if (( status != 0 )); then { local -ir width=6 batslib_print_kv_single "$width" 'status' "$status" diff --git a/src/refute_line.bash b/src/refute_line.bash index 332c384..8413b34 100644 --- a/src/refute_line.bash +++ b/src/refute_line.bash @@ -51,6 +51,7 @@ refute_line() { local -i is_match_line=0 local -i is_mode_partial=0 local -i is_mode_regexp=0 + : "${lines?}" # Handle options. while (( $# > 0 )); do @@ -94,7 +95,7 @@ refute_line() { if (( is_match_line )); then # Specific line. if (( is_mode_regexp )); then - if [[ ${lines[$idx]} =~ $unexpected ]] || (( $? == 0 )); then + if [[ ${lines[$idx]} =~ $unexpected ]]; then batslib_print_kv_single 6 \ 'index' "$idx" \ 'regexp' "$unexpected" \ diff --git a/src/refute_output.bash b/src/refute_output.bash index 93298f6..82b9677 100644 --- a/src/refute_output.bash +++ b/src/refute_output.bash @@ -38,6 +38,7 @@ refute_output() { local -i is_mode_regexp=0 local -i is_mode_empty=0 local -i use_stdin=0 + : "${output?}" # Handle options. if (( $# == 0 )); then @@ -85,7 +86,7 @@ refute_output() { | fail fi elif (( is_mode_regexp )); then - if [[ $output =~ $unexpected ]] || (( $? == 0 )); then + if [[ $output =~ $unexpected ]]; then batslib_print_kv_single_or_multi 6 \ 'regexp' "$unexpected" \ 'output' "$output" \ diff --git a/test/test_helper.bash b/test/test_helper.bash index 1461696..77120f1 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -1,25 +1,27 @@ -setup() { - export TEST_MAIN_DIR="${BATS_TEST_DIRNAME}/.." - export TEST_DEPS_DIR="${TEST_DEPS_DIR-${TEST_MAIN_DIR}/..}" +export TEST_MAIN_DIR="${BATS_TEST_DIRNAME}/.." +export TEST_DEPS_DIR="${TEST_DEPS_DIR-${TEST_MAIN_DIR}/..}" - # Load dependencies. - load "${TEST_DEPS_DIR}/bats-support/load.bash" +# Load dependencies. +load "${TEST_DEPS_DIR}/bats-support/load.bash" - # Load library. - load '../load' +# Load library. +load '../load' - assert_test_pass() { - test "$status" -eq 0 - test "${#lines[@]}" -eq 0 - } +: "${status:=}" +: "${lines:=}" +: "${output:=}" - assert_test_fail() { - local err_msg="${1-$(cat -)}" - local num_lines="$(printf '%s' "$err_msg" | wc -l)" +assert_test_pass() { + test "$status" -eq 0 + test "${#lines[@]}" -eq 0 +} +assert_test_fail() { + local err_msg="${1-$(cat -)}" + local num_lines + num_lines="$(printf '%s' "$err_msg" | wc -l)" - test "$status" -eq 1 - test "${#lines[@]}" -eq "$num_lines" - test "$output" == "$err_msg" - } + test "$status" -eq 1 + test "${#lines[@]}" -eq "$num_lines" + test "$output" == "$err_msg" } |