From: Mike Taylor Date: Mon, 8 Dec 2014 16:56:40 +0000 (+0000) Subject: Add tests for counter. X-Git-Tag: v0.02~20 X-Git-Url: http://jira.indexdata.com/?a=commitdiff_plain;h=452e4301773f3ed690f7081d113a22087a5eef9c;p=perl-indexdata-utils.git Add tests for counter. --- diff --git a/t/02-IndexData-Utils-PersistentCounter.t b/t/02-IndexData-Utils-PersistentCounter.t index 491bc7d..d6930dc 100644 --- a/t/02-IndexData-Utils-PersistentCounter.t +++ b/t/02-IndexData-Utils-PersistentCounter.t @@ -1,5 +1,26 @@ use strict; use warnings; -use Test::More tests => 1; +use Test::More tests => 15; BEGIN { use_ok('IndexData::Utils::PersistentCounter') }; + +my $file = "/tmp/id-u-pc-$$"; +my $counter = new IndexData::Utils::PersistentCounter($file); +ok(!defined $counter, "can't open non-existent counter"); + +$counter = new IndexData::Utils::PersistentCounter("/x/$file", 1); +ok(!defined $counter, "can't create counter in silly place"); + +$counter = new IndexData::Utils::PersistentCounter($file, 1); +ok(defined $counter, "created new counter: $!"); + +foreach my $i (1..10) { + my $n = $counter->next(); + is($n, $i); +} + +### should test access from multiple processes + +$counter->delete(); +$counter = new IndexData::Utils::PersistentCounter($file); +ok(!defined $counter, "can't open deleted counter");