line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::V8x::TestMoreish; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
491852
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
548
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
353
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
JavaScript::V8x::TestMoreish - Run and test JavaScript code in Perl using Test::More and v8 |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.013 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.013'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
use Test::More |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
plan qw/no_plan/ |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
is( 1, 1 ) |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
use JavaScript::V8x::TestMoreish |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
test_js( <<'_END_' ) |
29
|
|
|
|
|
|
|
diag( "Hello, World." ); |
30
|
|
|
|
|
|
|
areEqual( 1, 1 ); |
31
|
|
|
|
|
|
|
areEqual( 1, 2 ); |
32
|
|
|
|
|
|
|
like( "Hello, World.", /o, World/ ) |
33
|
|
|
|
|
|
|
like( "Hello, World.", /Alice/ ) |
34
|
|
|
|
|
|
|
_END_ |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 DESCRIPTION |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
JavaScript::V8x::TestMoreish uses the Google V8 JavaScript engine (via L) to execute JavaScript code on demand in Perl. In addition, the customized context binds some functions that expose parts of Test::More to facillate testing. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
An installation of C (for L) is required. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
You can interleave regular Test::More tests and JavaScript tests as usual. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 JavaScript USAGE |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 diag( $message ) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
"Print" $message as Test::More does with diag |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 areEqual( $got, $expected, $name ) |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$got == $expected |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head2 like( $got, $match, $name ) |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
isValue( $got ) && isString( $got ) && $got.match( $match ) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 USAGE |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 test_js( $js ) |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Evaluate $js in a Test::More-ish context (see JavaScript USAGE for available functionality) |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=cut |
65
|
|
|
|
|
|
|
|
66
|
1
|
|
|
1
|
|
2042
|
use Any::Moose; |
|
1
|
|
|
|
|
74634
|
|
|
1
|
|
|
|
|
6
|
|
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
1
|
|
1661
|
use JavaScript::V8x::TestMoreish::JS; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
1
|
|
2015
|
use JavaScript::V8; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
use Path::Abstract; |
72
|
|
|
|
|
|
|
use Test::Builder(); |
73
|
|
|
|
|
|
|
use Sub::Exporter -setup => { |
74
|
|
|
|
|
|
|
exports => [ |
75
|
|
|
|
|
|
|
test_js => sub { sub { local $Test::Builder::Level = $Test::Builder::Level + 2; return __test_js( @_ ) } }, |
76
|
|
|
|
|
|
|
test_js_tester => sub { sub { return __test_js_tester( @_ ) } }, |
77
|
|
|
|
|
|
|
test_js_bind => sub { sub { return __test_js_bind( @_ ) } }, |
78
|
|
|
|
|
|
|
test_js_eval => sub { sub { local $Test::Builder::Level = $Test::Builder::Level + 2; return __test_js_eval( @_ ) } }, |
79
|
|
|
|
|
|
|
], |
80
|
|
|
|
|
|
|
groups => { |
81
|
|
|
|
|
|
|
default => [qw/ test_js test_js_tester test_js_bind test_js_eval /], |
82
|
|
|
|
|
|
|
}, |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $__tester; |
86
|
|
|
|
|
|
|
sub __test_js_tester { return $__tester ||= __PACKAGE__->new } |
87
|
|
|
|
|
|
|
sub __test_js { return __test_js_tester->test( @_ ) } |
88
|
|
|
|
|
|
|
sub __test_js_bind { return __test_js_tester->bind( @_ ) } |
89
|
|
|
|
|
|
|
sub __test_js_eval { return __test_js_tester->eval( @_ ) } |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
has context => qw/is ro lazy_build 1/; |
93
|
|
|
|
|
|
|
sub _build_context { |
94
|
|
|
|
|
|
|
return JavaScript::V8::Context->new(); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
has builder => qw/is ro lazy_build 1/; |
98
|
|
|
|
|
|
|
sub _build_builder { |
99
|
|
|
|
|
|
|
require Test::More; |
100
|
|
|
|
|
|
|
return Test::More->builder; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub BUILD { |
104
|
|
|
|
|
|
|
my $self = shift; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
$self->bind( |
107
|
|
|
|
|
|
|
_TestMoreish_diag => sub { Test::More->builder->diag( @_ ) }, |
108
|
|
|
|
|
|
|
_TestMoreish_ok => sub { Test::More->builder->ok( @_ ) }, |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
$self->eval( JavaScript::V8x::TestMoreish::JS->TestMoreish ); |
112
|
|
|
|
|
|
|
$self->eval( <<'_END_' ); |
113
|
|
|
|
|
|
|
if (! TestMoreish) |
114
|
|
|
|
|
|
|
var TestMoreish = _TestMoreish; |
115
|
|
|
|
|
|
|
_END_ |
116
|
|
|
|
|
|
|
$self->eval( join "\n", map { "function $_() { TestMoreish.$_.apply( TestMoreish, arguments ) }" } split m/\n+/, <<_END_ ); |
117
|
|
|
|
|
|
|
diag |
118
|
|
|
|
|
|
|
areEqual |
119
|
|
|
|
|
|
|
areNotEqual |
120
|
|
|
|
|
|
|
areSame |
121
|
|
|
|
|
|
|
areNotSame |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
isTrue |
124
|
|
|
|
|
|
|
isFalse |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
isString |
127
|
|
|
|
|
|
|
isValue |
128
|
|
|
|
|
|
|
isObject |
129
|
|
|
|
|
|
|
isNumber |
130
|
|
|
|
|
|
|
isBoolean |
131
|
|
|
|
|
|
|
isFunction |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
like |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
fail |
136
|
|
|
|
|
|
|
_END_ |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub bind { |
140
|
|
|
|
|
|
|
my $self = shift; |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
while( @_ ) { |
143
|
|
|
|
|
|
|
$self->context->bind_function( shift, shift ); |
144
|
|
|
|
|
|
|
} |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub eval { |
148
|
|
|
|
|
|
|
my $self = shift; |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# TODO TryCatch? |
151
|
|
|
|
|
|
|
local $@ = undef; |
152
|
|
|
|
|
|
|
$self->context->eval( @_ ); |
153
|
|
|
|
|
|
|
die $@ if $@; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub test { |
157
|
|
|
|
|
|
|
my $self = shift; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
local $Test::Builder::Level = $Test::Builder::Level + 2; |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
for ( @_ ) { |
162
|
|
|
|
|
|
|
if (m/\n/) { |
163
|
|
|
|
|
|
|
$self->eval( $_ ); |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
else { |
166
|
|
|
|
|
|
|
my $path = Path::Abstract->new( $_ ); |
167
|
|
|
|
|
|
|
my $file = $path->file; |
168
|
|
|
|
|
|
|
$self->eval( scalar $file->slurp ); |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
} |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SEE ALSO |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
L |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=head1 AUTHOR |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Robert Krimen, C<< >> |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=head1 BUGS |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
184
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
185
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=head1 SUPPORT |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
perldoc JavaScript::V8x::TestMoreish |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
You can also look for information at: |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=over 4 |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
L |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
L |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item * CPAN Ratings |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
L |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=item * Search CPAN |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
L |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=back |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Copyright 2010 Robert Krimen. |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
228
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
229
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=cut |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; # End of JavaScript::V8x::TestMoreish |