Added unflocks to all tests so that the tests run on OSX
[dbsrgits/DBM-Deep.git] / t / 26_scalar_ref.t
CommitLineData
a8026397 1use strict;
2
eea0d863 3use Test::More tests => 10;
4use Test::Exception;
2a81bf9e 5use File::Temp qw( tempfile tempdir );
58910373 6use Fcntl qw( :flock );
a8026397 7
8use_ok( 'DBM::Deep' );
9
2a81bf9e 10my $dir = tempdir( CLEANUP => 1 );
11my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
58910373 12flock $fh, LOCK_UN;
2a81bf9e 13
eea0d863 14my $x = 25;
a8026397 15{
2a81bf9e 16 my $db = DBM::Deep->new( $filename );
a8026397 17
eea0d863 18 throws_ok {
19 $db->{scalarref} = \$x;
20 } qr/Storage of variables of type 'SCALAR' is not supported/,
21 'Storage of scalar refs not supported';
a8026397 22
eea0d863 23 throws_ok {
24 $db->{scalarref} = \\$x;
25 } qr/Storage of variables of type 'REF' is not supported/,
26 'Storage of ref refs not supported';
27
28 throws_ok {
29 $db->{scalarref} = sub { 1 };
30 } qr/Storage of variables of type 'CODE' is not supported/,
31 'Storage of code refs not supported';
32
33 throws_ok {
34 $db->{scalarref} = $db->_get_self->_fh;
35 } qr/Storage of variables of type 'GLOB' is not supported/,
36 'Storage of glob refs not supported';
37
38 $db->{scalar} = $x;
a8026397 39 TODO: {
eea0d863 40 todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2;
41 lives_ok {
42 $db->{selfref} = \$db->{scalar};
43 } "Refs to DBM::Deep objects are ok";
44
45 is( ${$db->{selfref}}, $x, "A ref to a DBM::Deep object is ok" );
a8026397 46 }
47}
48
49{
2a81bf9e 50 my $db = DBM::Deep->new( $filename );
a8026397 51
a8026397 52 is( $db->{scalar}, $x, "Scalar retrieved ok" );
53 TODO: {
eea0d863 54 todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2;
a8026397 55 is( ${$db->{scalarref}}, 30, "Scalarref retrieved ok" );
eea0d863 56 is( ${$db->{selfref}}, 26, "Scalarref to stored scalar retrieved ok" );
a8026397 57 }
58}