File: capture.t

package info (click to toggle)
libperl5i-perl 2.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, stretch
  • size: 996 kB
  • ctags: 343
  • sloc: perl: 6,259; makefile: 5
file content (38 lines) | stat: -rw-r--r-- 589 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env perl

use perl5i::latest;

use Test::More;

note "scalar context"; {
    is capture { print "Hello" }, "Hello";

    is capture {
        print "Hello";
        warn "you should not see this";
    }, "Hello", "stderr is silenced";
}


note "tee"; {
    my($out, $err) = capture {
        capture {
            print "out";
            warn  "err";
        } tee => 1;
    };
    is $out, "out";
    like $err, qr/^err\b/;
}


note "merge"; {
    my $out = capture {
        print "out";
        print STDERR "err";
    } merge => 1;

    is $out, "outerr";
}

done_testing;