1#!/usr/bin/perl 2 3BEGIN { 4 die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" 5 unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; 6 unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; 7}; 8 9use strict; 10use warnings FATAL => 'all'; 11use English qw(-no_match_vars); 12use Test::More; 13use IPC::Cmd qw(can_run run); 14 15use PerconaTest; 16use Percona::Toolkit; 17 18use File::Temp qw(tempfile); 19 20my $version = $Percona::Toolkit::VERSION; 21 22my $perl = $^X; 23 24use File::Basename qw(basename); 25my @vc_tools = grep { chomp; basename($_) =~ /\A[a-z-]+\z/ } glob("$trunk/bin/*"); 26 27foreach my $tool ( @vc_tools ) { 28 my $output = `$tool --version 2>/dev/null`; 29 my ($tool_version) = $output =~ /(\b[0-9]\.[0-9]\.[0-9]\b)/; 30 next unless $tool_version; # Some tools don't have --version implemented 31 my $base = basename($tool); 32 is( 33 $tool_version, 34 $version, 35 "$base --version and Percona::Toolkit::VERSION agree" 36 ); 37 38 # Now let's check that lib/Percona/Toolkit.pm and each tool's 39 # $Percona::Toolkit::VERSION agree, sow e can avoid the 2.1.4 pt-table-sync 40 # debacle 41 open my $tmp_fh, q{<}, $tool or die "$!"; 42 my $is_perl = scalar(<$tmp_fh>) =~ /perl/; 43 close $tmp_fh; 44 45 next unless $is_perl; 46 47 my ($fh, $filename) = tempfile( "pt-version-test-XXXXXXX", UNLINK => 1 ); 48 print { $fh } "require q{$tool}; print \$Percona::Toolkit::VERSION, qq{\\n}"; 49 close $fh; 50 51 my ($success, undef, $full_buf) = 52 run( command => [ $perl, $filename ] ); 53 54 if ( !$success ) { 55 fail("Failed to get \$Percona::Toolkit::VERSION from $base: " . $full_buf ? join("", @$full_buf) : '') 56 } 57 else { 58 chomp(@$full_buf); 59 my $out = join "", @$full_buf; 60 if ($out) { 61 is( 62 "@$full_buf", 63 $version, 64 "$base and lib/Percona/Toolkit.pm agree" 65 ); 66 } 67 } 68} 69 70my $bzr = can_run('bzr'); 71SKIP: { 72 skip "Can't run bzr, skipping tag checking", 1 unless $bzr; 73 chomp(my $root = `$bzr root 2>/dev/null`); 74 skip '$trunk and bzr root differ, skipping tag checking', 1 75 unless $root eq $trunk; 76 77 my @tags = split /\n/, `$bzr tags`; 78 # sort the version numbers (some bzr versions do not sort them) 79 @tags = sort { calc_value($a) <=> calc_value($b) } @tags; 80 my ($current_tag) = $tags[-1] =~ /^(\S+)/; 81 82 is( 83 $current_tag, 84 $version, 85 "bzr tags and Percona::Toolkit::VERSION agree" 86 ); 87} 88 89# we use this function to help sort version numbers 90sub calc_value { 91 my $version = shift; 92 $version =~ s/ +[^ ]*$//; 93 my $value = 0; 94 my $exp = 0; 95 foreach my $num (reverse split /\./, $version) { 96 $value += $num * 10 ** $exp++; 97 } 98 print "$version = $value\n"; 99 return $value; 100} 101 102 103done_testing; 104