diff --git a/bin/pt-eustack-resolver b/bin/pt-eustack-resolver index ab50b92b..f834f9eb 100755 --- a/bin/pt-eustack-resolver +++ b/bin/pt-eustack-resolver @@ -5,7 +5,7 @@ # notices and disclaimers. use strict; -#use warnings FATAL => 'all'; +use warnings FATAL => 'all'; # This tool is "fat-packed": most of its dependent modules are embedded # in this file. Setting %INC to this file for each module makes Perl aware @@ -1247,7 +1247,6 @@ if ( PTDEBUG ) { # End OptionParser package # ########################################################################### - # ########################################################################### # This is a combination of modules and programs in one -- a runnable module. # http://www.perl.com/pub/a/2006/07/13/lightning-articles.html?page=last @@ -1259,7 +1258,10 @@ if ( PTDEBUG ) { package pt_eu_stack_resolver; use strict; -#use warnings FATAL => 'all'; +use warnings FATAL => 'all'; +# We have to disable warnings here because Perl prints +# warnings for numbers greater than 2^32. +no warnings 'portable'; use Percona::Toolkit; use constant PTDEBUG => $ENV{PTDEBUG} || 0; @@ -1370,7 +1372,7 @@ sub load_mapping { push @$arr, { S => hex($1), E => hex($2), B => hex($3), F => $4 }; } close $FH; - sort { $a->{S} <=> $b->{S} } @$arr; + @$arr = sort { $a->{S} <=> $b->{S} } @$arr; return $arr; } @@ -1414,7 +1416,7 @@ and resolve symbols. Usage: pt-eustack-resolver PID -pt-eustack-resolver collects stack traces for the process with specified C. +pt-eustack-resolver collects stack traces for the process with specified C. =head1 RISKS @@ -1463,7 +1465,6 @@ Show help and exit. Show version and exit. - =head1 ATTENTION Using might expose passwords. When debug is enabled, all command line diff --git a/t/pt-eustack-resolver/option_sanity.t b/t/pt-eustack-resolver/option_sanity.t new file mode 100644 index 00000000..22680c4a --- /dev/null +++ b/t/pt-eustack-resolver/option_sanity.t @@ -0,0 +1,70 @@ +#!/usr/bin/env perl + +BEGIN { + die "The PERCONA_TOOLKIT_BRANCH environment variable is not set.\n" + unless $ENV{PERCONA_TOOLKIT_BRANCH} && -d $ENV{PERCONA_TOOLKIT_BRANCH}; + unshift @INC, "$ENV{PERCONA_TOOLKIT_BRANCH}/lib"; +}; + +use strict; +use warnings FATAL => 'all'; +use English qw(-no_match_vars); +use Test::More; + +use PerconaTest; + +# ############################################################################ +# We only check basic option sanity here. It is hard to create tests for the +# eu-stack output that work in all environments. So we will simply check that +# the help and version options work as expected. +# ############################################################################ + +my $output = `$trunk/bin/pt-eustack-resolver --help`; + +like( + $output, + qr/^\s+--help\s+Show help and exit/m, + "--help option is documented" +); + +like( + $output, + qr/^\s+--version\s+Show version and exit/m, + "--version option is documented" +); + +like( + $output, + qr/Options and values after processing arguments:/m, + "Help output contains expected section" +); + +# ############################################################################ +# Check error when no arguments are provided +# ############################################################################ +my $error_output = `$trunk/bin/pt-eustack-resolver 2>&1`; + +like( + $error_output, + qr/A PID must be specified/m, + "Error message shown when no PID is provided" +); + +like( + $error_output, + qr/Usage: pt-eustack-resolver PID/m, + "Usage line shown in error" +); + +# ############################################################################ +# Check --version option +# ############################################################################ +my $version_output = `$trunk/bin/pt-eustack-resolver --version`; + +like( + $version_output, + qr/pt-eustack-resolver \d+\.\d+\.\d+(?:-\d+)?/m, + "--version shows tool name and version" +); + +done_testing;