pv_uni_display () omitted backslash in output string
[p5sagit/p5-mst-13.2.git] / ext / XS / APItest / APItest.pm
CommitLineData
3e61d65a 1package XS::APItest;
2
3use 5.008;
4use strict;
5use warnings;
6use Carp;
7
8use base qw/ DynaLoader Exporter /;
9
10# Items to export into callers namespace by default. Note: do not export
11# names by default without a very good reason. Use EXPORT_OK instead.
12# Do not simply export all your public functions/methods/constants.
13
14# Export everything since these functions are only used by a test script
deec275f 15our @EXPORT = qw( print_double print_int print_long
9d911683 16 print_float print_long_double have_long_double print_flush
d4b90eee 17 mpushp mpushn mpushi mpushu
18 mxpushp mxpushn mxpushi mxpushu
d1f347d7 19 call_sv call_pv call_method eval_sv eval_pv require_pv
20 G_SCALAR G_ARRAY G_VOID G_DISCARD G_EVAL G_NOARGS
b8d2d791 21 G_KEEPERR G_NODEBUG G_METHOD G_WANT
7a646707 22 apitest_exception mycroak strtab
85ce96a1 23 my_cxt_getint my_cxt_getsv my_cxt_setint my_cxt_setsv
34482cd6 24 sv_setsv_cow_hashkey_core sv_setsv_cow_hashkey_notcore
218787bd 25 rmagical_cast rmagical_flags
3e61d65a 26);
27
218787bd 28our $VERSION = '0.14';
84ac5fd7 29
30use vars '$WARNINGS_ON_BOOTSTRAP';
0932863f 31use vars map "\$${_}_called_PP", qw(BEGIN UNITCHECK CHECK INIT END);
32
9568a123 33BEGIN {
34 # This is arguably a hack, but it disposes of the UNITCHECK block without
35 # needing to preprocess the source code
36 if ($] < 5.009) {
37 eval 'sub UNITCHECK (&) {}; 1' or die $@;
38 }
39}
40
0932863f 41# Do these here to verify that XS code and Perl code get called at the same
42# times
43BEGIN {
44 $BEGIN_called_PP++;
45}
46UNITCHECK {
47 $UNITCHECK_called_PP++;
9568a123 48};
0932863f 49{
50 # Need $W false by default, as some tests run under -w, and under -w we
51 # can get warnings about "Too late to run CHECK" block (and INIT block)
52 no warnings 'void';
53 CHECK {
54 $CHECK_called_PP++;
55 }
56 INIT {
57 $INIT_called_PP++;
58 }
59}
60END {
61 $END_called_PP++;
62}
63
84ac5fd7 64if ($WARNINGS_ON_BOOTSTRAP) {
65 bootstrap XS::APItest $VERSION;
66} else {
0932863f 67 # More CHECK and INIT blocks that could warn:
84ac5fd7 68 local $^W;
84ac5fd7 69 bootstrap XS::APItest $VERSION;
70}
3e61d65a 71
721;
73__END__
74
75=head1 NAME
76
77XS::APItest - Test the perl C API
78
79=head1 SYNOPSIS
80
81 use XS::APItest;
82 print_double(4);
83
84=head1 ABSTRACT
85
86This module tests the perl C API. Currently tests that C<printf>
87works correctly.
88
89=head1 DESCRIPTION
90
91This module can be used to check that the perl C API is behaving
92correctly. This module provides test functions and an associated
93test script that verifies the output.
94
95This module is not meant to be installed.
96
97=head2 EXPORT
98
99Exports all the test functions:
100
101=over 4
102
103=item B<print_double>
104
105Test that a double-precision floating point number is formatted
106correctly by C<printf>.
107
108 print_double( $val );
109
110Output is sent to STDOUT.
111
112=item B<print_long_double>
113
114Test that a C<long double> is formatted correctly by
115C<printf>. Takes no arguments - the test value is hard-wired
116into the function (as "7").
117
118 print_long_double();
119
120Output is sent to STDOUT.
121
122=item B<have_long_double>
123
124Determine whether a C<long double> is supported by Perl. This should
125be used to determine whether to test C<print_long_double>.
126
127 print_long_double() if have_long_double;
128
129=item B<print_nv>
130
131Test that an C<NV> is formatted correctly by
132C<printf>.
133
134 print_nv( $val );
135
136Output is sent to STDOUT.
137
138=item B<print_iv>
139
140Test that an C<IV> is formatted correctly by
141C<printf>.
142
143 print_iv( $val );
144
145Output is sent to STDOUT.
146
147=item B<print_uv>
148
149Test that an C<UV> is formatted correctly by
150C<printf>.
151
152 print_uv( $val );
153
154Output is sent to STDOUT.
155
156=item B<print_int>
157
158Test that an C<int> is formatted correctly by
159C<printf>.
160
161 print_int( $val );
162
163Output is sent to STDOUT.
164
165=item B<print_long>
166
167Test that an C<long> is formatted correctly by
168C<printf>.
169
170 print_long( $val );
171
172Output is sent to STDOUT.
173
174=item B<print_float>
175
176Test that a single-precision floating point number is formatted
177correctly by C<printf>.
178
179 print_float( $val );
180
181Output is sent to STDOUT.
182
d1f347d7 183=item B<call_sv>, B<call_pv>, B<call_method>
184
185These exercise the C calls of the same names. Everything after the flags
186arg is passed as the the args to the called function. They return whatever
187the C function itself pushed onto the stack, plus the return value from
188the function; for example
189
190 call_sv( sub { @_, 'c' }, G_ARRAY, 'a', 'b'); # returns 'a', 'b', 'c', 3
191 call_sv( sub { @_ }, G_SCALAR, 'a', 'b'); # returns 'b', 1
192
193=item B<eval_sv>
194
3c4b39be 195Evaluates the passed SV. Result handling is done the same as for
d1f347d7 196C<call_sv()> etc.
197
198=item B<eval_pv>
199
3c4b39be 200Exercises the C function of the same name in scalar context. Returns the
d1f347d7 201same SV that the C function returns.
202
203=item B<require_pv>
204
3c4b39be 205Exercises the C function of the same name. Returns nothing.
d1f347d7 206
3e61d65a 207=back
208
209=head1 SEE ALSO
210
211L<XS::Typemap>, L<perlapi>.
212
213=head1 AUTHORS
214
215Tim Jenness, E<lt>t.jenness@jach.hawaii.eduE<gt>,
216Christian Soeller, E<lt>csoelle@mph.auckland.ac.nzE<gt>,
217Hugo van der Sanden E<lt>hv@crypt.compulink.co.ukE<gt>
218
219=head1 COPYRIGHT AND LICENSE
220
d1f347d7 221Copyright (C) 2002,2004 Tim Jenness, Christian Soeller, Hugo van der Sanden.
3e61d65a 222All Rights Reserved.
223
224This library is free software; you can redistribute it and/or modify
225it under the same terms as Perl itself.
226
227=cut