1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
|
#!/bin/bash
# -*- shell-script -*-
test_copies()
{
typeset result='bogus'
# _Dbg_copies 'a' 'b'
# assertFalse '_Dbg_copies "a" "b" should fail' "$?"
_Dbg_copies 'a' -1
assertFalse '_Dbg_copies "a" -1 should fail' "$?"
_Dbg_copies 'a' 3
assertTrue '_Dbg_copies "a" 3 should succeed' "$?"
assertEquals 'aaa' $result
_Dbg_copies ' ab' 4
assertTrue '_Dbg_copies " ab" 4 should succeed' "$?"
assertEquals ' ab ab ab ab' "$result"
}
test_defined()
{
typeset p=5
_Dbg_defined p
assertTrue 'p should be defined' "$?"
unset p
_Dbg_defined p
assertFalse 'p should now not defined' "$?"
}
test_esc_dq()
{
check_esc_dq () {
local orig="$1"
local transform="$(_Dbg_esc_dq "$orig")"
eval 'got=$(echo "$1")'
assertEquals "$orig" "$got"
}
check_esc_dq 'Now is the time'
check_esc_dq '"Now is the time"'
check_esc_dq 'Make $$'
assertEquals 'abc' $(_Dbg_esc_dq abc)
assertEquals '\\\"abc\\\"' $(_Dbg_esc_dq '\"abc\"')
assertEquals '\\\"a\\bc\\\"' $(_Dbg_esc_dq '\"a\bc\"')
}
test_is_function()
{
_Dbg_is_function
assertFalse 'No function given; is_function should report false' $?
unset -f function_test
_Dbg_is_function function_test
assertFalse 'function_test should not be defined' "$?"
typeset -i function_test=1
_Dbg_is_function function_test
assertFalse 'test_function should still not be defined' "$?"
function_test() { :; }
_Dbg_is_function function_test
assertTrue 'test_function should now be defined' "$?"
function another_function_test { :; }
_Dbg_is_function another_function_test "$?"
_function_test() { :; }
_Dbg_is_function _function_test
assertFalse 'fn _function_test is system fn; is_function should report false' $?
_Dbg_is_function _function_test 1
assertTrue 'fn _function_test is system fn which we want; should report true' $?
}
test_traced()
{
set +x
_Dbg_is_traced
assertFalse 'is_traced should be false' "$?"
{
set -x
_Dbg_is_traced
rc=$?
set +x
} 2>/dev/null
assertTrue 'is_traced should be true' "$rc"
}
test_onoff()
{
assertEquals 'on.' $(_Dbg_onoff 1)
assertEquals 'off.' $(_Dbg_onoff 0)
}
test_parse_linespec()
{
# Necessary set up for function call.
typeset _seteglob='local __eopt=-u ; shopt -q extglob && __eopt=-s ; shopt -s extglob'
shopt -s extdebug
typeset -r int_pat="[0-9]*([0-9])"
typeset -i _Dbg_debug_debugger=1
function foo { echo 'foo here'; }
typeset -a words=( $(_Dbg_parse_linespec 'foo:4') )
assertEquals 'a' '4' ${words[0]}
assertEquals 'b' '0' ${words[1]}
typeset -a words=( $(_Dbg_parse_linespec 'test_defined') )
assertEquals 'c' '23' ${words[0]}
assertEquals 'd' '1' ${words[1]}
typeset -a words=( $(_Dbg_parse_linespec '_Dbg_parse_linespec') )
assertEquals 'e' '3' ${#words[@]}
typeset _Dbg_debug_debugger=0
typeset -a words=( $(_Dbg_parse_linespec '_Dbg_parse_linespec') )
assertEquals 'e' '0' ${#words[@]}
unset foo
typeset -a words=( $(_Dbg_parse_linespec 'foo') )
assertEquals 'f' '0' ${#words[@]}
}
test_set_debugger_internal()
{
typeset _Dbg_space_IFS=' '
_Dbg_set_debugger_internal
assertEquals "$_Dbg_space_IFS" "$IFS"
assertEquals '+ dbg (${BASH_SOURCE}:${LINENO}[$BASH_SUBSHELL]): ${FUNCNAME[0]}\n' "$PS4"
}
# Test _Dbg_set_dol_q
test_set_q()
{
_Dbg_set_dol_q 1
assertFalse '$? should have been set to 1==false' $?
_Dbg_set_dol_q 0
assertTrue '$? should have been set to 0==true' $?
# Test without giving a parameter
local _Ddg_debugged_exit_code=0
_Dbg_set_dol_q
assertTrue '$? should be set true via _Dbg_debugged_exit_code' $?
_Ddg_debugged_exit_code=1
# _Dbg_set_dol_q
# assertFalse '$? should be set false via _Dbg_debugged_exit_code' $?
}
test_split()
{
typeset -a words
words=($(_Dbg_split ':' 'foo:bar'))
assertEquals 'foo' ${words[0]}
assertEquals 'bar' ${words[1]}
words=($(_Dbg_split ':' 'foo'))
assertEquals 'foo' ${words[0]}
}
abs_top_srcdir=/src/external-vcs/bashdb
abs_top_srcdir=${abs_top_srcdir%%/}/
_Dbg_libdir=$abs_top_srcdir
set -- -q # Don't need to show banner
. $abs_top_srcdir/dbg-pre.sh
. $abs_top_srcdir/lib/fns.sh
. $abs_top_srcdir/lib/journal.sh
. $abs_top_srcdir/lib/save-restore.sh
# load shunit2
srcdir=.
srcdir=${srcdir}/
. ${srcdir}/shunit2
|