Skip to content

Commit

Permalink
Fix parameters passed to format()
Browse files Browse the repository at this point in the history
  • Loading branch information
lestrrat committed Oct 14, 2015
1 parent 7d3efca commit 3e90d9b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
[![Build Status](https://travis-ci.org/lestrrat/p6-Apache-LogFormat-Compiler.svg?branch=master)](https://travis-ci.org/lestrrat/p6-Apache-LogFormat-Compiler)
[![Build Status](https://travis-ci.org/lestrrat/p6-Apache-LogFormat.svg?branch=master)](https://travis-ci.org/lestrrat/p6-Apache-LogFormat)

NAME
====
Expand Down
6 changes: 2 additions & 4 deletions lib/Apache/LogFormat/Formatter.pm6
Expand Up @@ -12,10 +12,8 @@ submethod BUILD(:&!callback) { }

# %env is the PSGI environment hash
# @res is a 3 item list, in PSGI style
method format(Apache::LogFormat::Formatter:D: %env, @res) {
# TODO: provide proper parameters to callback
my $time = DateTime.now();
return &!callback(%env, @res, Nil, Nil, $time) ~ "\n";
method format(Apache::LogFormat::Formatter:D: %env, @res, $length, $reqtime, $time) {
return &!callback(%env, @res, $length, $reqtime, $time) ~ "\n";
}


Expand Down
5 changes: 4 additions & 1 deletion t/01-basic.t
Expand Up @@ -19,7 +19,10 @@ my %env = (
SERVER_PROTOCOL => "HTTP/1.0",
);
my @res = (200, ["Content-Type" => "text/plain"], ["Hello, World".encode('ascii')]);
my $got = $fmt.format(%env, @res);
my $t0 = DateTime.now.Instant;
sleep 1;
my $now = DateTime.now;
my $got = $fmt.format(%env, @res, 10, $t0 - $now.Instant, $now);

if ! ok($got ~~ m!'GET /foo/bar/baz HTTP/1.0'!, "Checking %r") {
note $got;
Expand Down
7 changes: 5 additions & 2 deletions t/02-predefined.t
Expand Up @@ -17,9 +17,12 @@ my %env = (
SERVER_PROTOCOL => "HTTP/1.0",
);
my @res = (200, ["Content-Type" => "text/plain"], ["Hello, World".encode('ascii')]);
my $got = $fmt.format(%env, @res);
my $t0 = DateTime.now.Instant;
sleep 1;
my $now = DateTime.now;
my $got = $fmt.format(%env, @res, 10, $t0 - $now.Instant, $now);

if !ok $got ~~ /^ "192.168.1.1 - foo [" \d**2\/<[A..Z]><[a..z]>**2\/\d**4\:\d**2\:\d**2\:\d**2 " " <[\+\-]>\d**4 '] "GET /foo/bar/baz HTTP/1.0" 200 - "http://doc.perl6.org" "Firefox foo blah\x0a"' /, "line matches" {
if !ok $got ~~ /^ "192.168.1.1 - foo [" \d**2\/<[A..Z]><[a..z]>**2\/\d**4\:\d**2\:\d**2\:\d**2 " " <[\+\-]>\d**4 '] "GET /foo/bar/baz HTTP/1.0" 200 ' \d+ ' "http://doc.perl6.org" "Firefox foo blah\x0a"' /, "line matches" {
note $got;
}
done-testing;
5 changes: 4 additions & 1 deletion t/03-custom.t
Expand Up @@ -24,7 +24,10 @@ my @res = (
["Content-Type" => "text/plain", "Content-Length" => 2],
["OK"],
);
my $got = $fmt.format(%env, @res);
my $t0 = DateTime.now.Instant;
sleep 1;
my $now = DateTime.now;
my $got = $fmt.format(%env, @res, 10, $t0 - $now.Instant, $now);

if ! ok($got ~~ m!'7 application/x-www-form-urlencoded text/plain 2'!, "line is as expected") {
note $got;
Expand Down
5 changes: 4 additions & 1 deletion t/04-extra.t
Expand Up @@ -35,7 +35,10 @@ my @res = (
["X-Res-Test" => "bar"],
["OK"],
);
my $got = $fmt.format(%env, @res);
my $t0 = DateTime.now.Instant;
sleep 1;
my $now = DateTime.now;
my $got = $fmt.format(%env, @res, 10, $t0 - $now.Instant, $now);

if ! ok($got ~~ m!'foo HTTP_X_FORWARDED_FOR|REMOTE_ADDR'!, "line is as expected") {
note $got;
Expand Down

0 comments on commit 3e90d9b

Please sign in to comment.