From 0146e7d9731fb365c3277928f98410ad4d2434ab Mon Sep 17 00:00:00 2001 From: erdgeist <> Date: Sat, 21 Sep 2013 18:20:09 +0000 Subject: Add test routines for the config file parser --- test/configs/bar | 8 ++++++++ test/configs/foo | 15 +++++++++++++++ test/conftest | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 60 insertions(+) create mode 100644 test/configs/bar create mode 100644 test/configs/foo create mode 100755 test/conftest diff --git a/test/configs/bar b/test/configs/bar new file mode 100644 index 0000000..b2b901f --- /dev/null +++ b/test/configs/bar @@ -0,0 +1,8 @@ +# hier nochmal + +[ordentlich] + geht es weiter + + +[bl*] + env.gack komm diff --git a/test/configs/foo b/test/configs/foo new file mode 100644 index 0000000..56c1ff0 --- /dev/null +++ b/test/configs/foo @@ -0,0 +1,15 @@ +# Hallohallo + +[foo] + x y + a.v z + +[bar] + env.blub blab + user + +[blub*] + undso + env.das muss ${so} + env.so bleiben + diff --git a/test/conftest b/test/conftest new file mode 100755 index 0000000..e202e87 --- /dev/null +++ b/test/conftest @@ -0,0 +1,37 @@ +#!/bin/sh + +CONFIG_DIR=./configs +CONFIGS=`/usr/bin/find ${CONFIG_DIR} -type f -exec /usr/bin/grep -v -e ^\# -e ^$ {} \; -exec /bin/echo [] \; 2> /dev/null` + +parse_lines() { + unset in_sect + while read line; do + case ${line## } in + \[*\]) v="${line#*[}"; v="${v%%]*}" + case $select in + ${v}) echo Starting our section "${select}" >&2 + in_sect=true + ;; + *) [ "${in_sect}" ] && echo Ending our section "${select}" >&2 + echo Start other section "${v}" >&2 + unset in_sect + ;; + esac + ;; + env.*) echo "### ${line} ### ${in_sect} ###" >&2 + [ "${in_sect}" ] || continue + echo Setting environment: ${line#*env.} >&2 + _pref=${line#*env.}; _suf=${_pref#* } + printf "%s " ${_pref%% *}=\'${_suf}\' + ;; + *) echo Ignoring ${line} >&2 + ;; + esac + done +} + +select=blubber +_env=$( printf "%s\n" "${CONFIGS}" | parse_lines ) + +printf "%s\n" "${_env}" +eval env ${_env} printenv -- cgit v1.2.3