Skip to content

Commit 4d75926

Browse files
author
Chris White
committed
Began switching tests to Capture::Tiny
1 parent 01ff3c2 commit 4d75926

12 files changed

+176
-52
lines changed

Makefile.PL

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,26 @@ use 5.010;
22
use strict;
33
use warnings;
44
use ExtUtils::MakeMaker;
5+
use Config;
56

6-
sub MY::postamble {
7+
# Get the filename of the Perl interpreter running this. From perlvar.
8+
my $secure_perl_path = $Config{perlpath};
9+
if ($^O ne 'VMS') {
10+
$secure_perl_path .= $Config{_exe}
11+
unless $secure_perl_path =~ m/$Config{_exe}$/i;
12+
}
13+
14+
sub MY::postamble { # TODO also handle Windows nmake syntax (SET vs. export)
715
return <<EOT;
816
authortest:
917
\tRELEASE_TESTING=1 prove -l xt"
1018
1119
testhere: # Run the tests from lib rather than blib
12-
\texport PERLPP_CMD="perl -Ilib bin/perlpp"; \\
20+
\texport PERLPP_CMD="\\\"$secure_perl_path\\\" -Ilib bin/perlpp"; \\
1321
\tperl -Ilib -e 'use Test::Harness "runtests"; runtests \@ARGV;' -- t/*.t
1422
1523
testpacked: pack # Test the packed version
16-
\texport PERLPP_NOUSE=1 PERLPP_CMD="perl blib/perlpp"; \\
24+
\texport PERLPP_NOUSE=1 PERLPP_CMD="\\\"$secure_perl_path\\\" blib/perlpp"; \\
1725
\tperl -e 'use Test::Harness "runtests"; runtests \@ARGV;' -- t/*.t
1826
EOT
1927
} #postamble
@@ -35,6 +43,7 @@ WriteMakefile(
3543
'IPC::Run3' => '0',
3644
'Test::More' => '0',
3745
},
46+
# TODO add TEST_REQUIRES
3847
PREREQ_PM => {
3948
'Getopt::Long' => '2.5', # Per issue #17
4049
'Pod::Usage' => '0',

t/00-load.t

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,27 @@ use 5.010;
33
use strict;
44
use warnings;
55
use Test::More;
6+
use rlib './lib';
67

78
BEGIN {
8-
if($ENV{PERLPP_NOUSE} || 0) {
9-
plan skip_all => 'Loading not tested in this configuration (PERLPP_NOUSE)';
10-
} else {
11-
plan tests => 1;
12-
use_ok( 'Text::PerlPP' ) || print "Bail out!\n";
13-
diag("Included from $INC{'Text/PerlPP.pm'}");
14-
}
15-
}
9+
if($ENV{PERLPP_NOUSE} || 0) {
10+
plan skip_all => 'Loading not tested in this configuration (PERLPP_NOUSE)';
11+
} else {
12+
plan tests => 2;
13+
unless(use_ok( 'Text::PerlPP' )) {
14+
diag("@INC is:\n ", join("\n ", @INC), "\n");
15+
BAIL_OUT("Cannot load Text::PerlPP");
16+
};
17+
18+
unless(use_ok( 'PerlPPTest' )) {
19+
diag("@INC is:\n ", join("\n ", @INC), "\n");
20+
BAIL_OUT("Cannot load PerlPPTest");
21+
};
22+
diag("Running as $0");
23+
diag("Text::PerlPP included from $INC{'Text/PerlPP.pm'}");
24+
diag("PerlPPTest included from $INC{'PerlPPTest.pm'}");
25+
}
26+
} # BEGIN
1627

1728
done_testing();
1829
# vi: set ts=4 sts=4 sw=4 et ai: #

t/01-capture.t

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!perl
2+
# Some basic tests for perlpp
3+
use rlib './lib';
4+
use PerlPPTest;
5+
6+
my ($stdout, $stderr, @result);
7+
($stdout, $stderr, @result) = capture {
8+
local *STDIN;
9+
close STDIN;
10+
Text::PerlPP::Main(['-e','say 42;']);
11+
};
12+
13+
is($stdout, "42\n");
14+
15+
done_testing();
16+
# vi: set ts=4 sts=4 sw=4 et ai: #

t/01-basic.t renamed to t/02-basic.t

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#!/usr/bin/env perl -W
22
# Some basic tests for perlpp
3-
use strict;
4-
use warnings;
5-
use Test::More;
6-
use IPC::Run3;
7-
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
8-
diag "perlpp command: " . CMD;
9-
(my $whereami = __FILE__) =~ s/01-basic\.t$//;
3+
use rlib './lib';
4+
use PerlPPTest;
105

11-
my ($in, $out, $err);
6+
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;
10+
(my $whereami = __FILE__) =~ s/02-basic\.t$//;
11+
diag join(' ', 'File is' . __FILE__, 'whereami', $whereami);
1212

1313
my @testcases=(
1414
# [$in (the script), $out (expected output), $err (stderr output, if any)]
@@ -46,10 +46,14 @@ plan tests => scalar @testcases;
4646

4747
for my $lrTest (@testcases) {
4848
my ($testin, $refout, $referr) = @$lrTest;
49-
run3 CMD, \$testin, \$out, \$err;
49+
50+
my ($in, $out, $err);
51+
run_perlpp [], \$testin, \$out, \$err;
52+
5053
if(defined $refout) {
5154
is($out, $refout);
5255
}
56+
5357
if(defined $referr) {
5458
is($err, $referr);
5559
}

t/01-readme.t renamed to t/02-readme.t

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/usr/bin/env perl -W
22
# Tests from perlpp's README.md and bin/perlpp's POD.
3-
use strict;
4-
use warnings;
5-
use Test::More;
6-
use IPC::Run3;
73
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
4+
use rlib './lib';
5+
use PerlPPTest;
86

97
my ($in, $out, $err);
108

t/02-cmdline.t renamed to t/03-cmdline.t

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/usr/bin/env perl -W
22
# Tests of perlpp command-line options
3-
use strict;
4-
use warnings;
5-
use Test::More;
6-
use IPC::Run3;
73
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
4+
use rlib './lib';
5+
use PerlPPTest;
86

97
my @testcases=(
108
# [$cmdline_options, $in (the script), $out_re (expected output),
@@ -111,21 +109,25 @@ for my $lrTest (@testcases) {
111109
}
112110

113111
plan tests => $testcount;
112+
diag "Running $testcount tests";
114113

115114
for my $lrTest (@testcases) {
116115
my ($opts, $testin, $out_re, $err_re) = @$lrTest;
117116

118117
my ($out, $err);
119-
#print STDERR CMD . " $opts", " <<<'", $testin, "'\n";
120-
run3 CMD . " $opts", \$testin, \$out, \$err;
118+
diag "$opts", " <<<'", $testin, "'\n";
119+
run_perlpp $opts, \$testin, \$out, \$err;
120+
diag "Done running";
121121

122122
if(defined $out_re) {
123+
diag "checking output";
123124
like($out, $out_re);
124125
}
125126
if(defined $err_re) {
127+
diag "checking stderr";
126128
like($err, $err_re);
127129
}
128-
#print STDERR "$err\n";
130+
print STDERR "$err\n";
129131

130132
} # foreach test
131133

t/03-idempotency.t

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
#!/usr/bin/env perl -W
22
# Test running perlpp on itself - nothing should change.
33
# Always uses the Text/PerlPP.pm in lib, for simplicity.
4-
use strict;
5-
use warnings;
6-
use Test::More tests => 1;
7-
use IPC::Run3;
8-
4+
use rlib './lib';
5+
use PerlPPTest;
96
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp')
107
. ' lib/Text/PerlPP.pm';
118
diag 'idempotency-test command: ' . CMD;

t/04-include.t

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/env perl -W
22
# Tests of :include, :macro Include, :immediate ProcessFile
3-
use strict;
4-
use warnings;
5-
use Test::More;
6-
use IPC::Run3;
3+
use rlib './lib';
4+
use PerlPPTest;
75
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
86

97
(my $whereami = __FILE__) =~ s/04-include\.t$//;

t/05-external-command.t

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/env perl -W
22
# Tests of perlpp <?!...?> external commands
3-
use strict;
4-
use warnings;
5-
use Test::More;
6-
use IPC::Run3;
3+
use rlib './lib';
4+
use PerlPPTest;
75
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
86

97
(my $whereami = __FILE__) =~ s/macro\.t$//;

t/06-macro.t

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/env perl -W
22
# Tests of perlpp :macro and related
3-
use strict;
4-
use warnings;
5-
use Test::More 'no_plan';
6-
use IPC::Run3;
3+
use rlib './lib';
4+
use PerlPPTest;
75
use constant CMD => ($ENV{PERLPP_CMD} || 'perl -Iblib/lib blib/script/perlpp');
86

97
(my $whereami = __FILE__) =~ s/06-macro\.t$//;

0 commit comments

Comments
 (0)