Commit f55c6b76 authored by Andy Yates's avatar Andy Yates
Browse files

Registry edge case to deal with mis-spellings which can be common place for Ensembl beginners

parent 259897f0
......@@ -1570,6 +1570,21 @@ sub load_registry_from_db {
$species_suffix = "";
}
if(! defined $db_version) {
# Do checking for the -DB_VERSION flag which can be mis-spelt. Regex assembled using:
# perl -MRegexp::Assemble -e '$r=Regexp::Assemble->new(); $r->add($_) for ("-dbversion","-version","-verion","-verison"); print $r->re, "\n";'
my $db_version_flag_re = qr/(?-xism:-(?:ver(?:is?|si)|dbversi)on)/xism;
for(my $i = 0; $i <= @args; $i = $i+2) {
if($args[$i] =~ $db_version_flag_re) {
my $msg = sprintf(q{Detected no -DB_VERSION flag but found '%s'; assuming a mis-spelling. Please fix}, $args[$i]);
warning($msg);
$db_version = $args[$i+1];
last;
}
}
}
my $ontology_db;
my $ontology_version;
......
......@@ -6,6 +6,7 @@ use Test::More;
use File::Temp qw/tempfile/;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::Test::MultiTestDB;
use Bio::EnsEMBL::Test::TestUtils qw/warns_like/;
my $threads;
if($Config{useithreads} && ! $ENV{ENS_FORCE_NOTHREADS}) {
......@@ -40,6 +41,7 @@ my $registry_template = <<'TMPL';
1;
TMPL
#Testing threaded re-loads of the registry
{
my ($fh, $filename) = tempfile();
my $final = sprintf($registry_template, $dbc->host(), $dbc->port(), $dbc->username(), $dbc->password(), $dbc->dbname());
......@@ -78,4 +80,21 @@ TMPL
}
}
#Testing auto-correction of arguments for common 1st line methods
{
my $tester = sub {
my ($misspelling) = @_;
my %params = (-HOST => $dbc->host(), -PORT => $dbc->port(), -USER => $dbc->username());
$params{-PASS} = $dbc->password() if $dbc->password();
my $db_version = -2;
$params{"-${misspelling}"} = $db_version;
warns_like( sub { $reg->load_registry_from_db(%params) }, qr/${misspelling}.+mis-spelling/, "Testing that param -${misspelling} succeeded");
return;
};
$tester->('dbversion');
$tester->('version');
$tester->('verion');
$tester->('verison');
}
done_testing();
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment