bin/mktestsuite
#!/bin/sh
##
## We attempt to locate a working m4
##
M4=m4
IFS="${IFS= }"; save_ifs="$IFS"; IFS="${IFS}:"
HAVEGNU=no
HAVEWORKS=no
# GNU m4 is named gm4 on FreeBSD and Solaris 10.
PATHS=$PATH:/usr/sfw/bin:/opt/sfw/bin:/opt/csw/bin:/opt/gnu/bin:/usr/gnu/bin
for m4 in gm4 m4
do
for d in $PATHS; do
test -z "$d" && ac_dir=.
if test -f $d/$m4; then
# "m4.c 1.9 89/07/10 SMI" (of SunOS 4.1.1_U1) is broken and hangs
# during the quote test.
m4_ident="`strings $d/$m4|grep '@(#)m4.c' 2>/dev/null`"
if test "x$m4_ident" '!=' "x" && \
echo "$m4_ident"|egrep 'm4.c 1\.[0-9] .* SMI' >/dev/null 2>&1; then
works=no
elif echo 'divert(-1)changequote([[,]])define(DOIT,ifelse([foo],foo,[DOIT($1)]))DOIT([[m4exit(1)]])' | $d/$m4 >/dev/null; then
works=yes
else
works=no
fi
# FIXME: Ought to check for "pushed back more than 4096 chars".
case `echo __gnu__ | $d/$m4` in
__gnu__) isgnu=no ;;
*) isgnu=yes ;;
esac
case "$HAVEGNU-$isgnu:$HAVEWORKS-$works" in
*:no-yes|no-yes:*)
M4=$d/$m4
HAVEGNU=$isgnu
HAVEWORKS=$works
;;
esac
fi
if test "$HAVEGNU:$HAVEWORKS" = "yes:yes"; then
break
fi
done
if test "$HAVEGNU:$HAVEWORKS" = "yes:yes"; then
break
fi
done
IFS="$save_ifs"
(
cat <<EOF
divert(-1)
dnl generates a script that is supposed to test Pike
dnl note that not everything is tested yet, you are welcome to
dnl submit more tests.
changequote([[,]])
define(DOIT,ifelse([foo],foo,[DOIT(\$1)]))dnl
DOIT([[errprint([This m4 cannot handle quote strings with more than one character
Please consider installing GNU m4.])
m4exit(1)
]])dnl
changecom
define(real_checkarg,[[dnl
ifelse(index([[\$3]],format([[%c]],255)),-1,,[[dnl
format([%c],255)
errprint(__file__:__line__: [[
Argument \$2 to \$1 contains the character ]]format([[%c]],255)[[,
which is treated as EOF by some m4 implementations.
]])m4exit(1)]])dnl
ifelse(eval(len([[\$3]])>4096),0,,[[dnl
errprint(__file__:__line__: [[
Argument \$2 to \$1 has ]]len([[\$3]])[[ characters,
some m4 implementations only allow 4096.
]])m4exit(1)]])dnl
ifelse(index([[\$3]],[[
....
]]),-1,,[[dnl
errprint(__file__:__line__: [[
Argument \$2 to \$1 contains the "...." sequence, used internally by
the testsuite.
]])m4exit(1)]])dnl
]])
ifdef([[__gnu__]],
[[define(checkarg,[[[[real_checkarg([[\$1]],\$2,[[\$\$2]])]]]])]],
[[define(checkarg,)]]
)
define(SEPARATOR,[[....]])
define(CONDITION,[[]])
define(DOTEST,dnl
checkarg([[DOTEST]],1)dnl
checkarg([[DOTEST]],2)dnl
[[dnl
divert(0)dnl
define([[TESTNO]],incr(TESTNO))dnl
CONDITION()__file__:__line__: test TESTNO, expected result: [[\$1]]
[[\$2]]
SEPARATOR
divert(-1)dnl]])
define(START_MARKER,[[divert(0)START [[\$1]]
divert(-1)]])
define(END_MARKER,[[divert(0)END
divert(-1)]])
define(ignore_warning, dnl
checkarg([[ignore_warning]],1)dnl
checkarg([[ignore_warning]],2)dnl
[[DOTEST(PUSH_WARNING,dnl
mixed a() { return [[\$1]]; })
\$2
DOTEST(POP_WARNING,dnl
mixed a() { return [[\$1]]; })
]])
define(test_any, [[DOTEST(EQ,dnl
mixed a() { [[\$1]]; }
mixed b() { return [[\$2]]; })]])
define(test_any_equal, [[DOTEST(EQUAL,dnl
mixed a() { [[\$1]]; }
mixed b() { return [[\$2]]; })]])
define(test_eq,[[DOTEST(EQ,dnl
mixed a() { return [[\$1]]; }
mixed b() { return [[\$2]]; })]])
define(test_equal,[[DOTEST(EQUAL,dnl
mixed a() { return [[\$1]]; }
mixed b() { return [[\$2]]; })]])
define(test_do,[[DOTEST(RUN,dnl
mixed a() { [[\$1]]; })]])
define(test_true, [[DOTEST(TRUE,dnl
mixed a() { return [[\$1]]; })]])
define(test_false, [[DOTEST(FALSE,dnl
mixed a() { return [[\$1]]; })]])
define(test_compile,[[DOTEST(COMPILE,dnl
void x() { [[\$1]] ; } )]])
define(test_compile_any,[[DOTEST(COMPILE,dnl
[[\$1]] )]])
define(test_compile_error,[[DOTEST(COMPILE_ERROR,dnl
mixed a() { [[\$1]];})]])
define(test_compile_error_any,[[DOTEST(COMPILE_ERROR,dnl
[[\$1]])]])
define(test_compile_warning,[[DOTEST(COMPILE_WARNING,dnl
mixed a() { [[\$1]];})]])
define(test_eval_error,[[DOTEST(EVAL_ERROR,dnl
mixed a() { [[\$1]]; })]])
define(test_define_program,[[DOTEST(RUN,dnl
void a() { class [[\$1]] { [[\$2]] }
add_constant("[[\$1]]", [[\$1]]);
})]])
define(test_program, [[DOTEST(TRUE,dnl
[[\$1]])]])
define(test_program_eq, [[DOTEST(EQ,dnl
[[\$1]]
mixed b() {return [[\$2]];})]])
define(test_program_equal, [[DOTEST(EQUAL,dnl
[[\$1]]
mixed b() {return [[\$2]];})]])
define(test_tests, [[DOTEST(RUNCT,dnl
[[\$1]])]])
define(cond_begin,dnl
checkarg([[cond]],1)dnl
[[
define([[CONDITION]],[[COND \$1
]])
]])
define(cond_end,dnl
[[
define([[CONDITION]],[[]])
]])
define(cond,dnl
checkarg([[cond]],2)dnl
[[
cond_begin([[\$1]])
\$2
cond_end
]])
define(cond_resolv,[[cond([[master()->resolv(dnl
String.trim("\$1"))]],[[\$2]])]])
define(ifefun,[[cond([[all_constants()->\$1]],[[\$2]])]])
define(TESTNO,0)
// testing < > <= >=
define([[test_cmp]],[[
test_true(\$1<\$2)
test_false(\$1>\$2)
test_true(\$2>\$1)
test_false(\$2<\$1)
test_true(\$1<=\$2)
test_false(\$1>=\$2)
test_true(\$2>=\$1)
test_false(\$2<=\$1)
test_true(\$2<=\$2)
test_true(\$1>=\$1) ]])
define([[test_cmp3]],[[
test_cmp(\$1,\$2)
test_cmp(\$2,\$3)
test_cmp(\$1,\$3)
test_true(\`<(\$1,\$2,\$3))
test_false(!\`<(\$1,\$2,\$3))
test_false(\`<(\$1,\$3,\$2))
test_true(!\`<(\$1,\$3,\$2))
test_false(\`<(\$2,\$3,\$1))
test_false(\`<(\$2,\$1,\$3))
test_false(\`<(\$3,\$1,\$2))
test_false(\`<(\$3,\$2,\$1))
test_false(\`<(\$3,\$2,\$2,\$1))
test_true(\`<=(\$1,\$2,\$3))
test_false(!\`<=(\$1,\$2,\$3))
test_false(\`<=(\$1,\$3,\$2))
test_false(\`<=(\$2,\$3,\$1))
test_false(\`<=(\$2,\$1,\$3))
test_true(!\`<=(\$2,\$1,\$3))
test_false(\`<=(\$3,\$1,\$2))
test_false(\`<=(\$3,\$2,\$1))
test_true(\`<=(\$1,\$1,\$2,\$2,\$3,\$3))
test_false(\`>(\$1,\$2,\$3))
test_false(\`>(\$1,\$3,\$2))
test_false(\`>(\$2,\$3,\$1))
test_false(\`>(\$2,\$1,\$3))
test_false(\`>(\$3,\$1,\$2))
test_true(\`>(\$3,\$2,\$1))
test_false(\`>(\$3,\$2,\$2,\$1))
test_false(\`>=(\$1,\$2,\$3))
test_false(\`>=(\$1,\$3,\$2))
test_false(\`>=(\$2,\$3,\$1))
test_false(\`>=(\$2,\$1,\$3))
test_false(\`>=(\$3,\$1,\$2))
test_true(!\`>=(\$3,\$1,\$2))
test_true(\`>=(\$3,\$2,\$1))
test_true(\`>=(\$3,\$3,\$2,\$2,\$1,\$1))
test_false(!\`>=(\$3,\$3,\$2,\$2,\$1,\$1))
test_equal(min(\$2,\$1,\$3), \$1)
test_equal(max(\$2,\$1,\$3), \$3)
]])
include($1)
EOF
) | (shift ; $M4 -d "$@" - )
exit $?