WWW/Mechanize/runtests.pl untested

filter: Statementstmt 0.0% 0 / 55 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 0.0% 0 / 8 Podpod n/a totaltotal 0.0% 0 / 104 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!perl
2 use strict;
3 use warnings;
4 use lib '.';
5 use t::helper;
6 use WWW::Mechanize::Firefox;
7 use File::Glob qw( bsd_glob );
8 use Config;
9 use Getopt::Long;
10  
11 GetOptions(
12 't|test:s' => \my $tests,
13 'c|continue' => \my $continue,
14 );
15 my @tests;
16 if( $tests ) {
17 @tests= bsd_glob( $tests );
18 };
19  
20 =head1 NAME
21  
22 runtests.pl - runs the test suite across several instances of Firefox
23  
24 =cut
25  
26 my @instances = @ARGV
27 ? map { bsd_glob $_ } @ARGV
28 : t::helper::firefox_instances;
29 my $port = 4243;
30  
31 # Later, we could even parallelize the test suite
32 # if I find out how to make the mozrepl port dynamic
33 for my $instance (@instances) {
34 # Launch firefox
35 my $vis_instance = $instance ? $instance : "local instance";
36 warn $vis_instance;
37 my @launch = $instance
38 ? (launch => [$instance,'-repl', $port, 'about:blank'])
39 : ()
40 ;
41  
42 if( $instance ) {
43 $ENV{TEST_WWW_MECHANIZE_FIREFOX_VERSIONS} = $instance;
44 $ENV{MOZREPL}= "localhost:$port";
45 } else {
46 $ENV{TEST_WWW_MECHANIZE_FIREFOX_VERSIONS} = "don't test other instances";
47 delete $ENV{MOZREPL}; # my local setup ...
48 };
49 my $retries = 3;
50
51 my $ff;
52 while( $retries-- and !$ff) {
53 $ff= eval {
54 Firefox::Application->new(
55 @launch,
56 );
57 };
58 };
59 die "Couldn't launch Firefox instance from $instance"
60 unless $ff;
61
62 if( @tests ) {
63 for my $test (@tests) {
64 system(qq{perl -Ilib -w "$test"}) == 0
65 or ($continue and warn "Error while testing $vis_instance: $!/$?")
66 or die "Error while testing $vis_instance: $!/$?";
67 };
68 } else { # run all tests
69 system("$Config{ make } test") == 0
70 or ($continue and warn "Error while testing $vis_instance: $!/$?")
71 or die "Error while testing $vis_instance";
72 };
73
74 if( $instance ) {
75 # Close firefox again
76 # Quit in 500ms, so we have time to shut our socket down
77 $ff->repl->expr(<<'JS');
78 var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
79 .getService(Components.interfaces.nsIWindowMediator);
80 var win = wm.getMostRecentWindow('navigator:browser');
81 win.setTimeout(function() {
82 Components.classes["@mozilla.org/toolkit/app-startup;1"]
83 .getService(Components.interfaces.nsIAppStartup).quit(0x02);
84 }, 500);
85 JS
86 };
87 undef $ff;
88 # Safe wait until shutdown
89 sleep 5;
90 };