make getValue return values with hyphens

This commit is contained in:
Jeremy Singletary 2019-11-13 01:16:19 -07:00
parent 2b9ad470e3
commit 5c94830f7b
3 changed files with 26 additions and 1 deletions

2
msctl
View File

@ -606,7 +606,7 @@ getValue() {
# $VALUE may contains flag-like strings not intended for printf
printf -- "$VALUE"
else
printf "$3"
printf -- "$3"
fi
}

View File

@ -14,6 +14,7 @@ terr () {
# funcs like getMSCSValue have local vars based on WORLDS_LOCATION.
WORLDS_LOCATION=/tmp
MSCS_DEFAULTS="/tmp/mscs.defaults"
testworld="mscs-testdata"
# tests will write to this propfile to verify parsing etc.
propfile="$WORLDS_LOCATION/$testworld/mscs.properties"

View File

@ -1,3 +1,6 @@
# start with clean slate
[ -f $MSCS_DEFAULTS ] && rm $MSCS_DEFAULTS
want='$JVM_ARGS'
# verify DEFAULT_SERVER_COMMAND contains $JVM_ARGS string literal before -jar flag
if ! printf "$DEFAULT_SERVER_COMMAND" | grep -qs -- ".*$want.*-jar"; then
@ -49,6 +52,27 @@ if [ "$got" != "$want" ]; then
terr wrong value from getMSCSValue got \"$got\" want \"$want\"
fi
want="-Dlog4j.configurationFile=/opt/mscs/log4j2.xml"
# write the config under test
cat > $MSCS_DEFAULTS <<EOF
mscs-default-jvm-args=$want
EOF
got=$(getDefaultsValue "mscs-default-jvm-args" '')
# verify getDefaultsValue returns correct value for mscs-default-jvm-args when set
if [ "$got" != "$want" ]; then
terr "wrong value from getDefaultsValue for mscs-default-jvm-args got $got want $want"
fi
want="-Dlog4j.configurationFile=/opt/mscs/log4j2.xml"
cat > $MSCS_DEFAULTS <<EOF
mscs-default-jvm-args=
EOF
# when getValue returns a default value with a hyphen (like a flag)
got=$(getValue $MSCS_DEFAULTS mscs-default-jvm-args "$want")
if [ "$got" != "$want" ]; then
terr "wrong value from getValue for mscs-default-jvm-args got $got want $want"
fi
# verify mscs_defaults output contains correct value for mscs-default-jvm-args
got=`mscs_defaults | grep -- '^\# mscs-default-jvm-args=$'`
if [ $? -ne 0 ]; then