diff options
author | erdgeist <> | 2013-09-21 18:20:09 +0000 |
---|---|---|
committer | erdgeist <> | 2013-09-21 18:20:09 +0000 |
commit | 0146e7d9731fb365c3277928f98410ad4d2434ab (patch) | |
tree | 687931b6fcf9837911a2ecaaeeecd72ad71a7721 | |
parent | c07bdabbc3a7db48fe7ca63c10377368e1aca617 (diff) |
Add test routines for the config file parser
-rw-r--r-- | test/configs/bar | 8 | ||||
-rw-r--r-- | test/configs/foo | 15 | ||||
-rwxr-xr-x | test/conftest | 37 |
3 files changed, 60 insertions, 0 deletions
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 @@ | |||
1 | # hier nochmal | ||
2 | |||
3 | [ordentlich] | ||
4 | geht es weiter | ||
5 | |||
6 | |||
7 | [bl*] | ||
8 | 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 @@ | |||
1 | # Hallohallo | ||
2 | |||
3 | [foo] | ||
4 | x y | ||
5 | a.v z | ||
6 | |||
7 | [bar] | ||
8 | env.blub blab | ||
9 | user | ||
10 | |||
11 | [blub*] | ||
12 | undso | ||
13 | env.das muss ${so} | ||
14 | env.so bleiben | ||
15 | |||
diff --git a/test/conftest b/test/conftest new file mode 100755 index 0000000..e202e87 --- /dev/null +++ b/test/conftest | |||
@@ -0,0 +1,37 @@ | |||
1 | #!/bin/sh | ||
2 | |||
3 | CONFIG_DIR=./configs | ||
4 | CONFIGS=`/usr/bin/find ${CONFIG_DIR} -type f -exec /usr/bin/grep -v -e ^\# -e ^$ {} \; -exec /bin/echo [] \; 2> /dev/null` | ||
5 | |||
6 | parse_lines() { | ||
7 | unset in_sect | ||
8 | while read line; do | ||
9 | case ${line## } in | ||
10 | \[*\]) v="${line#*[}"; v="${v%%]*}" | ||
11 | case $select in | ||
12 | ${v}) echo Starting our section "${select}" >&2 | ||
13 | in_sect=true | ||
14 | ;; | ||
15 | *) [ "${in_sect}" ] && echo Ending our section "${select}" >&2 | ||
16 | echo Start other section "${v}" >&2 | ||
17 | unset in_sect | ||
18 | ;; | ||
19 | esac | ||
20 | ;; | ||
21 | env.*) echo "### ${line} ### ${in_sect} ###" >&2 | ||
22 | [ "${in_sect}" ] || continue | ||
23 | echo Setting environment: ${line#*env.} >&2 | ||
24 | _pref=${line#*env.}; _suf=${_pref#* } | ||
25 | printf "%s " ${_pref%% *}=\'${_suf}\' | ||
26 | ;; | ||
27 | *) echo Ignoring ${line} >&2 | ||
28 | ;; | ||
29 | esac | ||
30 | done | ||
31 | } | ||
32 | |||
33 | select=blubber | ||
34 | _env=$( printf "%s\n" "${CONFIGS}" | parse_lines ) | ||
35 | |||
36 | printf "%s\n" "${_env}" | ||
37 | eval env ${_env} printenv | ||