summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2016-08-30 01:39:07 -0400
committerJesse Luehrs <doy@tozt.net>2016-08-30 01:39:07 -0400
commit07edf5e4760c25baedc1e911221802918744d8f1 (patch)
tree104e663a7c01d808b5f133a2524a9db0bc58d216
parentc69ab718b2cd8a2e18da56c3dd49fae2d247c2a7 (diff)
downloadcarp-always-color-07edf5e4760c25baedc1e911221802918744d8f1.tar.gz
carp-always-color-07edf5e4760c25baedc1e911221802918744d8f1.zip
use a consistent implementation of output_like
not all of them were passing along @INC
-rw-r--r--t/detect.t17
-rw-r--r--t/eval.t14
-rw-r--r--t/html.t14
-rw-r--r--t/lib/TestHelpers.pm26
-rw-r--r--t/term.t14
5 files changed, 34 insertions, 51 deletions
diff --git a/t/detect.t b/t/detect.t
index ad03dcc..feaea1c 100644
--- a/t/detect.t
+++ b/t/detect.t
@@ -2,21 +2,8 @@
use strict;
use warnings;
use Test::More;
-BEGIN {
- eval "use IO::Pty::Easy;";
- plan skip_all => "IO::Pty::Easy is required for this test" if $@;
-}
-use B;
-
-sub output_like {
- local $Test::Builder::Level = $Test::Builder::Level + 1;
- my ($script, $expected, $desc) = @_;
- my $pty = IO::Pty::Easy->new;
- my $inc = '(' . join(',', map { B::perlstring($_) } @INC) . ')';
- $script = "BEGIN { \@INC = $inc }$script";
- $pty->spawn("$^X", "-e", $script);
- like($pty->read, $expected, $desc);
-}
+use lib 't/lib';
+use TestHelpers 'output_like';
output_like(<<EOF,
use Carp::Always::Color;
diff --git a/t/eval.t b/t/eval.t
index eb33d22..6ccf984 100644
--- a/t/eval.t
+++ b/t/eval.t
@@ -2,18 +2,8 @@
use strict;
use warnings;
use Test::More;
-BEGIN {
- eval "use IO::Pty::Easy;";
- plan skip_all => "IO::Pty::Easy is required for this test" if $@;
-}
-
-sub output_like {
- local $Test::Builder::Level = $Test::Builder::Level + 1;
- my ($script, $expected, $desc) = @_;
- my $pty = IO::Pty::Easy->new;
- $pty->spawn("$^X", "-e", $script);
- like($pty->read, $expected, $desc);
-}
+use lib 't/lib';
+use TestHelpers 'output_like';
output_like(<<EOF,
use Carp::Always::Color;
diff --git a/t/html.t b/t/html.t
index 046990e..57dd7db 100644
--- a/t/html.t
+++ b/t/html.t
@@ -2,18 +2,8 @@
use strict;
use warnings;
use Test::More;
-BEGIN {
- eval "use IO::Pty::Easy;";
- plan skip_all => "IO::Pty::Easy is required for this test" if $@;
-}
-
-sub output_like {
- local $Test::Builder::Level = $Test::Builder::Level + 1;
- my ($script, $expected, $desc) = @_;
- my $pty = IO::Pty::Easy->new;
- $pty->spawn("$^X", "-e", $script);
- like($pty->read, $expected, $desc);
-}
+use lib 't/lib';
+use TestHelpers 'output_like';
output_like(<<EOF,
use Carp::Always::Color::HTML;
diff --git a/t/lib/TestHelpers.pm b/t/lib/TestHelpers.pm
new file mode 100644
index 0000000..c44d045
--- /dev/null
+++ b/t/lib/TestHelpers.pm
@@ -0,0 +1,26 @@
+package TestHelpers;
+use strict;
+use warnings;
+
+BEGIN {
+ if (!eval { require IO::Pty::Easy; 1 }) {
+ Test::More::plan skip_all => "IO::Pty::Easy is required for this test"
+ }
+}
+
+use B;
+use Exporter 'import';
+
+our @EXPORT_OK = qw(output_like);
+
+sub output_like {
+ local $Test::Builder::Level = $Test::Builder::Level + 1;
+ my ($script, $expected, $desc) = @_;
+ my $pty = IO::Pty::Easy->new;
+ my $inc = '(' . join(',', map { B::perlstring($_) } @INC) . ')';
+ $script = "BEGIN { \@INC = $inc }$script";
+ $pty->spawn("$^X", "-e", $script);
+ Test::More::like($pty->read, $expected, $desc);
+}
+
+1;
diff --git a/t/term.t b/t/term.t
index f8af0b3..c2db4c7 100644
--- a/t/term.t
+++ b/t/term.t
@@ -2,18 +2,8 @@
use strict;
use warnings;
use Test::More;
-BEGIN {
- eval "use IO::Pty::Easy;";
- plan skip_all => "IO::Pty::Easy is required for this test" if $@;
-}
-
-sub output_like {
- local $Test::Builder::Level = $Test::Builder::Level + 1;
- my ($script, $expected, $desc) = @_;
- my $pty = IO::Pty::Easy->new;
- $pty->spawn("$^X", "-e", $script);
- like($pty->read, $expected, $desc);
-}
+use lib 't/lib';
+use TestHelpers 'output_like';
output_like(<<EOF,
use Carp::Always::Color::Term;