~ubuntu-branches/ubuntu/saucy/liblockfile-simple-perl/saucy

« back to all changes in this revision

Viewing changes to t/simple.t

  • Committer: Bazaar Package Importer
  • Author(s): John Goerzen
  • Date: 2001-01-06 17:52:19 UTC
  • Revision ID: james.westby@ubuntu.com-20010106175219-llbc68tinin5tjmv
Tags: upstream-0.2.5
ImportĀ upstreamĀ versionĀ 0.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!./perl
 
2
 
 
3
# $Id: simple.t,v 0.2.1.1 2000/08/15 18:37:45 ram Exp $
 
4
#
 
5
#  Copyright (c) 1998-1999, Raphael Manfredi
 
6
#  
 
7
#  You may redistribute only under the terms of the Artistic License,
 
8
#  as specified in the README file that comes with the distribution.
 
9
#
 
10
# $Log: simple.t,v $
 
11
# Revision 0.2.1.1  2000/08/15 18:37:45  ram
 
12
# patch3: forgot to remove "t.mark"
 
13
#
 
14
# Revision 0.2  1999/12/07 20:51:05  ram
 
15
# Baseline for 0.2 release.
 
16
#
 
17
 
 
18
use LockFile::Simple;
 
19
 
 
20
$| = 1;                         # We're going to fork
 
21
print "1..6\n";
 
22
 
 
23
#
 
24
# Basic tests made via the OO interface.
 
25
#
 
26
 
 
27
my $manager = LockFile::Simple->make;
 
28
 
 
29
unlink 't.lock';
 
30
 
 
31
my $lock = $manager->lock('t');
 
32
 
 
33
print "not " unless ref $lock;
 
34
print "ok 1\n";
 
35
 
 
36
print "not " unless -r 't.lock';
 
37
print "ok 2\n";
 
38
 
 
39
print "not " if $manager->trylock('t');
 
40
print "ok 3\n";
 
41
 
 
42
print "not " unless $manager->unlock('t');
 
43
print "ok 4\n";
 
44
 
 
45
print "not " if -f 't.lock';
 
46
print "ok 5\n";
 
47
 
 
48
#
 
49
# Autocleaning
 
50
#
 
51
 
 
52
sub mark {
 
53
        my ($msg) = join(' ', @_);
 
54
        open(MARK, ">t.mark");
 
55
        print MARK "$msg\n";
 
56
        close MARK;
 
57
}
 
58
 
 
59
$manager = LockFile::Simple->make(-autoclean => 1, -wfunc => \&mark);
 
60
 
 
61
unlink 't.mark';
 
62
 
 
63
if (0 == fork()) {
 
64
        $manager->lock('t');
 
65
        exit 0;
 
66
}
 
67
 
 
68
wait;
 
69
 
 
70
print "not " unless -r 't.mark';
 
71
print "ok 6\n";
 
72
 
 
73
unlink 't.mark';