X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Flib%2Fsyslog.t;h=04adb6bed977ceb87cda103aca648488a25da50a;hb=9ee2bb1a7c54b1866ff07ab9c157254810ee5205;hp=e1927bc4e307fea40e345c9cd36bdc2d924f6a1f;hpb=150b260b14b51796fc2bc1a3a4c7b0de7d4daf7d;p=p5sagit%2Fp5-mst-13.2.git diff --git a/t/lib/syslog.t b/t/lib/syslog.t index e1927bc..04adb6b 100755 --- a/t/lib/syslog.t +++ b/t/lib/syslog.t @@ -2,27 +2,62 @@ BEGIN { chdir 't' if -d 't'; - unshift @INC, '../lib'; + @INC = '../lib'; require Config; import Config; if ($Config{'extensions'} !~ /\bSyslog\b/) { print "1..0 # Skip: Sys::Syslog was not built\n"; exit 0; } + + require Socket; + + # This code inspired by Sys::Syslog::connect(): + require Sys::Hostname; + my ($host_uniq) = Sys::Hostname::hostname(); + my ($host) = $host_uniq =~ /([A-Za-z0-9_.-]+)/; + + if (! defined Socket::inet_aton($host)) { + print "1..0 # Skip: Can't lookup $host\n"; + exit 0; + } } use Sys::Syslog qw(:DEFAULT setlogsock); +# Test this to 1 if your syslog accepts udp connections. +# Most don't (or at least shouldn't) +my $Test_Syslog_INET = 0; + print "1..6\n"; if (Sys::Syslog::_PATH_LOG()) { - print defined(eval { setlogsock('unix') }) ? "ok 1\n" : "not ok 1\n"; - print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 2\n" : "not ok 2\n"; - print defined(eval { syslog('info', 'test') }) ? "ok 3\n" : "not ok 3\n"; + if (-e Sys::Syslog::_PATH_LOG()) { + print defined(eval { setlogsock('unix') }) ? "ok 1\n" : "not ok 1\n"; + print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 2\n" : "not ok 2\n"; + print defined(eval { syslog('info', 'test') }) ? "ok 3\n" : "not ok 3\n"; + } + else { + for (1..3) { + print + "ok $_ # skipping, file ", + Sys::Syslog::_PATH_LOG(), + " does not exist\n"; + } + } } else { for (1..3) { print "ok $_ # skipping, _PATH_LOG unavailable\n" } } -print defined(eval { setlogsock('inet') }) ? "ok 4\n" : "not ok 4\n"; -print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 5\n" : "not ok 5\n"; -print defined(eval { syslog('info', 'test') }) ? "ok 6\n" : "not ok 6\n"; +if( $Test_Syslog_INET ) { + print defined(eval { setlogsock('inet') }) ? "ok 4\n" + : "not ok 4\n"; + print defined(eval { openlog('perl', 'ndelay', 'local0') }) ? "ok 5\n" + : "not ok 5\n"; + print defined(eval { syslog('info', 'test') }) ? "ok 6\n" + : "not ok 6\n"; +} +else { + print "ok $_ # skipped(assuming syslog doesn't accept inet connections)\n" + foreach (4..6); +}