File: file.t

package info (click to toggle)
libcache-perl 2.10-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 428 kB
  • ctags: 301
  • sloc: perl: 2,577; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 1,745 bytes parent folder | download | duplicates (4)
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
#use strict;
use warnings;
use Cache::Tester;
use File::Temp qw(tempdir);
use File::Find;
use Carp;

$SIG{__DIE__} = sub { confess @_; };

BEGIN { plan tests => 2 + $CACHE_TESTS + 3 + 1 }

use_ok('Cache::File');

{
    # Test basic get/set and remove

    my $tempdir = tempdir(CLEANUP => 1);
    my $cache = Cache::File->new(cache_root => $tempdir,
                                 lock_level => Cache::File::LOCK_NFS());
    ok($cache, 'Cache created');

    run_cache_tests($cache);
}

{
    my $tempdir = tempdir(CLEANUP => 1);
    my $cache = Cache::File->new(cache_root => $tempdir,);
    {
        # See:
        # https://rt.cpan.org/Public/Bug/Display.html?id=95608
        my $warning;
        {
            local $SIG{__WARN__} = sub { $warning = shift; };

            $cache->set ('test', {x => 23}, '10 s');
        }
        like ($warning, qr/\AReference passed to set/,
            "Got the right warning on passing a reference to set.")

    }
}

{
    # Test setting of umask
    umask 077;
    my $tempdir = tempdir(CLEANUP => 1);
    my $cache = Cache::File->new(cache_root => $tempdir, cache_umask => 070);
    ok($cache, 'Cache created');


    my $entry = $cache->set('key1', 'data1');
    is($cache->count(), 1, 'Added entry');

    my $valid = 0;

    sub wanted {
        return if $_ eq $tempdir;
        my (undef, undef, $mode) = lstat($_) or die "lstat failed";
        $mode &= 0777;
        (-d and $mode == 0707) or (not -d and $mode == 0606)
            or die 'bad permissions ('.sprintf('%04o', $mode).") on $_";
    }
    eval { File::Find::find({ wanted => \&wanted, no_chdir => 1 }, $tempdir) };
    die if ($@ and $@ !~ /^bad permissions/);
    warn $@ if $@;
    ok((not $@), "Permissions are good");
}