File: class_pipe.t

package info (click to toggle)
libfilehandle-unget-perl 0.1634-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 324 kB
  • sloc: perl: 2,160; makefile: 2
file content (46 lines) | stat: -rwxr-xr-x 703 bytes parent folder | download | duplicates (9)
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
use strict;
use FileHandle::Unget;
use Test::More tests => 2;

#-------------------------------------------------------------------------------

{
  my ($out, $in) = FileHandle::Unget::pipe;
  die unless ref $out && ref $in;

  my $pid = fork();

  unless(defined $pid)
  {
    # 1
    ok(0, "Couldn't fork");

    # 2
    ok(0, "Couldn't get info from child");

    exit;
  }

  # In parent
  if ($pid)
  {
    close $in;

    # 1
    ok(1, 'Fork succeeded');

    local $/ = undef;
    my $results = <$out>;

    # 2
    is($results,"Some info from the child\nSome more\n", 'Child output');

    exit;
  }
  # In child
  else
  {
    print $in "Some info from the child\nSome more\n";
    exit;
  }
}