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
|
#!/usr/bin/perl -w
use strict;
use warnings;
use Test2::Bundle::Extended;
use Test2::Tools::Explain;
use Test2::Plugin::NoWarnings;
use Test::MockFile;
subtest(
'-x after unlink' => sub {
my $filename = '/bin/mine';
my $mocked = Test::MockFile->file( $filename => '#!/bin/true' );
chmod 0755, $filename;
ok( -e $filename, 'File should exist' );
ok( -x $filename, 'File should be executable' );
unlink $filename;
ok( !-e $filename, 'File should not exist' );
ok( !-x $filename, 'File should not be executable' );
}
);
subtest(
'-x with multiple files' => sub {
my $filename1 = q[/bin/one];
my $filename2 = q[/bin/two];
my $mock1 = Test::MockFile->file($filename1);
my $mock2 = Test::MockFile->file($filename2);
ok( !-x $filename1, 'First filename should not be executable' );
ok( !-x $filename2, 'Second filename should not be executable' );
$mock1->touch;
chmod 0755, $filename1;
ok( -e $filename1, 'First filename should now exist' );
ok( -x $filename1, 'First filename should now be executable' );
ok( !-e $filename2, 'Second filename should still not exist' );
ok( !-x $filename2, 'Second filename should still not be executable' );
}
);
subtest(
'rmdir works for mocked directories' => sub {
my $dir = q[/some/where];
my $mocked = Test::MockFile->dir($dir);
ok( mkdir($dir), 'Created directory successfully' );
ok( -d $dir, 'Directory now exists' );
is( $! + 0, 0, 'No errors yet' );
ok( rmdir($dir), 'Successfully rmdir directory' );
is( $! + 0, 0, 'Still no errors' );
ok( !-d $dir, 'Directory no longer exists' );
}
);
done_testing();
exit;
|