More suggested patches for NCR MP-RAS from Andy Dougherty.
[p5sagit/p5-mst-13.2.git] / ext / Sys / Syslog / t / 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         # The only known $^O eq 'svr4' that needs this is NCR MP-RAS,
51         # but assuming 'stream' in SVR4 is probably not that bad.
52         if ($^O =~ /^(solaris|irix|svr4)$/) {
53             # we should check for stream support here, not for solaris/irix
54             print defined(eval { setlogsock('stream') }) ? "ok 1\n" : "not ok 1 # $!\n";
55         } else { 
56             print defined(eval { setlogsock('unix') }) ? "ok 1\n" : "not ok 1 # $!\n";
57         }
58         if (defined(eval { openlog('perl', 'ndelay', 'local0') })) {
59             print "ok 2\n";
60             print defined(eval { syslog('info', $test_string ) })
61                     ? "ok 3\n" : "not ok 3 # $!\n";
62         } else {
63             if ($@ =~ /no connection to syslog available/) {
64                 print "ok 2 # Skip: syslogd not running\n";
65             } else {
66                 print "not ok 2 # $@\n";
67             }
68             print "ok 3 # Skip: openlog failed\n";
69         }
70     } else {
71         for (1..3) {
72             print
73                 "ok $_ # Skip: file ",
74                 Sys::Syslog::_PATH_LOG(),
75                 " does not exist\n";
76         }
77     }
78 }
79 else {
80     for (1..3) { print "ok $_ # Skip: _PATH_LOG unavailable\n" }
81 }
82
83 if( $Test_Syslog_INET ) {
84     print defined(eval { setlogsock('inet') }) ? "ok 4\n" 
85                                                : "not ok 4\n";
86     print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 5\n" 
87                                                                 : "not ok 5 # $!\n";
88     print defined(eval { syslog('info', $test_string ) }) ? "ok 6\n" 
89                                                    : "not ok 6 # $!\n";
90 }
91 else {
92     print "ok $_ # Skip: assuming syslog doesn't accept inet connections\n" 
93       foreach (4..6);
94 }