#!/usr/bin/perl -w
$| = 1;
BEGIN { use_ok(
'Apache::ConfigParser'
); }
chdir
't'
if
-d
't'
;
@ISA
=
qw(Apache::ConfigParser)
;
my
@conf_files
=
glob
(
'httpd[0-9][0-9].conf'
);
is(
@conf_files
, 8,
'eight httpd\d{2}.conf files found'
);
{
my
$c
= EmptySubclass->new;
ok(
$c
,
'Apache::ConfigParser created for no configuration file'
);
isa_ok(
$c
,
'EmptySubclass'
);
my
$rc
=
$c
->parse_file(
'non-existent file'
);
ok(!
$rc
,
'Apache::ConfigParser->parse_file fails for non-existent file'
);
my
$regex
=
"cannot stat 'non-existent file':"
;
$rc
=
$c
->errstr =~ /
$regex
/o;
ok(
$rc
,
"Apache::ConfigParser->errstr matches regex \"$regex\""
);
}
sub
post_transform_munge {
is(
@_
, 5,
'post_transform_munge passed 5 arguments'
);
my
(
$parser
,
$directive
,
$filename
) =
@_
;
if
(
$directive
eq
'documentroot'
or
$directive
eq
'serverroot'
) {
return
$filename
;
}
"MUNGE $filename"
;
}
sub
post_transform_path {
is(
@_
, 3,
'post_transform_path passed 3 arguments'
);
my
(
$parser
,
$directive
,
$filename
) =
@_
;
if
(
$directive
eq
'documentroot'
or
$directive
eq
'serverroot'
) {
return
$filename
;
}
my
@elements
=
split
(m
$elements
[-1];
}
for
(
my
$i
=0;
$i
<
@conf_files
; ++
$i
) {
my
$conf_file
=
$conf_files
[
$i
];
my
$c
;
my
$opts_ref
;
if
(
$conf_file
eq
'httpd05.conf'
) {
$opts_ref
= {
post_transform_path_sub
=> \
&post_transform_path
};
}
elsif
(
$conf_file
eq
'httpd07.conf'
) {
$opts_ref
= {
post_transform_path_sub
=> [\
&post_transform_munge
, 1, 2]};
}
if
(
$opts_ref
) {
$c
= EmptySubclass->new(
$opts_ref
);
}
else
{
$c
= EmptySubclass->new;
}
isa_ok(
$c
,
'EmptySubclass'
);
$c
->{_include_file_ignore_missing_file} = 1;
ok(
$c
->parse_file(
$conf_file
),
"loaded '$conf_file'"
);
delete
$c
->{_include_file_ignore_missing_file};
my
@load_modules
= (0, 37, 0, 37, 18, 0, 1, 37);
is(
$c
->find_down_directive_names(
'LoadModule'
),
$load_modules
[
$i
],
"found $load_modules[$i] LoadModule's in the whole file"
);
@load_modules
= (0, 26, 0, 26, 18, 0, 1, 26);
is(
$c
->find_siblings_directive_names(
'LoadModule'
),
$load_modules
[
$i
],
"found $load_modules[$i] LoadModule's at the top level"
);
is(
$c
->find_siblings_directive_names((
$c
->root->daughters)[-1],
'LoadModule'
),
$load_modules
[
$i
],
"found $load_modules[$i] LoadModule's one level down"
);
$c
->{errstr} =~ s/:[^:]*$/: operating
system
specific error message/;
my
@result
=
$c
->
dump
(
$c
);
my
$answer_file
=
$conf_file
;
$answer_file
=~ s/\.conf$/\.answer/;
my
$open_file
=
open
(ANSWER,
$answer_file
);
ok(
$open_file
,
"opened `$answer_file' for reading"
);
SKIP: {
skip
"Cannot open $answer_file: $!"
, 1
unless
$open_file
;
my
@answer
= <ANSWER>;
@answer
=
map
{
$_
=~ s/\r?\n$//;
$_
}
@answer
;
close
(ANSWER);
my
$ok
= eq_array(\
@answer
, \
@result
);
ok(
$ok
,
"internal structure is ok"
);
unless
(
$ok
) {
if
(
open
(ANSWER,
">$answer_file.tmp"
)) {
print
ANSWER
join
(
"\n"
,
@result
),
"\n"
;
close
(ANSWER);
}
}
}
}