1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
From f56689d929b8b00366e56439be1340c31c145825 Mon Sep 17 00:00:00 2001
From: Kenichi Ishigaki <ishigaki@cpan.org>
Date: Mon, 7 Jan 2019 03:41:09 +0900
Subject: [PATCH] use more test utility functions
--- a/t/lib/SQLiteTest.pm
+++ b/t/lib/SQLiteTest.pm
@@ -8,7 +8,11 @@
use Test::More ();
our @ISA = 'Exporter';
-our @EXPORT = qw/connect_ok dies dbfile @CALL_FUNCS $sqlite_call has_sqlite requires_sqlite/;
+our @EXPORT = qw/
+ connect_ok dies dbfile @CALL_FUNCS $sqlite_call
+ has_sqlite requires_sqlite requires_unicode_support
+ allow_warnings has_compile_option has_fts
+/;
our @CALL_FUNCS;
our $sqlite_call;
@@ -146,6 +150,40 @@
$CALL_FUNCS[-1]->($dbh, @_, $func_to_call);
};
+=head2 has_compile_option
+
+ has_compile_option('ENABLE_FTS3');
+ has_compile_option(qr/^ENABLE_FTS[345]/);
+
+returns true if DBD::SQLite is built with a specified compile option.
+
+=cut
+
+sub has_compile_option {
+ my $option = shift;
+ require DBD::SQLite;
+ return unless DBD::SQLite->can('compile_options');
+ my $re = ref $option eq ref qr// ? $option : qr/\b$option\b/;
+ grep /$re/, DBD::SQLite::compile_options();
+}
+
+=head2 has_fts
+
+ has_fts();
+ has_fts(3);
+
+returns true if DBD::SQLite is built with FTS.
+
+=cut
+
+sub has_fts {
+ if (my $version = shift) {
+ has_compile_option("ENABLE_FTS$version");
+ } else {
+ has_compile_option(qr/\bENABLE_FTS\d\b/);
+ }
+}
+
=head2 has_sqlite
has_sqlite('3.6.11');
@@ -179,4 +217,33 @@
}
}
+=head2 requires_unicode_support
+
+ BEGIN { requires_unicode_support(); }
+
+skips all the tests if Perl does not have sane Unicode support.
+
+=cut
+
+sub requires_unicode_support {
+ unless ($] >= 5.008005) {
+ Test::More::plan skip_all => "Unicode is not supported before 5.8.5";
+ exit;
+ }
+}
+
+=head2 allow_warnings
+
+ allow_warnings { eval {...} };
+
+hides SQLite warnings from Test::FailWarnings.
+
+=cut
+
+sub allow_warnings (&) {
+ my $code = shift;
+ local $SIG{__WARN__} = sub { Test::More::note @_ };
+ $code->();
+}
+
1;
|