mirror of
https://github.com/eth-p/bat-extras.git
synced 2025-01-31 09:29:14 +01:00
Updated test system to be a little more straightforward
This commit is contained in:
parent
b09f38190c
commit
9c2656312c
101
test/run.sh
101
test/run.sh
@ -1,21 +1,100 @@
|
||||
#!/usr/bin/env bash
|
||||
# -----------------------------------------------------------------------------
|
||||
# bat-extras | Copyright (C) 2019 eth-p | MIT License
|
||||
#
|
||||
# Repository: https://github.com/eth-p/bat-extras
|
||||
# Issues: https://github.com/eth-p/bat-extras/issues
|
||||
# -----------------------------------------------------------------------------
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
FAIL=false
|
||||
ACTION="snapshot-test"
|
||||
LIB="${HERE}/../lib"
|
||||
source "${LIB}/print.sh"
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
# Runs a test.
|
||||
#
|
||||
# Arguments:
|
||||
# 1 -- The test name.
|
||||
# 2 -- The test action.
|
||||
#
|
||||
# Returns:
|
||||
# 0 -- The test passed.
|
||||
# 1 -- The test failed.
|
||||
run_test() {
|
||||
local test_name="$1"
|
||||
local test_action="$2"
|
||||
|
||||
bash "$HERE/util/test-exec.sh" "$test_action" "$test_name"
|
||||
return $?
|
||||
}
|
||||
|
||||
# Runs all tests.
|
||||
#
|
||||
# Arguments:
|
||||
# 1 -- The test action.
|
||||
#
|
||||
# Variables:
|
||||
# RESULT -- "pass" or "fail".
|
||||
# RESULT_PASS -- The number of tests that passed.
|
||||
# RESULT_FAIL -- The number of tests that failed.
|
||||
run_all_tests() {
|
||||
local test_action="$1"
|
||||
|
||||
RESULT="pass"
|
||||
RESULT_PASS=0
|
||||
RESULT_FAIL=0
|
||||
|
||||
for test in "$HERE"/tests/*.sh; do
|
||||
if run_test "$(basename "$test" .sh)" "$test_action"; then
|
||||
((RESULT_PASS++))
|
||||
else
|
||||
((RESULT_FAIL++))
|
||||
RESULT="fail"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$RESULT" = "fail" ]; then
|
||||
return 1
|
||||
else
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
# Displays a summary of the tests run.
|
||||
display_test_summary() {
|
||||
local tpc
|
||||
local tfc
|
||||
|
||||
[[ "$RESULT_PASS" -gt 0 ]] && tpc="GREEN" || tpc="CLEAR";
|
||||
[[ "$RESULT_FAIL" -gt 0 ]] && tfc="RED" || tfc="CLEAR";
|
||||
|
||||
printc "%{YELLOW}RESULT: %{${tpc}}%s%{YELLOW} passed, %{${tfc}}%s%{YELLOW} failed.%{CLEAR}\n" \
|
||||
"$RESULT_PASS" \
|
||||
"$RESULT_FAIL"
|
||||
}
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
ACTION="$1"
|
||||
run_all_tests "$1"
|
||||
display_test_summary
|
||||
exit $?
|
||||
fi
|
||||
|
||||
for test in "$HERE"/tests/*.sh; do
|
||||
test_name="$(basename "$test" .sh)"
|
||||
bash "$HERE/util/test.sh" "$ACTION" "$test_name"
|
||||
if [ $? -ne 0 ]; then
|
||||
FAIL=true
|
||||
# Run all actions.
|
||||
FINAL_RESULT="pass"
|
||||
for action in "snapshot-test" "consistency-test"; do
|
||||
printc "%{CYAN}Running %{CLEAR}%s%{CYAN} tests:%{CLEAR}\n" "$action"
|
||||
run_all_tests "$action"
|
||||
display_test_summary
|
||||
printf "\n"
|
||||
|
||||
if [[ "$RESULT" = "fail" ]]; then
|
||||
FINAL_RESULT=fail
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$FAIL" = true ]; then
|
||||
exit 1
|
||||
fi
|
||||
case "$FINAL_RESULT" in
|
||||
pass) exit 0;;
|
||||
fail) exit 1;;
|
||||
esac
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
RUNNER="${HERE}/runner.sh"
|
||||
RUNNER="${HERE}/test-runner.sh"
|
||||
TEST_DATA="${HERE}/../data"
|
||||
|
||||
# Test data.
|
Loading…
Reference in New Issue
Block a user