slitaz-base-files rev 278
libtaz.sh: fix more importing cases; add test for importing using libtaz.sh
author | Aleksej Bobylev <al.bobylev@gmail.com> |
---|---|
date | Sat Jun 20 22:49:35 2015 +0300 (2015-06-20) |
parents | c3e5c8e74be3 |
children | 3a790a182103 |
files | rootfs/lib/libtaz.sh test-libtaz.sh |
line diff
1.1 --- a/rootfs/lib/libtaz.sh Thu Jun 18 21:52:33 2015 +0300 1.2 +++ b/rootfs/lib/libtaz.sh Sat Jun 20 22:49:35 2015 +0300 1.3 @@ -28,18 +28,12 @@ 1.4 1.5 # Parse cmdline options and store values in a variable. 1.6 for opt in "$@"; do 1.7 + opt_name="${opt%%=*}"; opt_name="$(echo -n "${opt_name#--}" | tr -c 'a-zA-Z0-9' '_')" 1.8 case "$opt" in 1.9 - --*=*) 1.10 - opt_name="${opt%%=*}"; opt_name="$(echo -n "${opt_name#--}" | tr -c 'a-zA-Z0-9' '_')" 1.11 - case "$opt_name" in 1.12 - [0-9]*) opt_name="_$opt_name";; 1.13 - esac 1.14 - opt_value="${opt#--}="; opt_value="${opt_value#*=}"; opt_value="${opt_value%=}" 1.15 - export "$opt_name=$opt_value" 1.16 - ;; 1.17 - --*) 1.18 - export "${opt#--}=yes" 1.19 - ;; 1.20 + --[0-9]*=*) export _$opt_name="${opt#*=}" ;; 1.21 + --[0-9]*) export _$opt_name=yes ;; 1.22 + --*=*) export $opt_name="${opt#*=}" ;; 1.23 + --*) export $opt_name=yes ;; 1.24 esac 1.25 done 1.26 [ "$HTTP_REFERER" ] && output='html' 1.27 @@ -222,7 +216,7 @@ 1.28 action() { 1.29 case $output in 1.30 raw|gtk|html) _n "$@";; 1.31 - *) echo -ne "\033[0;33m"$(_ "$@")"\033[0m";; 1.32 + *) echo -ne "\033[0;33m$(_ "$@")\033[0m";; 1.33 esac 1.34 } 1.35
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test-libtaz.sh Sat Jun 20 22:49:35 2015 +0300 2.3 @@ -0,0 +1,38 @@ 2.4 +#!/bin/sh 2.5 +# 2.6 +. rootfs/lib/libtaz.sh 2.7 + 2.8 +[ $# -eq 0 ] && title 'Check variables import using libtaz.sh' 2.9 + 2.10 +if [ "$1" == 'test' ]; then env; exit 0; fi 2.11 + 2.12 +ME=$(realpath $0); n=/tmp/n; echo 1 > $n; tests=18 2.13 + 2.14 +t() { 2.15 + i=$(cat $n) 2.16 + printf "%2d/%d: %-16s: test %s" "$i" "$tests" "$1" "$2 $3" >&2 2.17 + $ME test "$2" "$3" 2.18 + echo $((i + 1)) > $n 2.19 +} 2.20 + 2.21 +t 'without dashes' install | grep -qv '^install='; status 2.22 +t 'single dash' -install | grep -qv '^install='; status 2.23 +t 'with dashes' --install | grep -q '^install=yes$'; status 2.24 +t 'empty 1' --install= | grep -q '^install=$'; status 2.25 +t 'non-empty' --install=value | grep -q '^install=value$'; status 2.26 +t 'single quotes' --install='value' | grep -q '^install=value$'; status 2.27 +t 'double quotes' --install="value" | grep -q '^install=value$'; status 2.28 +t 'double "=" 1' --install=all=true | grep -q '^install=all=true$'; status 2.29 +t 'double "=" 2' --install==double | grep -q '^install==double$'; status 2.30 +t 'spaces 1' --install="a bb ccc" | grep -q '^install=a bb ccc$'; status 2.31 +t 'spaces 2' --install=a\ bb\ \ ccc | grep -q '^install=a bb ccc$'; status 2.32 +t 'start with digit' --7zip | grep -q '^_7zip=yes$'; status 2.33 +t 'extra dashes 1' ----install | grep -q '^__install=yes$'; status 2.34 +t 'extra dashes 2' --ins--tall | grep -q '^ins__tall=yes$'; status 2.35 +t 'extra dashes 3' --ins-tall | grep -q '^ins_tall=yes$'; status 2.36 +t 'extra dashes 4' --ins-tall=ins-tall | grep -q '^ins_tall=ins-tall$'; status 2.37 +t 'repeated' --abc=1 --abc=2 | grep -q '^abc=2$'; status 2.38 +t 'dollar sign' --a\$bc=a\$bc | grep -q '^a_bc=a\$bc$'; status 2.39 + 2.40 +footer 'Tests completed' 2.41 +rm $n