MacOS X 10.1.5 still failing the DB tests.
[p5sagit/p5-mst-13.2.git] / ext / Sys / Syslog / syslog.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require Config; import Config;
7     if ($Config{'extensions'} !~ /\bSyslog\b/) {
8         print "1..0 # Skip: Sys::Syslog was not built\n";
9         exit 0;
10     }
11     if ($Config{'extensions'} !~ /\bSocket\b/) {
12         print "1..0 # Skip: Socket was not built\n";
13         exit 0;
14     }
15
16     require Socket;
17
18     # This code inspired by Sys::Syslog::connect():
19     require Sys::Hostname;
20     my ($host_uniq) = Sys::Hostname::hostname();
21     my ($host)      = $host_uniq =~ /([A-Za-z0-9_.-]+)/;
22
23     if (! defined Socket::inet_aton($host)) {
24         print "1..0 # Skip: Can't lookup $host\n";
25         exit 0;
26     }
27 }
28
29 BEGIN {
30   eval {require Sys::Syslog} or do {
31     if ($@ =~ /Your vendor has not/) {
32       print "1..0 # Skip: missing macros\n";
33       exit 0;
34     }
35   }
36 }
37
38 use Sys::Syslog qw(:DEFAULT setlogsock);
39
40 # Test this to 1 if your syslog accepts udp connections.
41 # Most don't (or at least shouldn't)
42 my $Test_Syslog_INET = 0;
43
44 my $test_string = "uid $< is testing perl $] syslog capabilities";
45
46 print "1..6\n";
47
48 if (Sys::Syslog::_PATH_LOG()) {
49     if (-e Sys::Syslog::_PATH_LOG()) {
50         print defined(eval { setlogsock('unix') }) ? "ok 1\n" : "not ok 1 # $!\n";
51         print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 2\n" : "not ok 2 # $!\n";
52         print defined(eval { syslog('info', $test_string ) }) ? "ok 3\n" : "not ok 3 # $!\n";
53     }
54     else {
55         for (1..3) {
56             print
57                 "ok $_ # Skip: file ",
58                 Sys::Syslog::_PATH_LOG(),
59                 " does not exist\n";
60         }
61     }
62 }
63 else {
64     for (1..3) { print "ok $_ # Skip: _PATH_LOG unavailable\n" }
65 }
66
67 if( $Test_Syslog_INET ) {
68     print defined(eval { setlogsock('inet') }) ? "ok 4\n" 
69                                                : "not ok 4\n";
70     print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 5\n" 
71                                                                 : "not ok 5 # $!\n";
72     print defined(eval { syslog('info', $test_string ) }) ? "ok 6\n" 
73                                                    : "not ok 6 # $!\n";
74 }
75 else {
76     print "ok $_ # Skip: assuming syslog doesn't accept inet connections\n" 
77       foreach (4..6);
78 }