Class/UnitTests/Class.pm

filter: Statementstmt 100% 166 / 166 Branchbran 50.0% 1 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 44 / 44 Podpod 0.0% 0 / 19 totaltotal 91.3% 211 / 231 CC 2 SCAR 0.4
CC
2
Cov
99%
invalid_defaults
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Class/Singleton/UnitTests/Singleton.pm ↑ Summary Class/Abstract/UnitTests/Interfaces.pm »
1 #!/usr/bin/perl
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 {
5 package OOP::Perlish::Class::UnitTests::Class;
6 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶ use OOP::Perlish::Class::UnitTests::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶ use base qw(OOP::Perlish::Class::UnitTests::Base);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶ use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 17 ▶ sub setup : Test(setup)
Subroutine setup: called CC=1 SCAR=0.0
Pod undocumented
13 {
14 17 my ($self) = @_;
15 17 undef $@;
16 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶ sub class_assignment : Test(1)
Subroutine class_assignment: called CC=1 SCAR=0.0
Pod undocumented
19 {
20 1 my ($self) = @_;
21  
22 1 my $f = OOP::Perlish::Class::UnitTests::Foo->new();
23 1 $f->foo("Hello foo!");
24 1 is($f->foo(), 'Hello foo!', 'Class assignment');
25 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
26  
27 1 ▶ sub multiple_classes : Test(2)
Subroutine multiple_classes: called CC=1 SCAR=0.0
Pod undocumented
28 {
29 1 my ($self) = @_;
30  
31 1 my $f = OOP::Perlish::Class::UnitTests::Foo->new();
32 1 $f->foo("Hello foo!");
33  
34 1 my $b = OOP::Perlish::Class::UnitTests::Bar->new();
35 1 $b->foo("Goodbye Ralph!");
36 1 is($f->foo(), 'Hello foo!', 'Multiple classes');
37 1 is($b->foo(), 'Goodbye Ralph!', 'Multiple classes');
38 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
39  
40 1 ▶ sub multiple_instances : Test(2)
Subroutine multiple_instances: called CC=1 SCAR=0.0
Pod undocumented
41 {
42 1 my ($self) = @_;
43  
44 1 my $f = OOP::Perlish::Class::UnitTests::Foo->new();
45 1 $f->foo("Hello foo!");
46  
47 1 my $ff = OOP::Perlish::Class::UnitTests::Foo->new();
48 1 $ff->foo("foo is the fooyist!");
49 1 is($f->foo(), 'Hello foo!', 'Multiple instances');
50 1 is($ff->foo(), 'foo is the fooyist!', 'Multiple instances');
51 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
52  
53 1 ▶ sub inheritance : Test(2)
Subroutine inheritance: called CC=1 SCAR=0.0
Pod undocumented
54 {
55 1 my ($self) = @_;
56  
57 1 my $fb = OOP::Perlish::Class::UnitTests::Bar::Bar->new( bar => { dodad => 'bars are great' }, foo => 'Ralph is pretty good too' );
58  
59 1 is($fb->foo(), 'Ralph is pretty good too', 'inheritance, we have foo');
60 1 is($fb->bar()->{dodad}, 'bars are great', 'inheritance, we have bar');
61 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
62  
63 1 ▶ sub overload_uniqueness : Test(4)
Subroutine overload_uniqueness: called CC=1 SCAR=0.0
Pod undocumented
64 {
65 1 my ($self) = @_;
66  
67 1 my $bfb = OOP::Perlish::Class::UnitTests::Baz::Foo::Bar->new( bar => 'bar', foo => 'foo');
68 1 my $bfbo = OOP::Perlish::Class::UnitTests::Baz::Foo::Bar::Overload->new( bar => 'Bar overloaded!' );
69  
70 1 is($bfb->foo(), 'foo', 'Multiple inheritance with overloading, non-overloaded foo');
71 1 is($bfb->bar(), 'bar', 'Multiple inheritance with overloading, non-overloaded bar');
72 1 is($bfb->baz(), 'baz', 'Multiple inheritance with overloading, non-overloaded baz');
73  
74 1 is($bfbo->bar(), 'Bar overloaded!', 'Multiple inheritance with overloading, overloaded bar');
75 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
76  
77 1 ▶ sub overload_uniqueness_reverse : Test(4)
Subroutine overload_uniqueness_reverse: called CC=1 SCAR=0.0
Pod undocumented
78 {
79 1 my ($self) = @_;
80  
81 1 my $bfbo = OOP::Perlish::Class::UnitTests::Baz::Foo::Bar::Overload->new( bar => 'Bar overloaded!' );
82 1 my $bfb = OOP::Perlish::Class::UnitTests::Baz::Foo::Bar->new( bar => 'bar', foo => 'foo');
83  
84 1 is($bfb->foo(), 'foo', 'Multiple inheritance with overloading, non-overloaded foo');
85 1 is($bfb->bar(), 'bar', 'Multiple inheritance with overloading, non-overloaded bar');
86 1 is($bfb->baz(), 'baz', 'Multiple inheritance with overloading, non-overloaded baz');
87  
88 1 is($bfbo->bar(), 'Bar overloaded!', 'Multiple inheritance with overloading, overloaded bar');
89 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
90  
91 1 ▶ sub multiple_inheritance : Test(3)
Subroutine multiple_inheritance: called CC=1 SCAR=0.0
Pod undocumented
92 {
93 1 my ($self) = @_;
94  
95 1 my $bfb = OOP::Perlish::Class::UnitTests::Baz::Foo::Bar->new( bar => 'bar', foo => 'foo');
96 1 is($bfb->foo(), 'foo', 'Multiple inheritance, foo');
97 1 is($bfb->bar(), 'bar', 'Multiple inheritance, bar');
98 1 is($bfb->baz(), 'baz', 'Multiple inheritance, baz');
99 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
100  
101  
102 1 ▶ sub value_set_derived : Test(2)
Subroutine value_set_derived: called CC=1 SCAR=0.0
Pod undocumented
103 {
104 1 my ($self) = @_;
105  
106 1 my $fred = OOP::Perlish::Class::UnitTests::Fred->new( bar => 'set this' );
107 1 ok( $fred->can('find'), 'Inherited from non-derived class' );
108 1 is($fred->bar(), 'set this', 'Value set on accessor still valid on derivded-class' );
109 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
110  
111 1 ▶ sub valid_defaults : Test(6)
Subroutine valid_defaults: called CC=1 SCAR=0.0
Pod undocumented
112 {
113 1 my ($self) = @_;
114  
115 1 my $obj;
116  
117 1 eval {
118 1 $obj = OOP::Perlish::Class::UnitTests::TestValidDefaults->new();
119 };
120 1 ok( ! "$@", 'did not croak on instantiation' );
121  
122 1 is( $obj->scalar(), 'test', 'scalar default' );
123 1 is( ($obj->array())[0], 'test', 'array default' );
124 1 is( { ($obj->hash()) }->{key}, 'test', 'hash default' );
125 1 is( $obj->code()->(), 'test', 'code default' );
126 1 ok( UNIVERSAL::isa($obj->object(), 'IO::File'), 'object default' );
127 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
128  
129 sub invalid_defaults
130 5 ▶ {
Subroutine invalid_defaults: called CC=2 SCAR=6.9
Pod undocumented
131 5 my ($self, $type) = @_;
132 5 my $classname = 'OOP::Perlish::Class::UnitTests::TestInvalidDefault' . ucfirst(lc($type));
133  
134 5 my $obj;
135  
136 5 eval {
137 5 $obj = $classname->new();
138 };
139 5 ok( "$@", 'did croak on instantiation' );
140 5 ok( "$@" =~ m/\Q$type\E/i, 'we saw the error we wanted' );
141 5 ▶ ok( "$@" =~ m#\QOOP::Perlish::Class::Accessor#gsim, 'we died from OOP::Perlish::Class::Accessor' ) || diag("$@");
Branch: 1 branch
BranchTrueFalseTotal
&ok(scalar "$@" =~ /OOP\:\:Perlish\:\:Class\:\:Accessor/gims, "we died from OOP::Perlish::Class::Accessor") or diag("$@") 5 0 5
142 5 ok( ! $obj, 'did not initialize' )
143 }
144  
145 1 ▶ sub invalid_defaults_scalar : Test(4)
Subroutine invalid_defaults_scalar: called CC=1 SCAR=0.0
Pod undocumented
146 {
147 1 my ($self) = @_;
148 1 $self->invalid_defaults('scalar');
149 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
150  
151 1 ▶ sub invalid_defaults_array : Test(4)
Subroutine invalid_defaults_array: called CC=1 SCAR=0.0
Pod undocumented
152 {
153 1 my ($self) = @_;
154 1 $self->invalid_defaults('array');
155 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
156  
157 1 ▶ sub invalid_defaults_hash : Test(4)
Subroutine invalid_defaults_hash: called CC=1 SCAR=0.0
Pod undocumented
158 {
159 1 my ($self) = @_;
160 1 $self->invalid_defaults('hash');
161 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
162  
163 1 ▶ sub invalid_defaults_code : Test(4)
Subroutine invalid_defaults_code: called CC=1 SCAR=0.0
Pod undocumented
164 {
165 1 my ($self) = @_;
166 1 $self->invalid_defaults('code');
167 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
168  
169 1 ▶ sub invalid_defaults_object : Test(4)
Subroutine invalid_defaults_object: called CC=1 SCAR=0.0
Pod undocumented
170 {
171 1 my ($self) = @_;
172 1 $self->invalid_defaults('object');
173 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
174  
175 1 ▶ sub method_overload_of_accessor : Test(1)
Subroutine method_overload_of_accessor: called CC=1 SCAR=0.0
Pod undocumented
176 {
177 1 my ($self) = @_;
178  
179 1 my $obj = OOP::Perlish::Class::UnitTests::TestAccessorOverloadingWithMethod->new( fud => 'bar' );
180 1 is( $obj->fud(), 'method, not accessor', 'we can successfully overload an accessor with a method' );
181 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
182  
183 1 ▶ sub method_overload_of_accessor_is_still_required : Test(2)
Subroutine method_overload_of_accessor_is_still_required: called CC=1 SCAR=0.0
Pod undocumented
184 {
185 1 my ($self) = @_;
186 1 eval {
187 1 my $obj = OOP::Perlish::Class::UnitTests::TestAccessorOverloadingWithMethod->new();
188 };
189  
190 1 ok( "$@", 'We died, presumably because of the missing required' );
191 1 ok( "$@" =~ m/Missing required/, 'Yep, missing required' );
192 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
193  
194 1 ▶ sub accessor_required : Test(2)
Subroutine accessor_required: called CC=1 SCAR=0.0
Pod undocumented
195 {
196 1 my ($self) = @_;
197 1 eval {
198 1 my $obj = OOP::Perlish::Class::UnitTests::TestRequired->new();
199 };
200  
201 1 ok( "$@", 'We died, presumably because of the missing required' );
202 1 ok( "$@" =~ m/Missing required/, 'Yep, missing required' );
203 1 ▶ }
Subroutine BEGIN: called CC=1 SCAR=0.0
204  
205 }
206 1 1;
207  
208 =head1 NAME
209  
210 =head1 VERSION
211  
212 =head1 SYNOPSIS
213  
214 =head1 METHODS
215  
216 =head1 AUTHOR
217  
218 Jamie Beverly, C<< <jbeverly at cpan.org> >>
219  
220 =head1 BUGS
221  
222 Please report any bugs or feature requests to C<bug-foo-bar at rt.cpan.org>,
223 or through
224 the web interface at
225 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=OOP-Perlish-Class>. I will be
226 notified, and then you'll
227 automatically be notified of progress on your bug as I make changes.
228  
229 =head1 SUPPORT
230  
231 You can find documentation for this module with the perldoc command.
232  
233 perldoc OOP::Perlish::Class
234  
235  
236 You can also look for information at:
237  
238 =over 4
239  
240 =item * RT: CPAN's request tracker
241  
242 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=OOP-Perlish-Class>
243  
244 =item * AnnoCPAN: Annotated CPAN documentation
245  
246 L<http://annocpan.org/dist/OOP-Perlish-Class>
247  
248 =item * CPAN Ratings
249  
250 L<http://cpanratings.perl.org/d/OOP-Perlish-Class>
251  
252 =item * Search CPAN
253  
254 L<http://search.cpan.org/dist/OOP-Perlish-Class/>
255  
256 =back
257  
258  
259 =head1 ACKNOWLEDGEMENTS
260  
261 =head1 COPYRIGHT & LICENSE
262  
263 Copyright 2009 Jamie Beverly
264  
265 This program is free software; you can redistribute it and/or modify it
266 under the terms of either: the GNU General Public License as published
267 by the Free Software Foundation; or the Artistic License.
268  
269 See http://dev.perl.org/licenses/ for more information.
270  
271 =cut
« Class/Singleton/UnitTests/Singleton.pm ↑ Summary Class/Abstract/UnitTests/Interfaces.pm »