2 # Before 'make install' is performed this script should be runnable with
3 # 'make test'. After 'make install' it should work as 'perl test.pl'
5 #########################
7 # change 'tests => 1' to 'tests => last_test_to_print';
11 BEGIN {$SIG{__WARN__} = sub { die "Terminating test due to warning: $_[0]" } };
15 BEGIN { plan tests => 6 };
16 use Xapian qw(:standard);
17 ok(1); # If we made it this far, we're ok.
19 #########################
21 # Insert your test code below, the Test module is use()ed here so read
22 # its man page ( perldoc Test ) for help writing this test script.
24 # first create database dir, if it doesn't exist;
25 my $db_dir = 'testdb-exception-modified';
27 if( (! -e $db_dir) or (! -d $db_dir) ) {
31 opendir( DB_DIR, $db_dir );
32 while( defined( my $file = readdir( DB_DIR ) ) ) {
33 next if $file =~ /^\.+$/;
34 unlink( "$db_dir/$file" ) or die "Could not delete '$db_dir/$file': $!";
38 my $create = Xapian::WritableDatabase->new( $db_dir, Xapian::DB_CREATE );
42 my $read = Xapian::Database->new( $db_dir );
44 my $write = Xapian::WritableDatabase->new( $db_dir, Xapian::DB_CREATE_OR_OPEN );
46 my $enq = $read->enquire(OP_OR, "test");
48 # Let's try to index something.
52 for my $num (1..1000) {
53 my $doc = Xapian::Document->new();
55 $doc->set_data( "$term $num" );
57 $doc->add_posting( $term, 0 );
58 $doc->add_posting( "$num", 1 );
60 $doc->add_value(0, "$num");
61 $write->add_document( $doc );
66 for my $num (qw(three four five)) {
67 my $doc = Xapian::Document->new();
69 $doc->set_data( "$term $num" );
71 $doc->add_posting( $term, 0 );
72 $doc->add_posting( $num, 1 );
74 $doc->add_value(0, $num);
75 $write->add_document( $doc );
80 my $mset = $enq->get_mset(0, 10);
83 ok(ref($@), "Xapian::DatabaseModifiedError", "correct class for exception");
84 ok($@->isa('Xapian::Error'));
86 ok($@->get_msg, "The revision being read has been discarded - you should call Xapian::Database::reopen() and retry the operation", "get_msg works");
88 # WritableDatabase::reopen() is a no-op, but it shouldn't fail.