EvanCarroll has asked for the wisdom of the Perl Monks concerning the following question:
Long time no see monks! Ok, I'm back and this time I'm more powerful than an ancient who just got force-descended by the full-ascended; and, I've got a galactic problem.
I can't figure out why Arhive::Zip is broken, here is a test case, someone fix this for me, and I will grace you all with more divine knowledge about the mighty power of tabs, and the evilness of the dark spaces horde.
Note, this is my first perl test, if anyone excessively bitches I will write lots of code and not make any more tests, khtnksxzs
Archive::Zip isn't $\ safe, #!/usr/bin/perl -l threw it off.
#!/usr/bin/perl -l use strict; use warnings; use Archive::Zip qw( :ERROR_CODES ); use Digest::MD5; use Test::More tests => 5; use Carp; use constant ERROR_PRONE_FILE => 'error.jpg'; use constant ERROR_FILE => 'corrupterror.jpg'; use constant ERROR_ARCHIVE => 'out.zip'; my $zip = Archive::Zip->new(); my ( $before, $after ); ## ## OPEN GOOD FILE GET MD5 ## { my $md5 = Digest::MD5->new; open ( my $fh, '<', ERROR_PRONE_FILE ) or die 'Can not open file' ; binmode( $fh ); $before = $md5->addfile( $fh )->md5_hex; close $fh; } ## ## Zip up and write out ## { my $md5 = Digest::MD5->new; $zip->addFile( ERROR_PRONE_FILE ); $zip->extractMember( ERROR_PRONE_FILE, ERROR_FILE ); open ( my $fh, '<', ERROR_FILE ) or die 'Can not open file' ; binmode( $fh ); $after = $md5->addfile( $fh )->md5_hex; close $fh; unlink ERROR_FILE; cmp_ok( $after, 'eq', $before , 'Failed test, pre-zip, and post-pre-zip do not match' ); my $status = $zip->writeToFileNamed( ERROR_ARCHIVE ); cmp_ok( $status, '==', AZ_OK, 'Wrote zip out alright' ); } ## ## Read back ## { my $md5 = Digest::MD5->new; my $zip2; eval { $zip2 = Archive::Zip->new( ERROR_ARCHIVE ); }; ok( !$@, "This stupid bugger crashed again, error:\n$@" ); ok ( defined $zip2, 'Perl failed at spawning the object of doom' ) +; $zip2->extractMember( ERROR_PRONE_FILE, ERROR_FILE ); open ( my $fh, '<', ERROR_FILE ) or croak 'Can not open file' ; binmode( $fh ); $after = $md5->addfile( $fh )->md5_hex; close $fh; unlink ERROR_FILE; unlink ERROR_ARCHIVE; cmp_ok( $after, 'eq', $before , 'Failed test, pre-zip, and post-zip do not match' ); } print "Success sums match up all th way through!! Congrats"; print "Verbose: [ $before eq $after ]"; 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: .o0O [(i^% Archive::Zip test %^i)]O0o.
by jwkrahn (Abbot) on Mar 30, 2007 at 03:18 UTC | |
| |
|
Re: .o0O [(i^% Archive::Zip test %^i)]O0o.
by diotalevi (Canon) on Mar 30, 2007 at 00:30 UTC | |
| |
| A reply falls below the community's threshold of quality. You may see it by logging in. |