Skip to content

Commit

Permalink
test: ✅ add runner and functions
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Villard <[email protected]>
  • Loading branch information
eviweb committed Apr 21, 2022
1 parent 1a19055 commit cf5092a
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/lib/functions
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#! /usr/bin/env bash

[ -n "${ERRORS}" ] || export ERRORS="${ERRORS:-0}"
[ -n "${TESTS}" ] || export TESTS="${TESTS:-0}"

# 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

((TESTS++))

[ -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
((ERRORS++))

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

return $result
}
19 changes: 19 additions & 0 deletions tests/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#! /usr/bin/env bash
tests_dir()
{
dirname "$(readlink -f "${BASH_SOURCE}")"
}

lib_dir()
{
echo "$(tests_dir)/lib"
}

. "$(lib_dir)"/functions

for testfile in "$(tests_dir)"/*-test; do
. "${testfile}"
done

PASSED="$((TESTS - ERRORS))"
echo -e "-- \n${PASSED} passed tests / ${TESTS} tests - ${ERRORS} errors."

0 comments on commit cf5092a

Please sign in to comment.