mirror of
https://github.com/MariaDB/server.git
synced 2025-08-05 13:16:09 +03:00
generalization of mtr to support suite.pm extensions:
* no automatic --loose-skip-innodb added by mtr based on the test name. instead loose-skip-innodb is now in the default_mysqld.cnf * have_innodb_plugin.inc is changed to give a verbose "skip" message (instead of "require: true") * My::Suite class. It's support in mtr, and everywhere * support for suite.pm * when sorting tests, take combinations into account * support for SUITENAME_COMBINATIONS * no special treatment for innodb_plugin in mtr_cases.pm * two special pre-created config groups: ENV and OPT * allow option names to start from # * allow magic option to have an argument * remove dead code * fix @-substitution to works as expected * new processes take the value of $opt_verbose automatically, no need to pass it to a constructor * innodb_plugin suite uses suite.pm and combinations file to test as much as possible (innodb plugin, xtradb plugin, xtradb static - whatever available) * besides test-master.opt and test-slave.opt a test.opt file is also loaded, both for master and slave * .opt files for all included files are loaded too * progress report in the xterm titlebar
This commit is contained in:
@@ -6,7 +6,6 @@ use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
|
||||
|
||||
sub new {
|
||||
my ($class, $option_name, $option_value)= @_;
|
||||
my $self= bless { name => $option_name,
|
||||
@@ -61,7 +60,7 @@ sub insert {
|
||||
$option->{value}= $value;
|
||||
}
|
||||
else {
|
||||
my $option= My::Config::Option->new($option_name, $value);
|
||||
$option= My::Config::Option->new($option_name, $value);
|
||||
# Insert option in list
|
||||
push(@{$self->{options}}, $option);
|
||||
# Insert option in hash
|
||||
@@ -163,6 +162,62 @@ sub if_exist {
|
||||
return $option->value();
|
||||
}
|
||||
|
||||
package My::Config::Group::ENV;
|
||||
our @ISA=qw(My::Config::Group);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
|
||||
sub new {
|
||||
my ($class, $group_name)= @_;
|
||||
bless My::Config::Group->new($group_name), $class;
|
||||
}
|
||||
|
||||
#
|
||||
# Return value for an option in the group, fail if it does not exist
|
||||
#
|
||||
sub value {
|
||||
my ($self, $option_name)= @_;
|
||||
my $option= $self->option($option_name);
|
||||
|
||||
if (! defined($option) and defined $ENV{$option_name}) {
|
||||
my $value= $ENV{$option_name};
|
||||
$option= My::Config::Option->new($option_name, $value);
|
||||
}
|
||||
|
||||
croak "No option named '$option_name' in group '$self->{name}'"
|
||||
if ! defined($option);
|
||||
|
||||
return $option->value();
|
||||
}
|
||||
|
||||
package My::Config::Group::OPT;
|
||||
our @ISA=qw(My::Config::Group);
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
use Carp;
|
||||
|
||||
sub new {
|
||||
my ($class, $group_name)= @_;
|
||||
bless My::Config::Group->new($group_name), $class;
|
||||
}
|
||||
|
||||
sub options {
|
||||
my ($self)= @_;
|
||||
()
|
||||
}
|
||||
|
||||
sub value {
|
||||
my ($self, $option_name)= @_;
|
||||
my $option= $self->option($option_name);
|
||||
|
||||
croak "No option named '$option_name' in group '$self->{name}'"
|
||||
if ! defined($option);
|
||||
|
||||
return $option->value()->();
|
||||
}
|
||||
|
||||
package My::Config;
|
||||
|
||||
@@ -182,7 +237,10 @@ sub new {
|
||||
my ($class, $path)= @_;
|
||||
my $group_name= undef;
|
||||
|
||||
my $self= bless { groups => [] }, $class;
|
||||
my $self= bless { groups => [
|
||||
My::Config::Group::ENV->new('ENV'),
|
||||
My::Config::Group::OPT->new('OPT'),
|
||||
] }, $class;
|
||||
my $F= IO::File->new($path, "<")
|
||||
or croak "Could not open '$path': $!";
|
||||
|
||||
@@ -199,19 +257,13 @@ sub new {
|
||||
}
|
||||
|
||||
# Magic #! comments
|
||||
elsif ( $line =~ /^#\!/) {
|
||||
my $magic= $line;
|
||||
elsif ( $line =~ /^(#\!\S+)(?:\s*(.*?)\s*)?$/) {
|
||||
my ($magic, $arg)= ($1, $2);
|
||||
croak "Found magic comment '$magic' outside of group"
|
||||
unless $group_name;
|
||||
|
||||
#print "$magic\n";
|
||||
$self->insert($group_name, $magic, undef);
|
||||
}
|
||||
|
||||
# Comments
|
||||
elsif ( $line =~ /^#/ || $line =~ /^;/) {
|
||||
# Skip comment
|
||||
next;
|
||||
$self->insert($group_name, $magic, $arg);
|
||||
}
|
||||
|
||||
# Empty lines
|
||||
@@ -236,7 +288,7 @@ sub new {
|
||||
}
|
||||
|
||||
# <option>
|
||||
elsif ( $line =~ /^([\@\w-]+)\s*$/ ) {
|
||||
elsif ( $line =~ /^(#?[\w-]+)\s*$/ ) {
|
||||
my $option= $1;
|
||||
|
||||
croak "Found option '$option' outside of group"
|
||||
@@ -247,7 +299,7 @@ sub new {
|
||||
}
|
||||
|
||||
# <option>=<value>
|
||||
elsif ( $line =~ /^([\@\w-]+)\s*=\s*(.*?)\s*$/ ) {
|
||||
elsif ( $line =~ /^(#?[\w-]+)\s*=\s*(.*?)\s*$/ ) {
|
||||
my $option= $1;
|
||||
my $value= $2;
|
||||
|
||||
@@ -256,10 +308,17 @@ sub new {
|
||||
|
||||
#print "$option=$value\n";
|
||||
$self->insert($group_name, $option, $value);
|
||||
} else {
|
||||
croak "Unexpected line '$line' found in '$path'";
|
||||
}
|
||||
|
||||
# Comments
|
||||
elsif ( $line =~ /^#/ || $line =~ /^;/) {
|
||||
# Skip comment
|
||||
next;
|
||||
}
|
||||
|
||||
else {
|
||||
croak "Unexpected line '$line' found in '$path'";
|
||||
}
|
||||
}
|
||||
undef $F; # Close the file
|
||||
|
||||
@@ -437,44 +496,4 @@ sub exists {
|
||||
return defined($option);
|
||||
}
|
||||
|
||||
|
||||
# Overload "to string"-operator with 'stringify'
|
||||
use overload
|
||||
'""' => \&stringify;
|
||||
|
||||
#
|
||||
# Return the config as a string in my.cnf file format
|
||||
#
|
||||
sub stringify {
|
||||
my ($self)= @_;
|
||||
my $res;
|
||||
|
||||
foreach my $group ($self->groups()) {
|
||||
$res .= "[$group->{name}]\n";
|
||||
|
||||
foreach my $option ($group->options()) {
|
||||
$res .= $option->name();
|
||||
my $value= $option->value();
|
||||
if (defined $value) {
|
||||
$res .= "=$value";
|
||||
}
|
||||
$res .= "\n";
|
||||
}
|
||||
$res .= "\n";
|
||||
}
|
||||
return $res;
|
||||
}
|
||||
|
||||
|
||||
#
|
||||
# Save the config to named file
|
||||
#
|
||||
sub save {
|
||||
my ($self, $path)= @_;
|
||||
my $F= IO::File->new($path, ">")
|
||||
or croak "Could not open '$path': $!";
|
||||
print $F $self;
|
||||
undef $F; # Close the file
|
||||
}
|
||||
|
||||
1;
|
||||
|
Reference in New Issue
Block a user