#!/bin/bash # -*- shell-script -*- proc test_validate_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 } # Test _Dbg_is_int proc test_validate_is_integer { _Dbg_is_int assertFalse 'No integer given; is_int should report false' $Status for arg in [a a1 '-+-]' { _Dbg_is_int $arg assertFalse "$arg is not an integer; is_int should report false" $Status } for arg in [0 123 9999999] { _Dbg_is_int $arg assertTrue "$arg is an integer; is_int should report true" $Status _Dbg_is_signed_int $arg assertTrue "$arg is a signed integer; is_int should report true" $Status } for arg in [+0 -123] { _Dbg_is_signed_int $arg assertTrue "$arg is not a signed integer; is_int should report true" $Status _Dbg_is_int $arg assertFalse "$arg is not an integer; is_int should report true" $Status } } # Make sure /src/external-vcs/sourceforge/bashdb has a trailing slash if test '/src/external-vcs/sourceforge/bashdb' = '' { echo "Something is wrong: abs_top_srcdir is not set." exit 1 } global abs_top_srcdir := '/src/external-vcs/sourceforge/bashdb' # Make sure $abs_top_srcr has a trailing slash global abs_top_srcdir := "$(abs_top_srcdir%%/)/" source ${abs_top_srcdir}test/unit/helper.sh source ${abs_top_srcdir}init/vars.sh source ${abs_top_srcdir}init/pre.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} (CommandList children: [ (FuncDef name: test_validate_is_function body: (BraceGroup children: [ (C {(_Dbg_is_function)}) (C {(assertFalse)} {(SQ <"No function given; is_function should report false">)} {($ VSub_QMark "$?")} ) (C {(unset)} {(-f)} {(function_test)}) (C {(_Dbg_is_function)} {(function_test)}) (C {(assertFalse)} {(SQ <"function_test should not be defined">)} {(DQ ($ VSub_QMark "$?"))}) (C {(typeset)} {(-i)} {(Lit_VarLike "function_test=") (1)}) (C {(_Dbg_is_function)} {(function_test)}) (C {(assertFalse)} {(SQ <"test_function should still not be defined">)} {(DQ ($ VSub_QMark "$?"))} ) (FuncDef name: function_test body: (BraceGroup children: [(Sentence child:(C {(Lit_Other ":")}) terminator:)] spids: [81] ) spids: [77 80] ) (C {(_Dbg_is_function)} {(function_test)}) (C {(assertTrue)} {(SQ <"test_function should now be defined">)} {(DQ ($ VSub_QMark "$?"))}) (FuncDef name: another_function_test body: (BraceGroup children: [(Sentence child:(C {(Lit_Other ":")}) terminator:)] spids: [110] ) spids: [106 109] ) (C {(_Dbg_is_function)} {(another_function_test)} {(DQ ($ VSub_QMark "$?"))}) (FuncDef name: _function_test body: (BraceGroup children: [(Sentence child:(C {(Lit_Other ":")}) terminator:)] spids: [132] ) spids: [128 131] ) (C {(_Dbg_is_function)} {(_function_test)}) (C {(assertFalse)} {(SQ <"fn _function_test is system fn; is_function should report false">)} {($ VSub_QMark "$?")} ) (C {(_Dbg_is_function)} {(_function_test)} {(1)}) (C {(assertTrue)} {(SQ <"fn _function_test is system fn which we want; should report true">)} {($ VSub_QMark "$?")} ) ] spids: [10] ) spids: [6 9] ) (FuncDef name: test_validate_is_integer body: (BraceGroup children: [ (C {(_Dbg_is_int)}) (C {(assertFalse)} {(SQ <"No integer given; is_int should report false">)} {($ VSub_QMark "$?")} ) (ForEach iter_name: arg iter_words: [{(a)} {(a1)} {(SQ <"-+-">)}] do_arg_iter: False body: (DoGroup children: [ (C {(_Dbg_is_int)} {($ VSub_Name "$arg")}) (C {(assertFalse)} {(DQ ($ VSub_Name "$arg") (" is not an integer; is_int should report false"))} {($ VSub_QMark "$?")} ) ] spids: [217 236] ) spids: [206 215] ) (ForEach iter_name: arg iter_words: [{(0)} {(123)} {(9999999)}] do_arg_iter: False body: (DoGroup children: [ (C {(_Dbg_is_int)} {($ VSub_Name "$arg")}) (C {(assertTrue)} {(DQ ($ VSub_Name "$arg") (" is an integer; is_int should report true"))} {($ VSub_QMark "$?")} ) (C {(_Dbg_is_signed_int)} {($ VSub_Name "$arg")}) (C {(assertTrue)} {(DQ ($ VSub_Name "$arg") (" is a signed integer; is_int should report true"))} {($ VSub_QMark "$?")} ) ] spids: [254 289] ) spids: [245 252] ) (ForEach iter_name: arg iter_words: [{(Lit_Other "+") (0)} {(-123)}] do_arg_iter: False body: (DoGroup children: [ (C {(_Dbg_is_signed_int)} {($ VSub_Name "$arg")}) (C {(assertTrue)} { (DQ ($ VSub_Name "$arg") (" is not a signed integer; is_int should report true") ) } {($ VSub_QMark "$?")} ) (C {(_Dbg_is_int)} {($ VSub_Name "$arg")}) (C {(assertFalse)} {(DQ ($ VSub_Name "$arg") (" is not an integer; is_int should report true"))} {($ VSub_QMark "$?")} ) ] spids: [306 341] ) spids: [298 304] ) ] spids: [184] ) spids: [180 183] ) (If arms: [ (if_arm cond: [ (Sentence child: (C {(Lit_Other "[")} {(SQ )} {(Lit_Other "=")} {(SQ )} {(Lit_Other "]")} ) terminator: ) ] action: [ (C {(echo)} {(DQ ("Something is wrong: abs_top_srcdir is not set."))}) (C {(exit)} {(1)}) ] spids: [-1 367] ) ] spids: [-1 381] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:abs_top_srcdir) op: Equal rhs: {(/src/external-vcs/sourceforge/bashdb)} spids: [383] ) ] spids: [383] ) (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:abs_top_srcdir) op: Equal rhs: { (BracedVarSub token: suffix_op: (StringUnary op_id:VOp1_DPercent arg_word:{(Lit_Slash /)}) spids: [390 394] ) (/) } spids: [389] ) ] spids: [389] ) (C {(.)} {(${ VSub_Name abs_top_srcdir) (test/unit/helper.sh)}) (C {(.)} {(${ VSub_Name abs_top_srcdir) (init/vars.sh)}) (C {(.)} {(${ VSub_Name abs_top_srcdir) (init/pre.sh)}) (C {(.)} {(${ VSub_Name abs_top_srcdir) (lib/journal.sh)}) (C {(.)} {(${ VSub_Name abs_top_srcdir) (lib/save-restore.sh)}) (C {(.)} {(${ VSub_Name abs_top_srcdir) (lib/validate.sh)}) (C {(set)} {(--)}) (AndOr children: [ (DBracket expr: (BoolBinary op_id: BoolBinary_GlobDEqual left: {($ VSub_Number "$0")} right: {(${ VSub_Name BASH_SOURCE)} ) ) (C {(.)} {(${ VSub_Name shunit_file)}) ] op_id: Op_DAmp ) ] )