]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/regressions/inc/Test/Builder/Module.pm
1 package Test
::Builder
::Module
;
8 our @ISA = qw(Exporter);
10 our $VERSION = '0.80';
12 # 5.004's Exporter doesn't have export_to_level.
13 my $_export_to_level = sub {
16 (undef) = shift; # redundant arg
17 my $callpkg = caller($level);
18 $pkg->export($callpkg, @_);
24 Test::Builder::Module - Base class for test modules
28 # Emulates Test::Simple
31 my $CLASS = __PACKAGE__;
33 use base 'Test::Builder::Module';
37 my $tb = $CLASS->builder;
46 This is a superclass for Test::Builder-based modules. It provides a
47 handful of common functionality and a method of getting at the underlying
53 Test::Builder::Module is a subclass of Exporter which means your
54 module is also a subclass of Exporter. @EXPORT, @EXPORT_OK, etc...
57 A few methods are provided to do the C<use Your::Module tests => 23> part
62 Test::Builder::Module provides an import() method which acts in the
63 same basic way as Test::More's, setting the plan and controling
64 exporting of functions and variables. This allows your module to set
65 the plan independent of Test::More.
67 All arguments passed to import() are passed onto
68 C<< Your::Module->builder->plan() >> with the exception of
69 C<import =>[qw(things to import)]>.
71 use Your::Module import => [qw(this that)], tests => 23;
73 says to import the functions this() and that() as well as set the plan
76 import() also sets the exported_to() attribute of your builder to be
77 the caller of the import() function.
79 Additional behaviors can be added to your import() method by overriding
87 # Don't run all this when loading ourself.
88 return 1 if $class eq 'Test::Builder::Module';
90 my $test = $class->builder;
94 $test->exported_to($caller);
96 $class->import_extra(\
@_);
97 my(@imports) = $class->_strip_imports(\
@_);
101 $class->$_export_to_level(1, $class, @imports);
112 while( $idx <= $#{$list} ) {
113 my $item = $list->[$idx];
115 if( defined $item and $item eq 'import' ) {
116 push @imports, @{$list->[$idx+1]};
134 Your::Module->import_extra(\@import_args);
136 import_extra() is called by import(). It provides an opportunity for you
137 to add behaviors to your module based on its import list.
139 Any extra arguments which shouldn't be passed on to plan() should be
140 stripped off by this method.
142 See Test::More for an example of its use.
144 B<NOTE> This mechanism is I<VERY ALPHA AND LIKELY TO CHANGE> as it
145 feels like a bit of an ugly hack in its current form.
154 Test::Builder::Module provides some methods of getting at the underlying
155 Test::Builder object.
159 my $builder = Your::Class->builder;
161 This method returns the Test::Builder object associated with Your::Class.
162 It is not a constructor so you can call it as often as you like.
164 This is the preferred way to get the Test::Builder object. You should
165 I<not> get it via C<< Test::Builder->new >> as was previously
168 The object returned by builder() may change at runtime so you should
169 call builder() inside each function rather than store it in a global.
172 my $builder = Your::Class->builder;
174 return $builder->ok(@_);
181 return Test
::Builder-
>new;