1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304
|
use strict;
use Test::Builder::Tester;
use Test::More 1;
use Test::File;
=pod
max_file non_zero_file not_readable readable zero_file
executable min_file not_executable not_writable writable
=cut
require "./t/setup_common";
diag "Warnings about file_writeable_ok are fine. It's a deprecated name that still works.";
subtest readable => sub {
my $label = 'file <readable> exists';
test_out( 'ok 1 - readable exists' );
file_exists_ok( 'readable' );
test_out( "ok 2 - $label" );
file_exists_ok( 'readable', $label );
test_test();
done_testing();
};
subtest exists_fails => sub {
test_out( 'not ok 1 - fooey exists' );
test_diag( 'file [fooey] does not exist');
test_diag( " Failed test 'fooey exists'");
test_diag( " at " . __FILE__ . " line " . (__LINE__+1) . ".");
file_exists_ok( 'fooey' );
test_test();
done_testing();
};
subtest not_exists => sub {
my $label = 'file <readable> exists';
test_out( 'ok 1 - fooey does not exist' );
file_not_exists_ok( 'fooey' );
test_out( "ok 2 - $label" );
file_not_exists_ok( 'fooey', $label );
test_test();
done_testing();
};
subtest not_exists_fails => sub {
test_out( 'not ok 1 - readable does not exist' );
test_diag( 'file [readable] exists');
test_diag( " Failed test 'readable does not exist'");
test_diag( " at " . __FILE__ . " line " . (__LINE__+1) . ".");
file_not_exists_ok( 'readable' );
test_test();
done_testing();
};
subtest readable => sub {
test_out( 'ok 1 - readable is readable' );
file_readable_ok( 'readable' );
test_out( 'ok 2 - readable really is readable' );
file_readable_ok( 'readable', 'readable really is readable' );
test_test();
done_testing();
};
subtest readable_fails => sub { SKIP: {
skip "Superuser has special privileges", 2, is_unix_superuser();
test_out( 'not ok 1 - non_readable is readable' );
test_diag("file [non_readable] is not readable");
test_diag(" Failed test 'non_readable is readable'");
test_diag( " at " . __FILE__ . " line " . (__LINE__+1) . ".");
file_readable_ok( 'non_readable' );
test_test();
done_testing();
}};
subtest not_readable_fails => sub { SKIP: {
skip "Superuser has special privileges", 3, if is_unix_superuser();
skip "Not possible to make file unreadable on MSYS" if is_msys();
test_out( 'ok 1 - writeable is not readable' );
file_not_readable_ok( 'writeable' );
test_out( 'ok 2 - writeable really is not readable' );
file_not_readable_ok( 'writeable', 'writeable really is not readable' );
test_out( 'not ok 3 - readable is not readable' );
test_diag('file [readable] is readable');
test_diag(" Failed test 'readable is not readable'");
test_diag( " at " . __FILE__ . " line " . (__LINE__+1) . ".");
file_not_readable_ok( 'readable' );
test_test();
done_testing();
}};
subtest writable_fails => sub {
my $label = 'writable has custom label';
test_out( 'ok 1 - writable is writable' );
file_writable_ok( 'writable' );
test_out( "ok 2 - $label" );
file_writable_ok( 'writable', $label );
if( is_msys() or is_unix_superuser() ) {
test_out( 'ok 3 - readable is writable' );
}
else {
test_out( 'not ok 3 - readable is writable' );
test_diag('file [readable] is not writable');
test_diag(" Failed test 'readable is writable'");
test_diag( " at " . __FILE__ . " line " . (__LINE__+2) . ".");
}
file_writable_ok( 'readable' );
test_test();
done_testing();
};
subtest not_writable => sub { SKIP: {
skip "Superuser has special privileges", 1, if is_unix_superuser();
skip "Not possible to make file unreadable on MSYS" if is_msys();
test_out( 'ok 1 - readable is not writable' );
test_out( 'not ok 2 - writable is not writable' );
test_diag('file [writable] is writable');
test_diag(" Failed test 'writable is not writable'");
test_diag( " at " . __FILE__ . " line " . (__LINE__+2) . ".");
file_not_writable_ok( 'readable' );
file_not_writable_ok( 'writable' );
test_test();
done_testing();
}};
subtest executable => sub {
if (Test::File::_win32()) {
test_out("ok 1 # skip file_executable_ok doesn't work on Windows");
test_out("ok 2 # skip file_executable_ok doesn't work on Windows");
test_out("ok 3 # skip file_executable_ok doesn't work on Windows");
}
else {
test_out("ok 1 - executable is executable");
test_out("ok 2 - executable really is executable");
test_out("not ok 3 - not_executable is executable");
test_diag("file [not_executable] is not executable");
test_diag(" Failed test 'not_executable is executable'");
test_diag(" at " . __FILE__ . " line " . (__LINE__+4) . ".");
}
file_executable_ok( 'executable' );
file_executable_ok( 'executable', 'executable really is executable' );
file_executable_ok( 'not_executable' );
test_test();
done_testing();
};
subtest not_executable => sub {
if (Test::File::_win32()) {
test_out("ok 1 # skip file_not_executable_ok doesn't work on Windows");
test_out("ok 2 # skip file_not_executable_ok doesn't work on Windows");
test_out("ok 3 # skip file_not_executable_ok doesn't work on Windows");
}
else {
test_out("ok 1 - not_executable is not executable");
test_out("ok 2 - not_executable really is not executable");
test_out("not ok 3 - executable is not executable");
test_diag("file [executable] is executable");
test_diag(" Failed test 'executable is not executable'");
test_diag(" at " . __FILE__ . " line " . (__LINE__+4) . ".");
}
file_not_executable_ok( 'not_executable' );
file_not_executable_ok( 'not_executable', 'not_executable really is not executable' );
file_not_executable_ok( 'executable' );
test_test();
done_testing();
};
subtest mode_is => sub {
if (Test::File::_win32()) {
test_out("ok 1 # skip file_mode_is doesn't work on Windows");
test_out("ok 2 # skip file_mode_is doesn't work on Windows");
test_out("ok 3 # skip file_mode_is doesn't work on Windows");
}
else {
test_out("ok 1 - executable mode is 0100");
test_out("ok 2 - executable mode really is 0100");
test_out("not ok 3 - executable mode is 0200");
test_diag("file [executable] mode is not 0200");
test_diag(" Failed test 'executable mode is 0200'");
test_diag(" at " . __FILE__ . " line " . (__LINE__+4) . ".");
}
file_mode_is( 'executable', 0100 );
file_mode_is( 'executable', 0100, 'executable mode really is 0100' );
file_mode_is( 'executable', 0200 );
test_test();
done_testing();
};
subtest mode_has => sub {
if (Test::File::_win32()) {
test_out("ok 1 # skip file_mode_has doesn't work on Windows");
test_out("ok 2 # skip file_mode_has doesn't work on Windows");
test_out("ok 3 # skip file_mode_has doesn't work on Windows");
test_out("ok 4 # skip file_mode_has doesn't work on Windows" );
}
else {
test_out("ok 1 - executable mode has all bits of 0100");
test_out("ok 2 - executable mode really has all bits of 0100");
test_out("not ok 3 - executable mode has all bits of 0200");
test_diag("file [executable] mode is missing component 0200");
test_diag(" Failed test 'executable mode has all bits of 0200'");
test_diag(" at " . __FILE__ . " line " . (__LINE__+8) . ".");
test_out( "not ok 4 - executable mode has all bits of 0111" );
test_diag("file [executable] mode is missing component 0011");
test_diag(" Failed test 'executable mode has all bits of 0111'");
test_diag(" at " . __FILE__ . " line " . (__LINE__+5) . ".");
}
file_mode_has( 'executable', 0100 );
file_mode_has( 'executable', 0100, 'executable mode really has all bits of 0100');
file_mode_has( 'executable', 0200 );
file_mode_has( 'executable', 0111 );
test_test();
done_testing();
};
subtest mode_isnt => sub {
if (Test::File::_win32) {
test_out( "ok 1 # skip file_mode_isnt doesn't work on Windows" );
test_out( "ok 2 # skip file_mode_isnt doesn't work on Windows" );
test_out( "ok 3 # skip file_mode_isnt doesn't work on Windows" );
}
else {
test_out( "ok 1 - executable mode is not 0200" );
test_out( "ok 2 - executable mode really is not 0200" );
test_out( "not ok 3 - executable mode is not 0100" );
test_diag("file [executable] mode is 0100");
test_diag(" Failed test 'executable mode is not 0100'");
test_diag(" at " . __FILE__ . " line " . (__LINE__+4) . ".");
}
file_mode_isnt( 'executable', 0200 );
file_mode_isnt( 'executable', 0200, 'executable mode really is not 0200' );
file_mode_isnt( 'executable', 0100 );
test_test();
done_testing();
};
subtest mode_hasnt => sub {
if (Test::File::_win32()) {
test_out( "ok 1 # skip file_mode_hasnt doesn't work on Windows" );
test_out( "ok 2 # skip file_mode_hasnt doesn't work on Windows" );
test_out( "ok 3 # skip file_mode_hasnt doesn't work on Windows" );
}
else {
test_out( "ok 1 - executable mode has no bits of 0200" );
test_out( "ok 2 - executable mode really has no bits of 0200" );
test_out( "not ok 3 - executable mode has no bits of 0111" );
test_diag("file [executable] mode has forbidden component 0100");
test_diag(" Failed test 'executable mode has no bits of 0111'");
test_diag(" at " . __FILE__ . " line " . (__LINE__+5) . ".");
}
file_mode_hasnt( 'executable', 0200 );
file_mode_hasnt( 'executable', 0200, 'executable mode really has no bits of 0200' );
file_mode_hasnt( 'executable', 0111 );
test_test();
done_testing();
};
subtest mode => sub {
my $s = Test::File::_win32()
? "# skip file_mode_is doesn't work on Windows"
: "- readable mode is 0400";
test_out( "ok 1 $s" );
file_mode_is( 'readable', 0400 );
test_test();
done_testing();
};
subtest mode_isnt => sub {
my $s = Test::File::_win32()
? "# skip file_mode_isnt doesn't work on Windows"
: "- readable mode is not 0200";
test_out( "ok 1 $s" );
file_mode_isnt( 'readable', 0200 );
test_test();
done_testing();
};
subtest mode_writable => sub {
my $s = Test::File::_win32()
? "# skip file_mode_is doesn't work on Windows"
: "- writable mode is 0200";
test_out( "ok 1 $s" );
file_mode_is( 'writable', 0200 );
test_test();
done_testing();
};
subtest mode => sub {
my $s = Test::File::_win32()
? "# skip file_mode_isnt doesn't work on Windows"
: "- writable mode is not 0100";
test_out( "ok 1 $s" );
file_mode_isnt( 'writable', 0100 );
test_test();
done_testing();
};
done_testing();
|