From 0cbcdb0d4083eb97a6e052471cb51f8b31f3c92c Mon Sep 17 00:00:00 2001 From: root Date: Sat, 24 Apr 2021 14:20:56 +0000 Subject: Improve testing capabilities --- t/basic.t | 65 +++++++++++++++++++++++++++++------------------ t/conf/extra.conf.in | 4 +++ t/conf/extra.last.conf.in | 3 --- 3 files changed, 44 insertions(+), 28 deletions(-) diff --git a/t/basic.t b/t/basic.t index 4833d68..c82f6e2 100644 --- a/t/basic.t +++ b/t/basic.t @@ -7,46 +7,61 @@ use Apache::TestRequest qw/GET_BODY/; plan tests => 5; -# Prepare environment +my $head; # expected page header +my $foot; # expected page footer +my @body; # sections of page body -open my $h, '<', 't/htdocs/head.html' or die; -open my $f, '<', 't/htdocs/foot.html' or die; -my $head = do { local $/; <$h> }; -my $foot = do { local $/; <$f> }; +# Read contents of header and footer + +open my $h, '<', 't/htdocs/head.html' or die "Could not open < head.html: $!"; +open my $f, '<', 't/htdocs/foot.html' or die "Could not open < foot.html: $!"; +$head = do { local $/; <$h> }; +$foot = do { local $/; <$f> }; close $h; close $f; -my @test; -sub prepare { - open my $t, '>', 't/htdocs/test.html' or die; - print $t join('', @_); - close $t; +# Set up helpers + +sub set_conf { + open my $c, '>', 't/htdocs/.htaccess' or die; + print $c shift; + close $c; +} +sub set_body { + open my $b, '>', 't/htdocs/test.html' or die; + print $b join('', @_); + close $b; } # Run tests -@test = ("Test\n", "This is a test page.\n"); -prepare @test; -ok GET_BODY('/test.html'), "${test[0]}$head${test[1]}$foot", +set_conf <Test\n", "This is a test page.\n"); +set_body @body; +ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot", '-less head'; -@test = ("...\n", "This is a test page.\n"); -prepare @test; -ok GET_BODY('/test.html'), "${test[0]}$head${test[1]}$foot", +@body = ("...\n", "This is a test page.\n"); +set_body @body; +ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot", '-ful head'; -@test = ("\n", "This is a test page.\n", "\n"); -prepare @test; -ok GET_BODY('/test.html'), "${test[0]}$head${test[1]}$foot${test[2]}", +@body = ("\n", "This is a test page.\n", "\n"); +set_body @body; +ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot${body[2]}", '-wrapped document'; -@test = ("\n", "This is a test page.\n"); -prepare @test; -ok GET_BODY('/test.html'), "${test[0]}$head${test[1]}$foot", +@body = ("\n", "This is a test page.\n"); +set_body @body; +ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot", ''; -@test = ("\n\n", "This is a test page.\n"); -prepare @test; -ok GET_BODY('/test.html'), "${test[0]}$head${test[1]}$foot", +@body = ("\n\n", "This is a test page.\n"); +set_body @body; +ok GET_BODY('/test.html'), "${body[0]}$head${body[1]}$foot", ' with leading newline'; +unlink 't/htdocs/.htaccess'; unlink 't/htdocs/test.html'; diff --git a/t/conf/extra.conf.in b/t/conf/extra.conf.in index fe9de1d..1a9ce52 100644 --- a/t/conf/extra.conf.in +++ b/t/conf/extra.conf.in @@ -1 +1,5 @@ PerlSwitches -I@ServerRoot@/../lib + + Options FollowSymLinks + AllowOverride All + diff --git a/t/conf/extra.last.conf.in b/t/conf/extra.last.conf.in index 0156023..b708606 100644 --- a/t/conf/extra.last.conf.in +++ b/t/conf/extra.last.conf.in @@ -1,4 +1 @@ PerlLoadModule Apache::Inject - - Inject head.html foot.html - -- cgit v1.2.3