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 | |
---|
10 | use strict; |
---|
11 | use FindBin qw($Bin); |
---|
12 | use Mail::ExpandAliases; |
---|
13 | use File::Spec::Functions qw(catfile); |
---|
14 | use Test::More; |
---|
15 | |
---|
16 | my ($aliases_file, $m, @a, $a); |
---|
17 | BEGIN { |
---|
18 | plan tests => 16; |
---|
19 | } |
---|
20 | |
---|
21 | use_ok("Mail::ExpandAliases"); |
---|
22 | |
---|
23 | $aliases_file = catfile($Bin, "aliases"); |
---|
24 | |
---|
25 | ok(defined($m = Mail::ExpandAliases->new($aliases_file))); |
---|
26 | |
---|
27 | @a = $m->expand('spam'); |
---|
28 | is($a[0], '/dev/null', "'spam' => '$a[0]'"); |
---|
29 | undef @a; |
---|
30 | |
---|
31 | # Lists of addresses are sorted |
---|
32 | @a = $m->expand('jones'); |
---|
33 | $a = join ',', @a; |
---|
34 | is($a, 'Barnaby_Jones@unresolvable.perl.org,Bridget_Jones@unresolvable.perl.org,Quincy_Jones@unresolvable.perl.org,Tom_Jones@unresolvable.perl.org', "'jones' => '$a'"); |
---|
35 | undef @a; |
---|
36 | |
---|
37 | # Standard MAILER-DAEMON expansion test |
---|
38 | @a = $m->expand('MAILER-DAEMON'); |
---|
39 | is($a[0], '/dev/null', "'MAILER-DAEMON' => '$a[0]'"); |
---|
40 | undef @a; |
---|
41 | |
---|
42 | # An alias that is not in the file; should "expand" to itself. |
---|
43 | @a = $m->expand('not-there'); |
---|
44 | is($a[0], 'not-there', "'not-there' => '$a[0]'"); |
---|
45 | undef @a; |
---|
46 | |
---|
47 | # Just a regular alias (see next test for why this one is here) |
---|
48 | @a = $m->expand('tjones'); |
---|
49 | is($a[0], 'Tom_Jones@unresolvable.perl.org', "'tjones' => '$a[0]'"); |
---|
50 | undef @a; |
---|
51 | |
---|
52 | # Different capitalization of the above alias -- they should return |
---|
53 | # the same value. |
---|
54 | @a = $m->expand('TJones'); |
---|
55 | is($a[0], 'Tom_Jones@unresolvable.perl.org', "'TJones' => '$a[0]'"); |
---|
56 | undef @a; |
---|
57 | |
---|
58 | # Another pair of capitilization tests |
---|
59 | @a = $m->expand('postmaster'); |
---|
60 | is($a[0], '/dev/null', "'postmaster' => '$a[0]'"); |
---|
61 | undef @a; |
---|
62 | |
---|
63 | @a = $m->expand('Postmaster'); |
---|
64 | is($a[0], '/dev/null', "'Postmaster' => '$a[0]'"); |
---|
65 | undef @a; |
---|
66 | |
---|
67 | |
---|
68 | # Expands to a command. |
---|
69 | @a = $m->expand("redist"); |
---|
70 | is($a[0], '| /path/to/redist', "'redist' => '$a[0]'"); |
---|
71 | undef @a; |
---|
72 | |
---|
73 | # Expands to a path |
---|
74 | @a = $m->expand("archive"); |
---|
75 | is($a[0], '/var/mail/archive', "'redist' => '$a[0]'"); |
---|
76 | undef @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"); |
---|
83 | is($a[0], "jones", "'backslashed' => '$a[0]'"); |
---|
84 | undef @a; |
---|
85 | |
---|
86 | # Self-referential alias: |
---|
87 | # nothing: nothing |
---|
88 | @a = $m->expand("nothing"); |
---|
89 | is($a[0], "nothing", "'nothing' => '$a[0]'"); |
---|
90 | undef @a; |
---|
91 | |
---|
92 | @a = $m->expand("silly"); |
---|
93 | $a = join ",", @a; |
---|
94 | is($a, "silly,stuff", "'silly' => '$a'"); |
---|
95 | undef @a; |
---|
96 | |
---|
97 | @a = $m->expand("spacetest"); |
---|
98 | is($a[0], "/dev/null", "'spacetest' => '$a[0]'"); |
---|