Subject: | [PATCH] minor test tweaks for portability |
When HTTP::Tiny came into blead, it failed a lot of tests on VMS but not for very deep reasons.
The attached patch gets everything passing.
I think the only thing that won't be self explanatory is that -s (or the st_size field returned by
fstat) has a delay in getting populated so it's not necessarily there when you first write to a file,
and this made the sanity check in the slurp() function in t/Util.pm always fail.
My hack/workaround was to seek to EOF and use the result of tell() as the file size for
comparison just before rewinding. May not be pretty but for these tiny files used for testing
purposes it shouldn't matter much.
Subject: | http_tiny.patch |
--- cpan/HTTP-Tiny/t/110_mirror.t;-0 2011-01-16 20:06:14 -0600
+++ cpan/HTTP-Tiny/t/110_mirror.t 2011-02-03 15:27:33 -0600
@@ -17,11 +17,12 @@ use t::Util qw[tmpfile rewind slurp m
set_socket_source sort_headers $CRLF $LF];
use HTTP::Tiny;
use File::Temp qw/tempdir/;
+use File::Spec qw/catfile/;
BEGIN { monkey_patch() }
my $tempdir = tempdir( TMPDIR => 1, CLEANUP => 1 );
-my $tempfile = $tempdir . "/tempfile.txt";
+my $tempfile = File::Spec->catfile( $tempdir, "tempfile.txt" );
my $known_epoch = 760233600;
my $day = 24*3600;
@@ -32,7 +33,7 @@ my %timestamp = (
);
for my $file ( dir_list("t/cases", qr/^mirror/ ) ) {
- unlink $tempfile;
+ 1 while unlink $tempfile;
my $data = do { local (@ARGV,$/) = $file; <> };
my ($params, $expect_req, $give_res) = split /--+\n/, $data;
# cleanup source data
--- cpan/HTTP-Tiny/t/Util.pm;-0 2011-01-16 20:06:14 -0600
+++ cpan/HTTP-Tiny/t/Util.pm 2011-02-03 15:19:32 -0600
@@ -11,7 +11,7 @@ package t::Util;
use strict;
use warnings;
-use IO::File q[SEEK_SET];
+use IO::File qw(SEEK_SET SEEK_END);
use IO::Dir;
BEGIN {
@@ -72,12 +72,16 @@ sub dir_list {
sub slurp (*) {
my ($fh) = @_;
+ seek($fh, 0, SEEK_END)
+ || die(qq/Couldn't navigate to EOF on file handle: '$!'/);
+
+ my $exp = tell($fh);
+
rewind($fh);
binmode($fh)
|| die(qq/Couldn't binmode file handle: '$!'/);
- my $exp = -s $fh;
my $buf = do { local $/; <$fh> };
my $got = length $buf;