diff options
author | Jesse Luehrs <doy@tozt.net> | 2010-04-30 18:16:01 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2010-04-30 18:16:01 -0500 |
commit | 5397fc87adb897178a4c23211cb44b310358fbd5 (patch) | |
tree | a8a7b693e593094d97f0f9e4f543e7cebc1bc9a7 /t | |
parent | 6b58f6f6e15615ef92aba8f24cffe9f43c6b0a49 (diff) | |
download | carp-always-color-5397fc87adb897178a4c23211cb44b310358fbd5.tar.gz carp-always-color-5397fc87adb897178a4c23211cb44b310358fbd5.zip |
tests0.01
Diffstat (limited to 't')
-rw-r--r-- | t/001-term.t | 51 | ||||
-rw-r--r-- | t/002-html.t | 51 | ||||
-rw-r--r-- | t/003-detect.t | 37 |
3 files changed, 139 insertions, 0 deletions
diff --git a/t/001-term.t b/t/001-term.t new file mode 100644 index 0000000..07c2751 --- /dev/null +++ b/t/001-term.t @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +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 $@; + plan tests => 4; +} + +sub output_is { + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($script, $expected, $desc) = @_; + my $pty = IO::Pty::Easy->new; + $pty->spawn("$^X", "-e", $script); + is($pty->read, $expected, $desc); +} + +output_is(<<EOF, + use Carp::Always::Color::Term; + warn "foo"; +EOF + "\e[33mfoo at -e line 2\e[m\n", + "simple warns work"); + +output_is(<<EOF, + use Carp::Always::Color::Term; + sub foo { + warn "foo"; + } + foo(); +EOF + "\e[33mfoo at -e line 3\e[m\n\tmain::foo() called at -e line 5\n", + "warns with a stacktrace work"); + +output_is(<<EOF, + use Carp::Always::Color::Term; + die "foo"; +EOF + "\e[31mfoo at -e line 2\e[m\n", + "simple dies work"); + +output_is(<<EOF, + use Carp::Always::Color::Term; + sub foo { + die "foo"; + } + foo(); +EOF + "\e[31mfoo at -e line 3\e[m\n\tmain::foo() called at -e line 5\n", + "dies with a stacktrace work"); diff --git a/t/002-html.t b/t/002-html.t new file mode 100644 index 0000000..86be6a9 --- /dev/null +++ b/t/002-html.t @@ -0,0 +1,51 @@ +#!/usr/bin/env perl +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 $@; + plan tests => 4; +} + +sub output_is { + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($script, $expected, $desc) = @_; + my $pty = IO::Pty::Easy->new; + $pty->spawn("$^X", "-e", $script); + is($pty->read, $expected, $desc); +} + +output_is(<<EOF, + use Carp::Always::Color::HTML; + warn "foo"; +EOF + "<span style=\"color:#880\">foo at -e line 2</span>\n", + "simple warns work"); + +output_is(<<EOF, + use Carp::Always::Color::HTML; + sub foo { + warn "foo"; + } + foo(); +EOF + "<span style=\"color:#880\">foo at -e line 3</span>\n\tmain::foo() called at -e line 5\n", + "warns with a stacktrace work"); + +output_is(<<EOF, + use Carp::Always::Color::HTML; + die "foo"; +EOF + "<span style=\"color:#800\">foo at -e line 2</span>\n", + "simple dies work"); + +output_is(<<EOF, + use Carp::Always::Color::HTML; + sub foo { + die "foo"; + } + foo(); +EOF + "<span style=\"color:#800\">foo at -e line 3</span>\n\tmain::foo() called at -e line 5\n", + "dies with a stacktrace work"); diff --git a/t/003-detect.t b/t/003-detect.t new file mode 100644 index 0000000..aadcf88 --- /dev/null +++ b/t/003-detect.t @@ -0,0 +1,37 @@ +#!/usr/bin/env perl +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 $@; + plan tests => 2; +} + +sub output_is { + local $Test::Builder::Level = $Test::Builder::Level + 1; + my ($script, $expected, $desc) = @_; + my $pty = IO::Pty::Easy->new; + $pty->spawn("$^X", "-e", $script); + is($pty->read, $expected, $desc); +} + +output_is(<<EOF, + use Carp::Always::Color; + warn "foo"; +EOF + "\e[33mfoo at -e line 2\e[m\n", + "detection works for terminal output"); + +output_is(<<EOF, + my \$stderr; + BEGIN { + close(STDERR); + open(STDERR, '>', \\\$stderr); + } + use Carp::Always::Color; + warn "foo"; + print \$stderr; +EOF + "<span style=\"color:#880\">foo at -e line 7</span>\n", + "detection works for terminal output"); |