Skip to content

Commit

Permalink
Regularize unit tests to make reuse easier between kshdb, zshdb and b…
Browse files Browse the repository at this point in the history
…ashdb.
  • Loading branch information
rocky committed May 16, 2011
1 parent 2d36eb7 commit 5695ecd
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 146 deletions.
1 change: 1 addition & 0 deletions command/trace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function _Dbg_do_trace {
return 3
}
cmd=$(typeset -f -- "$fn") || {
_Dbg_errmsg "trace: Can't get function definition for \"$fn\"."
return 4
}
if [[ $cmd =~ '^function ' ]] ; then
Expand Down
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ fi
AC_SUBST(DIFF)
AC_SUBST(DIFF_OPTS)

CMDLINE_INVOKED='${0##*/} == ${.sh.file##*/}'
AC_SUBST(CMDLINE_INVOKED)

## --with-ksh can be used to tell the kshdb script and the regression
## test which ksh to run. It can be omitted too in which case we'll
## look for a ksh binary.
Expand Down
9 changes: 2 additions & 7 deletions test/unit/test-alias.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,18 @@ test_alias()
assertEquals 'up' $expanded_alias
}

# Make sure @top_builddir@ has a trailing slash
if [ '@abs_top_srcdir@' = '' ] ; then
echo "Something is wrong abs_top_srcdir is not set."
exit 1
fi
abs_top_srcdir=@abs_top_srcdir@
# Make sure @abs_top_srcr@ has a trailing slash
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

. $abs_top_srcdir/lib/alias.sh
. $abs_top_srcdir/lib/help.sh
. $abs_top_srcdir/lib/run.sh
. $abs_top_srcdir/command/alias.sh
set --

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi
[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
11 changes: 2 additions & 9 deletions test/unit/test-break.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ test_breakpoint()
assertEquals 0 $_Dbg_brkpt_count
}

# Make sure @top_builddir@ has a trailing slash
if [ '@abs_top_srcdir@' = '' ] ; then
echo "Something is wrong abs_top_srcdir is not set."
exit 1
fi

abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

Expand All @@ -111,11 +111,4 @@ abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}lib/break.sh
set -- # reset $# so shunit2 doesn't get confused.

srcdir=.
srcdir=${srcdir%%/}/

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi

[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
8 changes: 2 additions & 6 deletions test/unit/test-cmd-complete.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@ if [ '@abs_top_srcdir@' = '' ] ; then
exit 1
fi
abs_top_srcdir=@abs_top_srcdir@
# Make sure @abs_top_srcr@ has a trailing slash
# Make sure @abs_top_srcrdir@ has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

. ${abs_top_srcdir}lib/alias.sh
. ${abs_top_srcdir}lib/help.sh
. ${abs_top_srcdir}lib/msg.sh
Expand All @@ -30,7 +29,4 @@ for _Dbg_file in ${abs_top_srcdir}command/d*.sh ; do
source $_Dbg_file
done

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi
[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
9 changes: 2 additions & 7 deletions test/unit/test-columns.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,14 @@ test_columnized()

}

# Make sure @top_builddir@ has a trailing slash
if [ '@abs_top_srcdir@' = '' ] ; then
echo "Something is wrong abs_top_srcdir is not set."
exit 1
fi
abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

. $abs_top_srcdir/lib/columnize.sh
set --

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi
[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
8 changes: 2 additions & 6 deletions test/unit/test-dbg-opts.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ if [ '@abs_top_srcdir@' = '' ] ; then
exit 1
fi
abs_top_srcdir=@abs_top_srcdir@
# Make sure @top_srcdir@ has a trailing slash
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi
[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
9 changes: 2 additions & 7 deletions test/unit/test-eval.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,10 @@ test_eval_subst()
}

abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_builddir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

srcdir=@srcdir@
srcdir=${srcdir%%/}/
. $abs_top_srcdir/lib/fns.sh
set -- # reset $# so shunit2 doesn't get confused.

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi
[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
8 changes: 2 additions & 6 deletions test/unit/test-examine.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ test_examine()
}

abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

. ${abs_top_srcdir}lib/fns.sh
. ${abs_top_srcdir}lib/msg.sh
. ${abs_top_srcdir}lib/help.sh
Expand All @@ -66,8 +66,4 @@ abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}command/examine.sh
set -- # reset $# so shunit2 doesn't get confused.

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi

[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
15 changes: 5 additions & 10 deletions test/unit/test-file.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ test_file_glob_filename()
typeset filename
filename=''
_Dbg_glob_filename $shunit_file
assertEquals '0' $?
assertEquals "Should be able to glob $shunit_file" '0' $?
filename=${filename##*/}
assertEquals 'shunit2' $filename

_Dbg_glob_filename ./${srcdir}shunit?
assertEquals '0' $?
filename=${filename##*/}
assertEquals 'shunit2' $filename
_Dbg_glob_filename ${srcdir}abcdefg
_Dbg_glob_filename ${abs_top_srcdir}abcdefg
assertEquals '1' $?
filename=${filename##*/}
assertEquals 'abcdefg' $filename
Expand Down Expand Up @@ -51,21 +52,15 @@ test_file_resolve_expand_filename()
}

abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

. $abs_top_srcdir/init/pre.sh
. $abs_top_srcdir/lib/filecache.sh
. $abs_top_srcdir/lib/file.sh
set -- # reset $# so shunit2 doesn't get confused.

SHUNIT_PARENT=$0

srcdir=@srcdir@
srcdir=${srcdir%%/}/

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi

[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
9 changes: 2 additions & 7 deletions test/unit/test-filecache.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,18 @@ test_filecache_check_line()
_Dbg_check_line 10000 $shunit_file
}

# Make sure @top_builddir@ has a trailing slash
if [ '@abs_top_srcdir@' = '' ] ; then
echo "Something is wrong abs_top_srcdir is not set."
exit 1
fi

abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

. ${abs_top_srcdir}init/pre.sh
. ${abs_top_srcdir}lib/filecache.sh
. ${abs_top_srcdir}lib/file.sh
set -- # reset $# so shunit2 doesn't get confused.

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi

[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
7 changes: 1 addition & 6 deletions test/unit/test-fns.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,10 @@ test_fns_split()
abs_top_srcdir=@abs_top_srcdir@
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

. $abs_top_srcdir/init/pre.sh
. $abs_top_srcdir/lib/msg.sh
. $abs_top_srcdir/lib/fns.sh
. $abs_top_srcdir/lib/frame.sh
. $abs_top_srcdir/lib/journal.sh
set -- # reset $# so shunit2 doesn't get confused.

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi
[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
10 changes: 2 additions & 8 deletions test/unit/test-frame.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,15 @@ test_frame_adjust()
done
}

# Make sure @top_builddir@ has a trailing slash
if [ '@abs_top_srcdir@' = '' ] ; then
echo "Something is wrong abs_top_srcdir is not set."
exit 1
fi
abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

. $abs_top_srcdir/lib/frame.sh
set -- # reset $# so shunit2 doesn't get confused.

# load shunit2
srcdir=@srcdir@
srcdir=${srcdir}/
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi
[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
8 changes: 2 additions & 6 deletions test/unit/test-get-sourceline.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
this_script=test-get-sourceline.sh

abs_top_srcdir=@abs_top_srcdir@
# Make sure @abs_top_srcdir@ has a trailing slash
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/

# Test _Dbg_get_source_line
Expand Down Expand Up @@ -44,8 +44,4 @@ fi
. ${abs_top_srcdir}lib/msg.sh
set -- # reset $# so shunit2 doesn't get confused.

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi

[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
11 changes: 2 additions & 9 deletions test/unit/test-journal.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -28,24 +28,17 @@ test_journal()
assertEquals 0 "$?"
}


# Make sure @abs_top_srcdir@ has a trailing slash
if [ '@abs_top_srcdir@' = '' ] ; then
echo "Something is wrong: abs_top_srcdir is not set."
exit 1
fi

abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh

. $abs_top_srcdir/init/pre.sh
. $abs_top_srcdir/lib/journal.sh
set -- # reset $# so shunit2 doesn't get confused.

# load shunit2
srcdir=@srcdir@
srcdir=${srcdir%%/}/
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${srcdir}shunit2
fi
[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
7 changes: 2 additions & 5 deletions test/unit/test-lib-complete.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,10 @@ if [ '@abs_top_srcdir@' = '' ] ; then
exit 1
fi
abs_top_srcdir=@abs_top_srcdir@
# Make sure @abs_top_srcr@ has a trailing slash
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh
. ${abs_top_srcdir}lib/complete.sh
set -- # reset $# so shunit2 doesn't get confused.

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi
[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
7 changes: 2 additions & 5 deletions test/unit/test-msg.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@ test_msg_undefined()
}

abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh
. ${abs_top_srcdir}lib/msg.sh
set -- # reset $# so shunit2 doesn't get confused.

# load shunit2
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi

[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
9 changes: 2 additions & 7 deletions test/unit/test-pre.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ test_pre_do_show_version()
}

abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh
. ${abs_top_srcdir}/init/pre.sh
set -- # reset $# so shunit2 doesn't get confused.

# load shunit2
srcdir=@srcdir@
srcdir=${srcdir}/
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${srcdir}/shunit2
fi

[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
8 changes: 2 additions & 6 deletions test/unit/test-run.sh.in
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@ test_run_not_running()
}

abs_top_srcdir=@abs_top_srcdir@
# Make sure $abs_top_srcdir has a trailing slash
abs_top_srcdir=${abs_top_srcdir%%/}/
. ${abs_top_srcdir}test/unit/helper.sh
. ${abs_top_srcdir}/lib/run.sh
set -- # reset $# so shunit2 doesn't get confused.

srcdir=@srcdir@
srcdir=${srcdir}/
if [[ ${0##*/} == ${.sh.file##*/} ]] ; then
. ${shunit_file}
fi

[[ @CMDLINE_INVOKED@ ]] && . ${shunit_file}
Loading

0 comments on commit 5695ecd

Please sign in to comment.