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