"Fossies" - the Fresh Open Source Software Archive

Member "bashdb-5.0-1.1.0/test/unit/test-fns.sh" (5 Sep 2019, 4601 Bytes) of package /linux/privat/bashdb-5.0-1.1.0.tar.bz2:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "test-fns.sh": 4.4-1.0.1_vs_5.0-1.1.0.

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