Cleanup; replace a croak("panic: ...") with assert().
[p5sagit/p5-mst-13.2.git] / ext / Sys / Syslog / t / syslog.t
CommitLineData
8168e71f 1#!/usr/bin/perl -T
34b7e82b 2
3BEGIN {
8168e71f 4 if( $ENV{PERL_CORE} ) {
5 chdir 't';
6 @INC = '../lib';
cc8876c3 7 }
8168e71f 8}
1b31946b 9
8168e71f 10use strict;
11use Test::More;
12use Config;
02d52598 13
8168e71f 14# check that the module is at least available
15plan skip_all => "Sys::Syslog was not build"
16 unless $Config{'extensions'} =~ /\bSyslog\b/;
1b31946b 17
8168e71f 18# we also need Socket
19plan skip_all => "Socket was not build"
20 unless $Config{'extensions'} =~ /\bSocket\b/;
34b7e82b 21
68a5ccec 22BEGIN {
8168e71f 23 plan tests => 16;
24
25 # ok, now loads them
26 eval 'use Socket';
27 use_ok('Sys::Syslog', ':DEFAULT', 'setlogsock');
68a5ccec 28}
29
8168e71f 30# check that the documented functions are correctly provided
31can_ok( 'Sys::Syslog' => qw(openlog syslog syslog setlogmask setlogsock closelog) );
32
33
34# check the diagnostics
35# setlogsock()
36eval { setlogsock() };
37like( $@, qr/^Invalid argument passed to setlogsock; must be 'stream', 'unix', 'tcp', 'udp' or 'inet'/,
38 "calling setlogsock() with no argument" );
39
40# syslog()
41eval { syslog() };
42like( $@, qr/^syslog: expecting argument \$priority/,
43 "calling syslog() with no argument" );
44
45my $test_string = "uid $< is testing Perl $] syslog(3) capabilities";
46my $r = 0;
47
48# try to test using a Unix socket
49SKIP: {
50 skip "can't connect to Unix socket: _PATH_LOG unavailable", 6
51 unless -e Sys::Syslog::_PATH_LOG();
52
53 # The only known $^O eq 'svr4' that needs this is NCR MP-RAS,
54 # but assuming 'stream' in SVR4 is probably not that bad.
55 my $sock_type = $^O =~ /^(solaris|irix|svr4|powerux)$/ ? 'stream' : 'unix';
56
57 eval { setlogsock($sock_type) };
58 is( $@, '', "setlogsock() called with '$sock_type'" );
59 TODO: {
60 local $TODO = "minor bug";
61 ok( $r, "setlogsock() should return true but returned '$r'" );
f41ed1f7 62 }
34b7e82b 63
8168e71f 64 SKIP: {
65 $r = eval { openlog('perl', 'ndelay', 'local0') };
66 skip "can't connect to syslog", 4 if $@ =~ /^no connection to syslog available/;
67 is( $@, '', "openlog()" );
68 ok( $r, "openlog() should return true but returned '$r'" );
69
70 $r = eval { syslog('info', "$test_string by connecting to a Unix socket") };
71 is( $@, '', "syslog()" );
72 ok( $r, "syslog() should return true but returned '$r'" );
73 }
b75c8c73 74}
8168e71f 75
76# try to test using a INET socket
77SKIP: {
78 skip "assuming syslog doesn't accept inet connections", 6 if 1;
79
80 my $sock_type = 'inet';
81
82 $r = eval { setlogsock('inet') };
83 is( $@, '', "setlogsock() called with '$sock_type'" );
84 ok( $r, "setlogsock() should return true but returned '$r'" );
85
86 $r = eval { openlog('perl', 'ndelay', 'local0') };
87 is( $@, '', "openlog()" );
88 ok( $r, " -> should return true but returned '$r'" );
89
90 $r = eval { syslog('info', "$test_string by connecting to a INET socket") };
91 is( $@, '', "syslog()" );
92 ok( $r, " -> should return true but returned '$r'" );
b75c8c73 93}
8168e71f 94