| 1 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Test::Expectation; | ||||||||||
| 5 | |||||||||||
| 6 | 2 | our $VERSION = 0.06; | |||||||||
| 7 | |||||||||||
| 8 | 2 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 2 | ▶ | use Test::More 'no_plan'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 2 | ▶ | use Test::Expectation::Positive; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use Test::Expectation::Negative; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 2 | require Exporter; | |||||||||
| 14 | 2 | ▶ | use vars qw(@EXPORT @ISA); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 2 | @ISA = qw(Exporter); | |||||||||
| 16 | 2 | @EXPORT = qw(it_should before_each after_each it_is_a); | |||||||||
| 17 | |||||||||||
| 18 | 2 | our @Expectations; | |||||||||
| 19 | 2 | our $Description = ''; | |||||||||
| 20 | 2 | ▶ | our $BeforeEach = sub {}; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 21 | 2 | ▶ | our $AfterEach = sub {}; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 2 | ▶ | sub it_is_a { | ||||||||
|
Subroutine
it_is_a: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 24 | 2 | $Description = shift; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 1 | ▶ | sub before_each { | ||||||||
|
Subroutine
before_each: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 28 | 1 | $BeforeEach = shift; | |||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | 1 | ▶ | sub after_each { | ||||||||
|
Subroutine
after_each: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 32 | 1 | $AfterEach = shift; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | 11 | ▶ | sub it_should { | ||||||||
|
Subroutine
it_should: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||
| 36 | 11 | my ($testName, $testRef) = @_; | |||||||||
| 37 | |||||||||||
| 38 | 11 | @Expectations = (); | |||||||||
| 39 | 11 | $BeforeEach->(); | |||||||||
| 40 | |||||||||||
| 41 | 11 | $testRef->(); | |||||||||
| 42 | |||||||||||
| 43 | 11 | $AfterEach->(); | |||||||||
| 44 | |||||||||||
| 45 | 11 | foreach my $expectation (@Expectations) { | |||||||||
| 46 | 12 | ▶ | my $testString = ($Description ? $Description . " " : 'it ') . "should $testName"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 47 | |||||||||||
| 48 | 12 | ▶ | if ($expectation->isMet()) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 12 | pass($testString); | |||||||||
| 50 | } | ||||||||||
| 51 | else { | ||||||||||
| 52 | 0 | fail($testString . ' (' . $expectation->failure . ')'); | |||||||||
| 53 | } | ||||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 11 | @Expectations = (); | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | 17 | ▶ | *UNIVERSAL::_bindExpectation = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 60 | 17 | my ($expectationType, $class, $method) = @_; | |||||||||
| 61 | |||||||||||
| 62 | 17 | my $expectation = $expectationType->new($class, $method); | |||||||||
| 63 | |||||||||||
| 64 | 17 | push(@Expectations, $expectation); | |||||||||
| 65 | 17 | return $expectation | |||||||||
| 66 | 2 | }; | |||||||||
| 67 | |||||||||||
| 68 | 15 | ▶ | *UNIVERSAL::expects = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 69 | 15 | UNIVERSAL::_bindExpectation('Test::Expectation::Positive', @_); | |||||||||
| 70 | 2 | }; | |||||||||
| 71 | |||||||||||
| 72 | 2 | ▶ | *UNIVERSAL::does_not_expect = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 73 | 2 | UNIVERSAL::_bindExpectation('Test::Expectation::Negative', @_); | |||||||||
| 74 | 2 | }; | |||||||||
| 75 | |||||||||||
| 76 | 2 | 1; | |||||||||
| 77 | |||||||||||
| 78 | __END__ | ||||||||||