Skip to content

Commit

Permalink
test: ✅ add assert_equals function to check two strings are equal
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Villard <[email protected]>
  • Loading branch information
eviweb committed Aug 31, 2022
1 parent b5b8af9 commit ec2b28f
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,36 @@ get_test_files()
ls "$(test_dir)"/*-test.sh
}

# Assert two strings are equal
#
# Usage:
# assert_equals "string 1" "string 2" "message"
function assert_equals {
local string1="$1"
local string2="$2"
local message="$3"
local fails="\u2718"
local succeed="\u2714"
local result=0

[ -n "${message}" ] || {
message="Assert \e[34m'${string1}'\e[0m equals \e[35m'${string2}'\e[0m."
}

local diff="$(diff <(echo "${string1}" ) <(echo "${string2}"))"

if [ -z "${diff}" ]; then
echo -e "\e[32m${succeed}\e[0m ${message}"
else

result=1
echo -e "\e[31m${fails}\e[0m ${message}"
echo -e "\e[2m${diff}\e[22m"
fi

return $result
}

TESTS=($(get_test_files))

for test in "${TESTS[@]}"; do
Expand Down

0 comments on commit ec2b28f

Please sign in to comment.