File Coverage

blib/lib/OOP/Perlish/Class/UnitTests/Class.pm
Criterion Covered Total %
statement 164 164 100.0
branch 1 2 50.0
condition n/a
subroutine 44 44 100.0
pod 0 19 0.0
total 209 229 91.2


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2 1     1   6 use warnings;
  1         3  
  1         34  
3 1     1   6 use strict;
  1         2  
  1         43  
4             {
5             package OOP::Perlish::Class::UnitTests::Class;
6 1     1   4 use warnings;
  1         2  
  1         30  
7 1     1   5 use strict;
  1         2  
  1         20  
8 1     1   4 use OOP::Perlish::Class::UnitTests::Base;
  1         2  
  1         35  
9 1     1   6 use base qw(OOP::Perlish::Class::UnitTests::Base);
  1         2  
  1         64  
10 1     1   5 use Test::More;
  1         2  
  1         11  
11              
12             sub setup : Test(setup)
13             {
14 17     17 0 12256 my ($self) = @_;
15 17         55 undef $@;
16 1     1   262 }
  1         1  
  1         4  
17              
18             sub class_assignment : Test(1)
19             {
20 1     1 0 136 my ($self) = @_;
21              
22 1         13 my $f = OOP::Perlish::Class::UnitTests::Foo->new();
23 1         6 $f->foo("Hello foo!");
24 1         5 is($f->foo(), 'Hello foo!', 'Class assignment');
25 1     1   320 }
  1         3  
  1         3  
26              
27             sub multiple_classes : Test(2)
28             {
29 1     1 0 109 my ($self) = @_;
30              
31 1         7 my $f = OOP::Perlish::Class::UnitTests::Foo->new();
32 1         5 $f->foo("Hello foo!");
33              
34 1         13 my $b = OOP::Perlish::Class::UnitTests::Bar->new();
35 1         4 $b->foo("Goodbye Ralph!");
36 1         6 is($f->foo(), 'Hello foo!', 'Multiple classes');
37 1         508 is($b->foo(), 'Goodbye Ralph!', 'Multiple classes');
38 1     1   314 }
  1         3  
  1         5  
39              
40             sub multiple_instances : Test(2)
41             {
42 1     1 0 104 my ($self) = @_;
43              
44 1         7 my $f = OOP::Perlish::Class::UnitTests::Foo->new();
45 1         6 $f->foo("Hello foo!");
46              
47 1         6 my $ff = OOP::Perlish::Class::UnitTests::Foo->new();
48 1         4 $ff->foo("foo is the fooyist!");
49 1         6 is($f->foo(), 'Hello foo!', 'Multiple instances');
50 1         423 is($ff->foo(), 'foo is the fooyist!', 'Multiple instances');
51 1     1   259 }
  1         2  
  1         29  
52              
53             sub inheritance : Test(2)
54             {
55 1     1 0 129 my ($self) = @_;
56              
57 1         16 my $fb = OOP::Perlish::Class::UnitTests::Bar::Bar->new( bar => { dodad => 'bars are great' }, foo => 'Ralph is pretty good too' );
58              
59 1         5 is($fb->foo(), 'Ralph is pretty good too', 'inheritance, we have foo');
60 1         566 is($fb->bar()->{dodad}, 'bars are great', 'inheritance, we have bar');
61 1     1   229 }
  1         3  
  1         4  
62              
63             sub overload_uniqueness : Test(4)
64             {
65 1     1 0 103 my ($self) = @_;
66              
67 1         9 my $bfb = OOP::Perlish::Class::UnitTests::Baz::Foo::Bar->new( bar => 'bar', foo => 'foo');
68 1         17 my $bfbo = OOP::Perlish::Class::UnitTests::Baz::Foo::Bar::Overload->new( bar => 'Bar overloaded!' );
69              
70 1         7 is($bfb->foo(), 'foo', 'Multiple inheritance with overloading, non-overloaded foo');
71 1         693 is($bfb->bar(), 'bar', 'Multiple inheritance with overloading, non-overloaded bar');
72 1         480 is($bfb->baz(), 'baz', 'Multiple inheritance with overloading, non-overloaded baz');
73              
74 1         516 is($bfbo->bar(), 'Bar overloaded!', 'Multiple inheritance with overloading, overloaded bar');
75 1     1   302 }
  1         2  
  1         5  
76              
77             sub overload_uniqueness_reverse : Test(4)
78             {
79 1     1 0 142 my ($self) = @_;
80              
81 1         17 my $bfbo = OOP::Perlish::Class::UnitTests::Baz::Foo::Bar::Overload->new( bar => 'Bar overloaded!' );
82 1         10 my $bfb = OOP::Perlish::Class::UnitTests::Baz::Foo::Bar->new( bar => 'bar', foo => 'foo');
83              
84 1         5 is($bfb->foo(), 'foo', 'Multiple inheritance with overloading, non-overloaded foo');
85 1         622 is($bfb->bar(), 'bar', 'Multiple inheritance with overloading, non-overloaded bar');
86 1         410 is($bfb->baz(), 'baz', 'Multiple inheritance with overloading, non-overloaded baz');
87              
88 1         410 is($bfbo->bar(), 'Bar overloaded!', 'Multiple inheritance with overloading, overloaded bar');
89 1     1   310 }
  1         2  
  1         4  
90              
91             sub multiple_inheritance : Test(3)
92             {
93 1     1 0 120 my ($self) = @_;
94              
95 1         15 my $bfb = OOP::Perlish::Class::UnitTests::Baz::Foo::Bar->new( bar => 'bar', foo => 'foo');
96 1         5 is($bfb->foo(), 'foo', 'Multiple inheritance, foo');
97 1         500 is($bfb->bar(), 'bar', 'Multiple inheritance, bar');
98 1         340 is($bfb->baz(), 'baz', 'Multiple inheritance, baz');
99 1     1   311 }
  1         2  
  1         5  
100              
101              
102             sub value_set_derived : Test(2)
103             {
104 1     1 0 126 my ($self) = @_;
105              
106 1         15 my $fred = OOP::Perlish::Class::UnitTests::Fred->new( bar => 'set this' );
107 1         9 ok( $fred->can('find'), 'Inherited from non-derived class' );
108 1         662 is($fred->bar(), 'set this', 'Value set on accessor still valid on derivded-class' );
109 1     1   290 }
  1         15  
  1         5  
110              
111             sub valid_defaults : Test(6)
112             {
113 1     1 0 118 my ($self) = @_;
114              
115 1         2 my $obj;
116              
117 1         2 eval {
118 1         17 $obj = OOP::Perlish::Class::UnitTests::TestValidDefaults->new();
119             };
120 1         17 ok( ! "$@", 'did not croak on instantiation' );
121              
122 1         638 is( $obj->scalar(), 'test', 'scalar default' );
123 1         428 is( ($obj->array())[0], 'test', 'array default' );
124 1         457 is( { ($obj->hash()) }->{key}, 'test', 'hash default' );
125 1         421 is( $obj->code()->(), 'test', 'code default' );
126 1         416 ok( UNIVERSAL::isa($obj->object(), 'IO::File'), 'object default' );
127 1     1   402 }
  1         2  
  1         9  
128              
129             sub invalid_defaults
130             {
131 5     5 0 13 my ($self, $type) = @_;
132 5         25 my $classname = 'OOP::Perlish::Class::UnitTests::TestInvalidDefault' . ucfirst(lc($type));
133              
134 5         8 my $obj;
135              
136 5         7 eval {
137 5         67 $obj = $classname->new();
138             };
139 5         2907 ok( "$@", 'did croak on instantiation' );
140 5         2757 ok( "$@" =~ m/\Q$type\E/i, 'we saw the error we wanted' );
141 5 50       2151 ok( "$@" =~ m#\QOOP::Perlish::Class::Accessor#gsim, 'we died from OOP::Perlish::Class::Accessor' ) || diag("$@");
142 5         2146 ok( ! $obj, 'did not initialize' )
143             }
144              
145             sub invalid_defaults_scalar : Test(4)
146             {
147 1     1 0 116 my ($self) = @_;
148 1         3 $self->invalid_defaults('scalar');
149 1     1   381 }
  1         3  
  1         5  
150              
151             sub invalid_defaults_array : Test(4)
152             {
153 1     1 0 119 my ($self) = @_;
154 1         5 $self->invalid_defaults('array');
155 1     1   232 }
  1         3  
  1         4  
156              
157             sub invalid_defaults_hash : Test(4)
158             {
159 1     1 0 158 my ($self) = @_;
160 1         6 $self->invalid_defaults('hash');
161 1     1   228 }
  1         2  
  1         5  
162              
163             sub invalid_defaults_code : Test(4)
164             {
165 1     1 0 167 my ($self) = @_;
166 1         7 $self->invalid_defaults('code');
167 1     1   221 }
  1         2  
  1         4  
168              
169             sub invalid_defaults_object : Test(4)
170             {
171 1     1 0 107 my ($self) = @_;
172 1         3 $self->invalid_defaults('object');
173 1     1   205 }
  1         2  
  1         4  
174              
175             sub method_overload_of_accessor : Test(1)
176             {
177 1     1 0 121 my ($self) = @_;
178              
179 1         15 my $obj = OOP::Perlish::Class::UnitTests::TestAccessorOverloadingWithMethod->new( fud => 'bar' );
180 1         5 is( $obj->fud(), 'method, not accessor', 'we can successfully overload an accessor with a method' );
181 1     1   258 }
  1         6  
  1         4  
182              
183             sub method_overload_of_accessor_is_still_required : Test(2)
184             {
185 1     1 0 106 my ($self) = @_;
186 1         2 eval {
187 1         7 my $obj = OOP::Perlish::Class::UnitTests::TestAccessorOverloadingWithMethod->new();
188             };
189              
190 1         342 ok( "$@", 'We died, presumably because of the missing required' );
191 1         397 ok( "$@" =~ m/Missing required/, 'Yep, missing required' );
192 1     1   264 }
  1         2  
  1         3  
193              
194             sub accessor_required : Test(2)
195             {
196 1     1 0 3603 my ($self) = @_;
197 1         3 eval {
198 1         19 my $obj = OOP::Perlish::Class::UnitTests::TestRequired->new();
199             };
200              
201 1         464 ok( "$@", 'We died, presumably because of the missing required' );
202 1         679 ok( "$@" =~ m/Missing required/, 'Yep, missing required' );
203 1     1   266 }
  1         2  
  1         3  
204              
205             }
206             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<< >>
219              
220             =head1 BUGS
221              
222             Please report any bugs or feature requests to C,
223             or through
224             the web interface at
225             L. 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
243              
244             =item * AnnoCPAN: Annotated CPAN documentation
245              
246             L
247              
248             =item * CPAN Ratings
249              
250             L
251              
252             =item * Search CPAN
253              
254             L
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