diff --git a/bin/pt-config-diff b/bin/pt-config-diff index 79bb4c53..ac2270fc 100755 --- a/bin/pt-config-diff +++ b/bin/pt-config-diff @@ -2470,6 +2470,9 @@ sub new { value_is_optional => \%value_is_optional, any_value_is_true => \%any_value_is_true, base_path => \%base_path, + ignore_case => exists $args{ignore_case} + ? $args{ignore_case} + : 1, }; return bless $self, $class; @@ -2496,6 +2499,7 @@ sub diff { my $config0 = $configs->[0]; my $last_config = @$configs - 1; my $vars = $self->_get_shared_vars(%args); + my $ignore_case = $self->{ignore_case}; my $diffs; VARIABLE: @@ -2520,7 +2524,9 @@ sub diff { next CONFIG if $val0 == $valN; } else { - next CONFIG if $val0 eq $valN; + next CONFIG if $ignore_case + ? lc($val0) eq lc($valN) + : $val0 eq $valN; if ( $config0->format() ne $configN->format() ) { if ( $any_value_is_true->{$var} ) { @@ -4332,6 +4338,7 @@ sub main { my $trp = new TextResultSetParser(); my $config_cmp = new MySQLConfigComparer( ignore_variables => $o->get('ignore-variables'), + ignore_case => $o->get('ignore-case'), ); my %common_modules = ( DSNParser => $dp, @@ -4574,6 +4581,12 @@ L<"SYNOPSIS"> and usage information for details. Prompt for a password when connecting to MySQL. +=item --[no]ignore-case + +default: yes + +Compare the variables case-insensitively. + =item --charset short form: -A; type: string diff --git a/lib/MySQLConfigComparer.pm b/lib/MySQLConfigComparer.pm index fdfbbfcc..febd023f 100644 --- a/lib/MySQLConfigComparer.pm +++ b/lib/MySQLConfigComparer.pm @@ -126,6 +126,9 @@ sub new { value_is_optional => \%value_is_optional, any_value_is_true => \%any_value_is_true, base_path => \%base_path, + ignore_case => exists $args{ignore_case} + ? $args{ignore_case} + : 1, }; return bless $self, $class; @@ -172,6 +175,7 @@ sub diff { my $config0 = $configs->[0]; my $last_config = @$configs - 1; my $vars = $self->_get_shared_vars(%args); + my $ignore_case = $self->{ignore_case}; # Compare variables from first config (config0) to other configs (configN). my $diffs; @@ -197,7 +201,9 @@ sub diff { next CONFIG if $val0 == $valN; } else { - next CONFIG if $val0 eq $valN; + next CONFIG if $ignore_case + ? lc($val0) eq lc($valN) + : $val0 eq $valN; # Special rules apply when comparing different inputs/formats, # e.g. when comparing an option file to SHOW VARIABLES. This diff --git a/t/lib/MySQLConfigComparer.t b/t/lib/MySQLConfigComparer.t index f3f04e5c..3977fd44 100644 --- a/t/lib/MySQLConfigComparer.t +++ b/t/lib/MySQLConfigComparer.t @@ -392,6 +392,39 @@ $c2 = new MySQLConfig( "Values are the same regardless of quoting" ) or diag(Dumper($diff)); } +# ############################################################################# +# Case insensitivity +# ############################################################################# + +$c1 = new MySQLConfig( + result_set => [['binlog_format', 'MIXED']], + format => 'option_file', +); + +$c2 = new MySQLConfig( + result_set => [['binlog_format', 'mixed']], + format => 'option_file', +); + +is_deeply( + diff($c1, $c2), + undef, + "Case insensitivity is on by default" +); + +my $case_cc = MySQLConfigComparer->new( ignore_case => undef, ); + +is_deeply( + $case_cc->diff(configs => [$c1, $c2]), + { + binlog_format => [ + 'MIXED', + 'mixed' + ] + }, + "..but can be turned off" +); + # ############################################################################# # Done. # ############################################################################# diff --git a/t/pt-config-diff/basics.t b/t/pt-config-diff/basics.t index 7dbe430b..cbcbfe61 100644 --- a/t/pt-config-diff/basics.t +++ b/t/pt-config-diff/basics.t @@ -26,11 +26,9 @@ if ( !$master_dbh ) { elsif ( !$slave_dbh ) { plan skip_all => 'Cannot connect to sandbox slave'; } -else { - plan tests => 13; -} my $cnf = '/tmp/12345/my.sandbox.cnf'; +my $samples = "$trunk/t/pt-config-diff/samples/"; my $output; my $retval; @@ -162,8 +160,44 @@ like( "Config diff output" ); +# ############################################################################# +# Case insensitivity +# ############################################################################# + +use File::Spec; + +$output = output( + sub { $retval = pt_config_diff::main( + File::Spec->catfile($samples, "case1.cnf"), + File::Spec->catfile($samples, "case2.cnf"), + ) }, + stderr => 1, +); + +is( + $output, + "", + "Case-insensitive by default, finds no diffs" +); + +$output = output( + sub { $retval = pt_config_diff::main( + File::Spec->catfile($samples, "case1.cnf"), + File::Spec->catfile($samples, "case2.cnf"), + '--no-ignore-case', + ) }, + stderr => 1, +); + +like( + $output, + qr/binlog_format\s+genlog\s+GENLOG/, + "With case-insensitivity turned off, finds one diff" +); + # ############################################################################# # Done. # ############################################################################# ok($sb->ok(), "Sandbox servers") or BAIL_OUT(__FILE__ . " broke the sandbox"); -exit; + +done_testing;