Use loop for interface functions

This commit is contained in:
Bob Mottram 2016-07-05 11:41:33 +01:00
parent 4123b712fc
commit cf4a38367e

View File

@ -34,19 +34,19 @@ export TEXTDOMAIN=${PROJECT_NAME}-tests
export TEXTDOMAINDIR="/usr/share/locale" export TEXTDOMAINDIR="/usr/share/locale"
function show_help { function show_help {
echo '' echo ''
echo $"${PROJECT_NAME}-tests" echo $"${PROJECT_NAME}-tests"
echo '' echo ''
echo $'Runs tests on the system' echo $'Runs tests on the system'
echo '' echo ''
echo $' --help Show help' echo $' --help Show help'
echo '' echo ''
exit 0 exit 0
} }
function test_app_function_type { function test_app_function_type {
filename=$1 filename=$1
fn_type=$2 fn_type=$2
app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}') app_name=$(echo "${filename}" | awk -F '-app-' '{print $2}')
app_function=$(cat "${filename}" | grep "function ${fn_type}_${app_name} {" | awk -F "${fn_type}_" '{print $2}' | awk -F ' ' '{print $1}') app_function=$(cat "${filename}" | grep "function ${fn_type}_${app_name} {" | awk -F "${fn_type}_" '{print $2}' | awk -F ' ' '{print $1}')
if [ ! ${app_function} ]; then if [ ! ${app_function} ]; then
@ -64,27 +64,33 @@ function test_app_functions {
FILES=/usr/bin/${PROJECT_NAME}-app-* FILES=/usr/bin/${PROJECT_NAME}-app-*
fi fi
# check that these functions exist
interface_functions=( install remove backup )
# for all the app scripts
for filename in $FILES for filename in $FILES
do do
test_app_function_type ${filename} install # for each expected interface function
test_app_function_type ${filename} remove for f in "${interface_functions[@]}"
test_app_function_type ${filename} backup do
test_app_function_type ${filename} $f
done
done done
} }
while [[ $# > 1 ]] while [[ $# > 1 ]]
do do
key="$1" key="$1"
case $key in case $key in
-h|--help) -h|--help)
show_help show_help
;; ;;
*) *)
# unknown option # unknown option
;; ;;
esac esac
shift shift
done done
echo $'Running tests' echo $'Running tests'