Updated perl minimum version to 5.004. Replaced three-argument open with
[archive-zip.git] / t / 10_chmod.t
blob688de9b3cffae2b25f7a161aae6839f8a18f0534
1 #!/usr/bin/perl
3 use strict;
4 BEGIN {
5 $| = 1;
6 $^W = 1;
8 use Test::More;
9 use File::Spec;
10 use File::Path;
11 use Archive::Zip;
13 sub get_perm
15 my $filename = shift;
17 return (((stat($filename))[2]) & 07777);
20 sub test_if_chmod_is_working
22 my $test_dir = File::Spec->catdir(
23 File::Spec->curdir(), "testdir", "chtest"
26 my $test_file = File::Spec->catfile($test_dir, "test.file");
28 mkdir($test_dir, 0755);
30 open my $out, ">$test_file";
31 print {$out} "Foobar.";
32 close($out);
34 my $test_perm = sub {
35 my $perm = shift;
37 chmod ($perm, $test_file);
39 return (get_perm($test_file) == $perm);
42 my $verdict = $test_perm->(0444) && $test_perm->(0666);
44 # Clean up
45 rmtree($test_dir);
47 return $verdict;
50 if (!test_if_chmod_is_working())
52 plan skip_all => "chmod() is not working on this machine.";
54 else
56 plan tests => 1;
59 my $zip = Archive::Zip->new();
61 $zip->read(File::Spec->catfile(File::Spec->curdir(), "t", "data", "chmod.zip"));
63 my $test_dir =
64 File::Spec->catdir(
65 File::Spec->curdir(), "testdir", "chtest"
68 mkdir($test_dir, 0777);
70 my $test_file = File::Spec->catfile($test_dir, "test_file");
72 $zip->memberNamed("test_dir/test_file")->extractToFileNamed($test_file);
74 # TEST
75 is (get_perm($test_file),
76 0444,
77 "File permission is OK."
80 # Clean up.
81 rmtree($test_dir);