Regen files for mainline.
[p5sagit/p5-mst-13.2.git] / t / lib / 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 }
1b31946b 11
12 require Socket;
13
14 # This code inspired by Sys::Syslog::connect():
15 require Sys::Hostname;
16 my ($host_uniq) = Sys::Hostname::hostname();
17 my ($host) = $host_uniq =~ /([A-Za-z0-9_.-]+)/;
18
19 if (! defined Socket::inet_aton($host)) {
20 print "1..0 # Skip: Can't lookup $host\n";
21 exit 0;
22 }
34b7e82b 23}
24
25use Sys::Syslog qw(:DEFAULT setlogsock);
26
b75c8c73 27# Test this to 1 if your syslog accepts udp connections.
28# Most don't (or at least shouldn't)
29my $Test_Syslog_INET = 0;
30
34b7e82b 31print "1..6\n";
32
f41ed1f7 33if (Sys::Syslog::_PATH_LOG()) {
34 if (-e Sys::Syslog::_PATH_LOG()) {
35 print defined(eval { setlogsock('unix') }) ? "ok 1\n" : "not ok 1\n";
36 print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 2\n" : "not ok 2\n";
37 print defined(eval { syslog('info', 'test') }) ? "ok 3\n" : "not ok 3\n";
38 }
39 else {
40 for (1..3) {
41 print
42 "ok $_ # skipping, file ",
43 Sys::Syslog::_PATH_LOG(),
44 " does not exist\n";
45 }
46 }
150b260b 47}
48else {
49 for (1..3) { print "ok $_ # skipping, _PATH_LOG unavailable\n" }
50}
34b7e82b 51
b75c8c73 52if( $Test_Syslog_INET ) {
53 print defined(eval { setlogsock('inet') }) ? "ok 4\n"
54 : "not ok 4\n";
55 print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 5\n"
56 : "not ok 5\n";
57 print defined(eval { syslog('info', 'test') }) ? "ok 6\n"
58 : "not ok 6\n";
59}
60else {
61 print "ok $_ # skipped(assuming syslog doesn't accept inet connections)\n"
62 foreach (4..6);
63}