|
Revision 2583, 1.0 kB
(checked in by mpaschal, 18 months ago)
|
|
Add Test::Deep to t/lib, since we already use it in driver-tests.pl
BugzID: 79953
|
| Line | |
|---|
| 1 | use strict; |
|---|
| 2 | use warnings; |
|---|
| 3 | |
|---|
| 4 | package Test::Deep::Cache; |
|---|
| 5 | |
|---|
| 6 | use Test::Deep::Cache::Simple; |
|---|
| 7 | |
|---|
| 8 | sub new |
|---|
| 9 | { |
|---|
| 10 | my $pkg = shift; |
|---|
| 11 | |
|---|
| 12 | my $self = bless {}, $pkg; |
|---|
| 13 | |
|---|
| 14 | $self->{expects} = [Test::Deep::Cache::Simple->new]; |
|---|
| 15 | $self->{normal} = [Test::Deep::Cache::Simple->new]; |
|---|
| 16 | |
|---|
| 17 | $self->local; |
|---|
| 18 | |
|---|
| 19 | return $self; |
|---|
| 20 | } |
|---|
| 21 | |
|---|
| 22 | sub add |
|---|
| 23 | { |
|---|
| 24 | my $self = shift; |
|---|
| 25 | |
|---|
| 26 | my $type = $self->type; |
|---|
| 27 | |
|---|
| 28 | $self->{$type}->[-1]->add(@_); |
|---|
| 29 | } |
|---|
| 30 | |
|---|
| 31 | sub cmp |
|---|
| 32 | { |
|---|
| 33 | # go through all the caches to see if we know this one |
|---|
| 34 | |
|---|
| 35 | my $self = shift; |
|---|
| 36 | |
|---|
| 37 | my $type = $self->type; |
|---|
| 38 | |
|---|
| 39 | foreach my $cache (@{$self->{$type}}) |
|---|
| 40 | { |
|---|
| 41 | return 1 if $cache->cmp(@_); |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | return 0 |
|---|
| 45 | } |
|---|
| 46 | |
|---|
| 47 | sub local |
|---|
| 48 | { |
|---|
| 49 | my $self = shift; |
|---|
| 50 | |
|---|
| 51 | foreach my $type (qw( expects normal )) |
|---|
| 52 | { |
|---|
| 53 | push(@{$self->{$type}}, Test::Deep::Cache::Simple->new); |
|---|
| 54 | } |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | sub finish |
|---|
| 58 | { |
|---|
| 59 | my $self = shift; |
|---|
| 60 | |
|---|
| 61 | my $keep = shift; |
|---|
| 62 | |
|---|
| 63 | foreach my $type (qw( expects normal )) |
|---|
| 64 | { |
|---|
| 65 | my $caches = $self->{$type}; |
|---|
| 66 | |
|---|
| 67 | my $last = pop @$caches; |
|---|
| 68 | |
|---|
| 69 | $caches->[-1]->absorb($last) if $keep; |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | sub type |
|---|
| 74 | { |
|---|
| 75 | return $Test::Deep::Expects ? "expects" : "normal"; |
|---|
| 76 | } |
|---|
| 77 | |
|---|
| 78 | 1; |
|---|