Improving test report and return values

This commit is contained in:
2022-03-23 10:56:37 +01:00
parent bf303a608b
commit eb626d0f90
3 changed files with 22 additions and 7 deletions

View File

@@ -2,14 +2,23 @@
savetest() { savetest() {
local target_file= local target_file=
local environment=
local failed_tests=0
readonly savetest_dir="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" readonly savetest_dir="$(cd "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
target_dir="${savetest_dir}/results" target_dir="${savetest_dir}/results"
mkdir -p "${target_dir}" mkdir -p "${target_dir}"
target_file="${target_dir}/$("${savetest_dir}/getenv.sh")_result.log" environment="$("${savetest_dir}/getenv.sh")"
target_file="${target_dir}/${environment:-"Unknown_Environemnt"}_result.log"
"${savetest_dir}/test_rdlink.sh" >"${target_file}" 2>&1 printf "# Test environment\n\n %s\n\n" "${environment}" >"${target_file}"
"${savetest_dir}/test_rdlink.sh" -a >>"${target_file}" 2>&1
failed_tests="$?"
(( failed_tests )) && printf "Failed tests: %s\n" "$failed_tests"
return $failed_tests
} }
savetest savetest

View File

@@ -85,7 +85,7 @@ rl::test() {
# Check if assertion tests need to be performed # Check if assertion tests need to be performed
(( ! flag_onlycompete )) && [[ ! "$@" ]] && toassert_init (( ! flag_onlycompete )) && [[ ! "$@" ]] && toassert_init
# Compare against expected result # Compare against expected result
if (( ${#toassert[@]} )) ; then if (( ${#toassert[@]} )) ; then
rl::printTitle rl::printTitle
@@ -173,15 +173,15 @@ rl::test() {
done done
rl::printTestSummary $tests_success $tests_failed $tests_skipped rl::printTestSummary $tests_success $tests_failed $tests_skipped
(( testend )) && return 1 || return 0 return ${tests_failed}
} }
rl::printTitle() { rl::printTitle() {
(( flag_title )) && return 0 (( flag_title )) && return 0
flag_title=1 flag_title=1
# See if some tests will be performed # See if some tests will be performed
printf "# Testing rdlink version %s\n" "${tool_rdlink_version}" printf "# Testing rdlink version %s\n\n" "${tool_rdlink_version}"
printf " Testdate: %s\n" "$(date -u +"%Y-%m-%d %H:%M:%S UTC")" printf " Testdate: %s\n" "$(date -u +"%Y-%m-%d %H:%M:%S UTC")"
} }
@@ -229,7 +229,7 @@ rl::testcmp() {
local testresult=0 #failed local testresult=0 #failed
local testresult_graphic="${color_red}${color_less}" # alt. symbol ≠ local testresult_graphic="${color_red}${color_less}" # alt. symbol ≠
local link="$(readlink -- "${input}")" local link="$(readlink -- "${input}")"
if [[ "${expect}" == "${actual}" ]] ; then if [[ "${expect}" == "${actual}" ]] ; then
# Don't print success for this flag # Don't print success for this flag
(( flag_printerror )) && return 0 (( flag_printerror )) && return 0
@@ -273,3 +273,4 @@ rl::testcmp() {
#time rl::test "$@" #time rl::test "$@"
rl::test "$@" rl::test "$@"

View File

@@ -152,9 +152,14 @@ toassert_init() {
"../rel_b" "$(cd ".." && pwd)/rel_b" "../rel_b" "$(cd ".." && pwd)/rel_b"
) )
assert_force_fail=( "Force fail"
"nix" ""
)
# Add test arrays to global test array from test_rdlink # Add test arrays to global test array from test_rdlink
toassert+=( toassert+=(
assert_invalid_files assert_invalid_files
#assert_force_fail
) )
} }