1Test::Alien(3)        User Contributed Perl Documentation       Test::Alien(3)
2
3
4

NAME

6       Test::Alien - Testing tools for Alien modules
7

VERSION

9       version 1.55
10

SYNOPSIS

12       Test commands that come with your Alien:
13
14        use Test2::V0;
15        use Test::Alien;
16        use Alien::patch;
17
18        alien_ok 'Alien::patch';
19        run_ok([ 'patch', '--version' ])
20          ->success
21          # we only accept the version written
22          # by Larry ...
23          ->out_like(qr{Larry Wall});
24
25        done_testing;
26
27       Test that your library works with "XS":
28
29        use Test2::V0;
30        use Test::Alien;
31        use Alien::Editline;
32
33        alien_ok 'Alien::Editline';
34        my $xs = do { local $/; <DATA> };
35        xs_ok $xs, with_subtest {
36          my($module) = @_;
37          ok $module->version;
38        };
39
40        done_testing;
41
42        __DATA__
43
44        #include "EXTERN.h"
45        #include "perl.h"
46        #include "XSUB.h"
47        #include <editline/readline.h>
48
49        const char *
50        version(const char *class)
51        {
52          return rl_library_version;
53        }
54
55        MODULE = TA_MODULE PACKAGE = TA_MODULE
56
57        const char *version(class);
58            const char *class;
59
60       Test that your library works with FFI::Platypus:
61
62        use Test2::V0;
63        use Test::Alien;
64        use Alien::LibYAML;
65
66        alien_ok 'Alien::LibYAML';
67        ffi_ok { symbols => ['yaml_get_version'] }, with_subtest {
68          my($ffi) = @_;
69          my $get_version = $ffi->function(yaml_get_version => ['int*','int*','int*'] => 'void');
70          $get_version->call(\my $major, \my $minor, \my $patch);
71          like $major, qr{[0-9]+};
72          like $minor, qr{[0-9]+};
73          like $patch, qr{[0-9]+};
74        };
75
76        done_testing;
77

DESCRIPTION

79       This module provides tools for testing Alien modules.  It has hooks to
80       work easily with Alien::Base based modules, but can also be used via
81       the synthetic interface to test non Alien::Base based Alien modules.
82       It has very modest prerequisites.
83
84       Prior to this module the best way to test a Alien module was via
85       Test::CChecker.  The main downside to that module is that it is heavily
86       influenced by and uses ExtUtils::CChecker, which is a tool for checking
87       at install time various things about your compiler.  It was also
88       written before Alien::Base became as stable as it is today.  In
89       particular, Test::CChecker does its testing by creating an executable
90       and running it.  Unfortunately Perl uses extensions by creating dynamic
91       libraries and linking them into the Perl process, which is different in
92       subtle and error prone ways.  This module attempts to test the
93       libraries in the way that they will actually be used, via either "XS"
94       or FFI::Platypus.  It also provides a mechanism for testing binaries
95       that are provided by the various Alien modules (for example
96       Alien::gmake and Alien::patch).
97
98       Alien modules can actually be useable without a compiler, or without
99       FFI::Platypus (for example, if the library is provided by the system,
100       and you are using FFI::Platypus, or if you are building from source and
101       you are using "XS"), so tests with missing prerequisites are
102       automatically skipped.  For example, "xs_ok" will automatically skip
103       itself if a compiler is not found, and "ffi_ok" will automatically skip
104       itself if FFI::Platypus is not installed.
105

FUNCTIONS

107   alien_ok
108        alien_ok $alien, $message;
109        alien_ok $alien;
110
111       Load the given Alien instance or class.  Checks that the instance or
112       class conforms to the same interface as Alien::Base.  Will be used by
113       subsequent tests.  The $alien module only needs to provide these
114       methods in order to conform to the Alien::Base interface:
115
116       cflags
117           String containing the compiler flags
118
119       libs
120           String containing the linker and library flags
121
122       dynamic_libs
123           List of dynamic libraries.  Returns empty list if the Alien module
124           does not provide this.
125
126       bin_dir
127           Directory containing tool binaries.  Returns empty list if the
128           Alien module does not provide this.
129
130       If your Alien module does not conform to this interface then you can
131       create a synthetic Alien module using the "synthetic" function.
132
133   synthetic
134        my $alien = synthetic \%config;
135
136       Create a synthetic Alien module which can be passed into "alien_ok".
137       "\%config" can contain these keys (all of which are optional):
138
139       cflags
140           String containing the compiler flags.
141
142       cflags_static
143           String containing the static compiler flags (optional).
144
145       libs
146           String containing the linker and library flags.
147
148       libs_static
149           String containing the static linker flags (optional).
150
151       dynamic_libs
152           List reference containing the dynamic libraries.
153
154       bin_dir
155           Tool binary directory.
156
157       runtime_prop
158           Runtime properties.
159
160       See Test::Alien::Synthetic for more details.
161
162   run_ok
163        my $run = run_ok $command;
164        my $run = run_ok $command, $message;
165
166       Runs the given command, falling back on any "Alien::Base#bin_dir"
167       methods provided by Alien modules specified with "alien_ok".
168
169       $command can be either a string or an array reference.
170
171       Only fails if the command cannot be found, or if it is killed by a
172       signal!  Returns a Test::Alien::Run object, which you can use to test
173       the exit status, output and standard error.
174
175       Always returns an instance of Test::Alien::Run, even if the command
176       could not be found.
177
178   xs_ok
179        xs_ok $xs;
180        xs_ok $xs, $message;
181
182       Compiles, links the given "XS" code and attaches to Perl.
183
184       If you use the special module name "TA_MODULE" in your "XS" code, it
185       will be replaced by an automatically generated package name.  This can
186       be useful if you want to pass the same "XS" code to multiple calls to
187       "xs_ok" without subsequent calls replacing previous ones.
188
189       $xs may be either a string containing the "XS" code, or a hash
190       reference with these keys:
191
192       xs  The XS code.  This is the only required element.
193
194       pxs Extra ExtUtils::ParseXS arguments passed in as a hash reference.
195
196       cbuilder_compile
197           Extra The ExtUtils::CBuilder arguments passed in as a hash
198           reference.
199
200       cbuilder_link
201           Extra The ExtUtils::CBuilder arguments passed in as a hash
202           reference.
203
204       verbose
205           Spew copious debug information via test note.
206
207       You can use the "with_subtest" keyword to conditionally run a subtest
208       if the "xs_ok" call succeeds.  If "xs_ok" does not work, then the
209       subtest will automatically be skipped.  Example:
210
211        xs_ok $xs, with_subtest {
212          # skipped if $xs fails for some reason
213          my($module) = @_;
214          is $module->foo, 1;
215        };
216
217       The module name detected during the XS parsing phase will be passed in
218       to the subtest.  This is helpful when you are using a generated module
219       name.
220
221   ffi_ok
222        ffi_ok;
223        ffi_ok \%opt;
224        ffi_ok \%opt, $message;
225
226       Test that FFI::Platypus works.
227
228       "\%opt" is a hash reference with these keys (all optional):
229
230       symbols
231           List references of symbols that must be found for the test to
232           succeed.
233
234       ignore_not_found
235           Ignores symbols that aren't found.  This affects functions accessed
236           via FFI::Platypus#attach and FFI::Platypus#function methods, and
237           does not influence the "symbols" key above.
238
239       lang
240           Set the language.  Used primarily for language specific native
241           types.
242
243       As with "xs_ok" above, you can use the "with_subtest" keyword to
244       specify a subtest to be run if "ffi_ok" succeeds (it will skip
245       otherwise).  The FFI::Platypus instance is passed into the subtest as
246       the first argument.  For example:
247
248        ffi_ok with_subtest {
249          my($ffi) = @_;
250          is $ffi->function(foo => [] => 'void')->call, 42;
251        };
252
253   helper_ok
254        helper_ok $name;
255        helper_ok $name, $message;
256
257       Tests that the given helper has been defined.
258
259   interpolate_template_is
260        interpolate_template_is $template, $string;
261        interpolate_template_is $template, $string, $message;
262        interpolate_template_is $template, $regex;
263        interpolate_template_is $template, $regex, $message;
264
265       Tests that the given template when evaluated with the appropriate
266       helpers will match either the given string or regular expression.
267

SEE ALSO

269       Alien
270       Alien::Base
271       Alien::Build
272       alienfile
273       Test2
274       Test::Alien::Run
275       Test::Alien::CanCompile
276       Test::Alien::CanPlatypus
277       Test::Alien::Synthetic
278

AUTHOR

280       Author: Graham Ollis <plicease@cpan.org>
281
282       Contributors:
283
284       Diab Jerius (DJERIUS)
285
286       Roy Storey
287
288       Ilya Pavlov
289
290       David Mertens (run4flat)
291
292       Mark Nunberg (mordy, mnunberg)
293
294       Christian Walde (Mithaldu)
295
296       Brian Wightman (MidLifeXis)
297
298       Zaki Mughal (zmughal)
299
300       mohawk (mohawk2, ETJ)
301
302       Vikas N Kumar (vikasnkumar)
303
304       Flavio Poletti (polettix)
305
306       Salvador Fandiño (salva)
307
308       Gianni Ceccarelli (dakkar)
309
310       Pavel Shaydo (zwon, trinitum)
311
312       Kang-min Liu (劉康民, gugod)
313
314       Nicholas Shipp (nshp)
315
316       Juan Julián Merelo Guervós (JJ)
317
318       Joel Berger (JBERGER)
319
320       Petr Pisar (ppisar)
321
322       Lance Wicks (LANCEW)
323
324       Ahmad Fatoum (a3f, ATHREEF)
325
326       José Joaquín Atria (JJATRIA)
327
328       Duke Leto (LETO)
329
330       Shoichi Kaji (SKAJI)
331
332       Shawn Laffan (SLAFFAN)
333
334       Paul Evans (leonerd, PEVANS)
335
337       This software is copyright (c) 2011-2018 by Graham Ollis.
338
339       This is free software; you can redistribute it and/or modify it under
340       the same terms as the Perl 5 programming language system itself.
341
342
343
344perl v5.28.1                      2019-02-24                    Test::Alien(3)
Impressum