Loading .gitlab-ci.yml +17 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,23 @@ include: # ENDSCRIPT e2e: bash-tests: stage: test needs: [] image: $IMAGE parallel: matrix: - IMAGE: "fedora" SHELLCMD: "bash" - IMAGE: "debian" SHELLCMD: "bash" - IMAGE: "alpine" SHELLCMD: "ash" script: - $SHELLCMD tests/run_tests.sh tests/bash_tests/test_*.sh allow_failure: true e2e-tests: stage: test needs: [] image: $IMAGE Loading tests/bash_tests/base.sh 0 → 100755 +48 −0 Original line number Diff line number Diff line set -eo pipefail log_info() { >&2 echo -e "[\\e[1;94mINFO\\e[0m] $*" } log_warn() { >&2 echo -e "[\\e[1;93mWARN\\e[0m] $*" } log_error() { >&2 echo -e "[\\e[1;91mERROR\\e[0m] $*" } fail() { >&2 echo -e " \\e[1;93mFAIL\\e[0m: $*" return ${FAILRC:-128} } assert_defined() { val=$(eval echo "\$$1") if [[ -z "$val" ]] then fail "Variable '$1' should be defined" fi } refute_defined() { val=$(eval echo "\$$1") if [[ "$val" ]] then fail "Variable '$1' should not be defined" fi } assert_equals() { if [[ "$1" != "$2" ]] then fail "Actual '$2' should be expected '$1'" fi } refute_equals() { if [[ "$1" == "$2" ]] then fail "Actual '$2' should not be expected '$1'" fi } tests/bash_tests/test_arithmetic_command.sh 0 → 100755 +11 −0 Original line number Diff line number Diff line source "$(dirname "$0")/base.sh" num=11 (( num ++ )) assert_equals "12" "$num" (( num += 30 )) assert_equals "42" "$num" (( num -= 2 )) assert_equals "40" "$num" (( num /= 5 )) assert_equals "8" "$num" tests/bash_tests/test_arithmetic_expansion.sh 0 → 100755 +25 −0 Original line number Diff line number Diff line # See: https://www.gnu.org/software/bash/manual/bash.html#Arithmetic-Expansion source "$(dirname "$0")/base.sh" num=12 num=$(( num + 30 )) assert_equals "42" "$num" num=$(( num - 2 )) assert_equals "40" "$num" num=$(( num / 5 )) assert_equals "8" "$num" # remainder assert_equals "2" $(( num % 3 )) # not assert_equals "0" $(( ! num )) # bitwise shift assert_equals 6 $(( 3 << 1 )) assert_equals 2 $(( 5 >> 1 )) # bitwise or assert_equals 11 $(( 9 | 3 )) # ternary op assert_equals 666 $(( num ? 666 : 42 )) tests/bash_tests/test_array_clone.sh 0 → 100755 +7 −0 Original line number Diff line number Diff line # See: https://devhints.io/bash#arrays source "$(dirname "$0")/base.sh" fruits=('Apple' 'Banana' 'Orange' 'Pineapple' 'Watermelon') clone_of_fruits=("${fruits[@]:1:3}") assert_equals "3" "${#clone_of_fruits[@]}" assert_equals "Banana Orange Pineapple" "${clone_of_fruits[*]}" Loading
.gitlab-ci.yml +17 −1 Original line number Diff line number Diff line Loading @@ -57,7 +57,23 @@ include: # ENDSCRIPT e2e: bash-tests: stage: test needs: [] image: $IMAGE parallel: matrix: - IMAGE: "fedora" SHELLCMD: "bash" - IMAGE: "debian" SHELLCMD: "bash" - IMAGE: "alpine" SHELLCMD: "ash" script: - $SHELLCMD tests/run_tests.sh tests/bash_tests/test_*.sh allow_failure: true e2e-tests: stage: test needs: [] image: $IMAGE Loading
tests/bash_tests/base.sh 0 → 100755 +48 −0 Original line number Diff line number Diff line set -eo pipefail log_info() { >&2 echo -e "[\\e[1;94mINFO\\e[0m] $*" } log_warn() { >&2 echo -e "[\\e[1;93mWARN\\e[0m] $*" } log_error() { >&2 echo -e "[\\e[1;91mERROR\\e[0m] $*" } fail() { >&2 echo -e " \\e[1;93mFAIL\\e[0m: $*" return ${FAILRC:-128} } assert_defined() { val=$(eval echo "\$$1") if [[ -z "$val" ]] then fail "Variable '$1' should be defined" fi } refute_defined() { val=$(eval echo "\$$1") if [[ "$val" ]] then fail "Variable '$1' should not be defined" fi } assert_equals() { if [[ "$1" != "$2" ]] then fail "Actual '$2' should be expected '$1'" fi } refute_equals() { if [[ "$1" == "$2" ]] then fail "Actual '$2' should not be expected '$1'" fi }
tests/bash_tests/test_arithmetic_command.sh 0 → 100755 +11 −0 Original line number Diff line number Diff line source "$(dirname "$0")/base.sh" num=11 (( num ++ )) assert_equals "12" "$num" (( num += 30 )) assert_equals "42" "$num" (( num -= 2 )) assert_equals "40" "$num" (( num /= 5 )) assert_equals "8" "$num"
tests/bash_tests/test_arithmetic_expansion.sh 0 → 100755 +25 −0 Original line number Diff line number Diff line # See: https://www.gnu.org/software/bash/manual/bash.html#Arithmetic-Expansion source "$(dirname "$0")/base.sh" num=12 num=$(( num + 30 )) assert_equals "42" "$num" num=$(( num - 2 )) assert_equals "40" "$num" num=$(( num / 5 )) assert_equals "8" "$num" # remainder assert_equals "2" $(( num % 3 )) # not assert_equals "0" $(( ! num )) # bitwise shift assert_equals 6 $(( 3 << 1 )) assert_equals 2 $(( 5 >> 1 )) # bitwise or assert_equals 11 $(( 9 | 3 )) # ternary op assert_equals 666 $(( num ? 666 : 42 ))
tests/bash_tests/test_array_clone.sh 0 → 100755 +7 −0 Original line number Diff line number Diff line # See: https://devhints.io/bash#arrays source "$(dirname "$0")/base.sh" fruits=('Apple' 'Banana' 'Orange' 'Pineapple' 'Watermelon') clone_of_fruits=("${fruits[@]:1:3}") assert_equals "3" "${#clone_of_fruits[@]}" assert_equals "Banana Orange Pineapple" "${clone_of_fruits[*]}"