Fix return of test_ini_config & test_meta_config

Convert test_ini_config to use the "passed / failed" functions in
unittest.sh.  test_meta_config wraps everything into a function; it's
not work unrolling this so just make sure it exits with non-zero if a
test fails.

Change-Id: I9e9883fdad42358255383eede9121b1d361799c8
This commit is contained in:
Ian Wienand 2015-04-17 13:02:49 +10:00
parent f56348bcb2
commit fcdca05de5
2 changed files with 53 additions and 47 deletions

View File

@ -7,6 +7,9 @@ TOP=$(cd $(dirname "$0")/.. && pwd)
# Import config functions # Import config functions
source $TOP/inc/ini-config source $TOP/inc/ini-config
source $TOP/tests/unittest.sh
set -e
echo "Testing INI functions" echo "Testing INI functions"
@ -70,86 +73,86 @@ echo -n "iniset: test missing attribute argument: "
iniset test.ini aaa iniset test.ini aaa
NO_ATTRIBUTE=$(cat test.ini) NO_ATTRIBUTE=$(cat test.ini)
if [[ "$BEFORE" == "$NO_ATTRIBUTE" ]]; then if [[ "$BEFORE" == "$NO_ATTRIBUTE" ]]; then
echo "OK" passed
else else
echo "failed" failed "failed"
fi fi
echo -n "iniset: test missing section argument: " echo -n "iniset: test missing section argument: "
iniset test.ini iniset test.ini
NO_SECTION=$(cat test.ini) NO_SECTION=$(cat test.ini)
if [[ "$BEFORE" == "$NO_SECTION" ]]; then if [[ "$BEFORE" == "$NO_SECTION" ]]; then
echo "OK" passed
else else
echo "failed" failed "failed"
fi fi
# Test with spaces # Test with spaces
VAL=$(iniget test.ini aaa handlers) VAL=$(iniget test.ini aaa handlers)
if [[ "$VAL" == "aa, bb" ]]; then if [[ "$VAL" == "aa, bb" ]]; then
echo "OK: $VAL" passed "OK: $VAL"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
iniset test.ini aaa handlers "11, 22" iniset test.ini aaa handlers "11, 22"
VAL=$(iniget test.ini aaa handlers) VAL=$(iniget test.ini aaa handlers)
if [[ "$VAL" == "11, 22" ]]; then if [[ "$VAL" == "11, 22" ]]; then
echo "OK: $VAL" passed "OK: $VAL"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
# Test with spaces in section header # Test with spaces in section header
VAL=$(iniget test.ini " ccc " spaces) VAL=$(iniget test.ini " ccc " spaces)
if [[ "$VAL" == "yes" ]]; then if [[ "$VAL" == "yes" ]]; then
echo "OK: $VAL" passed "OK: $VAL"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
iniset test.ini "b b" opt_ion 42 iniset test.ini "b b" opt_ion 42
VAL=$(iniget test.ini "b b" opt_ion) VAL=$(iniget test.ini "b b" opt_ion)
if [[ "$VAL" == "42" ]]; then if [[ "$VAL" == "42" ]]; then
echo "OK: $VAL" passed "OK: $VAL"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
# Test without spaces, end of file # Test without spaces, end of file
VAL=$(iniget test.ini bbb handlers) VAL=$(iniget test.ini bbb handlers)
if [[ "$VAL" == "ee,ff" ]]; then if [[ "$VAL" == "ee,ff" ]]; then
echo "OK: $VAL" passed "OK: $VAL"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
iniset test.ini bbb handlers "33,44" iniset test.ini bbb handlers "33,44"
VAL=$(iniget test.ini bbb handlers) VAL=$(iniget test.ini bbb handlers)
if [[ "$VAL" == "33,44" ]]; then if [[ "$VAL" == "33,44" ]]; then
echo "OK: $VAL" passed "OK: $VAL"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
# test empty option # test empty option
if ini_has_option test.ini ddd empty; then if ini_has_option test.ini ddd empty; then
echo "OK: ddd.empty present" passed "OK: ddd.empty present"
else else
echo "ini_has_option failed: ddd.empty not found" failed "ini_has_option failed: ddd.empty not found"
fi fi
# test non-empty option # test non-empty option
if ini_has_option test.ini bbb handlers; then if ini_has_option test.ini bbb handlers; then
echo "OK: bbb.handlers present" passed "OK: bbb.handlers present"
else else
echo "ini_has_option failed: bbb.handlers not found" failed "ini_has_option failed: bbb.handlers not found"
fi fi
# test changing empty option # test changing empty option
@ -157,9 +160,9 @@ iniset test.ini ddd empty "42"
VAL=$(iniget test.ini ddd empty) VAL=$(iniget test.ini ddd empty)
if [[ "$VAL" == "42" ]]; then if [[ "$VAL" == "42" ]]; then
echo "OK: $VAL" passed "OK: $VAL"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
# test pipe in option # test pipe in option
@ -167,9 +170,9 @@ iniset test.ini aaa handlers "a|b"
VAL=$(iniget test.ini aaa handlers) VAL=$(iniget test.ini aaa handlers)
if [[ "$VAL" == "a|b" ]]; then if [[ "$VAL" == "a|b" ]]; then
echo "OK: $VAL" passed "OK: $VAL"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
# test space in option # test space in option
@ -177,51 +180,51 @@ iniset test.ini aaa handlers "a b"
VAL="$(iniget test.ini aaa handlers)" VAL="$(iniget test.ini aaa handlers)"
if [[ "$VAL" == "a b" ]]; then if [[ "$VAL" == "a b" ]]; then
echo "OK: $VAL" passed "OK: $VAL"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
# Test section not exist # Test section not exist
VAL=$(iniget test.ini zzz handlers) VAL=$(iniget test.ini zzz handlers)
if [[ -z "$VAL" ]]; then if [[ -z "$VAL" ]]; then
echo "OK: zzz not present" passed "OK: zzz not present"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
iniset test.ini zzz handlers "999" iniset test.ini zzz handlers "999"
VAL=$(iniget test.ini zzz handlers) VAL=$(iniget test.ini zzz handlers)
if [[ -n "$VAL" ]]; then if [[ -n "$VAL" ]]; then
echo "OK: zzz not present" passed "OK: zzz not present"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
# Test option not exist # Test option not exist
VAL=$(iniget test.ini aaa debug) VAL=$(iniget test.ini aaa debug)
if [[ -z "$VAL" ]]; then if [[ -z "$VAL" ]]; then
echo "OK aaa.debug not present" passed "OK aaa.debug not present"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
if ! ini_has_option test.ini aaa debug; then if ! ini_has_option test.ini aaa debug; then
echo "OK aaa.debug not present" passed "OK aaa.debug not present"
else else
echo "ini_has_option failed: aaa.debug" failed "ini_has_option failed: aaa.debug"
fi fi
iniset test.ini aaa debug "999" iniset test.ini aaa debug "999"
VAL=$(iniget test.ini aaa debug) VAL=$(iniget test.ini aaa debug)
if [[ -n "$VAL" ]]; then if [[ -n "$VAL" ]]; then
echo "OK aaa.debug present" passed "OK aaa.debug present"
else else
echo "iniget failed: $VAL" failed "iniget failed: $VAL"
fi fi
# Test comments # Test comments
@ -230,9 +233,9 @@ inicomment test.ini aaa handlers
VAL=$(iniget test.ini aaa handlers) VAL=$(iniget test.ini aaa handlers)
if [[ -z "$VAL" ]]; then if [[ -z "$VAL" ]]; then
echo "OK" passed "OK"
else else
echo "inicomment failed: $VAL" failed "inicomment failed: $VAL"
fi fi
# Test multiple line iniset/iniget # Test multiple line iniset/iniget
@ -242,25 +245,25 @@ VAL=$(iniget_multiline test.ini eee multi)
if [[ "$VAL" == "bar1 bar2" ]]; then if [[ "$VAL" == "bar1 bar2" ]]; then
echo "OK: iniset_multiline" echo "OK: iniset_multiline"
else else
echo "iniset_multiline failed: $VAL" failed "iniset_multiline failed: $VAL"
fi fi
# Test iniadd with exiting values # Test iniadd with exiting values
iniadd test.ini eee multi bar3 iniadd test.ini eee multi bar3
VAL=$(iniget_multiline test.ini eee multi) VAL=$(iniget_multiline test.ini eee multi)
if [[ "$VAL" == "bar1 bar2 bar3" ]]; then if [[ "$VAL" == "bar1 bar2 bar3" ]]; then
echo "OK: iniadd" passed "OK: iniadd"
else else
echo "iniadd failed: $VAL" failed "iniadd failed: $VAL"
fi fi
# Test iniadd with non-exiting values # Test iniadd with non-exiting values
iniadd test.ini eee non-multi foobar1 foobar2 iniadd test.ini eee non-multi foobar1 foobar2
VAL=$(iniget_multiline test.ini eee non-multi) VAL=$(iniget_multiline test.ini eee non-multi)
if [[ "$VAL" == "foobar1 foobar2" ]]; then if [[ "$VAL" == "foobar1 foobar2" ]]; then
echo "OK: iniadd with non-exiting value" passed "OK: iniadd with non-exiting value"
else else
echo "iniadd with non-exsting failed: $VAL" failed "iniadd with non-exsting failed: $VAL"
fi fi
# Test inidelete # Test inidelete
@ -276,20 +279,22 @@ for x in $del_cases; do
inidelete test.ini $x a inidelete test.ini $x a
VAL=$(iniget_multiline test.ini $x a) VAL=$(iniget_multiline test.ini $x a)
if [ -z "$VAL" ]; then if [ -z "$VAL" ]; then
echo "OK: inidelete $x" passed "OK: inidelete $x"
else else
echo "inidelete $x failed: $VAL" failed "inidelete $x failed: $VAL"
fi fi
if [ "$x" = "del_separate_options" -o \ if [ "$x" = "del_separate_options" -o \
"$x" = "del_missing_option" -o \ "$x" = "del_missing_option" -o \
"$x" = "del_missing_option_multi" ]; then "$x" = "del_missing_option_multi" ]; then
VAL=$(iniget_multiline test.ini $x b) VAL=$(iniget_multiline test.ini $x b)
if [ "$VAL" = "c" -o "$VAL" = "c d" ]; then if [ "$VAL" = "c" -o "$VAL" = "c d" ]; then
echo "OK: inidelete other_options $x" passed "OK: inidelete other_options $x"
else else
echo "inidelete other_option $x failed: $VAL" failed "inidelete other_option $x failed: $VAL"
fi fi
fi fi
done done
rm test.ini rm test.ini
report_results

View File

@ -17,6 +17,7 @@ function check_result {
echo "OK" echo "OK"
else else
echo -e "failed: $actual != $expected\n" echo -e "failed: $actual != $expected\n"
exit 1
fi fi
} }