blib/lib/Test/Wait.pm

filter: Statementstmt 65.6% 21 / 32 Branchbran 20.0% 2 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 100% 2 / 2 totaltotal 56.3% 31 / 55 CC 7 SCAR 22.9
CC
7
Cov
51%
wait_x
19.0
wait_stdin
6.5
BEGIN
1.0
CRAP 9.9
↑ Summary
1 package Test::Wait;
2 # vim:syn=perl
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 ▶use vars qw( $VERSION @ISA @EXPORT );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 require Exporter;
10 3 @ISA = qw( Exporter );
11 3 @EXPORT = qw( wait_stdin wait_x );
12  
13 3 our $VERSION = '0.04';
14  
15 3 ▶use constant DEFAULT_WAIT_SECONDS => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 =head1 NAME
18  
19 Test::Wait - Make tests wait for manual testing purposes.
20  
21 =head1 DESCRIPTION
22  
23 Test::Wait is a tool for use in conjunction with test libraries such as Test::More for manual testing purposes.
24  
25 It was initially designed for use in Selenium based tests however it can be used in any test script.
26  
27 Test::Wait provides a simple interface to pause test scripts at any given point, allowing you to inspect the test output or
28 use the test-created data to run manual tests against the application in a browser or terminal.
29  
30 =head1 SYNOPSIS
31  
32 use Test::Wait;
33  
34 wait_stdin( [ 'i'm waiting for you to hit return' ] );
35  
36 wait_x( [ [ int seconds_to_wait ] [, "i'm waiting $seconds_to_wait seconds" ] ] );
37  
38 =head1 INTERFACE
39  
40 =cut
41  
42 =head2 wait_stdin( [ str message ] ) : nothing
43  
44 wait ( for return key press ) before continuing a test.
45  
46 ignored if running under prove or make test.
47  
48 =cut
49  
50 2 ▶sub wait_stdin {
Subroutine wait_stdin: called CC=3 SCAR=18.7
Pod documented
51 2 my $msg = shift;
52 2 ▶ return if ( $ENV{HARNESS_ACTIVE} ); # don't wait if running under test harness eg; prove, make test
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HARNESS_ACTIVE"} 2 0 2
53 0 my ( $pkg, $filename, $line ) = caller();
54 0 my $out_msg = 'I> ' . __PACKAGE__ . "::wait_stdin() - waiting at '$pkg' line '$line' ( $filename )";
55 0 ▶ $out_msg .= ": '$msg'" if ( defined($msg) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $msg 0 0 0
56 0 print STDERR "$out_msg\n";
57 0 <STDIN>;
58 }
59  
60 =head2 wait_x( [ [ int seconds_to_wait ] [, str message ] ] ) : nothing
61  
62 wait for $seconds_to_wait seconds before continuing a test.
63  
64 ignored if running under prove or make test.
65  
66 =cut
67  
68 5 ▶sub wait_x {
Subroutine wait_x: called CC=5 SCAR=29.4
Pod documented
69 5 my ( $seconds, $msg ) = @_;
70 5 ▶ return if ( $ENV{HARNESS_ACTIVE} ); # don't wait if running under test harness eg; prove, make test
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"HARNESS_ACTIVE"} 5 0 5
71 0 ▶ $seconds = DEFAULT_WAIT_SECONDS() if ( !defined($seconds) || $seconds !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $seconds and $seconds =~ /^\d+$/ 0 0 0
Condition0%0/3
defined $seconds and $seconds =~ /^\d+$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $seconds and $seconds =~ /^\d+$/
defined $seconds $seconds =~ /^\d+$/
Truth table0%0/3
A and B
A= defined $secondsB= $seconds =~ /^\d+$/
ABresult
0X0
100
111
72 0 my ( $pkg, $filename, $line ) = caller();
73 0 my $out_msg = 'I> ' . __PACKAGE__ . "::wait_x() - waiting '$seconds' seconds at '$pkg' line '$line' ( $filename )";
74 0 ▶ $out_msg .= ": '$msg'" if ( defined($msg) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $msg 0 0 0
75 0 print STDERR "$out_msg\n";
76 0 sleep( $seconds );
77 }
78  
79 =head1 SEE ALSO
80  
81 Test::More, Test::Builder, Test::Simple, Selenium::Remote::Driver, Test::Harness
82  
83 =head1 AUTHORS
84  
85 Ben Hare <ben@benhare.com>
86  
87 =head1 CREDITS
88  
89 Inspired by code written by Chris Hutchinson <chris@hutchinsonsoftware.com>.
90  
91 =head1 COPYRIGHT
92  
93 Copyright (c) Ben Hare <ben@benhare.com>, 2014.
94  
95 This program is free software. You can redistribute it and/or modify it under the same terms as Perl itself.
96  
97 See F<http://www.perl.com/perl/misc/Artistic.html>
98  
99 =cut
100  
101  
102 3 1;
103  
104 __END__
↑ Summary