Skip to content

Commit 6873968

Browse files
author
Chris White
committed
Continued reworking tests
Now runs through t/04-include
1 parent 458ace9 commit 6873968

File tree

10 files changed

+55
-56
lines changed

10 files changed

+55
-56
lines changed

t/01-capture.t

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# Some basic tests for perlpp
33
use rlib './lib';
44
use PerlPPTest;
5+
plan tests => 1;
56

67
my ($stdout, $stderr, @result);
78
($stdout, $stderr, @result) = capture {

t/02-basic.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env perl -W
1+
#!/usr/bin/env perl
22
# Some basic tests for perlpp
33
use rlib './lib';
44
use PerlPPTest;
@@ -42,7 +42,7 @@ my @testcases=(
4242

4343
); #@testcases
4444

45-
plan tests => scalar @testcases;
45+
plan tests => count_tests(\@testcases, 1, 2);
4646

4747
for my $lrTest (@testcases) {
4848
my ($testin, $refout, $referr) = @$lrTest;

t/02-readme.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env perl -W
1+
#!/usr/bin/env perl
22
# Tests from perlpp's README.md and bin/perlpp's POD.
33
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
44
use rlib './lib';
@@ -89,7 +89,7 @@ RESULT
8989
[ '<?= "!" . "?>foo<?= 42 ?><?" . "bar" ?>', '!foo42bar' ],
9090
); #@testcases
9191

92-
plan tests => scalar @testcases;
92+
plan tests => count_tests(\@testcases, 1, 2);
9393

9494
for my $lrTest (@testcases) {
9595
my ($testin, $refout, $referr) = @$lrTest;

t/03-cmdline.t

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -107,18 +107,7 @@ my @testcases=(
107107

108108
); #@testcases
109109

110-
# count the out_re and err_re in @testcases, since the number of
111-
# tests is the sum of those counts.
112-
my $testcount = 0;
113-
114-
for my $lrTest (@testcases) {
115-
my ($out_re, $err_re) = @$lrTest[3..4];
116-
++$testcount if defined $out_re;
117-
++$testcount if defined $err_re;
118-
}
119-
120-
plan tests => $testcount;
121-
diag "Running $testcount tests";
110+
plan tests => count_tests(\@testcases, 3, 4);
122111

123112
for my $lrTest (@testcases) {
124113
my ($where, $opts, $testin, $out_re, $err_re) = @$lrTest;

t/03-idempotency.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use PerlPPTest;
55
use Text::WordDiff;
66
use File::Spec;
77
use Data::Dumper;
8-
98
plan tests => 1;
9+
1010
my $fn = File::Spec->rel2abs($INC{'Text/PerlPP.pm'});
1111

1212
my $wholefile;

t/04-include.t

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
#!/usr/bin/env perl -W
1+
#!/usr/bin/env perl
22
# Tests of :include, :macro Include, :immediate ProcessFile
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/04-include\.t$//;
87
my $incfn = '"' . $whereami . 'included.txt"';
@@ -11,31 +10,37 @@ diag "Including from $incfn\n";
1110
my ($in, $out, $err);
1211

1312
my @testcases=(
14-
# [$in (the script), $out (expected output), $err (stderr output, if any)]
15-
['<?:include ' . $incfn . ' ?>',"a4b\n"],
13+
# [$lineno, $in (the script), $out (expected output),
14+
# $err (stderr output, if any)]
15+
[__LINE__, '<?:include ' . $incfn . ' ?>',"a4b\n"],
1616
# The newline comes from included.txt, which ends with a newline
17-
['Hello, <?:include ' . $incfn . ' ?>!',"Hello, a4b\n!"],
18-
['<?:macro Include ' . $incfn . ' ?>',"a4b\n"],
19-
['Hello, <?:macro Include ' . $incfn . ' ?>!',"Hello, a4b\n!"],
20-
['<?:immediate ProcessFile ' . $incfn . ' ?>',"a4b\n"],
21-
['Hello, <?:immediate ProcessFile ' . $incfn . ' ?>!',"Hello, a4b\n!"],
22-
['<?:immediate for my $fn (qw(a b c)) { ' .
23-
'ProcessFile "' . $whereami . '" . $fn . ".txt"; } ?>', "a\nb\nc\n"],
24-
['<?:macro for my $fn (qw(a b c)) { ' .
25-
'Include "' . $whereami . '" . $fn . ".txt"; } ?>', "a\nb\nc\n"],
17+
[__LINE__, 'Hello, <?:include ' . $incfn . ' ?>!',"Hello, a4b\n!"],
18+
[__LINE__, '<?:macro $PSelf->Include(' . $incfn . ') ?>',"a4b\n"],
19+
[__LINE__, 'Hello, <?:macro $PSelf->Include(' . $incfn . ') ?>!',
20+
"Hello, a4b\n!"],
21+
[__LINE__, '<?:immediate $PSelf->ProcessFile(' . $incfn . ') ?>',"a4b\n"],
22+
[__LINE__, 'Hello, <?:immediate $PSelf->ProcessFile(' . $incfn . ') ?>!',
23+
"Hello, a4b\n!"],
24+
[__LINE__, '<?:immediate for my $fn (qw(a b c)) { ' .
25+
"\$PSelf->ProcessFile(\"${whereami}\${fn}.txt\"); } ?>",
26+
"a\nb\nc\n"],
27+
[__LINE__, '<?:macro for my $fn (qw(a b c)) { ' .
28+
"\$PSelf->Include(\"${whereami}\${fn}.txt\"); } ?>",
29+
"a\nb\nc\n"],
2630
); #@testcases
2731

28-
plan tests => scalar @testcases;
29-
# thanks to http://edumaven.com/test-automation-using-perl/test-calculated-plan
32+
plan tests => count_tests(\@testcases, 2, 3);
3033

3134
for my $lrTest (@testcases) {
32-
my ($testin, $refout, $referr) = @$lrTest;
33-
run3 CMD, \$testin, \$out, \$err;
35+
my ($lineno, $testin, $refout, $referr) = @$lrTest;
36+
diag "<<<@{[Text::PerlPP::_QuoteString $testin]}";
37+
run_perlpp [], \$testin, \$out, \$err;
38+
3439
if(defined $refout) {
35-
is($out, $refout);
40+
is($out, $refout, "stdout $lineno");
3641
}
3742
if(defined $referr) {
38-
is($err, $referr);
43+
is($err, $referr, "stderr $lineno");
3944
}
4045

4146
} # foreach test

t/05-external-command.t

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env perl -W
1+
#!/usr/bin/env perl
22
# Tests of perlpp <?!...?> external commands
33
use rlib './lib';
44
use PerlPPTest;
@@ -20,17 +20,7 @@ my @testcases=(
2020

2121
); #@testcases
2222

23-
# count the out_re and err_re in @testcases, since the number of
24-
# tests is the sum of those counts.
25-
my $testcount = 0;
26-
27-
for my $lrTest (@testcases) {
28-
my ($out_re, $err_re) = @$lrTest[2..3];
29-
++$testcount if defined $out_re;
30-
++$testcount if defined $err_re;
31-
}
32-
33-
plan tests => $testcount;
23+
plan tests => count_tests(\@testcases, 2, 3);
3424

3525
for my $lrTest (@testcases) {
3626
my ($opts, $testin, $out_re, $err_re) = @$lrTest;

t/06-macro.t

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env perl -W
1+
#!/usr/bin/env perl
22
# Tests of perlpp :macro and related
33
use rlib './lib';
44
use PerlPPTest;
@@ -23,9 +23,7 @@ my @testcases=(
2323

2424
); #@testcases
2525

26-
#plan tests => scalar @testcases;
27-
# TODO count the out_re and err_re in @testcases, since the number of
28-
# tests is the sum of those counts.
26+
plan tests => count_tests(\@testcases, 2, 3);
2927

3028
for my $lrTest (@testcases) {
3129
my ($opts, $testin, $out_re, $err_re) = @$lrTest;

t/07-invalid.t

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#!/usr/bin/env perl -W
1+
#!/usr/bin/env perl
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');
5+
#use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
66
(my $whereami = __FILE__) =~ s/07-invalid\.t$//;
7-
diag "perlpp command " . CMD . "; whereami $whereami.";
7+
#diag "perlpp command " . CMD . "; whereami $whereami.";
88

99
my ($out, $err);
1010

t/lib/PerlPPTest.pm

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use Text::ParseWords qw(shellwords);
2424
use Data::Dumper;
2525
use Devel::StackTrace;
2626

27-
our @EXPORT = qw(run_perlpp L);
27+
our @EXPORT = qw(run_perlpp L count_tests);
2828
our @EXPORT_OK = qw(get_perl_filename);
2929

3030
# L: given a list, return an array ref that includes that list, with the
@@ -93,6 +93,22 @@ sub get_perl_filename {
9393
return $secure_perl_path;
9494
} # get_perl_filename()
9595

96+
# Count the number of tests in an array of arrays.
97+
# Input:
98+
# $lrTests arrayref, e.g., [ [test1], [test2], ... ]
99+
# @fields which fields in each test should be counted, e.g., (2, 3).
100+
sub count_tests {
101+
my ($lrTests, @fields) = @_;
102+
my $testcount = 0;
103+
104+
for my $lrTest (@$lrTests) {
105+
do { ++$testcount if defined $lrTest->[$_] } for @fields;
106+
}
107+
return $testcount;
108+
} # count_tests()
109+
110+
#########################################
111+
96112
sub import {
97113
my $target = caller;
98114

0 commit comments

Comments
 (0)