1use strict;
2use Test::More tests => 1;
3use POSIX qw(dup2);
4use IO::Handle;
5use FileHandle;
6
7use Net::FTPServer::InMem::Server;
8
9my $ok = 1;
10
11{
12  # Save old STDIN, STDOUT.
13  local (*STDIN, *STDOUT);
14
15  # By closing STDIN and STDOUT, we force the server to start up,
16  # try to read a command, and then immediately exit. The run()
17  # function returns, allowing us to examine the internal state of
18  # the FTP server.
19  open STDIN, "</dev/null";
20  open STDOUT, ">>/dev/null";
21
22  my $include1 = ".320include.t.1.$$";
23  my $include2 = ".320include.t.2.$$";
24  my $include3 = ".320include.t.3.$$";
25
26  open CF, ">$include1" or die "$include1: $!";
27  print CF <<EOT;
28key: 1
29EOT
30  close CF;
31
32  open CF, ">$include2" or die "$include2: $!";
33  print CF <<EOT;
34key: 2
35<Include $include3>
36EOT
37  close CF;
38
39  open CF, ">$include3" or die "$include3: $!";
40  print CF <<EOT;
41key: 3
42inner key: inner value
43EOT
44  close CF;
45
46  my $config = ".320include.t.$$";
47  open CF, ">$config" or die "$config: $!";
48  print CF <<EOT;
49key: 0
50outer key: outer value
51<Include $include1>
52<Include $include2>
53EOT
54  close CF;
55
56  my $ftps = Net::FTPServer::InMem::Server->run
57    (['--test', '-d', '-C', $config]);
58
59  unlink $config;
60  unlink $include1;
61  unlink $include2;
62  unlink $include3;
63
64  $ok = 0
65    unless $ftps->{_config_file} eq $config;
66
67  my @multi = $ftps->config ("key");
68
69  $ok = 0 unless @multi == 4;
70  $ok = 0 unless $multi[0] eq "0";
71  $ok = 0 unless $multi[1] eq "1";
72  $ok = 0 unless $multi[2] eq "2";
73  $ok = 0 unless $multi[3] eq "3";
74
75  $ok = 0
76    unless $ftps->config ("outer key") eq "outer value";
77
78  $ok = 0
79    unless $ftps->config ("inner key") eq "inner value";
80}
81
82# Old STDIN, STDOUT now restored.
83ok ($ok);
84
85__END__
86