xref: /openbsd/gnu/usr.bin/perl/ext/SDBM_File/t/prep.t (revision 76d0caae)
1#!./perl
2use strict;
3use Test::More tests => 4;
4
5use SDBM_File;
6use File::Temp 'tempfile';
7use Fcntl;
8
9my ($dirfh, $dirname) = tempfile(UNLINK => 1);
10my ($pagfh, $pagname) = tempfile(UNLINK => 1);
11
12# close so Win32 allows them to be re-opened
13close $dirfh;
14close $pagfh;
15
16{
17    my %h;
18
19    ok(eval { tie %h, "SDBM_File", $dirname, O_CREAT | O_RDWR | O_TRUNC, 0640, $pagname; 1 },
20       "create SDBM with explicit filenames")
21      or diag $@;
22    is(keys %h, 0, "should be empty");
23
24    # basic sanity checks, the real storage checks are done by sdbm.t
25    $h{abc} = 1;
26    $h{def} = 1;
27}
28
29{
30    my %h;
31    ok(eval { tie %h, "SDBM_File", $dirname, O_RDWR, 0640, $pagname; 1 },
32       "open SDBM with explicit filenames");
33    is_deeply([ sort keys  %h] , [ qw(abc def) ], "should have two keys");
34}
35