1
- # !/usr/bin/env perl -W
1
+ # !/usr/bin/env perl
2
2
# Tests of perlpp command-line options
3
3
use constant CMD => ($ENV {PERLPP_CMD } || ' perl -Iblib/lib blib/script/perlpp' );
4
4
use rlib ' ./lib' ;
5
5
use PerlPPTest;
6
6
7
+ # Note: for all the L() calls, without a do{} around them, the line number
8
+ # from caller() is the line number where `my @testcases` occurs.
9
+ # TODO find out if there's a better way than do{L()}. Maybe an L that
10
+ # takes a block that returns a list? That might or might not work ---
11
+ # syntactically,
12
+ # perl -MData::Dumper -E 'sub L :prototype(&) { my $func=shift; my @x = &$func(); say Dumper(\@x); }; L{1,2}'
13
+ # does work, but I don't know if it would have the right caller.
14
+
7
15
my @testcases =(
8
- # [$cmdline_options, $in (the script), $out_re (expected output),
16
+ # [scalar filename/lineno (added by L()),
17
+ # $cmdline_options, $in (the script), $out_re (expected output),
9
18
# $err_re (stderr output, if any)]
10
19
11
20
# version
12
- [ ' -v' ,' ' ,qr /\b version\b / ] ,
13
- [ ' --version' ,' ' ,qr /\b version\b / ] ,
21
+ do {L( ' -v' ,' ' ,qr /\b version\b / ) } ,
22
+ do {L( ' --version' ,' ' ,qr /\b version\b / )} ,
14
23
15
24
# Debug output
16
- [ ' -d' ,' ' ,qr / ^package PPP_[0-9]*;/ m] ,
17
- [ ' -d' , ' <?= 2+2 ?>' , qr { print\s +2\+ 2\s *;} ] ,
18
- [ ' --debug' , ' <?= 2+2 ?>' , qr { print\s +2\+ 2\s *;} ] ,
19
- [ ' -E' , ' <?= 2+2 ?>' , qr { print\s +2\+ 2\s *;} ] ,
25
+ L( ' -d' ,' ' ,qr / ^package PPP_[0-9]*;/ m ) ,
26
+ L( ' -d' , ' <?= 2+2 ?>' , qr { print\s +2\+ 2\s *;} ) ,
27
+ L( ' --debug' , ' <?= 2+2 ?>' , qr { print\s +2\+ 2\s *;} ) ,
28
+ L( ' -E' , ' <?= 2+2 ?>' , qr { print\s +2\+ 2\s *;} ) ,
20
29
21
30
# Usage
22
- [ ' -h --z_noexit_on_help' , ' ' , qr / ^Usage/ ] ,
23
- [ ' --help --z_noexit_on_help' , ' ' , qr / ^Usage/ ] ,
31
+ L( ' -h --z_noexit_on_help' , ' ' , qr / ^Usage/ ) ,
32
+ L( ' --help --z_noexit_on_help' , ' ' , qr / ^Usage/ ) ,
24
33
25
34
# Eval at start of file
26
- [[' -e' , ' my $foo=42;' ],' <?= $foo ?>' , qr / ^42$ / ],
27
- # TODO RESUME HERE: break down the command line arguments since the
28
- # shell is no longer parsing them. (Note that they will have to be
29
- # re-quoted for use by the packed test.)
30
- [' --eval \' my $foo=42;\' ' ,' <?= $foo ?>' , qr / ^42$ / ],
31
- [' -d -e \' my $foo=42;\' ' ,' <?= $foo ?>' , qr / ^my \$ foo=42;/ m],
32
- [' --debug --eval \' my $foo=42;\' ' ,' <?= $foo ?>' , qr / ^print\s +\$ foo\s *;/ m],
35
+ L(' -e \' my $foo=42;\' ' , ' <?= $foo ?>' , qr / ^42$ / ),
36
+ L(' --eval \' my $foo=42;\' ' ,' <?= $foo ?>' , qr / ^42$ / ),
37
+ L(' -d -e \' my $foo=42;\' ' ,' <?= $foo ?>' , qr / ^my \$ foo=42;/ m ),
38
+ L(' --debug --eval \' my $foo=42;\' ' ,' <?= $foo ?>' , qr / ^print\s +\$ foo\s *;/ m ),
33
39
34
40
# Definitions: name formats
35
- [ ' -Dfoo' , ' <? print "yes" if $D{foo}; ?>' ,qr / ^yes$ / ] ,
36
- [ ' -Dfoo42' , ' <? print "yes" if $D{foo42}; ?>' ,qr / ^yes$ / ] ,
37
- [ ' -Dfoo_42' , ' <? print "yes" if $D{foo_42}; ?>' ,qr / ^yes$ / ] ,
38
- [ ' -D_x' , ' <? print "yes" if $D{_x}; ?>' ,qr / ^yes$ / ] ,
39
- [ ' -D_1' , ' <? print "yes" if $D{_1}; ?>' ,qr / ^yes$ / ] ,
41
+ L( ' -Dfoo' , ' <? print "yes" if $D{foo}; ?>' ,qr / ^yes$ / ) ,
42
+ L( ' -Dfoo42' , ' <? print "yes" if $D{foo42}; ?>' ,qr / ^yes$ / ) ,
43
+ L( ' -Dfoo_42' , ' <? print "yes" if $D{foo_42}; ?>' ,qr / ^yes$ / ) ,
44
+ L( ' -D_x' , ' <? print "yes" if $D{_x}; ?>' ,qr / ^yes$ / ) ,
45
+ L( ' -D_1' , ' <? print "yes" if $D{_1}; ?>' ,qr / ^yes$ / ) ,
40
46
41
47
# Definitions with --define
42
- [ ' --define foo' , ' <? print "yes" if $D{foo}; ?>' ,qr / ^yes$ / ] ,
43
- [ ' --define foo=42 --define bar=127' , ' <?= $D{foo} * $D{bar} ?>' ,qr / ^5334$ / ] ,
48
+ L( ' --define foo' , ' <? print "yes" if $D{foo}; ?>' ,qr / ^yes$ / ) ,
49
+ L( ' --define foo=42 --define bar=127' , ' <?= $D{foo} * $D{bar} ?>' ,qr / ^5334$ / ) ,
44
50
45
51
# Definitions: :define/:undef
46
- [ ' ' ,' <?:define foo?><?:ifdef foo?>yes<?:else?>no<?:endif?>' ,qr / ^yes$ / ] ,
47
- [ ' ' ,' <?:define foo 42?><?:ifdef foo?>yes<?:else?>no<?:endif?>' ,qr / ^yes$ / ] ,
48
- [ ' ' ,' <?:define foo 42?><?= $D{foo} ?>' ,qr / ^42$ / ] ,
49
- [ ' ' ,' <?:define foo "a" . "b" ?><?= $D{foo} ?>' ,qr / ^ab$ / ] ,
50
- [ ' -Dfoo' ,' <?:undef foo?><?:ifdef foo?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ] ,
52
+ L( ' ' ,' <?:define foo?><?:ifdef foo?>yes<?:else?>no<?:endif?>' ,qr / ^yes$ / ) ,
53
+ L( ' ' ,' <?:define foo 42?><?:ifdef foo?>yes<?:else?>no<?:endif?>' ,qr / ^yes$ / ) ,
54
+ L( ' ' ,' <?:define foo 42?><?= $D{foo} ?>' ,qr / ^42$ / ) ,
55
+ L( ' ' ,' <?:define foo "a" . "b" ?><?= $D{foo} ?>' ,qr / ^ab$ / ) ,
56
+ L( ' -Dfoo' ,' <?:undef foo?><?:ifdef foo?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ) ,
51
57
52
58
# Definitions: values
53
- [ ' -Dfoo=41025.5' , ' <?= $D{foo} ?>' ,qr / ^41025.5$ / ] ,
54
- [ ' -D foo=2017' , ' <?= $D{foo} ?>' ,qr / ^2017$ / ] ,
55
- [ ' -D foo=\"blah\"' , ' <?= $D{foo} ?>' ,qr / ^blah$ / ] ,
59
+ L( ' -Dfoo=41025.5' , ' <?= $D{foo} ?>' ,qr / ^41025.5$ / ) ,
60
+ L( ' -D foo=2017' , ' <?= $D{foo} ?>' ,qr / ^2017$ / ) ,
61
+ L( ' -D foo=\"blah\"' , ' <?= $D{foo} ?>' ,qr / ^blah$ / ) ,
56
62
# Have to escape the double-quotes so perl sees it as a string
57
63
# literal instead of a bareword.
58
- [ ' -D foo=42 -D bar=127' , ' <?= $D{foo} * $D{bar} ?>' ,qr / ^5334$ / ] ,
59
- [ ' ' , ' <? $D{x}="%D always exists even if empty"; ?><?= $D{x} ?>' ,
60
- qr / ^%D always exists even if empty$ / ] ,
64
+ L( ' -D foo=42 -D bar=127' , ' <?= $D{foo} * $D{bar} ?>' ,qr / ^5334$ / ) ,
65
+ L( ' ' , ' <? $D{x}="%D always exists even if empty"; ?><?= $D{x} ?>' ,
66
+ qr / ^%D always exists even if empty$ / ) ,
61
67
62
68
# Textual substitution
63
- [ ' -Dfoo=42' ,' <? my $foo; ?>foo' ,qr / ^42$ / ] ,
64
- [ ' -Dfoo=\' "a phrase"\' ' ,' <? my $foo; ?>foo' ,qr / ^a phrase$ / ] ,
65
- [ ' -Dfoo=\"bar\"' ,' _foo foo foobar barfoo' ,qr / ^_foo bar foobar barfoo$ / ] ,
66
- [ ' -Dfoo=\"bar\" --define barfoo' ,' _foo foo foobar barfoo' ,
67
- qr / ^_foo bar foobar barfoo$ / ] ,
69
+ L( ' -Dfoo=42' ,' <? my $foo; ?>foo' ,qr / ^42$ / ) ,
70
+ L( ' -Dfoo=\' "a phrase"\' ' ,' <? my $foo; ?>foo' ,qr / ^a phrase$ / ) ,
71
+ L( ' -Dfoo=\"bar\"' ,' _foo foo foobar barfoo' ,qr / ^_foo bar foobar barfoo$ / ) ,
72
+ L( ' -Dfoo=\"bar\" --define barfoo' ,' _foo foo foobar barfoo' ,
73
+ qr / ^_foo bar foobar barfoo$ / ) ,
68
74
69
75
# Sets, which do not textually substitute
70
- [ ' - sfoo=42' ,' <? my $foo; ?>foo' ,qr / ^foo$ / ] ,
71
- [ ' -sfoo=42' ,' <? my $foo; ?><?= $S{foo} ?>' ,qr / ^42$ / ] ,
72
- [' --set foo=42' ,' <? my $foo; ?>foo' ,qr / ^foo$ / ],
73
- [ ' --set foo=42' ,' <? my $foo; ?><?= $S{foo} ?>' ,qr / ^42$ / ] ,
76
+ do {L( ' -E - sfoo=42' ,' <? my $foo; ?>foo' ,qr / ^foo$ / )} ,
77
+ do {L( ' -sfoo=42' ,' <? my $foo; ?><?= $S{foo} ?>' ,qr / ^42$ / )} ,
78
+ [__LINE__ , ' --set foo=42' ,' <? my $foo; ?>foo' ,qr / ^foo$ / ],
79
+ do {L( ' --set foo=42' ,' <? my $foo; ?><?= $S{foo} ?>' ,qr / ^42$ / )} ,
74
80
75
81
# Conditionals
76
- [ ' -Dfoo=42' ,' <?:if foo==2?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ] ,
77
- [ ' -Dfoo=2' ,' <?:if foo==2?>yes<?:else?>no<?:endif?>' ,qr / ^yes$ / ] ,
78
- [ ' -Dfoo' ,' <?:if foo==2?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ] ,
79
- [ ' -Dfoo' ,' <?:if foo==1?>yes<?:else?>no<?:endif?>' ,qr / ^yes$ / ] ,
82
+ L( ' -Dfoo=42' ,' <?:if foo==2?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ) ,
83
+ L( ' -Dfoo=2' ,' <?:if foo==2?>yes<?:else?>no<?:endif?>' ,qr / ^yes$ / ) ,
84
+ L( ' -Dfoo' ,' <?:if foo==2?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ) ,
85
+ L( ' -Dfoo' ,' <?:if foo==1?>yes<?:else?>no<?:endif?>' ,qr / ^yes$ / ) ,
80
86
# The default value is true, which compares equal to 1.
81
- [ ' -Dfoo' ,' <?:if foo?>yes<?:else?>no<?:endif?>' ,qr / ^yes$ / ] ,
82
- [ ' ' ,' <?:if foo?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ] ,
83
- [ ' ' ,' <?:if foo==2?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ] ,
87
+ L( ' -Dfoo' ,' <?:if foo?>yes<?:else?>no<?:endif?>' ,qr / ^yes$ / ) ,
88
+ L( ' ' ,' <?:if foo?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ) ,
89
+ L( ' ' ,' <?:if foo==2?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ) ,
84
90
# For consistency, all :if tests evaluate to false if the
85
91
# named variable is not defined.
86
92
87
93
# Undefining
88
- [ ' -Dfoo' ,' <?:undef foo?><?:if foo?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ] ,
89
-
94
+ L( ' -Dfoo' ,' <?:undef foo?><?:if foo?>yes<?:else?>no<?:endif?>' ,qr / ^no$ / ) ,
95
+ #
90
96
# Three forms of elsif
91
- [ ' ' , ' <?:if foo eq "1" ?>yes<?:elif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^no$ / ] ,
92
- [ ' ' , ' <?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^no$ / ] ,
93
- [ ' ' , ' <?:if foo eq "1" ?>yes<?:elseif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^no$ / ] ,
97
+ L( ' ' , ' <?:if foo eq "1" ?>yes<?:elif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^no$ / ) ,
98
+ L( ' ' , ' <?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^no$ / ) ,
99
+ L( ' ' , ' <?:if foo eq "1" ?>yes<?:elseif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^no$ / ) ,
94
100
95
101
# elsif with definitions
96
- [ ' -Dfoo' , ' <?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^yes$ / ] ,
97
- [ ' -Dfoo=1' , ' <?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^yes$ / ] ,
102
+ L( ' -Dfoo' , ' <?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^yes$ / ) ,
103
+ L( ' -Dfoo=1' , ' <?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^yes$ / ) ,
98
104
# Automatic conversion of numeric 1 to string in "eq" context
99
- [ ' -Dfoo=\\ "x\\ "' , ' <?= $D{foo} . "\n" ?><?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^x\n maybe$ / ] ,
100
- [ ' -Dfoo=\\ "y\\ "' , ' <?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^no$ / ] ,
105
+ L( ' -Dfoo=\\ "x\\ "' , ' <?= $D{foo} . "\n" ?><?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^x\n maybe$ / ) ,
106
+ L( ' -Dfoo=\\ "y\\ "' , ' <?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>' , qr / ^no$ / ) ,
101
107
102
108
); # @testcases
103
109
@@ -106,7 +112,7 @@ my @testcases=(
106
112
my $testcount = 0;
107
113
108
114
for my $lrTest (@testcases ) {
109
- my ($out_re , $err_re ) = @$lrTest [2..3 ];
115
+ my ($out_re , $err_re ) = @$lrTest [3..4 ];
110
116
++$testcount if defined $out_re ;
111
117
++$testcount if defined $err_re ;
112
118
}
@@ -115,20 +121,21 @@ plan tests => $testcount;
115
121
diag " Running $testcount tests" ;
116
122
117
123
for my $lrTest (@testcases ) {
118
- my ($opts , $testin , $out_re , $err_re ) = @$lrTest ;
124
+ my ($where , $ opts , $testin , $out_re , $err_re ) = @$lrTest ;
119
125
120
126
my ($out , $err );
127
+ diag ' =' x 70 ;
121
128
diag $opts , " <<<'" , $testin , " '\n " ;
122
129
run_perlpp $opts , \$testin , \$out , \$err ;
123
130
# diag "Done running";
124
131
125
132
if (defined $out_re ) {
126
133
# diag "checking output";
127
- like($out , $out_re );
134
+ like($out , $out_re , " stdout $where " );
128
135
}
129
136
if (defined $err_re ) {
130
137
# diag "checking stderr";
131
- like($err , $err_re );
138
+ like($err , $err_re , " stderr $where " );
132
139
}
133
140
print STDERR " $err \n " ;
134
141
0 commit comments