MacOS X 10.1.5 still failing the DB tests.
[p5sagit/p5-mst-13.2.git] / ext / Sys / Syslog / syslog.t
CommitLineData
34b7e82b 1#!./perl
2
3BEGIN {
4 chdir 't' if -d 't';
20822f61 5 @INC = '../lib';
34b7e82b 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 }
cc8876c3 11 if ($Config{'extensions'} !~ /\bSocket\b/) {
12 print "1..0 # Skip: Socket was not built\n";
13 exit 0;
14 }
1b31946b 15
02d52598 16 require Socket;
17
1b31946b 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 }
34b7e82b 27}
28
68a5ccec 29BEGIN {
30 eval {require Sys::Syslog} or do {
31 if ($@ =~ /Your vendor has not/) {
cf2bd340 32 print "1..0 # Skip: missing macros\n";
68a5ccec 33 exit 0;
34 }
35 }
36}
37
34b7e82b 38use Sys::Syslog qw(:DEFAULT setlogsock);
39
b75c8c73 40# Test this to 1 if your syslog accepts udp connections.
41# Most don't (or at least shouldn't)
42my $Test_Syslog_INET = 0;
43
b8a35e92 44my $test_string = "uid $< is testing perl $] syslog capabilities";
45
34b7e82b 46print "1..6\n";
47
f41ed1f7 48if (Sys::Syslog::_PATH_LOG()) {
49 if (-e Sys::Syslog::_PATH_LOG()) {
cf2bd340 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";
f41ed1f7 53 }
54 else {
55 for (1..3) {
56 print
cf2bd340 57 "ok $_ # Skip: file ",
f41ed1f7 58 Sys::Syslog::_PATH_LOG(),
59 " does not exist\n";
60 }
61 }
150b260b 62}
63else {
cf2bd340 64 for (1..3) { print "ok $_ # Skip: _PATH_LOG unavailable\n" }
150b260b 65}
34b7e82b 66
b75c8c73 67if( $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"
cf2bd340 71 : "not ok 5 # $!\n";
b8a35e92 72 print defined(eval { syslog('info', $test_string ) }) ? "ok 6\n"
cf2bd340 73 : "not ok 6 # $!\n";
b75c8c73 74}
75else {
cf2bd340 76 print "ok $_ # Skip: assuming syslog doesn't accept inet connections\n"
b75c8c73 77 foreach (4..6);
78}