goto_xs.t revision 7c478bd95313f5f23a4c958a745db2134aa03244
#!./perl
# tests for "goto &sub"-ing into XSUBs
# $RCSfile$$Revision$$Date$
# Note: This only tests things that should *work*. At some point, it may
# be worth while to write some failure tests for things that should
# *break* (such as calls with wrong number of args). For now, I'm
# guessing that if all of these work correctly, the bad ones will
# break correctly as well.
chdir 't' if -d 't';
@INC = '../lib';
# turn warnings into fatal errors
BEGIN { $| = 1; }
eval 'require Fcntl'
print "1..10\n";
# We don't know what symbols are defined in platform X's system headers.
# We don't even want to guess, because some platform out there will
# likely do the unthinkable. However, Fcntl::constant("LOCK_SH",0)
# should always return a value, even on platforms which don't define the
# cpp symbol; Fcntl.xs says:
# /* We support flock() on systems which don't have it, so
# always supply the constants. */
# If this ceases to be the case, we're in trouble. =)
### First, we check whether Fcntl::constant returns sane answers.
# Fcntl::constant("LOCK_SH",0) should always succeed.
? "not ok 1\n# Sanity check broke, remaining tests will fail.\n"
: "ok 1\n");
### OK, we're ready to do real tests.
# test "goto &function_constant"
sub goto_const { goto &Fcntl::constant; }
# test "goto &$function_package_and_name"
sub goto_name1 { goto &$FNAME1; }
# test "goto &$function_package_and_name" again, with dirtier stack
# test "goto &$function_name" from local package
sub goto_name2 { goto &$FNAME2; }
# test "goto &$function_ref"
### tests where the args are not on stack but in GvAV(defgv) (ie, @_)
# test "goto &function_constant" from a sub called without arglist
sub call_goto_const { &goto_const; }
# test "goto &$function_package_and_name" from a sub called without arglist
sub call_goto_name1 { &goto_name1; }
# test "goto &$function_ref" from a sub called without arglist
sub call_goto_ref { &goto_ref; }