| 1 | use ExtUtils::MakeMaker; |
|---|
| 2 | use DBI; |
|---|
| 3 | use Data::Dumper; |
|---|
| 4 | use strict; |
|---|
| 5 | |
|---|
| 6 | # Large chunks of this were inspired by the Makefile.PL supplied with |
|---|
| 7 | # DBIx::FullTextSearch -- thanks! |
|---|
| 8 | |
|---|
| 9 | # See if we already have some config variables set. |
|---|
| 10 | use lib "lib"; |
|---|
| 11 | eval "use Wiki::Toolkit::TestConfig"; |
|---|
| 12 | |
|---|
| 13 | # Even if we do have a previous configuration saved, we can over-ride and |
|---|
| 14 | # be asked all the questions again by specifying the -s flag or setting |
|---|
| 15 | # the appropriate environment variable. |
|---|
| 16 | if ($Wiki::Toolkit::TestConfig::configured |
|---|
| 17 | and not (@ARGV and $ARGV[0] eq '-s') |
|---|
| 18 | and not $ENV{WIKI_TOOLKIT_RERUN_CONFIG} |
|---|
| 19 | ) { |
|---|
| 20 | print "\nFor the test suite, we use the database and user info\n" |
|---|
| 21 | . "specified during the previous run. If you want to change\n" |
|---|
| 22 | . "some or all of the values, run 'perl Makefile.PL -s'.\n\n" |
|---|
| 23 | . "**** REMEMBER THAT THESE TESTS ARE DESTRUCTIVE. ****\n" |
|---|
| 24 | . "**** DO NOT RUN THEM ON A DATABASE THAT CONTAINS ****\n" |
|---|
| 25 | . "**** OR EVER WILL CONTAIN LIVE DATA. ****\n" |
|---|
| 26 | . "**** ****\n" |
|---|
| 27 | . "**** THE DATABASE VALUES YOU GAVE PREVIOUSLY ARE ****\n" |
|---|
| 28 | . "**** STORED IN Wiki::Toolkit::TestConfig AND ****\n" |
|---|
| 29 | . "**** WILL BE USED FOR FUTURE INSTALLS OF THIS ****\n" |
|---|
| 30 | . "**** AND RELATED MODULES. ****\n\n"; |
|---|
| 31 | } else { |
|---|
| 32 | print "\nYou should supply at least one set of options for testing,\n" |
|---|
| 33 | . "preferably relevant to the backend(s) you intend to use live.\n" |
|---|
| 34 | . "Running the tests under every possible backend combination is\n" |
|---|
| 35 | . "recommended. To enter an undefined value, accept the empty\n" |
|---|
| 36 | . "string or explicitly enter 'undef'.\n\n" |
|---|
| 37 | . "**** THESE TESTS ARE DESTRUCTIVE. ****\n" |
|---|
| 38 | . "**** DO NOT RUN THEM ON A DATABASE THAT CONTAINS ****\n" |
|---|
| 39 | . "**** OR EVER WILL CONTAIN LIVE DATA. ****\n" |
|---|
| 40 | . "**** ****\n" |
|---|
| 41 | . "**** THE DATABASE VALUES YOU GIVE HERE WILL BE ****\n" |
|---|
| 42 | . "**** STORED IN Wiki::Toolkit::TestConfig AND ****\n" |
|---|
| 43 | . "**** WILL BE USED FOR FUTURE INSTALLS OF THIS ****\n" |
|---|
| 44 | . "**** AND RELATED MODULES. ****\n\n"; |
|---|
| 45 | |
|---|
| 46 | my %config; |
|---|
| 47 | |
|---|
| 48 | # Grab information from previous runs. |
|---|
| 49 | if ($Wiki::Toolkit::TestConfig::configured) { |
|---|
| 50 | %config = %Wiki::Toolkit::TestConfig::config; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | # Grab information from environment variables. |
|---|
| 54 | foreach my $store (qw(MySQL Pg)) { |
|---|
| 55 | my $dbname = $ENV{"WIKI_TOOLKIT_".uc($store)."_DBNAME"}; |
|---|
| 56 | if ($dbname and $dbname ne "undef") { |
|---|
| 57 | $config{$store}{dbname} = $dbname; |
|---|
| 58 | foreach my $var (qw(dbuser dbpass dbhost)) { |
|---|
| 59 | my $value = $ENV{"WIKI_TOOLKIT_".uc($store)."_".uc($var)}; |
|---|
| 60 | if ($value and $value ne "undef") { $config{$store}{$var} = $value; |
|---|
| 61 | } elsif ($value eq "undef") { |
|---|
| 62 | $config{$store}{$var} = undef; |
|---|
| 63 | } |
|---|
| 64 | } |
|---|
| 65 | } elsif ($dbname eq "undef") { |
|---|
| 66 | $config{$store}{dbname} = undef; |
|---|
| 67 | } |
|---|
| 68 | } |
|---|
| 69 | |
|---|
| 70 | my $dbixfts = $ENV{WIKI_TOOLKIT_DBIXFTS_MYSQL}; |
|---|
| 71 | if ($dbixfts and $dbixfts ne "undef") { |
|---|
| 72 | $config{dbixfts} = 1; |
|---|
| 73 | } elsif ($dbixfts eq "undef") { |
|---|
| 74 | $config{dbixfts} = 0; |
|---|
| 75 | } |
|---|
| 76 | |
|---|
| 77 | # Finally ask questions; then check the settings work. |
|---|
| 78 | my %dsn_prefix = ( MySQL => "dbi:mysql:", |
|---|
| 79 | Pg => "dbi:Pg:dbname=" ); |
|---|
| 80 | my %driver = ( MySQL => "DBD::mysql", |
|---|
| 81 | Pg => "DBD::Pg" ); |
|---|
| 82 | foreach my $store_type (qw(MySQL Pg)) { |
|---|
| 83 | # See whether we have the driver installed. |
|---|
| 84 | eval "require " . $driver{$store_type}; |
|---|
| 85 | if ($@) { |
|---|
| 86 | print "\n$driver{$store_type} not installed... skipping...\n"; |
|---|
| 87 | $config{$store_type}{dbname} = undef; |
|---|
| 88 | next; |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | # Prompt for the options. |
|---|
| 92 | my ($dbname, $dbuser, $dbpass, $dbhost); |
|---|
| 93 | my $pad = ' ' x (7-length $store_type); |
|---|
| 94 | $dbname = prompt "\n${pad}Database name for $store_type: ", |
|---|
| 95 | $config{$store_type}{dbname}; |
|---|
| 96 | undef $dbname unless ($dbname and $dbname ne "undef"); |
|---|
| 97 | if ($dbname and $dbname ne "undef") { |
|---|
| 98 | $dbuser = prompt " Database user: ", |
|---|
| 99 | $config{$store_type}{dbuser}; |
|---|
| 100 | undef $dbuser unless ($dbuser and $dbuser ne "undef"); |
|---|
| 101 | $dbpass = prompt " Database password: ", |
|---|
| 102 | $config{$store_type}{dbpass}; |
|---|
| 103 | undef $dbpass unless ($dbpass and $dbpass ne "undef"); |
|---|
| 104 | $dbhost = prompt "Database host (if needed): ", |
|---|
| 105 | $config{$store_type}{dbhost}; |
|---|
| 106 | undef $dbhost unless ($dbhost and $dbhost ne "undef"); |
|---|
| 107 | |
|---|
| 108 | # Check that these connection parameters actually work. |
|---|
| 109 | my $dsn = $dsn_prefix{$store_type}.$dbname; |
|---|
| 110 | $dsn .= ";host=$dbhost" if $dbhost; |
|---|
| 111 | my $dbh = eval { DBI->connect($dsn, |
|---|
| 112 | $dbuser, $dbpass, {PrintError => 1}) |
|---|
| 113 | or die DBI->errstr; |
|---|
| 114 | }; |
|---|
| 115 | die "\nCan't connect to $store_type with those parameters:" |
|---|
| 116 | . "\n" . $@ . "\n\n" |
|---|
| 117 | . "Please re-run 'perl Makefile.PL' and supply correct " |
|---|
| 118 | . "parameters.\n\n" if $@; |
|---|
| 119 | $dbh->disconnect; |
|---|
| 120 | |
|---|
| 121 | # Save them if they do. |
|---|
| 122 | $config{$store_type}{dbname} = $dbname; |
|---|
| 123 | $config{$store_type}{dbuser} = $dbuser; |
|---|
| 124 | $config{$store_type}{dbpass} = $dbpass; |
|---|
| 125 | $config{$store_type}{dbhost} = $dbhost; |
|---|
| 126 | } else { |
|---|
| 127 | print "\nNo database name supplied... skipping...\n"; |
|---|
| 128 | $config{$store_type}{dbname} = undef; |
|---|
| 129 | } |
|---|
| 130 | } |
|---|
| 131 | |
|---|
| 132 | print "\n"; |
|---|
| 133 | |
|---|
| 134 | # Copy the config hash to the right namespace. |
|---|
| 135 | %Wiki::Toolkit::TestConfig::config = %config; |
|---|
| 136 | } |
|---|
| 137 | |
|---|
| 138 | # If we have a MySQL store configured, we can test the DBIx::FullTextSearch |
|---|
| 139 | # search backend. |
|---|
| 140 | eval { require DBIx::FullTextSearch; |
|---|
| 141 | require Lingua::Stem; |
|---|
| 142 | }; |
|---|
| 143 | my $fts_inst = $@ ? 0 : 1; |
|---|
| 144 | if ($Wiki::Toolkit::TestConfig::config{MySQL}{dbname} and $fts_inst) { |
|---|
| 145 | print "You have DBIx::FullTextSearch and Lingua::Stem installed,\n"; |
|---|
| 146 | print " and a MySQL store configured... configuring for test...\n\n"; |
|---|
| 147 | $Wiki::Toolkit::TestConfig::config{dbixfts} = 1; |
|---|
| 148 | } else { |
|---|
| 149 | print "Either DBIx::FullTextSearch or Lingua::Stem not installed,\n"; |
|---|
| 150 | print "or no MySQL store configured... so won't test that...\n\n"; |
|---|
| 151 | $Wiki::Toolkit::TestConfig::config{dbixfts} = undef; |
|---|
| 152 | } |
|---|
| 153 | |
|---|
| 154 | # We can test the SQLite backend without asking questions, if it's installed. |
|---|
| 155 | eval { require DBD::SQLite; }; |
|---|
| 156 | if ($@) { |
|---|
| 157 | print "DBD::SQLite not installed... so won't test that...\n\n"; |
|---|
| 158 | $Wiki::Toolkit::TestConfig::config{SQLite} = { dbname => undef }; |
|---|
| 159 | } else { |
|---|
| 160 | print "You have DBD::SQLite... configuring test SQLite database...\n\n"; |
|---|
| 161 | $Wiki::Toolkit::TestConfig::config{SQLite} = { dbname => "t/sqlite-test.db" }; |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | # If we have Search::InvertedIndex installed, we can test that without |
|---|
| 165 | # asking questions. |
|---|
| 166 | eval { require Search::InvertedIndex; }; |
|---|
| 167 | my $sii_inst = $@ ? 0 : 1; |
|---|
| 168 | if ( $sii_inst ) { |
|---|
| 169 | print "You have Search::InvertedIndex installed, so will test the S:II\n"; |
|---|
| 170 | print "search backend...\n\n"; |
|---|
| 171 | $Wiki::Toolkit::TestConfig::config{search_invertedindex} = 1; |
|---|
| 172 | } else { |
|---|
| 173 | print "You do not have Search::InvertedIndex installed; skipping test\n"; |
|---|
| 174 | print "of S:II search backend...\n\n"; |
|---|
| 175 | $Wiki::Toolkit::TestConfig::config{search_invertedindex} = undef; |
|---|
| 176 | } |
|---|
| 177 | |
|---|
| 178 | # If we have Plucene installed, we can test that without asking questions. |
|---|
| 179 | eval { require Plucene; require File::Spec::Functions }; |
|---|
| 180 | my $plucene_inst = $@ ? 0 : 1; |
|---|
| 181 | if ( $plucene_inst ) { |
|---|
| 182 | print "You have Plucene installed, so will test with that...\n\n"; |
|---|
| 183 | $Wiki::Toolkit::TestConfig::config{plucene} = 1; |
|---|
| 184 | } else { |
|---|
| 185 | print "Either Plucene or File::Spec::Functions not installed; skipping test...\n\n"; |
|---|
| 186 | $Wiki::Toolkit::TestConfig::config{plucene} = undef; |
|---|
| 187 | } |
|---|
| 188 | |
|---|
| 189 | # Write out the config for next run. |
|---|
| 190 | open OUT, ">lib/Wiki/Toolkit/TestConfig.pm" |
|---|
| 191 | or die "Couldn't open lib/Wiki/Toolkit/TestConfig.pm for writing: $!"; |
|---|
| 192 | # warning - blind copy and paste follows. FIXME. |
|---|
| 193 | print OUT Data::Dumper->new([ \%Wiki::Toolkit::TestConfig::config ], |
|---|
| 194 | [ '*Wiki::Toolkit::TestConfig::config' ] |
|---|
| 195 | )->Dump, |
|---|
| 196 | "\$Wiki::Toolkit::TestConfig::configured = 1;\n1;\n"; |
|---|
| 197 | close OUT; |
|---|
| 198 | |
|---|
| 199 | # Some modules are only prerequisites if we intend to test a |
|---|
| 200 | # particular backend. |
|---|
| 201 | my %config = %Wiki::Toolkit::TestConfig::config; |
|---|
| 202 | my %extras; |
|---|
| 203 | if ( $config{MySQL}{dbname} ) { |
|---|
| 204 | $extras{'DBD::mysql'} = 0; |
|---|
| 205 | } |
|---|
| 206 | if ( $config{Pg}{dbname} ) { |
|---|
| 207 | $extras{'DBD::Pg'} = 0; |
|---|
| 208 | } |
|---|
| 209 | if ( $config{SQLite}{dbname} ) { |
|---|
| 210 | $extras{'DBD::SQLite'} = '0.25'; # some of my tests fail on earlier ones |
|---|
| 211 | } |
|---|
| 212 | if ( $config{dbixfts} ) { |
|---|
| 213 | $extras{'DBIx::FullTextSearch'} = '0.71'; # earlier ones buggy |
|---|
| 214 | } |
|---|
| 215 | if ( $config{plucene} ) { |
|---|
| 216 | $extras{'Plucene'} = '1.19'; # earlier has trouble with delete |
|---|
| 217 | } |
|---|
| 218 | |
|---|
| 219 | # Write the Makefile. |
|---|
| 220 | WriteMakefile( NAME => "Wiki::Toolkit", |
|---|
| 221 | VERSION_FROM => "lib/Wiki/Toolkit.pm", |
|---|
| 222 | PREREQ_PM => { 'Text::WikiFormat' => '0.78', #earlier's buggy |
|---|
| 223 | 'HTML::PullParser' => 0, |
|---|
| 224 | 'Digest::MD5' => 0, |
|---|
| 225 | 'Test::More' => 0, |
|---|
| 226 | 'Time::Piece' => 0, |
|---|
| 227 | %extras }, |
|---|
| 228 | EXE_FILES => [ "bin/wiki-toolkit-setupdb", |
|---|
| 229 | "bin/wiki-toolkit-rename-node", |
|---|
| 230 | "bin/wiki-toolkit-delete-node" ], |
|---|
| 231 | clean => { FILES => "Config lib/Wiki/Toolkit/TestConfig.pm " |
|---|
| 232 | . "t/sqlite-test.db t/sii-db-file-test.db " |
|---|
| 233 | . "t/node.db t/plucene" |
|---|
| 234 | } |
|---|
| 235 | ); |
|---|