Upgrade to Sys-Syslog-0.10
[p5sagit/p5-mst-13.2.git] / ext / Sys / Syslog / t / constants.t
1 #!/usr/bin/perl -T
2 use strict;
3 use Test::More;
4 my @names;
5 BEGIN {
6     if(open(MACROS, 'macros.all')) {
7         @names = map {chomp;$_} <MACROS>;
8         close(MACROS);
9         plan tests => @names + 3;
10     } else {
11         plan skip_all => "can't read 'macros.all': $!"
12     }
13 }
14 use Sys::Syslog;
15
16 eval "use Test::Exception"; my $has_test_exception = !$@;
17
18 # Testing error messages
19 SKIP: {
20     skip "Test::Exception not available", 1 unless $has_test_exception;
21
22     # constant() errors
23     throws_ok(sub {
24         Sys::Syslog::constant()
25     }, '/^Usage: Sys::Syslog::constant\(sv\)/',
26        "calling constant() with no argument");
27 }
28
29 # Testing constant()
30 like( Sys::Syslog::constant('This'), 
31     '/^This is not a valid Sys::Syslog macro/', 
32     "calling constant() with a non existing name" );
33
34 like( Sys::Syslog::constant('NOSUCHNAME'), 
35     '/^NOSUCHNAME is not a valid Sys::Syslog macro/', 
36     "calling constant() with a non existing name" );
37
38 # Testing all macros
39 if(@names) {
40     for my $name (@names) {
41         like( Sys::Syslog::constant($name), 
42               '/^(?:\d+|Your vendor has not defined Sys::Syslog macro '.$name.', used)$/', 
43               "checking that $name is a number (".Sys::Syslog::constant($name).")" );
44     }
45 }
46