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");
23 # test if we can open and read a db using its filehandle
26 ok( ($db = DBM::Deep->new( fh => $fh )), "open db in filehandle" );
27 ok( $db->{hash}{foo}[1] eq 'b', "and get at stuff in the database" );
30 } qr/Cannot write to a readonly filehandle/, "Can't write to a read-only filehandle";
31 ok( !$db->exists( 'foo' ), "foo doesn't exist" );
33 my $db_obj = $db->_get_self;
34 ok( $db_obj->_storage->{inode}, "The inode has been set" );
40 # now the same, but with an offset into the file. Use the database that's
41 # embedded in the test for the DATA filehandle. First, find the database ...
43 my ($fh,$filename) = new_fh();
46 print $fh <<'__END_FH__';
48 use Test::More no_plan => 1;
49 Test::More->builder->no_ending(1);
50 Test::More->builder->{Curr_Test} = 12;
52 use_ok( 'DBM::Deep' );
54 my $db = DBM::Deep->new({
57 is($db->{x}, 'b', "and get at stuff in the database");
59 print $fh "__DATA__\n";
63 open my $fh, '<', $filename;
64 while(my $line = <$fh>) {
65 last if($line =~ /^__DATA__/);
71 my $db = DBM::Deep->new({
73 file_offset => $offset,
74 #XXX For some reason, this is needed to make the test pass. Figure out why later.
79 is( $db->{x}, 'b', 'and it was stored' );
83 open my $fh, '<', $filename;
84 my $db = DBM::Deep->new({
86 file_offset => $offset,
89 is($db->{x}, 'b', "and get at stuff in the database");
91 ok( !$db->exists( 'foo' ), "foo doesn't exist yet" );
94 } qr/Cannot write to a readonly filehandle/, "Can't write to a read-only filehandle";
95 ok( !$db->exists( 'foo' ), "foo still doesn't exist" );
100 exec( "$^X -Iblib/lib $filename" );