Added unflocks to all tests so that the tests run on OSX
[dbsrgits/DBM-Deep.git] / t / 26_scalar_ref.t
1 use strict;
2
3 use Test::More tests => 10;
4 use Test::Exception;
5 use File::Temp qw( tempfile tempdir );
6 use Fcntl qw( :flock );
7
8 use_ok( 'DBM::Deep' );
9
10 my $dir = tempdir( CLEANUP => 1 );
11 my ($fh, $filename) = tempfile( 'tmpXXXX', UNLINK => 1, DIR => $dir );
12 flock $fh, LOCK_UN;
13
14 my $x = 25;
15 {
16     my $db = DBM::Deep->new( $filename );
17
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';
22
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;
39     TODO: {
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" );
46     }
47 }
48
49 {
50     my $db = DBM::Deep->new( $filename );
51
52     is( $db->{scalar}, $x, "Scalar retrieved ok" );
53     TODO: {
54         todo_skip "Refs to DBM::Deep objects aren't implemented yet", 2;
55         is( ${$db->{scalarref}}, 30, "Scalarref retrieved ok" );
56         is( ${$db->{selfref}}, 26, "Scalarref to stored scalar retrieved ok" );
57     }
58 }