Initial file structrue and rdlink with essential content

This commit is contained in:
2022-03-18 17:17:28 +01:00
parent 9ab4b12829
commit 6dc6b305b9
3 changed files with 190 additions and 0 deletions

72
test/test_rdlink.sh Executable file
View File

@@ -0,0 +1,72 @@
#!/bin/bash
tool_a="/opt/rdlink/rdlink.sh"
tool_b="$(command -v readlink) -f"
test_links=( "Valid links"
"/dev/stdin"
"$HOME/tmp/a"*
"$HOME/tmp/a 3"
"/bin/adb"
)
test_all=( "Test everything starting from /"
/**/*
)
test_args=( "Tests from command line"
"$@"
)
totest=(
test_links
)
[[ "$@" ]] && totest=(test_args)
rl::test() {
local i=0
local ra=
local rb=
local path=
local testarray=
local testend=0
for testarray in "${totest[@]}"; do
i=0
testarray="$testarray"[@]
for path in "${!testarray}"; do
if (( ! i )); then
# Print title in array element 0
printf " ### %s ###\n" "$path"
else
# Execute tests
printf -- "%-3d --- %-30s ---" $i "$path"
ra="$(${tool_a} "$path")"
rb="$(${tool_b} "$path")"
if [[ "$ra" = "$rb" ]]; then
# Test successful
printf " OK\n"
else
# Test failed
printf " FAIL\n"
printf "\n Result:\n%s\n%s\n" "$ra" "$rb"
printf "\n Subject:\n"
ls -al "$path"
# Print debug output of tool_a
printf "\n Debug:\n"
( "${tool_a}" -d "${path}" )
testend=1 && break
fi
fi
((i++))
done
(( testend )) && break
done
}
time rl::test