source: trunk/debathena/debathena/libmail-expandaliases-perl/t/aliases.t @ 24013

Revision 24013, 2.7 KB checked in by broder, 15 years ago (diff)
Create a package for the Mail::ExpandAliases Perl module. This will be used for an updated version of the debathena-msmtp-mta which can understand /etc/aliases files.
Line 
1#!/usr/bin/perl -w
2# ----------------------------------------------------------------------
3# vim: set ft=perl:
4# ----------------------------------------------------------------------
5# All email addresses in this file go to unresolvable.perl.org, which
6# I think I made up.  My apologies to Tom, Barnaby, Bridget, and Quincy
7# if you get mail at these addresses.
8# ----------------------------------------------------------------------
9
10use strict;
11use FindBin qw($Bin);
12use Mail::ExpandAliases;
13use File::Spec::Functions qw(catfile);
14use Test::More;
15
16my ($aliases_file, $m, @a, $a);
17BEGIN {
18    plan tests => 16;
19}
20
21use_ok("Mail::ExpandAliases");
22
23$aliases_file = catfile($Bin, "aliases");
24
25ok(defined($m = Mail::ExpandAliases->new($aliases_file)));
26
27@a = $m->expand('spam');
28is($a[0], '/dev/null', "'spam' => '$a[0]'");
29undef @a;
30
31# Lists of addresses are sorted
32@a = $m->expand('jones');
33$a = join ',', @a;
34is($a, 'Barnaby_Jones@unresolvable.perl.org,Bridget_Jones@unresolvable.perl.org,Quincy_Jones@unresolvable.perl.org,Tom_Jones@unresolvable.perl.org', "'jones' => '$a'");
35undef @a;
36
37# Standard MAILER-DAEMON expansion test
38@a = $m->expand('MAILER-DAEMON');
39is($a[0], '/dev/null', "'MAILER-DAEMON' => '$a[0]'");
40undef @a;
41
42# An alias that is not in the file; should "expand" to itself.
43@a = $m->expand('not-there');
44is($a[0], 'not-there', "'not-there' => '$a[0]'");
45undef @a;
46
47# Just a regular alias (see next test for why this one is here)
48@a = $m->expand('tjones');
49is($a[0], 'Tom_Jones@unresolvable.perl.org', "'tjones' => '$a[0]'");
50undef @a;
51
52# Different capitalization of the above alias -- they should return
53# the same value.
54@a = $m->expand('TJones');
55is($a[0], 'Tom_Jones@unresolvable.perl.org', "'TJones' => '$a[0]'");
56undef @a;
57
58# Another pair of capitilization tests
59@a = $m->expand('postmaster');
60is($a[0], '/dev/null', "'postmaster' => '$a[0]'");
61undef @a;
62
63@a = $m->expand('Postmaster');
64is($a[0], '/dev/null', "'Postmaster' => '$a[0]'");
65undef @a;
66
67
68# Expands to a command.
69@a = $m->expand("redist");
70is($a[0], '| /path/to/redist', "'redist' => '$a[0]'");
71undef @a;
72
73# Expands to a path
74@a = $m->expand("archive");
75is($a[0], '/var/mail/archive', "'redist' => '$a[0]'");
76undef @a;
77
78# Backslashed alias:
79# backslashed: \jones
80# Note that jones is another alias in this file; the backslash
81# should prevent it from being further expanded.
82@a = $m->expand("backslashed");
83is($a[0], "jones", "'backslashed' => '$a[0]'");
84undef @a;
85
86# Self-referential alias:
87# nothing: nothing
88@a = $m->expand("nothing");
89is($a[0], "nothing", "'nothing' => '$a[0]'");
90undef @a;
91
92@a = $m->expand("silly");
93$a = join ",", @a;
94is($a, "silly,stuff", "'silly' => '$a'");
95undef @a;
96
97@a = $m->expand("spacetest");
98is($a[0], "/dev/null", "'spacetest' => '$a[0]'");
Note: See TracBrowser for help on using the repository browser.