Testsuite: Add POD to Exim::Runtest
[exim.git] / test / lib / Exim / Runtest.pm
CommitLineData
1f187290
HSHR
1package Exim::Runtest;
2use strict;
3use warnings;
b369d470 4use IO::Socket::INET;
1f187290
HSHR
5use Carp;
6
7use List::Util qw'shuffle';
8
10012250
HSHR
9=head1 NAME
10
11Exim::Runtest - helper functions for the runtest script
12
13=head1 SYNOPSIS
14
15 use Exim::Runtest;
16 my $foo = Exim::Runtest::foo('foo');
17
18=head1 DESCRIPTION
19
20The B<Exim::Runtest> module provides some simple functions
21for the F<runtest> script. No functions are exported yet.
22
23=cut
1f187290 24
1f187290
HSHR
25sub mailgroup {
26 my $group = shift;
27
28 croak "Need a group *name*, not a numeric group id."
29 if $group =~ /^\d+$/;
30
31 return $group if getgrnam $group;
32
33 my @groups;
34 setgrent or die "setgrent: $!\n";
35 push @groups, $_ while defined($_ = getgrent);
36 endgrent;
37 return (shuffle @groups)[0];
b369d470
HSHR
38}
39
40sub dynamic_socket {
41 my $socket;
42 for (my $port = 1024; $port < 65000; $port++) {
43 $socket = IO::Socket::INET->new(
44 LocalHost => '127.0.0.1',
45 LocalPort => $port,
46 Listen => 10,
47 ReuseAddr => 1,
48 ) and return $socket;
49 }
50 croak 'Can not allocate a free port.';
51}
1f187290
HSHR
52
531;
10012250
HSHR
54
55__END__
56
57=head1 FUNCTIONS
58
59=over
60
61=item B<mailgroup>(I<$default>)
62
63Check if the mailgroup I<$default> exists. Return the checked
64group name or some other random but existing group.
65
66=item B<dynamic_socket>()
67
68Return a dynamically allocated listener socket in the range
69between 1024 and 65534;
70
71=back
72
73=cut