summaryrefslogtreecommitdiffstats
path: root/t/001-term.t
blob: 07c27510317d1cfa9906893fb44983119ae8f305 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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");