diff --git a/cqfd b/cqfd index 809c57e..6f9668d 100755 --- a/cqfd +++ b/cqfd @@ -79,22 +79,23 @@ parse_ini_config_file() { die "Can't find $1 - create it or pick one using 'cqfd -f'" fi - ini="$(<"$1")" # read the file - ini="${ini//[/\\[}" # escape [ - ini="${ini//]/\\]}" # escape ] - IFS=$'\n' && ini=( ${ini} ) # convert to line-array - ini=( ${ini[*]//;*/} ) # remove comments with ; - ini=( ${ini[*]/\ =/=} ) # remove tabs before = - ini=( ${ini[*]/=\ /=} ) # remove tabs be = - ini=( ${ini[*]/\ =\ /=} ) # remove anything with a space around = - ini=( ${ini[*]/#\\[/\}$'\n'cfg.section.} ) # set section prefix - ini=( ${ini[*]/%\\]/ \(} ) # convert text2function (1) - ini=( ${ini[*]/%\(/ \( \)} ) # close array parenthesis - ini=( ${ini[*]/%\\ \)/ \\} ) # the multiline trick - ini=( ${ini[*]/%\( \)/\(\) \{} ) # convert text2function (2) - ini=( ${ini[*]/%\} \)/\}} ) # remove extra parenthesis - ini[0]="" # remove first element - ini[${#ini[*]} + 1]='}' # add the last brace + ini="$(<"$1")" # read the file + ini="${ini//[/\\[}" # escape [ + ini="${ini//]/\\]}" # escape ] + IFS=$'\n' && ini=( ${ini} ) # convert to line-array + ini=( ${ini[*]//;*/} ) # remove comments with ; + ini=( ${ini[*]/$'\t'=/=} ) # remove tabs before = + ini=( ${ini[*]/=$'\t'/=} ) # remove tabs after = + ini=( ${ini[*]/\ =/=} ) # remove space before = + ini=( ${ini[*]/=\ /=} ) # remove space after = + ini=( ${ini[*]/#\\[/\}$'\n'cfg.section.} ) # set section prefix + ini=( ${ini[*]/%\\]/ \(} ) # convert text2function (1) + ini=( ${ini[*]/%\(/ \( \)} ) # close array parenthesis + ini=( ${ini[*]/%\\ \)/ \\} ) # the multiline trick + ini=( ${ini[*]/%\( \)/\(\) \{} ) # convert text2function (2) + ini=( ${ini[*]/%\} \)/\}} ) # remove extra parenthesis + ini[0]="" # remove first element + ini[${#ini[*]} + 1]='}' # add the last brace if ! eval "$(echo "${ini[*]}")" 2>/dev/null; then # eval the result die "$1: Invalid ini-file!" fi diff --git a/tests/03-cqfdrc_error b/tests/03-cqfdrc_error new file mode 100755 index 0000000..eff238f --- /dev/null +++ b/tests/03-cqfdrc_error @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# validate the .cqfdrc syntax + +. "$(dirname "$0")"/jtest.inc "$1" +cqfd="$TDIR/.cqfd/cqfd" + +cd $TDIR/ + +cqfdrc_old=$(mktemp) +cp -f .cqfdrc "$cqfdrc_old" +echo "foo =bar" >>.cqfdrc + +jtest_prepare "cqfdrc with tabulation before should pass" +if $cqfd run true; then + jtest_result pass +else + jtest_result fail +fi + +cp -f "$cqfdrc_old" .cqfdrc +echo "foo= bar" >>.cqfdrc + +jtest_prepare "cqfdrc with tabulation after should pass" +if $cqfd run true; then + jtest_result pass +else + jtest_result fail +fi + +cp -f "$cqfdrc_old" .cqfdrc +echo "foo =bar" >>.cqfdrc + +jtest_prepare "cqfdrc with space before should pass" +if $cqfd run true; then + jtest_result pass +else + jtest_result fail +fi + +cp -f "$cqfdrc_old" .cqfdrc +echo "foo= bar" >>.cqfdrc + +jtest_prepare "cqfdrc with space after should pass" +if $cqfd run true; then + jtest_result pass +else + jtest_result fail +fi + +mv -f "$cqfdrc_old" .cqfdrc