summaryrefslogtreecommitdiffstats
path: root/t/lib/TestHelpers.pm
blob: c44d045a515c00f3f42167fba1b5c0921a346b6b (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
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;