#!/bin/bash # -*- shell-script -*- proc test_fns_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' "$Status" _Dbg_copies 'a' 3 assertTrue '_Dbg_copies "a" 3 should succeed' "$Status" assertEquals 'aaa' $result _Dbg_copies ' ab' 4 assertTrue '_Dbg_copies " ab" 4 should succeed' "$Status" assertEquals ' ab ab ab ab' $result } proc test_fns_defined { typeset p = '5' _Dbg_defined p assertTrue 'p should be defined' "$Status" unset p _Dbg_defined p assertFalse 'p should now not defined' "$Status" } proc test_fns_esc_dq { proc check_esc_dq { var orig = $1 var 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\"] } proc test_fns_is_function { _Dbg_is_function assertFalse 'No function given; is_function should report false' $Status unset -f function_test _Dbg_is_function function_test assertFalse 'function_test should not be defined' "$Status" typeset -i function_test = '1' _Dbg_is_function function_test assertFalse 'test_function should still not be defined' "$Status" proc function_test { :; } _Dbg_is_function function_test assertTrue 'test_function should now be defined' "$Status" proc another_function_test { :; } _Dbg_is_function another_function_test "$Status" proc _function_test { :; } _Dbg_is_function _function_test assertFalse 'fn _function_test is system fn; is_function should report false' $Status _Dbg_is_function _function_test 1 assertTrue 'fn _function_test is system fn which we want; should report true' $Status } proc test_fns_traced { set +x _Dbg_is_traced assertFalse 'is_traced should be false' "$Status" do { set -x _Dbg_is_traced setglobal rc = $Status set +x } 2>/dev/null assertTrue 'is_traced should be true' $rc } proc test_fns_onoff { assertEquals 'on.' $[_Dbg_onoff 1] assertEquals 'off.' $[_Dbg_onoff 0] } proc test_fns_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 int_pat = '"[0-9]*([0-9])'" typeset -i _Dbg_set_debug = '1' proc 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_fns_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_set_debug = '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[@]) } proc 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 proc test_fns_set_q { _Dbg_set_dol_q 1 assertFalse '$? should have been set to 1==false' $Status _Dbg_set_dol_q 0 assertTrue '$? should have been set to 0==true' $Status # Test without giving a parameter var _Ddg_debugged_exit_code = '0' _Dbg_set_dol_q assertTrue '$? should be set true via _Dbg_debugged_exit_code' $Status set _Ddg_debugged_exit_code = '1' # _Dbg_set_dol_q # assertFalse '$? should be set false via _Dbg_debugged_exit_code' $? } proc test_fns_split { typeset -a words = '' setglobal words = '('$(_Dbg_split ':' 'foo:bar')) assertEquals 'foo' $(words[0]) assertEquals 'bar' $(words[1]) setglobal words = '('$(_Dbg_split ':' 'foo')) assertEquals 'foo' $(words[0]) } 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}init/pre.sh source ${abs_top_srcdir}lib/fns.sh source ${abs_top_srcdir}lib/journal.sh source ${abs_top_srcdir}lib/save-restore.sh source ${abs_top_srcdir}lib/validate.sh set -- # reset $# so shunit2 doesn't get confused. [[ $0 == ${BASH_SOURCE} ]] && source ${shunit_file}