line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# This software is copyright (c) 2011 by Jeffrey Kegler |
2
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it |
3
|
|
|
|
|
|
|
# under the same terms as the Perl 5 programming language system |
4
|
|
|
|
|
|
|
# itself. |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Marpa::HTML::Test::Util; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# The original of this code was copied from Andy Lester's Ack |
9
|
|
|
|
|
|
|
# package |
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
3579
|
use 5.010; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
83
|
|
12
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
71
|
|
13
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
63
|
|
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
12
|
use Test::More; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
20
|
|
16
|
2
|
|
|
2
|
|
813
|
use English qw( -no_match_vars ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
19
|
|
17
|
2
|
|
|
2
|
|
981
|
use File::Spec; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
68
|
|
18
|
2
|
|
|
2
|
|
11
|
use Fatal qw(unlink open close); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
18
|
|
19
|
2
|
|
|
2
|
|
3157
|
use Carp; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
1282
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# capture stderr output into this file |
22
|
|
|
|
|
|
|
my $catcherr_file = 'stderr.log'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub is_win32 { |
25
|
4
|
|
|
4
|
0
|
29
|
return $OSNAME =~ /Win32/xms; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# capture-stderr is executing ack and storing the stderr output in |
29
|
|
|
|
|
|
|
# $catcherr_file in a portable way. |
30
|
|
|
|
|
|
|
# |
31
|
|
|
|
|
|
|
# The quoting of command line arguments depends on the OS |
32
|
|
|
|
|
|
|
sub build_command_line { |
33
|
4
|
|
|
4
|
0
|
12
|
my (@args) = @_; |
34
|
|
|
|
|
|
|
|
35
|
4
|
50
|
|
|
|
25
|
if ( is_win32() ) { |
36
|
0
|
|
|
|
|
0
|
for (@args) { |
37
|
0
|
|
|
|
|
0
|
s/(\\+)$/$1$1/xms; # Double all trailing backslashes |
38
|
0
|
|
|
|
|
0
|
s/"/\\"/gxms; # Backslash all quotes |
39
|
0
|
|
|
|
|
0
|
$_ = qq{"$_"}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} ## end if ( is_win32() ) |
42
|
|
|
|
|
|
|
else { |
43
|
4
|
|
|
|
|
10
|
@args = map { quotemeta $_ } @args; |
|
8
|
|
|
|
|
27
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
4
|
|
|
|
|
24
|
return "$EXECUTABLE_NAME -Ilib @args"; |
47
|
|
|
|
|
|
|
# capture-stderr drops core on my Mac OS Tiger laptop |
48
|
|
|
|
|
|
|
# return |
49
|
|
|
|
|
|
|
# "$EXECUTABLE_NAME -Ilib ./lib/Marpa/HTML/Test/capture-stderr $catcherr_file @args"; |
50
|
|
|
|
|
|
|
} ## end sub build_command_line |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub run_command { |
53
|
4
|
|
|
4
|
0
|
23319
|
my ( $command, @args ) = @_; |
54
|
|
|
|
|
|
|
|
55
|
4
|
|
|
|
|
19
|
my ( $stdout, $stderr ) = run_with_stderr( $command, @args ); |
56
|
|
|
|
|
|
|
|
57
|
4
|
50
|
|
|
|
389
|
Test::More::is( $stderr, q{}, |
58
|
|
|
|
|
|
|
"Should have no output to stderr: $command @args" ) |
59
|
|
|
|
|
|
|
or Test::More::diag("STDERR:\n$stderr"); |
60
|
|
|
|
|
|
|
|
61
|
4
|
|
|
|
|
3445
|
return $stdout; |
62
|
|
|
|
|
|
|
} ## end sub run_command |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub run_with_stderr { |
65
|
4
|
|
|
4
|
0
|
12
|
my @args = @_; |
66
|
|
|
|
|
|
|
|
67
|
4
|
|
|
|
|
17
|
my $cmd = build_command_line(@args); |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
## no critic (InputOutput::ProhibitBacktickOperators) |
70
|
4
|
|
|
|
|
1575795
|
my $stdout = `$cmd`; |
71
|
|
|
|
|
|
|
## use critic |
72
|
|
|
|
|
|
|
|
73
|
4
|
|
|
|
|
112
|
my ( $sig, $core, $rc ) = ( |
74
|
|
|
|
|
|
|
( $CHILD_ERROR & 127 ), |
75
|
|
|
|
|
|
|
( $CHILD_ERROR & 128 ), |
76
|
|
|
|
|
|
|
( $CHILD_ERROR >> 8 ), |
77
|
|
|
|
|
|
|
); |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# Previous logic drops core on Darwin |
80
|
|
|
|
|
|
|
# open my $fh, '<', $catcherr_file; |
81
|
|
|
|
|
|
|
# my $stderr = do { local $RS = undef; <$fh> }; |
82
|
|
|
|
|
|
|
# close $fh; |
83
|
|
|
|
|
|
|
# unlink $catcherr_file; |
84
|
|
|
|
|
|
|
|
85
|
4
|
|
|
|
|
154
|
return ( $stdout, q{}, $rc ); |
86
|
|
|
|
|
|
|
# return ( $stdout, $stderr, $rc ); |
87
|
|
|
|
|
|
|
} ## end sub run_with_stderr |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |