Adding more tests and excludes to be able to traverse through /**/* wihtout error

Added test summary to stdout
This commit is contained in:
2022-03-20 14:37:18 +01:00
parent dcabe75887
commit 3d9113377c
2 changed files with 68 additions and 18 deletions

View File

@@ -53,6 +53,25 @@ rl::printPath() {
fi
}
rl::printTestSummary() {
local success=${1:-0}
local failed=${2:-0}
local skipped=${3:-0}
local total=$(( success + failed + skipped ))
local separator="--------------------"
cat <<TEST_SUMMARY_EOF
# Test summary:
successful: ${success}
failed: ${failed}
skipped: ${skipped}
TEST_SUMMARY_EOF
printf "%15s-%s\n" "------" "${separator:0:${#total}}"
printf "%15s %d\n" "total:" ${total}
}
# rl::testcmp <TEST NUMBER> <TEST INPUT> <EXPECTED RESULT> <ACTUAL RESULT>
# Compare results and print summary
rl::testcmp() {
@@ -111,6 +130,9 @@ rl::test() {
local testend=0
local arg=
local excludemsg=
local tests_success=0
local tests_failed=0
local tests_skipped=0
for arg in "$@"; do
case "$1" in
@@ -163,22 +185,27 @@ rl::test() {
# Check for excludes
elif excludemsg="$(toexclude "${firstelement}")"; then
rl::printPath "$((i-1))" "${firstelement}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
(( tests_skipped++ ))
rl::printPath "$(( i/2 ))" "${firstelement}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
# Execute tests
else
# Do the compare between two following elements
if ! rl::testcmp "$((i-1))" "${firstelement}" \
if ! rl::testcmp "$(( i/2 ))" "${firstelement}" \
"${path}" "$($tool_rdlink -- "${firstelement}")"; then
(( tests_failed++ ))
# Run all tests if option -a is pressend
(( ! $flag_runall )) && testend=1 && break
else
(( tests_success++ ))
fi
firstelement=
fi
((i++))
done
(( testend )) && return 1
(( testend )) && break
done
(( testend )) && rl::printTestSummary $tests_success $tests_failed $tests_skipped && return 1
# Initialize competition tests
(( ! flag_onlyassert )) && tocompete_init
@@ -206,19 +233,26 @@ rl::test() {
else
# Check for excludes
if excludemsg="$(toexclude "${path}")" ; then
rl::printPath "" "${path}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
(( tests_skipped++ ))
rl::printPath "${i}" "${path}" && printf " %b skip (%s)\n" "🛇" "${excludemsg}"
# Execute tests
elif ! rl::testcmp "${i}" "${path}" \
"$(${tool_readlink} "$path")" "$(${tool_rdlink} -- "$path")"; then
(( tests_failed++ ))
# Run all tests if option -a is pressend
(( ! $flag_runall )) && testend=1 && break
else
(( tests_success++ ))
fi
fi
((i++))
done
(( testend )) && return 1
(( testend )) && break
done
rl::printTestSummary $tests_success $tests_failed $tests_skipped
(( testend )) && return 1 || return 0
}
#time rl::test "$@"

View File

@@ -40,8 +40,9 @@ tocompete_init() {
# compete_no_permission
mkdir -p "${_tc_tmp}/noperm"
chmod 400 "${_tc_tmp}/noperm"
ln -s "noperm" "${_tc_tmp}/lnoperm"
ln -s "noperm" "${_tc_tmp}/noperml"
ln -s "/" "${_tc_tmp}/lroot"
ln -s "/root" "${_tc_tmp}/lroothome"
#echo "rl: " && readlink "${_tc_tmp}/lnoperm"
#ls -l "${_tc_tmp}"
@@ -53,6 +54,12 @@ tocompete_init() {
# Compete test arrays with "dynamic" cases need to be inside the init function
# e.g. "$(cd ../test && pwd)/file" - base directory must be set first
# e.g. "${_tc_tmp}/"* - _tc_tmp must be populated first
compete_invalid=( "Invalid files with and without valid path"
"${_tc_tmp}/invalid_file"
"/invalid_file"
"/invalid_direcotry/invalidfile"
)
compete_links=( "Test - Valid links"
"${_tc_tmp}/a 3" # slink chain a3 -> a2 -> a
"${_tc_tmp}/a"*
@@ -62,18 +69,21 @@ tocompete_init() {
"/dev/stdout" # skip - different output
"/etc/mtab" # skip - Always different
"/proc/mounts" # skip - Always different
"/proc/net/"* # skip - Always different
)
compete_no_permission=( "No permission to enter directory (direct and link)"
"lnoperm"
"noperm"
"lroot"
"/proc/"**/cwd # special - no permission for links
"noperm"*
"lroot"*
"/"
)
# Add tests to global test array from test_rdlink
tocompete+=(
compete_no_permission
compete_invalid
compete_links
compete_no_permission
compete_canonicalize
compete_all
)
@@ -109,7 +119,7 @@ toassert_init() {
# e.g. "${_tc_tmp}/"* - _tc_tmp must be populated first
assert_invalid_files=( "Assert - invalid files"
"${_ta_tmp}/missing_file" "${_ta_tmp}/missing_file"
"${_ta_tmp}/missd/missf" "${_ta_tmp}/missd/missf"
"${_ta_tmp}/missd/missf" ""
"${_ta_tmp}/miss c" "${_ta_tmp}/miss c"
"rel_a" "${_ta_tmp}/rel_a"
"../rel_b" "$(cd ".." && pwd)/rel_b"
@@ -127,13 +137,19 @@ toassert_clean() {
########## Common data and functions ##########
#
# [0] path to exclude [1] Reason for exclution
# [2] path to exclude [3] Reason for exclution
# [0] exclude regex [1] Reason for exclution
# [2] exclude regex [3] Reason for exclution
exclude_path=(
"/dev/fd" "Always different"
"/dev/stdout" "Always different in pipes"
"/etc/mtab" "Always different"
"/proc/mounts" "Always different"
"/dev/fd$" "Different on every call"
"/dev/stdout$" "Always different in pipes"
"/etc/mtab$" "Different on every call"
"/proc/mounts$" "Different on every call"
"/proc/net$" "Different on every call"
"/proc/net/.*" "Different on every call"
"/proc/self/fd/(1|3|255)" "Different on every call"
"/proc/self$" "Different on every call"
"/proc/self/(attr|fdinfo|map_files|net|ns|task)/.*" "Different on every call"
"/proc/thread-self$" "Different on every call"
)
toexclude() {
@@ -144,7 +160,7 @@ toexclude() {
exclude="${path}"
else
# return reason for exclution
if [[ "${exclude}" == "${1:-}" ]] ; then
if [[ "${1:-}" =~ ${exclude} ]] ; then
printf "${path}"
return 0
fi