|
Packit |
d18d0a |
# By Yary Hluchan with portions copied from David Golden
|
|
Packit |
d18d0a |
# Copyright (c) 2015 assigned by Yary Hluchan to David Golden.
|
|
Packit |
d18d0a |
# All rights reserved.
|
|
Packit |
d18d0a |
# Licensed under Apache License, Version 2.0 (the "License").
|
|
Packit |
d18d0a |
# You may not use this file except in compliance with the License.
|
|
Packit |
d18d0a |
# A copy of the License was distributed with this file or you may obtain a
|
|
Packit |
d18d0a |
# copy of the License from http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
d18d0a |
|
|
Packit |
d18d0a |
use strict;
|
|
Packit |
d18d0a |
use warnings;
|
|
Packit |
d18d0a |
use Test::More;
|
|
Packit |
d18d0a |
use lib 't/lib';
|
|
Packit |
d18d0a |
use Utils qw/next_fd/;
|
|
Packit |
d18d0a |
use Capture::Tiny 'capture';
|
|
Packit |
d18d0a |
|
|
Packit |
d18d0a |
use Config;
|
|
Packit |
d18d0a |
my $no_fork = $^O ne 'MSWin32' && ! $Config{d_fork};
|
|
Packit |
d18d0a |
if ( $no_fork ) {
|
|
Packit |
d18d0a |
plan skip_all => 'tee() requires fork';
|
|
Packit |
d18d0a |
}
|
|
Packit |
d18d0a |
else {
|
|
Packit |
d18d0a |
plan 'no_plan';
|
|
Packit |
d18d0a |
}
|
|
Packit |
d18d0a |
|
|
Packit |
d18d0a |
my $builder = Test::More->builder;
|
|
Packit |
d18d0a |
binmode($builder->failure_output, ':utf8') if $] >= 5.008;
|
|
Packit |
d18d0a |
|
|
Packit |
d18d0a |
my $fd = next_fd;
|
|
Packit |
d18d0a |
|
|
Packit |
d18d0a |
|
|
Packit |
d18d0a |
my ($stdout, $stderr, @result) = capture {
|
|
Packit |
d18d0a |
if (!defined(my $child = fork)) { die "fork() failed" }
|
|
Packit |
d18d0a |
elsif ($child == 0) {
|
|
Packit |
d18d0a |
print "Happiness";
|
|
Packit |
d18d0a |
print STDERR "Certainty\n";
|
|
Packit |
d18d0a |
exit;
|
|
Packit |
d18d0a |
}
|
|
Packit |
d18d0a |
else {
|
|
Packit |
d18d0a |
wait;
|
|
Packit |
d18d0a |
print ", a parent-ly\n";
|
|
Packit |
d18d0a |
}
|
|
Packit |
d18d0a |
return qw(a b c);
|
|
Packit |
d18d0a |
};
|
|
Packit |
d18d0a |
|
|
Packit |
d18d0a |
is ( $stdout, "Happiness, a parent-ly\n", "got stdout");
|
|
Packit |
d18d0a |
is ( $stderr, "Certainty\n", "got stderr");
|
|
Packit |
d18d0a |
is ( "@result", "a b c" , "got result");
|
|
Packit |
d18d0a |
is ( next_fd, $fd, "no file descriptors leaked" );
|
|
Packit |
d18d0a |
|
|
Packit |
d18d0a |
exit 0;
|