line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::JsonAPI::Autodoc; |
2
|
15
|
|
|
15
|
|
1112138
|
use 5.008005; |
|
15
|
|
|
|
|
47
|
|
|
15
|
|
|
|
|
491
|
|
3
|
15
|
|
|
15
|
|
89
|
use strict; |
|
15
|
|
|
|
|
23
|
|
|
15
|
|
|
|
|
437
|
|
4
|
15
|
|
|
15
|
|
61
|
use warnings; |
|
15
|
|
|
|
|
45
|
|
|
15
|
|
|
|
|
432
|
|
5
|
15
|
|
|
15
|
|
5920
|
use parent qw/Exporter/; |
|
15
|
|
|
|
|
3171
|
|
|
15
|
|
|
|
|
81
|
|
6
|
15
|
|
|
15
|
|
660
|
use Carp; |
|
15
|
|
|
|
|
23
|
|
|
15
|
|
|
|
|
1054
|
|
7
|
15
|
|
|
15
|
|
63
|
use Test::More (); |
|
15
|
|
|
|
|
23
|
|
|
15
|
|
|
|
|
179
|
|
8
|
15
|
|
|
15
|
|
8161
|
use Scope::Guard; |
|
15
|
|
|
|
|
5509
|
|
|
15
|
|
|
|
|
622
|
|
9
|
15
|
|
|
15
|
|
3361
|
use LWP::UserAgent; |
|
15
|
|
|
|
|
117144
|
|
|
15
|
|
|
|
|
382
|
|
10
|
15
|
|
|
15
|
|
6003
|
use Test::JsonAPI::Autodoc::Markdown; |
|
15
|
|
|
|
|
45
|
|
|
15
|
|
|
|
|
413
|
|
11
|
15
|
|
|
15
|
|
5597
|
use Test::JsonAPI::Autodoc::Request; |
|
15
|
|
|
|
|
35
|
|
|
15
|
|
|
|
|
543
|
|
12
|
15
|
|
|
15
|
|
6332
|
use Test::JsonAPI::Autodoc::Response; |
|
15
|
|
|
|
|
32
|
|
|
15
|
|
|
|
|
987
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT = qw/ |
15
|
|
|
|
|
|
|
describe |
16
|
|
|
|
|
|
|
http_ok |
17
|
|
|
|
|
|
|
plack_ok |
18
|
|
|
|
|
|
|
set_documents_path |
19
|
|
|
|
|
|
|
set_template |
20
|
|
|
|
|
|
|
/; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = "0.22"; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $in_describe; |
25
|
|
|
|
|
|
|
my $results; |
26
|
|
|
|
|
|
|
my $first_time; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $output_path; |
29
|
|
|
|
|
|
|
my $template; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
BEGIN { |
32
|
15
|
|
|
15
|
|
7500
|
$first_time = 1; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub set_documents_path { |
36
|
13
|
|
|
13
|
1
|
165174
|
$output_path = shift; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub set_template { |
40
|
1
|
|
|
1
|
1
|
8
|
$template = shift; |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub describe { |
44
|
18
|
50
|
|
18
|
1
|
38645
|
if ($in_describe) { |
45
|
0
|
|
|
|
|
0
|
croak '`describe` must not call as nesting'; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
my $guard = sub { |
49
|
|
|
|
|
|
|
return Scope::Guard->new(sub { |
50
|
18
|
|
|
|
|
205
|
undef $in_describe; |
51
|
18
|
|
|
|
|
29
|
undef $results; |
52
|
18
|
|
|
|
|
250
|
undef $first_time; |
53
|
18
|
|
|
18
|
|
204
|
}); |
54
|
18
|
|
|
|
|
107
|
}->(); |
55
|
|
|
|
|
|
|
|
56
|
18
|
|
|
|
|
251
|
$in_describe = 1; |
57
|
|
|
|
|
|
|
|
58
|
18
|
|
|
|
|
43
|
my ($description, $coderef) = @_; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# change location of test failure to be included Test::More's output |
61
|
|
|
|
|
|
|
# to be more helpful to user. |
62
|
18
|
|
|
|
|
45
|
local $Test::Builder::Level = $Test::Builder::Level + 1; |
63
|
|
|
|
|
|
|
|
64
|
18
|
|
|
|
|
89
|
my $result = Test::More::subtest($description => $coderef); |
65
|
|
|
|
|
|
|
|
66
|
18
|
100
|
66
|
|
|
15813
|
if ($result && $results && $ENV{TEST_JSONAPI_AUTODOC}) { |
|
|
|
100
|
|
|
|
|
67
|
16
|
|
|
|
|
156
|
my $markdown = Test::JsonAPI::Autodoc::Markdown->new($output_path, $template); |
68
|
16
|
|
|
|
|
74
|
$markdown->generate($description, $results, $first_time); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub http_ok { |
73
|
12
|
|
|
12
|
1
|
66962
|
my ($req, $expected_code, $note) = @_; |
74
|
12
|
|
|
|
|
54
|
return _api_ok($req, $expected_code, $note); |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub plack_ok { |
78
|
6
|
|
|
6
|
1
|
16270
|
my ($plack_app, $req, $expected_code, $note) = @_; |
79
|
6
|
|
|
|
|
23
|
return _api_ok($req, $expected_code, $note, $plack_app); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub _api_ok { |
83
|
18
|
|
|
18
|
|
39
|
my ($req, $expected_code, $note, $plack_app) = @_; |
84
|
|
|
|
|
|
|
|
85
|
18
|
|
|
|
|
28
|
my $description = $note; |
86
|
18
|
|
|
|
|
39
|
my $param_description = {}; |
87
|
18
|
100
|
|
|
|
78
|
if (ref $note eq 'HASH') { |
88
|
1
|
|
|
|
|
3
|
$description = $note->{description}; |
89
|
1
|
|
|
|
|
3
|
$param_description = $note->{param_description}; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
18
|
|
|
|
|
42
|
my $res; |
93
|
18
|
|
|
|
|
30
|
my $is_plack_app = 0; |
94
|
18
|
100
|
|
|
|
65
|
if ($plack_app) { # for Plack::Test |
95
|
6
|
100
|
|
|
|
31
|
$res = ref $plack_app eq 'CODE' ? $plack_app->($req) # use `test_psgi` |
96
|
|
|
|
|
|
|
: $plack_app->request($req); # not use `test_psgi` |
97
|
6
|
|
|
|
|
17401
|
$is_plack_app = 1; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
else { |
100
|
12
|
|
|
|
|
130
|
$res = LWP::UserAgent->new->request($req); |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# change location of test failure to be included Test::More's output |
104
|
|
|
|
|
|
|
# to be more helpful to user. |
105
|
18
|
|
|
|
|
31956
|
local $Test::Builder::Level = $Test::Builder::Level + 2; |
106
|
|
|
|
|
|
|
|
107
|
18
|
|
|
|
|
72
|
my $result = Test::More::is $res->code, $expected_code; |
108
|
18
|
50
|
|
|
|
10177
|
return unless $result; |
109
|
18
|
100
|
|
|
|
91
|
return unless $in_describe; |
110
|
|
|
|
|
|
|
|
111
|
17
|
|
|
|
|
173
|
my $parsed_request = Test::JsonAPI::Autodoc::Request->new->parse($req, $param_description); |
112
|
17
|
|
|
|
|
753
|
my $parsed_response = Test::JsonAPI::Autodoc::Response->new->parse($res); |
113
|
|
|
|
|
|
|
|
114
|
17
|
|
|
|
|
143
|
my $response_body = $parsed_response->{body}; |
115
|
17
|
|
|
|
|
233
|
my $response_content_type = $parsed_response->{content_type}; |
116
|
|
|
|
|
|
|
|
117
|
17
|
|
|
|
|
229
|
push @$results, { |
118
|
|
|
|
|
|
|
note => $description, |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
path => $parsed_request->{path}, |
121
|
|
|
|
|
|
|
server => $parsed_request->{server}, |
122
|
|
|
|
|
|
|
method => $parsed_request->{method}, |
123
|
|
|
|
|
|
|
query => $parsed_request->{query}, |
124
|
|
|
|
|
|
|
request_content_type => $parsed_request->{content_type}, |
125
|
|
|
|
|
|
|
request_parameters => $parsed_request->{parameters}, |
126
|
|
|
|
|
|
|
is_plack_app => $is_plack_app, |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
status => $expected_code, |
129
|
|
|
|
|
|
|
response_body => $response_body, |
130
|
|
|
|
|
|
|
response_content_type => $response_content_type, |
131
|
|
|
|
|
|
|
}; |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
return +{ |
134
|
17
|
|
|
|
|
228
|
status => $expected_code, |
135
|
|
|
|
|
|
|
body => $response_body, |
136
|
|
|
|
|
|
|
content_type => $response_content_type, |
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
1; |
140
|
|
|
|
|
|
|
__END__ |