File: simple.t

package info (click to toggle)
liblockfile-simple-perl 0.2.5-1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 220 kB
  • ctags: 204
  • sloc: perl: 507; makefile: 435; sh: 111; ansic: 1
file content (73 lines) | stat: -rw-r--r-- 1,241 bytes parent folder | download | duplicates (2)
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
#!./perl

# $Id: simple.t,v 0.2.1.1 2000/08/15 18:37:45 ram Exp $
#
#  Copyright (c) 1998-1999, Raphael Manfredi
#  
#  You may redistribute only under the terms of the Artistic License,
#  as specified in the README file that comes with the distribution.
#
# $Log: simple.t,v $
# Revision 0.2.1.1  2000/08/15 18:37:45  ram
# patch3: forgot to remove "t.mark"
#
# Revision 0.2  1999/12/07 20:51:05  ram
# Baseline for 0.2 release.
#

use LockFile::Simple;

$| = 1;				# We're going to fork
print "1..6\n";

#
# Basic tests made via the OO interface.
#

my $manager = LockFile::Simple->make;

unlink 't.lock';

my $lock = $manager->lock('t');

print "not " unless ref $lock;
print "ok 1\n";

print "not " unless -r 't.lock';
print "ok 2\n";

print "not " if $manager->trylock('t');
print "ok 3\n";

print "not " unless $manager->unlock('t');
print "ok 4\n";

print "not " if -f 't.lock';
print "ok 5\n";

#
# Autocleaning
#

sub mark {
	my ($msg) = join(' ', @_);
	open(MARK, ">t.mark");
	print MARK "$msg\n";
	close MARK;
}

$manager = LockFile::Simple->make(-autoclean => 1, -wfunc => \&mark);

unlink 't.mark';

if (0 == fork()) {
	$manager->lock('t');
	exit 0;
}

wait;

print "not " unless -r 't.mark';
print "ok 6\n";

unlink 't.mark';