more testsuite smarts (many of them courtesy Ilya)
[p5sagit/p5-mst-13.2.git] / t / lib / io_unix.t
CommitLineData
cf7fe8a2 1#!./perl
2
3BEGIN {
4 unless(grep /blib/, @INC) {
5 chdir 't' if -d 't';
93430cb4 6 unshift @INC, '../lib' if -d '../lib';
cf7fe8a2 7 }
8}
9
10use Config;
11
12BEGIN {
13 if(-d "lib" && -f "TEST") {
45c0de28 14 my $reason;
15 if (! $Config{'d_fork'}) {
16 $reason = 'no fork';
17 }
18 elsif ($Config{'extensions'} !~ /\bSocket\b/) {
19 $reason = 'Socket extension unavailable';
20 }
21 elsif ($Config{'extensions'} !~ /\bIO\b/) {
22 $reason = 'IO extension unavailable';
23 }
24 undef $reason if $^O eq 'VMS' and $Config{d_socket};
25 if ($reason) {
26 print "1..0 # Skip: $reason\n";
27 exit 0;
cf7fe8a2 28 }
29 }
30}
31
32$PATH = "/tmp/sock-$$";
33
34# Test if we can create the file within the tmp directory
35if (-e $PATH or not open(TEST, ">$PATH")) {
36 print "1..0\n";
37 exit 0;
38}
39close(TEST);
40unlink($PATH) or die "Can't unlink $PATH: $!";
41
42# Start testing
43$| = 1;
44print "1..5\n";
45
46use IO::Socket;
47
48$listen = IO::Socket::UNIX->new(Local=>$PATH, Listen=>0) || die "$!";
49print "ok 1\n";
50
51if($pid = fork()) {
52
53 $sock = $listen->accept();
54 print "ok 2\n";
55
56 print $sock->getline();
57
58 print $sock "ok 4\n";
59
60 $sock->close;
61
62 waitpid($pid,0);
63 unlink($PATH) || warn "Can't unlink $PATH: $!";
64
65 print "ok 5\n";
66
67} elsif(defined $pid) {
68
69 $sock = IO::Socket::UNIX->new(Peer => $PATH) or die "$!";
70
71 print $sock "ok 3\n";
72
73 print $sock->getline();
74
75 $sock->close;
76
77 exit;
78} else {
79 die;
80}