@matheusbsbs / matheus-bagliano / commits / bf55778855
Fork 0

t9700/test.pl: remove File::Temp requirement

The object oriented version of File::Temp is a rather new incarnation it seems. The File::Temp man page for v5.8.0 says "(NOT YET IMPLEMENTED)" in the 'Objects' section. Instead of creating a file with a unique name in the system TMPDIR, we can create our own temporary file with a static name and use that instead. Signed-off-by: Brandon Casey <casey@nrlssc.navy.mil> Tested-by: Tom G. Christensen <tgc@statsbiblioteket.dk> on RHEL 3, Perl 5.8.0 Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Casey committed Sep 15, 2008 at 11:25 UTC bf55778855c2c95fdc4919a4d42ee68d348b75ef
1 file changed +13 -10
t/t9700/test.pl
+13 -10
@@ -9,7 +9,6 @@ use Test::More qw(no_plan);
9
10 use Cwd;
11 use File::Basename;
12 -use File::Temp;
12
13 BEGIN { use_ok('Git') }
14
@@ -69,21 +68,25 @@ is($r->ident_person("Name", "email", "123 +0000"), "Name <email>",
68
69 # objects and hashes
70 ok(our $file1hash = $r->command_oneline('rev-parse', "HEAD:file1"), "(get file hash)");
72 -our $tmpfile = File::Temp->new;
73 -is($r->cat_blob($file1hash, $tmpfile), 15, "cat_blob: size");
71 +my $tmpfile = "file.tmp";
72 +open TEMPFILE, "+>$tmpfile" or die "Can't open $tmpfile: $!";
73 +is($r->cat_blob($file1hash, \*TEMPFILE), 15, "cat_blob: size");
74 our $blobcontents;
75 -{ local $/; seek $tmpfile, 0, 0; $blobcontents = <$tmpfile>; }
75 +{ local $/; seek TEMPFILE, 0, 0; $blobcontents = <TEMPFILE>; }
76 is($blobcontents, "changed file 1\n", "cat_blob: data");
77 -seek $tmpfile, 0, 0;
77 +close TEMPFILE or die "Failed writing to $tmpfile: $!";
78 is(Git::hash_object("blob", $tmpfile), $file1hash, "hash_object: roundtrip");
79 -$tmpfile = File::Temp->new();
80 -print $tmpfile my $test_text = "test blob, to be inserted\n";
79 +open TEMPFILE, ">$tmpfile" or die "Can't open $tmpfile: $!";
80 +print TEMPFILE my $test_text = "test blob, to be inserted\n";
81 +close TEMPFILE or die "Failed writing to $tmpfile: $!";
82 like(our $newhash = $r->hash_and_insert_object($tmpfile), qr/[0-9a-fA-F]{40}/,
83 "hash_and_insert_object: returns hash");
83 -$tmpfile = File::Temp->new;
84 -is($r->cat_blob($newhash, $tmpfile), length $test_text, "cat_blob: roundtrip size");
85 -{ local $/; seek $tmpfile, 0, 0; $blobcontents = <$tmpfile>; }
84 +open TEMPFILE, "+>$tmpfile" or die "Can't open $tmpfile: $!";
85 +is($r->cat_blob($newhash, \*TEMPFILE), length $test_text, "cat_blob: roundtrip size");
86 +{ local $/; seek TEMPFILE, 0, 0; $blobcontents = <TEMPFILE>; }
87 is($blobcontents, $test_text, "cat_blob: roundtrip data");
88 +close TEMPFILE;
89 +unlink $tmpfile;
90
91 # paths
92 is($r->repo_path, "./.git", "repo_path");