#!/bin/bash # -*- shell-script -*- proc test_eval_subst { # Set up necessary vars typeset extracted typeset -a texts setglobal texts = ''( 'if (( x == 1 )); then' 'if (( y == 2 )) ; then' 'if (( y == 3 )) ;' 'if (( y == 4 ))' 'if (( z == 5 )) ' 'return something' 'elif [[ $x = test1 ]] && [ $? -eq 0 ] ; then' 'while [[ $x = test2 ]] && [ $? -eq 0 ] ; do' 'while [[ $x = test3 ]] && [ $? -eq 0 ]' ) setglobal expected = ''( '(( x == 1 ))' '(( y == 2 )) ' '(( y == 3 )) ' '(( y == 4 ))' '(( z == 5 )) ' 'echo something' '[[ $x = test1 ]] && [ $? -eq 0 ] ' '[[ $x = test2 ]] && [ $? -eq 0 ] ' '[[ $x = test3 ]] && [ $? -eq 0 ]' ) typeset -i i for (( i=0 ; i<${#expected[@]}; i++ )) ; do _Dbg_eval_extract_condition "${texts[i]}" assertEquals "${expected[i]}" "$extracted" done setglobal assign = ''foo=bar'' setglobal pat = ''^[ \t]*[A-Za-z_][A-Za-z_0-9[]*[]-+]?=(.*$)'' if [[ $assign =~ $pat ]] { setglobal texts = ''( 'x=10' 'array[1]=20' '__fn__+=30' 'PROFILES="/etc/apparmor.d"' ) setglobal expected = ''( 'echo 10' 'echo 20' 'echo 30' 'echo "/etc/apparmor.d"' ) for (( i=0 ; i<${#expected[@]}; i++ )) ; do _Dbg_eval_extract_condition "${texts[i]}" assertEquals "${expected[i]}" "$extracted" done } } setglobal abs_top_srcdir = '/src/external-vcs/sourceforge/bashdb' # Make sure $abs_top_srcrdir has a trailing slash setglobal abs_top_srcdir = "$(abs_top_srcdir%%/)/" source ${abs_top_srcdir}test/unit/helper.sh source $abs_top_srcdir/lib/fns.sh set -- # reset $# so shunit2 doesn't get confused. [[ $0 == ${BASH_SOURCE} ]] && source ${shunit_file}