line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DDG::Test::Goodie; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:DDG'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Adds keywords to easily test Goodie plugins. |
4
|
|
|
|
|
|
|
$DDG::Test::Goodie::VERSION = '1017'; |
5
|
4
|
|
|
4
|
|
50077
|
use strict; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
103
|
|
6
|
4
|
|
|
4
|
|
21
|
use warnings; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
93
|
|
7
|
4
|
|
|
4
|
|
18
|
use Carp; |
|
4
|
|
|
|
|
23
|
|
|
4
|
|
|
|
|
217
|
|
8
|
4
|
|
|
4
|
|
22
|
use Test::More; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
22
|
|
9
|
4
|
|
|
4
|
|
2940
|
use Test::Deep; |
|
4
|
|
|
|
|
33656
|
|
|
4
|
|
|
|
|
29
|
|
10
|
4
|
|
|
4
|
|
2224
|
use DDG::Test::Block; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
16
|
|
11
|
4
|
|
|
4
|
|
981
|
use DDG::ZeroClickInfo; |
|
4
|
|
|
|
|
17
|
|
|
4
|
|
|
|
|
133
|
|
12
|
4
|
|
|
4
|
|
27
|
use Package::Stash; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
1455
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
binmode STDOUT, ':utf8'; |
15
|
|
|
|
|
|
|
binmode Test::More->builder->output, ':utf8'; |
16
|
|
|
|
|
|
|
binmode Test::More->builder->failure_output, ':utf8'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub import { |
20
|
4
|
|
|
4
|
|
36
|
my ( $class, %params ) = @_; |
21
|
4
|
|
|
|
|
9
|
my $target = caller; |
22
|
4
|
|
|
|
|
40
|
my $stash = Package::Stash->new($target); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
9
|
my %zci_params; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
$stash->add_symbol('&test_zci', sub { |
28
|
8
|
|
|
8
|
|
6920
|
my $answer = shift; |
29
|
|
|
|
|
|
|
ref $_[0] eq 'HASH' ? |
30
|
8
|
50
|
|
|
|
134
|
DDG::ZeroClickInfo->new(%zci_params, %{$_[0]}, answer => $answer ) : |
|
0
|
|
|
|
|
0
|
|
31
|
|
|
|
|
|
|
DDG::ZeroClickInfo->new(%zci_params, @_, answer => $answer ) |
32
|
4
|
|
|
|
|
59
|
}); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$stash->add_symbol('&zci', sub { |
36
|
2
|
50
|
|
2
|
|
22
|
if (ref $_[0] eq 'HASH') { |
37
|
0
|
|
|
|
|
0
|
for (keys %{$_[0]}) { |
|
0
|
|
|
|
|
0
|
|
38
|
0
|
|
|
|
|
0
|
$zci_params{$_} = $_[0]->{$_}; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
} else { |
41
|
2
|
|
|
|
|
9
|
while (@_) { |
42
|
2
|
|
|
|
|
6
|
my $key = shift; |
43
|
2
|
|
|
|
|
5
|
my $value = shift; |
44
|
2
|
|
|
|
|
12
|
$zci_params{$key} = $value; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
} |
47
|
4
|
|
|
|
|
28
|
}); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$stash->add_symbol('&ddg_goodie_test', sub { block_test(sub { |
51
|
8
|
|
|
8
|
|
19
|
my ($query, $answer, $zci) = @_; |
52
|
|
|
|
|
|
|
subtest "Query: $query" => sub { |
53
|
8
|
50
|
|
|
|
6200
|
if ($answer) { |
54
|
8
|
|
|
|
|
39
|
$zci->{caller} = $answer->caller; # TODO: Review all this cheating; seriously. |
55
|
8
|
|
|
|
|
37
|
cmp_deeply($answer,$zci,'Deep: full ZCI object'); |
56
|
|
|
|
|
|
|
} else { |
57
|
0
|
0
|
|
|
|
|
fail('Expected result but dont get one on '.$query) unless defined $answer; |
58
|
|
|
|
|
|
|
} |
59
|
8
|
|
|
|
|
60
|
}; |
60
|
6
|
|
|
6
|
|
87
|
},@_) |
61
|
4
|
|
|
|
|
106
|
}); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
__END__ |