diff options
-rw-r--r-- | lib/Apache/Config/Preproc/include.pm | 3 | ||||
-rw-r--r-- | t/00compact.t | 22 | ||||
-rw-r--r-- | t/01include00.t | 34 | ||||
-rw-r--r-- | t/01include01.t (renamed from t/pattern.t) | 4 | ||||
-rw-r--r-- | t/01include02.t | 39 | ||||
-rw-r--r-- | t/01include03.t (renamed from t/recursive.t) | 4 | ||||
-rw-r--r-- | t/02incopt00.t (renamed from t/patopt01.t) | 2 | ||||
-rw-r--r-- | t/02incopt01.t (renamed from t/patopt02.t) | 0 | ||||
-rw-r--r-- | t/03ifmodule00.t | 75 | ||||
-rw-r--r-- | t/03ifmodule01.t | 73 | ||||
-rw-r--r-- | t/04macro00.t (renamed from t/macro01.t) | 0 | ||||
-rw-r--r-- | t/04macro01.t (renamed from t/macro02.t) | 0 | ||||
-rw-r--r-- | t/99all00.t | 128 | ||||
-rw-r--r-- | t/TestPreproc.pm | 1 | ||||
-rw-r--r-- | t/inc.t | 70 | ||||
-rw-r--r-- | t/nested.t | 69 |
16 files changed, 379 insertions, 145 deletions
diff --git a/lib/Apache/Config/Preproc/include.pm b/lib/Apache/Config/Preproc/include.pm index 800e77a..dfa841c 100644 --- a/lib/Apache/Config/Preproc/include.pm +++ b/lib/Apache/Config/Preproc/include.pm @@ -31,7 +31,8 @@ sub expand { } if (my $inc = new Apache::Admin::Config($file, @{$tree->options})) { - push @$repl, $inc->select; + # NOTE: make sure each item is cloned + push @$repl, map { $_->clone } $inc->select; } else { croak $Apache::Admin::Config::ERROR; } diff --git a/t/00compact.t b/t/00compact.t new file mode 100644 index 0000000..e7c68c5 --- /dev/null +++ b/t/00compact.t @@ -0,0 +1,22 @@ +# -*- perl -*- +use lib qw(t lib); +use strict; +use Test; +plan test => 1; + +use TestPreproc; + +my $obj = new TestPreproc -expand => [qw(compact)]; +ok($obj->dump_raw, $obj->dump_expect); +__DATA__ +!>httpd.conf +# Main file +ServerName localhost + + ServerRoot "$server_root" +# Comment 1 +# Comment 2 +!= +ServerName localhost + ServerRoot "$server_root" +!$ diff --git a/t/01include00.t b/t/01include00.t new file mode 100644 index 0000000..7745871 --- /dev/null +++ b/t/01include00.t @@ -0,0 +1,34 @@ +# -*- perl -*- +use lib qw(t lib); +use strict; +use Test; +plan test => 1; + +use TestPreproc; + +my $obj = new TestPreproc -expand => [qw(include)]; +ok($obj->dump_raw, $obj->dump_expect); + +__DATA__ +!>httpd.conf +# Main file +ServerName localhost +ServerRoot "$server_root" +Include vhost.conf +PidFile logs/httpd.pid +!>vhost.conf +# Vhost include +<VirtualHost *:80> + ServerName foo.bar.example.com +</VirtualHost> +!= +# Main file +ServerName localhost +ServerRoot "$server_root" +# Vhost include +<VirtualHost *:80> + ServerName foo.bar.example.com +</VirtualHost> +PidFile logs/httpd.pid +!$ + diff --git a/t/pattern.t b/t/01include01.t index 3a8d978..98ea840 100644 --- a/t/pattern.t +++ b/t/01include01.t @@ -5,8 +5,8 @@ use Test; plan test => 1; use TestPreproc; - -my $obj = new TestPreproc '-compact'; +# Test include by globbing pattern +my $obj = new TestPreproc -expand => [qw(include)]; ok($obj->dump_raw, $obj->dump_expect); __DATA__ !>httpd.conf diff --git a/t/01include02.t b/t/01include02.t new file mode 100644 index 0000000..51dec9f --- /dev/null +++ b/t/01include02.t @@ -0,0 +1,39 @@ +# -*- perl -*- +use lib qw(t lib); +use strict; +use Test; +plan test => 1; + +use TestPreproc; +# Test nested includes +my $obj = new TestPreproc -expand => [qw(include)]; +ok($obj->dump_raw, $obj->dump_expect); + +__DATA__ +!>httpd.conf +# Main configuration +ServerType standalone +ServerRoot "$server_root" +Include "level1.conf" +PidFile logs/httpd.pid +!>level1.conf +# First-level include file +Timeout 300 +Include level2.conf +KeepAlive On +!>level2.conf +# Second-level include file +MaxKeepAliveRequests 100 +KeepAliveTimeout 15 +!= +# Main configuration +ServerType standalone +ServerRoot "$server_root" +# First-level include file +Timeout 300 +# Second-level include file +MaxKeepAliveRequests 100 +KeepAliveTimeout 15 +KeepAlive On +PidFile logs/httpd.pid +!$ diff --git a/t/recursive.t b/t/01include03.t index 9423a04..1f9df6a 100644 --- a/t/recursive.t +++ b/t/01include03.t @@ -5,8 +5,8 @@ use Test; plan test => 2; use TestPreproc; - -ok(!new TestPreproc '-expect_fail', '-compact'); +# Test recursive inclusion handling +ok(!new TestPreproc '-expect_fail', -expand => [qw(include)]); ok($Apache::Admin::Config::ERROR, qr/level1.conf already included/); __DATA__ !>httpd.conf diff --git a/t/patopt01.t b/t/02incopt00.t index bfe7fd9..8e6a93f 100644 --- a/t/patopt01.t +++ b/t/02incopt00.t @@ -5,7 +5,7 @@ use Test; plan test => 1; use TestPreproc; - +# Test IncludeOptional my $obj = new TestPreproc '-compact'; ok($obj->dump_raw, $obj->dump_expect); __DATA__ diff --git a/t/patopt02.t b/t/02incopt01.t index f64c52d..f64c52d 100644 --- a/t/patopt02.t +++ b/t/02incopt01.t diff --git a/t/03ifmodule00.t b/t/03ifmodule00.t new file mode 100644 index 0000000..7d2c286 --- /dev/null +++ b/t/03ifmodule00.t @@ -0,0 +1,75 @@ +# -*- perl -*- +use lib qw(t lib); +use strict; +use Test; +plan test => 1; + +use TestPreproc; + +my $obj = new TestPreproc -expand => [qw(ifmodule)]; +ok($obj->dump_raw, $obj->dump_expect); + +__DATA__ +!>httpd.conf +LoadModule mpm_prefork_module lib/httpd/modules/mod_mpm_prefork.so +LoadModule unixd_module lib/httpd/modules/mod_unixd.so + +<IfModule !mpm_netware_module> + PidFile "/var/run/httpd.pid" +</IfModule> +<IfModule mpm_prefork_module> + StartServers 1 + MinSpareServers 1 + MaxSpareServers 1 + MaxClients 10 + MaxRequestsPerChild 0 +</IfModule> +<IfModule mpm_worker_module> + StartServers 2 + MaxClients 150 + MinSpareThreads 25 + MaxSpareThreads 75 + ThreadsPerChild 25 + MaxRequestsPerChild 0 +</IfModule> +<IfModule mpm_beos_module> + StartThreads 10 + MaxClients 50 + MaxRequestsPerThread 10000 +</IfModule> +<IfModule mpm_netware_module> + ThreadStackSize 65536 + StartThreads 250 + MinSpareThreads 25 + MaxSpareThreads 250 + MaxThreads 1000 + MaxRequestsPerChild 0 + MaxMemFree 100 +</IfModule> +<IfModule mpm_mpmt_os2_module> + StartServers 2 + MinSpareThreads 5 + MaxSpareThreads 10 + MaxRequestsPerChild 0 +</IfModule> +<IfModule unixd_module> + User apache + Group apache +</IfModule> +<IfModule mpm_winnt_module> + ThreadsPerChild 150 + MaxRequestsPerChild 0 +</IfModule> +!= +LoadModule mpm_prefork_module lib/httpd/modules/mod_mpm_prefork.so +LoadModule unixd_module lib/httpd/modules/mod_unixd.so + + PidFile "/var/run/httpd.pid" + StartServers 1 + MinSpareServers 1 + MaxSpareServers 1 + MaxClients 10 + MaxRequestsPerChild 0 + User apache + Group apache +!$ diff --git a/t/03ifmodule01.t b/t/03ifmodule01.t new file mode 100644 index 0000000..54f135b --- /dev/null +++ b/t/03ifmodule01.t @@ -0,0 +1,73 @@ +# -*- perl -*- +use lib qw(t lib); +use strict; +use Test; +plan test => 4; + +use TestPreproc; + +my $obj = new TestPreproc -expand => [qw(ifmodule)]; +ok($obj->dump_raw, $obj->dump_expect); + +$obj = new TestPreproc -expand => [qw(ifmodule)]; +ok($obj->dump_raw, $obj->dump_expect); + +$obj = new TestPreproc -expand => [qw(ifmodule)]; +ok($obj->dump_raw, $obj->dump_expect); + +$obj = new TestPreproc -expand => [qw(ifmodule)]; +ok($obj->dump_raw, $obj->dump_expect); +__DATA__ +!>httpd.conf +LoadModule mpm_prefork_module lib/httpd/modules/mod_mpm_prefork.so +<IfModule log_config_module> +LogFormat "%a" combined +<IfModule logio_module> +LogFormat "%a %I %O" combinedio +</IfModule> +</IfModule> +!= +LoadModule mpm_prefork_module lib/httpd/modules/mod_mpm_prefork.so +!$ +__END__ +!>httpd.conf +LoadModule log_config_module lib/httpd/modules/mod_log_config.so +<IfModule log_config_module> +LogFormat "%a" combined +<IfModule logio_module> +LogFormat "%a %I %O" combinedio +</IfModule> +</IfModule> +!= +LoadModule log_config_module lib/httpd/modules/mod_log_config.so +LogFormat "%a" combined +!$ +__END__ +!>httpd.conf +LoadModule log_config_module lib/httpd/modules/mod_log_config.so +LoadModule logio_module lib/httpd/modules/mod_logio.so +<IfModule log_config_module> +LogFormat "%a" combined +<IfModule logio_module> +LogFormat "%a %I %O" combinedio +</IfModule> +</IfModule> +!= +LoadModule log_config_module lib/httpd/modules/mod_log_config.so +LoadModule logio_module lib/httpd/modules/mod_logio.so +LogFormat "%a" combined +LogFormat "%a %I %O" combinedio +!$ +__END__ +!>httpd.conf +LoadModule logio_module lib/httpd/modules/mod_logio.so +<IfModule log_config_module> +LogFormat "%a" combined +<IfModule logio_module> +LogFormat "%a %I %O" combinedio +</IfModule> +</IfModule> +!= +LoadModule logio_module lib/httpd/modules/mod_logio.so +!$ + diff --git a/t/macro01.t b/t/04macro00.t index 7c0a5d1..7c0a5d1 100644 --- a/t/macro01.t +++ b/t/04macro00.t diff --git a/t/macro02.t b/t/04macro01.t index c4bd730..c4bd730 100644 --- a/t/macro02.t +++ b/t/04macro01.t diff --git a/t/99all00.t b/t/99all00.t new file mode 100644 index 0000000..a70dd6a --- /dev/null +++ b/t/99all00.t @@ -0,0 +1,128 @@ +# -*- perl -*- +use lib qw(t lib); +use strict; +use Test; +plan test => 1; + +use TestPreproc; + +my $obj = new TestPreproc -expand => [qw(compact include ifmodule macro)]; +ok($obj->dump_raw, $obj->dump_expect); +__DATA__ +!>httpd.conf +# Main file +ServerName localhost +ServerRoot "$server_root" + +Include conf.d/*.conf + +Include mpm.conf +Include log.conf +Include vhost.conf +Timeout 300 +!>conf.d/load.conf +# Load prefork mpm +LoadModule mpm_prefork_module lib/httpd/modules/mod_mpm_prefork.so +# Load logging modules +LoadModule log_config_module lib/httpd/modules/mod_log_config.so +LoadModule logio_module lib/httpd/modules/mod_logio.so +!>conf.d/vhost.conf +<Macro vhost $name $port $dir> + <VirtualHost *:$port> + # Comment + ServerName $name + DocumentRoot $dir + + <Directory $dir> + Require all granted + </Directory> + </VirtualHost> + +</Macro> +!>mpm.conf +<IfModule !mpm_netware_module> + PidFile "/var/run/httpd.pid" +</IfModule> +<IfModule mpm_prefork_module> + StartServers 1 + MinSpareServers 1 + MaxSpareServers 1 + MaxClients 10 + MaxRequestsPerChild 0 +</IfModule> +<IfModule mpm_worker_module> + StartServers 2 + MaxClients 150 + MinSpareThreads 25 + MaxSpareThreads 75 + ThreadsPerChild 25 + MaxRequestsPerChild 0 +</IfModule> +<IfModule mpm_beos_module> + StartThreads 10 + MaxClients 50 + MaxRequestsPerThread 10000 +</IfModule> +<IfModule mpm_netware_module> + ThreadStackSize 65536 + StartThreads 250 + MinSpareThreads 25 + MaxSpareThreads 250 + MaxThreads 1000 + MaxRequestsPerChild 0 + MaxMemFree 100 +</IfModule> +<IfModule mpm_mpmt_os2_module> + StartServers 2 + MinSpareThreads 5 + MaxSpareThreads 10 + MaxRequestsPerChild 0 +</IfModule> +<IfModule unixd_module> + User apache + Group apache +</IfModule> +<IfModule mpm_winnt_module> + ThreadsPerChild 150 + MaxRequestsPerChild 0 +</IfModule> +!>log.conf +<IfModule log_config_module> + LogFormat "%a" combined + <IfModule logio_module> + LogFormat "%a %I %O" combinedio + </IfModule> +</IfModule> +!>vhost.conf +Use vhost foo 80 /var/www/foo +Use vhost bar 443 /var/www/bar +!= +ServerName localhost +ServerRoot "$server_root" +LoadModule mpm_prefork_module lib/httpd/modules/mod_mpm_prefork.so +LoadModule log_config_module lib/httpd/modules/mod_log_config.so +LoadModule logio_module lib/httpd/modules/mod_logio.so + PidFile "/var/run/httpd.pid" + StartServers 1 + MinSpareServers 1 + MaxSpareServers 1 + MaxClients 10 + MaxRequestsPerChild 0 + LogFormat "%a" combined + LogFormat "%a %I %O" combinedio + <VirtualHost *:80> + ServerName foo + DocumentRoot /var/www/foo + <Directory /var/www/foo> + Require all granted + </Directory> + </VirtualHost> + <VirtualHost *:443> + ServerName bar + DocumentRoot /var/www/bar + <Directory /var/www/bar> + Require all granted + </Directory> + </VirtualHost> +Timeout 300 +!$ diff --git a/t/TestPreproc.pm b/t/TestPreproc.pm index 7bcf121..9de5fe2 100644 --- a/t/TestPreproc.pm +++ b/t/TestPreproc.pm @@ -21,6 +21,7 @@ sub new { my $fd; my $confname; while (<main::DATA>) { + last if /^__END__/; if (/^!%\s*(.+)\s*$/) { $confname = File::Spec->catfile($dir, $1); } elsif (/^!>\s*(.+)\s*$/) { diff --git a/t/inc.t b/t/inc.t deleted file mode 100644 index c9d0bd4..0000000 --- a/t/inc.t +++ /dev/null @@ -1,70 +0,0 @@ -# -*- perl -*- -use lib qw(t lib); -use strict; -use Test; -plan test => 1; - -use TestPreproc; - -my $obj = new TestPreproc '-compact'; -ok($obj->dump_raw, $obj->dump_expect); - -__DATA__ -!>httpd.conf -# Test configuration file - -# -# ServerType is either inetd, or standalone. Inetd mode is only supported on -# Unix platforms. -# -ServerType standalone - -# -# ServerRoot: The top of the directory tree under which the server's -# configuration, error, and log files are kept. -# -ServerRoot "$server_root" - -Include "level1.conf" - -PidFile logs/httpd.pid - -Include level2.conf - -!>level1.conf -# First-level include file - -# -# Timeout: The number of seconds before receives and sends time out. -# -Timeout 300 - -# -# KeepAlive: Whether or not to allow persistent connections (more than -# one request per connection). Set to "Off" to deactivate. -# -KeepAlive On -!>level2.conf -# Second-level include file - -# -# MaxKeepAliveRequests: The maximum number of requests to allow -# during a persistent connection. Set to 0 to allow an unlimited amount. -# We recommend you leave this number high, for maximum performance. -# -MaxKeepAliveRequests 100 - -# -# KeepAliveTimeout: Number of seconds to wait for the next request from the -# same client on the same connection. -# -KeepAliveTimeout 15 -!= -ServerType standalone -ServerRoot "$server_root" -Timeout 300 -KeepAlive On -PidFile logs/httpd.pid -MaxKeepAliveRequests 100 -KeepAliveTimeout 15 -!$ diff --git a/t/nested.t b/t/nested.t deleted file mode 100644 index d116b47..0000000 --- a/t/nested.t +++ /dev/null @@ -1,69 +0,0 @@ -# -*- perl -*- -use lib qw(t lib); -use strict; -use Test; -plan test => 1; - -use TestPreproc; - -my $obj = new TestPreproc '-compact'; -ok($obj->dump_raw, $obj->dump_expect); - -__DATA__ -!>httpd.conf -# Test configuration file - -# -# ServerType is either inetd, or standalone. Inetd mode is only supported on -# Unix platforms. -# -ServerType standalone - -# -# ServerRoot: The top of the directory tree under which the server's -# configuration, error, and log files are kept. -# -ServerRoot "$server_root" - -Include "level1.conf" - -PidFile logs/httpd.pid -!>level1.conf -# First-level include file - -# -# Timeout: The number of seconds before receives and sends time out. -# -Timeout 300 - -Include level2.conf - -# -# KeepAlive: Whether or not to allow persistent connections (more than -# one request per connection). Set to "Off" to deactivate. -# -KeepAlive On -!>level2.conf -# Second-level include file - -# -# MaxKeepAliveRequests: The maximum number of requests to allow -# during a persistent connection. Set to 0 to allow an unlimited amount. -# We recommend you leave this number high, for maximum performance. -# -MaxKeepAliveRequests 100 - -# -# KeepAliveTimeout: Number of seconds to wait for the next request from the -# same client on the same connection. -# -KeepAliveTimeout 15 -!= -ServerType standalone -ServerRoot "$server_root" -Timeout 300 -MaxKeepAliveRequests 100 -KeepAliveTimeout 15 -KeepAlive On -PidFile logs/httpd.pid -!$ |