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" );
34 skip( "No inode tests on Win32", 1 )
35 if ( $^O eq 'MSWin32' || $^O eq 'cygwin' );
36 my $db_obj = $db->_get_self;
37 ok( $db_obj->_engine->storage->{inode}, "The inode has been set" );
44 # now the same, but with an offset into the file. Use the database that's
45 # embedded in the test for the DATA filehandle. First, find the database ...
47 my ($fh,$filename) = new_fh();
50 print $fh <<'__END_FH__';
52 use Test::More no_plan => 1;
53 Test::More->builder->no_ending(1);
54 Test::More->builder->{Curr_Test} = 12;
56 use_ok( 'DBM::Deep' );
58 my $db = DBM::Deep->new({
61 is($db->{x}, 'b', "and get at stuff in the database");
63 print $fh "__DATA__\n";
67 open my $fh, '<', $filename;
68 while(my $line = <$fh>) {
69 last if($line =~ /^__DATA__/);
75 my $db = DBM::Deep->new({
77 file_offset => $offset,
78 #XXX For some reason, this is needed to make the test pass. Figure out why later.
83 is( $db->{x}, 'b', 'and it was stored' );
87 open my $fh, '<', $filename;
88 my $db = DBM::Deep->new({
90 file_offset => $offset,
93 is($db->{x}, 'b', "and get at stuff in the database");
95 ok( !$db->exists( 'foo' ), "foo doesn't exist yet" );
98 } qr/Cannot write to a readonly filehandle/, "Can't write to a read-only filehandle";
99 ok( !$db->exists( 'foo' ), "foo still doesn't exist" );
101 is( $db->{x}, 'b', "x is still 'b'" );
104 exec( "$^X -Iblib/lib $filename" );