line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Mocha::PhantomJS; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
204469
|
use strict; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
80
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
64
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
9
|
use Exporter qw(import); |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
70
|
|
7
|
2
|
|
|
2
|
|
1758
|
use Net::EmptyPort qw(empty_port wait_port); |
|
2
|
|
|
|
|
120743
|
|
|
2
|
|
|
|
|
458
|
|
8
|
2
|
|
|
2
|
|
2200
|
use Scope::Guard qw(scope_guard); |
|
2
|
|
|
|
|
1045
|
|
|
2
|
|
|
|
|
1435
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
11
|
|
|
|
|
|
|
our @EXPORT = qw(test_mocha_phantomjs); |
12
|
|
|
|
|
|
|
our @EXPORT_OK = @EXPORT; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub test_mocha_phantomjs { |
15
|
1
|
50
|
|
1
|
1
|
17
|
my %args = @_ == 1 ? %{$_[0]} : @_; |
|
0
|
|
|
|
|
0
|
|
16
|
1
|
50
|
|
|
|
5
|
Carp::croak("missing mandatory parameter 'server'") |
17
|
|
|
|
|
|
|
unless exists $args{server}; |
18
|
|
|
|
|
|
|
%args = ( |
19
|
|
|
|
|
|
|
auto_skip => undef, |
20
|
|
|
|
|
|
|
max_wait => 10, |
21
|
|
|
|
|
|
|
build_uri => sub { |
22
|
0
|
|
|
0
|
|
0
|
my $port = shift; |
23
|
0
|
|
|
|
|
0
|
"http://127.0.0.1:$port/"; |
24
|
|
|
|
|
|
|
}, |
25
|
1
|
|
|
|
|
9
|
%args, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
1
|
50
|
|
|
|
4
|
if ($args{auto_skip}) { |
29
|
1
|
|
|
|
|
14910
|
system "which mocha-phantomjs > /dev/null"; |
30
|
1
|
50
|
|
|
|
75
|
if ($? != 0) { |
31
|
1
|
|
|
|
|
2162
|
require "Test/More.pm"; |
32
|
1
|
|
|
|
|
34201
|
Test::More::plan(skip_all => "could not find mocha-phantomjs"); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
0
|
|
|
|
|
|
my $client_pid = $$; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# determine empty port |
39
|
0
|
|
|
|
|
|
my $port = empty_port(); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# start server |
42
|
0
|
|
|
|
|
|
my $server_pid = fork; |
43
|
0
|
0
|
|
|
|
|
die "fork failed:$!" |
44
|
|
|
|
|
|
|
unless defined $server_pid; |
45
|
0
|
0
|
|
|
|
|
if ($server_pid == 0) { |
46
|
0
|
|
|
|
|
|
eval { |
47
|
0
|
|
|
|
|
|
$args{server}->($port); |
48
|
|
|
|
|
|
|
}; |
49
|
|
|
|
|
|
|
# should not reach here |
50
|
0
|
|
|
|
|
|
warn $@; |
51
|
0
|
|
|
|
|
|
die "[Test::Mocha::PhantomJS] server callback should not return"; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# setup guard to kill the server |
55
|
|
|
|
|
|
|
my $guard = scope_guard sub { |
56
|
0
|
|
|
0
|
|
|
kill 'TERM', $server_pid; |
57
|
0
|
|
|
|
|
|
waitpid $server_pid, 0; |
58
|
0
|
|
|
|
|
|
print STDERR "hi"; |
59
|
0
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# wait for the port to start |
62
|
0
|
|
|
|
|
|
wait_port($port, $args{max_wait}); |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# run the test |
65
|
0
|
|
|
|
|
|
system qw(mocha-phantomjs -R tap), $args{build_uri}->($port); |
66
|
0
|
|
|
|
|
|
my $status = $?; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
undef $guard; # stop the server |
69
|
|
|
|
|
|
|
|
70
|
0
|
0
|
|
|
|
|
if ($status == 1) { |
|
|
0
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
die "failed to execute mocha-phantomjs: $status"; |
72
|
|
|
|
|
|
|
} elsif (($status & 127) != 0) { |
73
|
0
|
|
|
|
|
|
die "mocha-phantomjs died with signal " . ($status & 127); |
74
|
|
|
|
|
|
|
} else { |
75
|
0
|
|
|
|
|
|
warn "mocha-phantomjs exitted with: $status"; |
76
|
0
|
|
|
|
|
|
exit $status >> 8; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
1; |
81
|
|
|
|
|
|
|
__END__ |