Skip to content

Commit 55b0049

Browse files
michal-josef-spacekoalders
authored andcommitted
Fix test writing to files
There were situation when test write to local directory instead of /tmp file. This is bad practice in testing.
1 parent 09fb86e commit 55b0049

File tree

5 files changed

+11
-3
lines changed

5 files changed

+11
-3
lines changed

Changes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Revision history for HTTP-Message
22

33
{{$NEXT}}
4+
- Fix test writing to files (GH#156) (Michal Josef Špaček)
45

56
6.30 2021-05-10 14:55:55Z
67
- Don't inherit from Exporter anymore (GH#155) (Max Maischein)

META.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"requires" : {
8282
"ExtUtils::MakeMaker" : "0",
8383
"File::Spec" : "0",
84+
"File::Temp" : "0",
8485
"PerlIO::encoding" : "0",
8586
"Test::More" : "0.88",
8687
"Time::Local" : "0",

Makefile.PL

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ my %WriteMakefileArgs = (
4242
"TEST_REQUIRES" => {
4343
"ExtUtils::MakeMaker" => 0,
4444
"File::Spec" => 0,
45+
"File::Temp" => 0,
4546
"PerlIO::encoding" => 0,
4647
"Test::More" => "0.88",
4748
"Time::Local" => 0,
@@ -65,6 +66,7 @@ my %FallbackPrereqs = (
6566
"Exporter" => "5.57",
6667
"ExtUtils::MakeMaker" => 0,
6768
"File::Spec" => 0,
69+
"File::Temp" => 0,
6870
"HTTP::Date" => 6,
6971
"IO::Compress::Bzip2" => "2.021",
7072
"IO::Compress::Deflate" => 0,

cpanfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ suggests "Clone" => "0";
2828
on 'test' => sub {
2929
requires "ExtUtils::MakeMaker" => "0";
3030
requires "File::Spec" => "0";
31+
requires "File::Temp" => "0";
3132
requires "PerlIO::encoding" => "0";
3233
requires "Test::More" => "0.88";
3334
requires "Time::Local" => "0";

t/common-req.t

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use warnings;
44
use Test::More;
55
plan tests => 71;
66

7+
use File::Spec;
8+
use File::Temp qw(tempfile);
79
use HTTP::Request::Common;
810

911
my $r = GET 'http://www.sn.no/';
@@ -117,7 +119,8 @@ is($r->content_type, "text/plain");
117119
#
118120
# POST for File upload
119121
#
120-
my $file = "test-$$";
122+
my (undef, $file) = tempfile();
123+
my $form_file = (File::Spec->splitpath($file))[-1];
121124
open(FILE, ">$file") or die "Can't create $file: $!";
122125
print FILE "foo\nbar\nbaz\n";
123126
close(FILE);
@@ -151,7 +154,7 @@ like($c[6], qr/^--\n/); # 5 parts + header & trailer
151154
ok($c[2] =~ /^Content-Disposition:\s*form-data;\s*name="email"/m);
152155
ok($c[2] =~ /^gisle\@aas.no$/m);
153156

154-
ok($c[5] =~ /^Content-Disposition:\s*form-data;\s*name="file";\s*filename="$file"/m);
157+
ok($c[5] =~ /^Content-Disposition:\s*form-data;\s*name="file";\s*filename="$form_file"/m);
155158
ok($c[5] =~ /^Content-Type:\s*text\/plain$/m);
156159
ok($c[5] =~ /^foo\nbar\nbaz/m);
157160

@@ -187,7 +190,7 @@ is($r->content_length, 13);
187190
#
188191
use HTTP::Request::Common qw($DYNAMIC_FILE_UPLOAD);
189192

190-
$file = "test-$$";
193+
(undef, $file) = tempfile();
191194
open(FILE, ">$file") or die "Can't create $file: $!";
192195
for (1..1000) {
193196
print FILE "a" .. "z";

0 commit comments

Comments
 (0)