########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1994-2011 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# Glenn Fowler <gsf@research.att.com> #
# #
########################################################################
command=mktest
stdin=8
stdout=9
PREFIX=test
WIDTH=80
eval "exec $stdout>&1"
USAGE=$'
[-?
@(#)$Id: mktest (AT&T Labs Research) 2010-08-11 $
]
[+NAME?mktest - generate a regression test scripts]
[+DESCRIPTION?\bmktest\b generates regression test scripts from test
template commands in the \aunit\a.\brt\b file. The generated test
script with the \b--accept\b option to (re)generate the
{
[+regress?\bregress\b(1) command input.]
[+shell?Standalone test shell script.]
}
[w:width?Set the output format width to approximately
unit.rt [ unit [ arg ... ] ]
[+INPUT FILES?The regression test command file \aunit\a\b.rt\b is a
\bksh\b(1) script that makes calls to the following functions:]
{
[+DATA \afile\a [ - | [ options ]] data]]?Create input data
\afile\a that is empty (-) or contains \adata\a subject to
\bprint\b(1) \aoptions\a or that is a copy of the DATA command
standard input. Set \afile\a to \b-\b to name the standard
input.]
[+DIAGNOSTICS?Diagnostic messages of unspecified format are
expected.]
[+DO \acommand\a [ \aarg\a ... ]]?Execute \acommand\a if the
current test is active.]
[+EXEC [ \aarg\a ... ]]?Run the command under test with
optional arguments. If the standard input is not specified then
the standard input of the previous EXEC is used. The standard
input of the first EXEC in a TEST group is an empty regular
file.]
[+EXPORT \aname\a=\avalue\a ...?Export list for subsequent
commands in the TEST group or for all TEST groups if before
the first TEST group.]
[+IGNORESPACE [ 0 | 1 ]
?Ignore space differences when comparing expected output.]
[+KEEP \apattern\a ...?File match patterns of files to retain
between TEST groups.]
[+NOTE \acomment\a?\acomment\a is added to the current test
script.]
[+PROG \acommand\a [ \aarg\a ... ]]?Run \acommand\a with
optional arguments.]
[+TEST [ \anumber\a ]] [ \adescription\a ... ]]?Define a new
test group with optional \anumber\a and \adescripion\a.]
[+TWD [ \adir\a ... ]]?Set the temporary test dir to \adir\a.
The default is \aunit\a\b.tmp\b, where \aunit\a is the test
input file sans directory and suffix. If \adir\a matches \b/*\b
then it is the directory name; if \adir\a is non-null then the
prefix \b${TMPDIR:-/tmp}\b is added; otherwise if \adir\a is
omitted then
\b${TMPDIR:-/tmp}/tst-\b\aunit\a-$$-$RANDOM.\b\aunit\a is
used.]
[+UMASK [ \amask\a ]]?Run subsequent tests with \bumask\b(1)
\amask\a. If \amask\a is omitted then the original \bumask\b is
used.]
[+UNIT \acommand\a [ \aarg\a ... ]]?Define the command and
optional default arguments to be tested. \bUNIT\b explicitly
overrides the default command name derived from the test script
file name.]
[+WIDTH \awidth\a?Set the output format width to approximately
\awidth\a.]
}
[+SEE ALSO?\bregress\b(1), \bksh\b(1)]
'
;;
*) ARGV0=""
;;
esac
typeset -C STATE
;;
exit 1
;;
esac
;;
;;
*) OPTIND=0
exit 2
;;
esac
done
shift $OPTIND-1
if [[ $1 == - ]]
then shift
fi
if (( ! $# ))
then
exit 1
fi
SCRIPT=$1
shift
if [[ ! -r $SCRIPT ]]
exit 1
fi
if (( $# ))
then set -A UNIT -- "$@"
set -A UNIT -- "${ARG%.*}"
fi
function LINE
{
then print -u$stdout
fi
}
function NOTE
{
;;
;;
esac
}
function UNIT
{
print -u$stdout -r -f $'UNIT'
done
print -u$stdout
;;
done
print -u$stdout
print -u$stdout shift
;;
esac
}
function TEST
{
typeset i
typeset -A REM
then unset ${!STATE.RESET[@]}
shell) print -u$stdout -r -- unset ${!STATE.RESET[@]} ;;
esac
unset STATE.RESET
typeset -A STATE.RESET
fi
if (( ${#REMOVE[@]} ))
then rm -f -- "${!REMOVE[@]}"
done
print -u$stdout
;;
esac
do unset REMOVE[$i]
done
fi
if [[ $1 == +([0-9]) ]]
then TEST=${1##0}
shift
fi
;;
;;
esac
CODE=0
}
function TWD
{
print -u$stdout -r -f $'TWD'
done
print -u$stdout
;;
esac
}
function RUN
{
op=$1
shift
while :
do case $1 in
*) break ;;
esac
shift
done
then unit=$1
shift
elif (( ! ${#UNIT[@]} ))
exit 1
fi
sep=$' '
sep=$'\t'
fi
sep=$' '
done
print -u$stdout
n=
n=-n
fi
{
[[ $UMASK != $UMASK_ORIG ]] && umask $UMASK
cd $WORK
then "$unit" "$@"
code=$?
else "${UNIT[@]}" "$@"
code=$?
fi
cd ..
[[ $UMASK != $UMASK_ORIG ]] && umask $UMASK_ORIG
INPUT_N=$n
if [[ ${FORMAT[-]} ]]
then print -u$stdout -n -r -- $'\t\tINPUT'
unset FORMAT[-]
fi
print -u$stdout
unset DATA[-]
fi
do if [[ ${FORMAT[$i]} ]]
then print -u$stdout -n -r -- $'\t\tINPUT'
unset FORMAT[$i]
else case $i in
*) p=$WORK/$i ;;
esac
n=
n=-n
fi
fi
print -u$stdout
unset DATA[$i]
done
n=
n=-n
fi
OUTPUT_N=$n
if [[ $output ]]
print -u$stdout -n -r -- $'\t\tSAME OUTPUT INPUT'
fi
print -u$stdout
fi
fi
n=
n=-n
fi
ERROR_N=$n
if [[ $error ]]
print -u$stdout
fi
fi
:) OUTPUT=
print -u$stdout -r -- $'\t\tIGNORE OUTPUT ERROR'
;;
:1) OUTPUT=
print -u$stdout -r -- $'\t\tIGNORE OUTPUT'
;;
1:) ERROR=
print -u$stdout -r -- $'\t\tIGNORE ERROR'
;;
esac
if [[ $UMASK_DONE != $UMASK ]]
then UMASK_DONE=$UMASK
fi
if [[ $exitcode ]]
fi
fi
;;
shell) [[ $UMASK != $UMASK_ORIG ]] && print -u$stdout -r -f "{ umask $UMASK; "
else print -u$stdout -r -f $'"$@"'
fi
done
[[ $UMASK != $UMASK_ORIG ]] && print -u$stdout -r -f "umask $UMASK_ORIG; } "
if [[ ! $output ]]
fi
if [[ ! $error ]]
then if [[ ! $output ]]
then print -u$stdout -r -f " 2>&1"
fi
fi
if [[ $IO ]]
then print -u$stdout -r -- "<<'!TEST-INPUT!'"
else print -u$stdout
fi
if [[ $exitcode ]]
then print -u$stdout -r -- $'CODE=$?\ncase $CODE in\n0) ;;\n*) echo exit status $CODE ;;\nesac'
fi
;;
esac
}
function DO
{
}
function EXEC
{
}
function DATA
{
typeset f p o
f=$1
shift
case $f in
*) p=$WORK/$f ;;
esac
case $1 in
-) ;;
*) print -r "$@" ;;
esac > $p
DATA[$f]=1
if (( $# == 1 )) && [[ $1 == -?* ]]
then FORMAT[$f]=$1
else FORMAT[$f]=
fi
if [[ $f != $KEEP ]]
then REMOVE[$f]=1
fi
then {
cat "$p"
} >&$stdout
fi
}
function KEEP
{
typeset p
for p
do if [[ $KEEP ]]
fi
done
}
function DIAGNOSTICS
{
shell) DIAGNOSTICS=1 ;;
esac
}
function EXPORT
{
typeset x n v
esac
for x
do n=${x%%=*}
v=${x#*=}
export "$x"
done
print -u$stdout
}
function PROG
{
}
function WIDTH
{
WIDTH=${1:-80}
}
function IGNORESPACE
{
IGNORESPACE=-b
print -u$stdout -r IGNORESPACE
}
{
[[ $UMASK_ORIG ]] || UMASK_ORIG=$(umask)
UMASK=$1
[[ $UMASK ]] || UMASK=$UMASK_ORIG
}
trap 'CODE=$?; rm -rf $TEMP.* $WORK; exit $CODE' 0 1 2 3 15
UMASK_ORIG=$(umask)
ACCEPT=0
while :
do case \$1 in
-a|--accept)
ACCEPT=1
;;
!!
exit 2
;;
exit 1
;;
*) break
;;
esac
shift
done
export COLUMNS=80
{
!
;;
esac
export COLUMNS=80
;;
;;
esac
sed 's/
fi
fi
;;
;;
esac
!
;;
esac