Fix testing.
[perl-indexdata-utils.git] / t / 02-IndexData-Utils-PersistentCounter.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 16;
5 BEGIN { use_ok('IndexData::Utils::PersistentCounter') };
6
7 my $file = "/tmp/id-u-pc-$$";
8 my $counter = new IndexData::Utils::PersistentCounter($file);
9 ok(!defined $counter, "can't open non-existent counter");
10
11 $counter = new IndexData::Utils::PersistentCounter("/x/$file", 1);
12 ok(!defined $counter, "can't create counter in silly place");
13
14 $counter = new IndexData::Utils::PersistentCounter($file, 1);
15 my $detail = defined $counter ? '' : ": $!@";
16 ok(defined $counter, "created new counter$detail");
17
18 foreach my $i (1..5) {
19     my $n = $counter->next();
20     ok(defined $n, "n is defined");
21     ok($n == $i, "n has correct value $i");
22 }
23
24 ### should test access from multiple processes
25
26 my $ok = $counter->delete();
27 ok($ok, "deleted counter file");
28 $counter = new IndexData::Utils::PersistentCounter($file);
29 ok(!defined $counter, "can't open deleted counter");