Commit | Line | Data |
34b7e82b |
1 | #!./perl |
2 | |
3 | BEGIN { |
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 | |
16 | # This code inspired by Sys::Syslog::connect(): |
17 | require Sys::Hostname; |
18 | my ($host_uniq) = Sys::Hostname::hostname(); |
19 | my ($host) = $host_uniq =~ /([A-Za-z0-9_.-]+)/; |
20 | |
21 | if (! defined Socket::inet_aton($host)) { |
22 | print "1..0 # Skip: Can't lookup $host\n"; |
23 | exit 0; |
24 | } |
34b7e82b |
25 | } |
26 | |
68a5ccec |
27 | BEGIN { |
28 | eval {require Sys::Syslog} or do { |
29 | if ($@ =~ /Your vendor has not/) { |
cf2bd340 |
30 | print "1..0 # Skip: missing macros\n"; |
68a5ccec |
31 | exit 0; |
32 | } |
33 | } |
34 | } |
35 | |
34b7e82b |
36 | use Sys::Syslog qw(:DEFAULT setlogsock); |
37 | |
b75c8c73 |
38 | # Test this to 1 if your syslog accepts udp connections. |
39 | # Most don't (or at least shouldn't) |
40 | my $Test_Syslog_INET = 0; |
41 | |
b8a35e92 |
42 | my $test_string = "uid $< is testing perl $] syslog capabilities"; |
43 | |
34b7e82b |
44 | print "1..6\n"; |
45 | |
f41ed1f7 |
46 | if (Sys::Syslog::_PATH_LOG()) { |
47 | if (-e Sys::Syslog::_PATH_LOG()) { |
cf2bd340 |
48 | print defined(eval { setlogsock('unix') }) ? "ok 1\n" : "not ok 1 # $!\n"; |
49 | print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 2\n" : "not ok 2 # $!\n"; |
50 | print defined(eval { syslog('info', $test_string ) }) ? "ok 3\n" : "not ok 3 # $!\n"; |
f41ed1f7 |
51 | } |
52 | else { |
53 | for (1..3) { |
54 | print |
cf2bd340 |
55 | "ok $_ # Skip: file ", |
f41ed1f7 |
56 | Sys::Syslog::_PATH_LOG(), |
57 | " does not exist\n"; |
58 | } |
59 | } |
150b260b |
60 | } |
61 | else { |
cf2bd340 |
62 | for (1..3) { print "ok $_ # Skip: _PATH_LOG unavailable\n" } |
150b260b |
63 | } |
34b7e82b |
64 | |
b75c8c73 |
65 | if( $Test_Syslog_INET ) { |
66 | print defined(eval { setlogsock('inet') }) ? "ok 4\n" |
67 | : "not ok 4\n"; |
68 | print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 5\n" |
cf2bd340 |
69 | : "not ok 5 # $!\n"; |
b8a35e92 |
70 | print defined(eval { syslog('info', $test_string ) }) ? "ok 6\n" |
cf2bd340 |
71 | : "not ok 6 # $!\n"; |
b75c8c73 |
72 | } |
73 | else { |
cf2bd340 |
74 | print "ok $_ # Skip: assuming syslog doesn't accept inet connections\n" |
b75c8c73 |
75 | foreach (4..6); |
76 | } |