1
0
mirror of https://github.com/deuill/fawkss.git synced 2024-09-28 04:02:43 +00:00
fawkss/run-tests

80 lines
1.9 KiB
Plaintext
Raw Normal View History

#!/bin/bash
#
# Test runner for Fawkss.
# --------------
# USER VARIABLES
# --------------
# Current working directory.
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# Fawkss main script location.
FAWKSS_SCRIPT="${ROOT}/fawkss"
# ANSI Color definitions.
COLOR_WHITE="\033[1m"
COLOR_RED="\033[31m"
COLOR_GREEN="\033[32m"
COLOR_RESET="\033[0m"
# Initialize summary count array.
SUMMARY=(0 0 0)
# Helpers for extracting sections of test files.
read -d '' SECTION_TEST <<-'_EOF_'
/--- TEST ---/ { test = 1; next }
/--- EXPECTED ---/ { exit }
test { print }
_EOF_
read -d '' SECTION_EXPECTED <<-'_EOF_'
/--- EXPECTED ---/ { expected = 1; next }
/--- END ---/ { exit }
expected { print }
_EOF_
# --------------
# TEST EXECUTION
# --------------
echo -e ">> ${COLOR_WHITE}Executing tests...${COLOR_RESET}"
for file in ${@:-${ROOT}/tests/*.scss}
do
# Check if file exists and is readable.
if [ ! -f "${file}" ]
then
echo -e ">> ${COLOR_RED}Failed to find test file '${file}'${COLOR_RESET}"
continue
fi
# Increase count of total tests run.
SUMMARY[0]=$((${SUMMARY[0]} + 1))
# Get diff between expected and actual output.
result=$(colordiff -ud <(awk "${SECTION_EXPECTED}" "${file}") <(exec ${FAWKSS_SCRIPT} <(awk "${SECTION_TEST}" "${file}")) | tail -n +3)
# Echo per-test results.
echo -ne ">> ${COLOR_WHITE}Testing file '$(basename ${file})'...${COLOR_RESET} "
if [ "x${result}" != "x" ]
then
# Increase total of failed tests run.
SUMMARY[1]=$((${SUMMARY[1]} + 1))
echo -e "${COLOR_RED}FAIL${COLOR_RESET}"
echo "${result}"
else
# Increase total of successful tests run.
SUMMARY[2]=$((${SUMMARY[2]} + 1))
echo -e "${COLOR_GREEN}OK${COLOR_RESET}"
fi
done
# Echo total results.
echo -ne ">> ${COLOR_WHITE}Summary:${COLOR_RESET} "
echo -ne "Total ${COLOR_WHITE}${SUMMARY[0]}${COLOR_RESET}, "
echo -ne "Failed ${COLOR_RED}${SUMMARY[1]}${COLOR_RESET}, "
echo -e "Successful ${COLOR_GREEN}${SUMMARY[2]}${COLOR_RESET}"