Skip to content

Commit f1fed06

Browse files
author
Chris White
committed
Cleaned up test cases
Almost done with #24 - still need to test on Perl 5.10.1.
1 parent 3296bfc commit f1fed06

File tree

9 files changed

+68
-82
lines changed

9 files changed

+68
-82
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
/tags
33
/fatlib
44
/stuff
5+
*.stackdump
6+
core
57

68
# Dist
79
/Text-PerlPP*

MANIFEST.SKIP

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,4 @@
7575
# Skip some specific files
7676
^Makefile-premodule
7777
^tags
78-
79-
# Things we're still working on
80-
^t\/lib
78+
\.stackdump$

t/02-basic.t

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ use rlib './lib';
44
use PerlPPTest;
55

66
use IPC::Run3;
7-
#use constant CMD => ($ENV{PERLPP_CMD} || "$^X -Iblib/lib blib/script/perlpp");
8-
# # TODO use $^X even if a PERLPP_CMD is provided.
9-
#diag "perlpp command: " . CMD;
107
(my $whereami = __FILE__) =~ s/02-basic\.t$//;
118
#diag join(' ', 'File is', __FILE__, 'whereami', $whereami);
129

t/02-readme.t

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#!/usr/bin/env perl
22
# Tests from perlpp's README.md and bin/perlpp's POD.
3-
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
43
use rlib './lib';
54
use PerlPPTest;
65

@@ -95,7 +94,6 @@ for my $lrTest (@testcases) {
9594
my ($testin, $refout, $referr) = @$lrTest;
9695
my ($in, $out, $err);
9796

98-
#run3 CMD, \$testin, \$out, \$err;
9997
run_perlpp [], \$testin, \$out, \$err;
10098

10199
if(defined $refout) {

t/03-cmdline.t

Lines changed: 63 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,109 @@
11
#!/usr/bin/env perl
22
# Tests of perlpp command-line options
3-
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
43
use rlib './lib';
54
use PerlPPTest;
5+
use TestcaseList;
66

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.
7+
# Testcase format:
8+
# [scalar filename/lineno (added by the TestcaseList code),
9+
# $cmdline_options, $in (the script), $out_re (expected output),
10+
# $err_re (stderr output, if any)]
1411

15-
my @testcases=(
16-
# [scalar filename/lineno (added by L()),
17-
# $cmdline_options, $in (the script), $out_re (expected output),
18-
# $err_re (stderr output, if any)]
12+
# TODO add skip() to TestcaseList loader --- otherwise the line numbers
13+
# will be off here.
1914

15+
my $testcases = TestcaseList->new(__LINE__);
2016
# version
21-
do{L('-v','',qr/\bversion\b/) },
22-
do{L('--version','',qr/\bversion\b/)},
17+
$testcases->load('-v','',qr/\bversion\b/)->
18+
('--version','',qr/\bversion\b/)
2319

2420
# Debug output
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*;}),
21+
('-d','',qr/^package PPP_[0-9]*;/m)
22+
('-d', '<?= 2+2 ?>', qr{print\s+2\+2\s*;})
23+
('--debug', '<?= 2+2 ?>', qr{print\s+2\+2\s*;})
24+
('-E', '<?= 2+2 ?>', qr{print\s+2\+2\s*;})
2925

3026
# Usage
31-
L('-h --z_noexit_on_help', '', qr/^Usage/),
32-
L('--help --z_noexit_on_help', '', qr/^Usage/),
27+
('-h --z_noexit_on_help', '', qr/^Usage/)
28+
('--help --z_noexit_on_help', '', qr/^Usage/)
3329

3430
# Eval at start of file
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),
31+
(['-e', q(my $foo=42;)], '<?= $foo ?>', qr/^42$/)
32+
(['--eval', q(my $foo=42;)],'<?= $foo ?>', qr/^42$/)
33+
(['-d','-e', q(my $foo=42;)],'<?= $foo ?>', qr/^my \$foo=42;/m)
34+
(['--debug','--eval', q(my $foo=42;)],'<?= $foo ?>', qr/^print\s+\$foo\s*;/m)
3935

4036
# Definitions: name formats
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$/),
37+
('-Dfoo', '<? print "yes" if $D{foo}; ?>',qr/^yes$/)
38+
('-Dfoo42', '<? print "yes" if $D{foo42}; ?>',qr/^yes$/)
39+
('-Dfoo_42', '<? print "yes" if $D{foo_42}; ?>',qr/^yes$/)
40+
('-D_x', '<? print "yes" if $D{_x}; ?>',qr/^yes$/)
41+
('-D_1', '<? print "yes" if $D{_1}; ?>',qr/^yes$/)
4642

4743
# Definitions with --define
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+
('--define foo', '<? print "yes" if $D{foo}; ?>',qr/^yes$/)
45+
('--define foo=42 --define bar=127', '<?= $D{foo} * $D{bar} ?>',qr/^5334$/)
5046

5147
# Definitions: :define/:undef
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$/),
48+
('','<?:define foo?><?:ifdef foo?>yes<?:else?>no<?:endif?>',qr/^yes$/)
49+
('','<?:define foo 42?><?:ifdef foo?>yes<?:else?>no<?:endif?>',qr/^yes$/)
50+
('','<?:define foo 42?><?= $D{foo} ?>',qr/^42$/)
51+
('','<?:define foo "a" . "b" ?><?= $D{foo} ?>',qr/^ab$/)
52+
('-Dfoo','<?:undef foo?><?:ifdef foo?>yes<?:else?>no<?:endif?>',qr/^no$/)
5753

5854
# Definitions: values
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$/),
55+
('-Dfoo=41025.5', '<?= $D{foo} ?>',qr/^41025.5$/)
56+
('-D foo=2017', '<?= $D{foo} ?>',qr/^2017$/)
57+
([qw(-D foo="blah")], '<?= $D{foo} ?>',qr/^blah$/)
6258
# Have to escape the double-quotes so perl sees it as a string
6359
# literal instead of a bareword.
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$/),
60+
('-D foo=42 -D bar=127', '<?= $D{foo} * $D{bar} ?>',qr/^5334$/)
61+
('', '<? $D{x}="%D always exists even if empty"; ?><?= $D{x} ?>', qr/^%D always exists even if empty$/)
6762

6863
# Textual substitution
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$/ ),
64+
('-Dfoo=42','<? my $foo; ?>foo',qr/^42$/ )
65+
([q(-Dfoo="a phrase")],'<? my $foo; ?>foo',qr/^a phrase$/ )
66+
(['-Dfoo="bar"'], '_foo foo foobar barfoo 1',qr/^_foo bar foobar barfoo 1$/ )
67+
(['-Dfoo="bar"', '--define', 'barfoo'], '_foo foo foobar barfoo 2', qr/^_foo bar foobar barfoo 2$/ )
7468

7569
# Sets, which do not textually substitute
76-
do{L('-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$/ )},
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$/ )
8074

8175
# Conditionals
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$/ ),
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$/ )
8680
# The default value is true, which compares equal to 1.
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$/ ),
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$/ )
9084
# For consistency, all :if tests evaluate to false if the
9185
# named variable is not defined.
9286

9387
# Undefining
94-
L('-Dfoo','<?:undef foo?><?:if foo?>yes<?:else?>no<?:endif?>',qr/^no$/ ),
88+
('-Dfoo','<?:undef foo?><?:if foo?>yes<?:else?>no<?:endif?>',qr/^no$/ )
9589
#
9690
# Three forms of elsif
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$/),
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$/)
10094

10195
# elsif with definitions
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$/),
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$/)
10498
# Automatic conversion of numeric 1 to string in "eq" context
105-
L('-Dfoo=\\"x\\"', '<?= $D{foo} . "\n" ?><?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>', qr/^x\nmaybe$/),
106-
L('-Dfoo=\\"y\\"', '<?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>', qr/^no$/),
99+
(['-Dfoo="x"'], '<?= $D{foo} . "\n" ?><?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>', qr/^x\nmaybe$/)
100+
(['-Dfoo="y"'], '<?:if foo eq "1" ?>yes<?:elsif foo eq "x" ?>maybe<?:else?>no<?:endif?>', qr/^no$/)
107101

108-
); #@testcases
102+
; #$testcases
109103

110-
plan tests => count_tests(\@testcases, 3, 4);
104+
plan tests => count_tests($testcases->arr, 3, 4);
111105

112-
for my $lrTest (@testcases) {
106+
for my $lrTest (@{$testcases->arr}) {
113107
my ($where, $opts, $testin, $out_re, $err_re) = @$lrTest;
114108

115109
my ($out, $err);

t/04-include.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ plan tests => count_tests(\@testcases, 2, 3);
3333

3434
for my $lrTest (@testcases) {
3535
my ($lineno, $testin, $refout, $referr) = @$lrTest;
36-
diag "<<<@{[Text::PerlPP::_QuoteString $testin]}";
36+
#diag "<<<@{[Text::PerlPP::_QuoteString $testin]}";
3737
run_perlpp [], \$testin, \$out, \$err;
3838

3939
if(defined $refout) {

t/05-external-command.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ for my $lrTest (@testcases) {
2828
my ($opts, $testin, $out_re, $err_re) = @$lrTest;
2929

3030
my ($out, $err);
31-
diag "perlpp $opts <<<@{[Text::PerlPP::_QuoteString $testin]}";
31+
#diag "perlpp $opts <<<@{[Text::PerlPP::_QuoteString $testin]}";
3232
run_perlpp $opts, \$testin, \$out, \$err;
3333

3434
if(defined $out_re) {

t/06-macro.t

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# Tests of perlpp :macro and related
33
use rlib './lib';
44
use PerlPPTest;
5-
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
65

76
(my $whereami = __FILE__) =~ s/06-macro\.t$//;
87
my $incfn = '\"' . $whereami . 'included.txt\"';

t/07-invalid.t

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22
# Testing perlpp with invalid input
33
use rlib './lib';
44
use PerlPPTest;
5-
#use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
65
(my $whereami = __FILE__) =~ s/07-invalid\.t$//;
7-
#diag "perlpp command " . CMD . "; whereami $whereami.";
86

97
my ($out, $err);
108

0 commit comments

Comments
 (0)