Yes, i do that. It is called "regression test" because functions in my library usually do some pretty abstracted things and i want them to be as reliable as possible. If you search the forums for my name and "ksh function" you will even find some examples of what i wrote.
My usual setup is like this:
i have my library in "/usr/local/lib/ksh" and all my function names start with "f_". This way i know immediately which are external functions and which are not in complex scripts.
I have one "environment" function, which i source in at the beginning of every script and which sets the environment from the beginning, including PATH, FPATH and so on. This way i have always the same environment in every script i write and don't have to worry about scripts being started from crontab and similar common problems.
In addition i have one environment variable "DEVELOP", which is tested in the environment function. If it has any value at all FPATH is not set to "/usr/local/lib/ksh" but to "~/lib", so that a local copy of the library in my $HOME is used. This way i can locally test the scripts with new versions of the lib functions (my user has this variable set in ".kshrc") and then just roll out the scripts. Other users don't have the variable set so they will automatically use the general version of the library with no change.
usual script start:
#! /bin/ksh
if [ -n "$DEVELOP" ] ; then
. ~/lib/f_env
else
. /usr/local/lib/ksh/f_env
fi
# set local vars after this, f_env clears the environment first
typeset localvar=....
... rest of code
exit 0
f_env would look like this (parts):
f_env ()
{
if [ -z "$NEVER_USE_THIS_VAR" ] ; then # are we called recursively ?
unset ENV # clear the environment
#---------------------------------------------------- set basic environment
typeset -x OS=$(uname -a | cut -d' ' -f1) # find out the OS
# read in standard environment
case "$OS" in
AIX)
. /etc/environment
;;
Linux)
. /etc/profile
;;
*)
. /etc/environment
;;
esac
# set default TERM variable
case "$OS" in
AIX)
TERMDEF="$(termdef)"
;;
Linux)
TERMDEF="$TERM"
;;
*)
TERMDEF="$TERM"
;;
esac
typeset -x TERM=${TERMDEF:-'wyse60'} # set default TERM variable
typeset -x LANG=C # default language environment
typeset -x EDITOR=vi # what else ? ;-))
typeset -x VISUAL=$EDITOR
typeset -x PATH="/usr/bin" # set the path
PATH="$PATH:/bin"
PATH="$PATH:/etc"
PATH="$PATH:/usr/sbin"
PATH="$PATH:/usr/ucb"
PATH="$PATH:/sbin"
PATH="$PATH:/usr/bin/X11"
PATH="$PATH:/usr/local/bin" # tools, home for scripts
PATH="$PATH:/usr/local/sbin" # -"-
typeset -x chTmpDir="" # path for temporary files
#---------------------------------------------------- debugging stuff
if [ -z "$chFullDebug" ] ; then # debug switch
typeset -x chFullDebug=""
else
typeset -x chFullDebug # export if already set
fi
typeset -x SIMULATE='' # set to 'print' for
# simulation mode
typeset -x TRACE='' # set to 'on' for trace mode
if [ -z "$DEVELOP" ] ; then
typeset -x FPATH="/usr/local/lib/ksh" # set fnc path for fnc lib
FPATH="$FPATH:/usr/local/bin"
FPATH="$FPATH:/usr/local/sbin"
else
typeset -x FPATH=~/lib # for lib development
fi
#---------------------------------------------------- global constants
typeset -x chProgName="$0" # const. for main program name
typeset -x chUsageShort="" # short usage message
typeset -x achUsageLong[0]="" # long usage message (line)
if [ -z "$fLogFile" ] ; then # log file
if [ $(f_ImRoot ; print $?) -eq 0 ] ; then
typeset -x fLogFile='/usr/local/log/swd.log'
else
typeset -x fLogFile=~/swd.log
fi
else
typeset -x fLogFile
fi
if [ -z "$fErrFile" ] ; then # error file
if [ $(f_ImRoot ; print $?) -eq 0 ] ; then
typeset -x fErrFile='/usr/local/log/swd.err'
else
typeset -x fErrFile=~/swd.err
fi
else
typeset -x fErrFile
fi
.... etc. ....
#-------------------------------------------------- reentrancy protection
typeset -x NEVER_USE_THIS_VAR="KILROY_WAS_HERE"
fi
}
There are also parts dealing with supported alerting systems (BMC Patrol, HP OpenView, and some other are supported), and some site-dependent stuff, but i think you get the drift.
Notice the "if [ -z "$DEVELOP" ]" line, where the FPATH is set accordingly.
I hope this helps.
bakunin