summaryrefslogtreecommitdiff
path: root/t/01_mutex_flock.t
blob: 494244da0270343c5b6303d13ad9395bc991f4e8 (plain)
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
#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;
use MCE::Mutex;

{
    my $mutex = MCE::Mutex->new( impl => 'Flock' );

    is( $mutex->impl(), 'Flock', 'implementation name 1' );
}
{
    my ($tmp_dir, $tmp_file);

    if ($ENV{TEMP} && -d $ENV{TEMP} && -w _) {
        $tmp_dir = $ENV{TEMP};
    }
    elsif ($ENV{TMPDIR} && -d $ENV{TMPDIR} && -w _) {
        $tmp_dir = $ENV{TMPDIR};
    }
    elsif (-d '/tmp' && -w _) {
        $tmp_dir = '/tmp';
    }
    else {
        done_testing;
        exit;
    }

    $tmp_dir =~ s{/$}{};

    # remove tainted'ness from $tmp_dir
    if ($^O eq 'MSWin32') {
        ($tmp_file) = "$tmp_dir\\lockfile.$$.lock" =~ /(.*)/;
    } else {
        ($tmp_file) = "$tmp_dir/lockfile.$$.lock" =~ /(.*)/;
    }

    my $mutex = MCE::Mutex->new( path => $tmp_file );

    is( $mutex->impl(), 'Flock', 'implementation name 2' );

    unlink $tmp_file;
}

done_testing;