5 use Test::More tests => 14;
7 use t::common qw( new_fh );
12 my ($fh, $filename) = new_fh();
14 # Create the datafile to be used
16 my $db = DBM::Deep->new( $filename );
17 $db->{hash} = { foo => [ 'a' .. 'c' ] };
21 open(my $fh, '<', $filename) || die("Can't open '$filename' for reading: $!\n");
25 # test if we can open and read a db using its filehandle
27 ok(($db = DBM::Deep->new(fh => $fh)), "open db in filehandle");
28 ok($db->{hash}->{foo}->[1] eq 'b', "and get at stuff in the database");
31 } qr/Cannot write to a readonly filehandle/,
32 "Can't write to a read-only filehandle";
33 ok( !$db->exists( 'foo' ), "foo doesn't exist" );
35 my $db_obj = $db->_get_self;
36 ok( $db_obj->_fileobj->{inode}, "The inode has been set" );
42 # now the same, but with an offset into the file. Use the database that's
43 # embedded in the test for the DATA filehandle. First, find the database ...
45 my ($fh,$filename) = new_fh();
48 print $fh <<'__END_FH__';
50 use Test::More no_plan => 1;
51 Test::More->builder->no_ending(1);
52 Test::More->builder->{Curr_Test} = 12;
54 use_ok( 'DBM::Deep' );
56 my $db = DBM::Deep->new({
59 is($db->{x}, 'b', "and get at stuff in the database");
61 print $fh "__DATA__\n";
65 open my $fh, '<', $filename;
66 while(my $line = <$fh>) {
67 last if($line =~ /^__DATA__/);
73 my $db = DBM::Deep->new({
75 file_offset => $offset,
79 is( $db->{x}, 'b', 'and it was stored' );
84 open my $fh, '<', $filename;
85 my $db = DBM::Deep->new({
87 file_offset => $offset,
90 is($db->{x}, 'b', "and get at stuff in the database");
92 ok( !$db->exists( 'foo' ), "foo doesn't exist yet" );
95 } qr/Cannot write to a readonly filehandle/, "Can't write to a read-only filehandle";
96 ok( !$db->exists( 'foo' ), "foo still doesn't exist" );
101 exec( "$^X -Iblib/lib $filename" );