From af1240b6f6ac65abf40b4b31d00296f526c32034 Mon Sep 17 00:00:00 2001 From: Daniel Nichter Date: Mon, 22 Oct 2012 12:16:42 -0600 Subject: [PATCH] Test cases. --- t/lib/OptionParser.t | 22 ++++++++++++++++++++++ t/pt-deadlock-logger/option_sanity.t | 15 ++++++++++++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/t/lib/OptionParser.t b/t/lib/OptionParser.t index 34268222..303e07ce 100644 --- a/t/lib/OptionParser.t +++ b/t/lib/OptionParser.t @@ -2057,6 +2057,28 @@ is( "..and has the specified value", ); +# ############################################################################# +# Bug 1039074: Tools exit 0 on error parsing options, should exit non-zero +# ############################################################################# + +# pt-archiver requires at least one of --dest, --file or --purge, as well as +# --where and --source. So specifying no options should cause errors. +@ARGV = qw(); +$o = new OptionParser(file => "$trunk/bin/pt-archiver"); +$o->get_specs(); +$o->get_opts(); + +my $exit_status = 0; +($output, $exit_status) = full_output( + sub { $o->usage_or_errors("$trunk/bin/pt-archiver"); }, +); + +is( + $exit_status, + 1, + "Non-zero exit status on error parsing options (bug 1039074)" +); + # ############################################################################# # Done. # ############################################################################# diff --git a/t/pt-deadlock-logger/option_sanity.t b/t/pt-deadlock-logger/option_sanity.t index 64149763..ce75689c 100644 --- a/t/pt-deadlock-logger/option_sanity.t +++ b/t/pt-deadlock-logger/option_sanity.t @@ -9,7 +9,7 @@ BEGIN { use strict; use warnings FATAL => 'all'; use English qw(-no_match_vars); -use Test::More tests => 3; +use Test::More tests => 4; use PerconaTest; @@ -39,6 +39,19 @@ like( 'Dest DSN requires t' ); +# ############################################################################# +# Bug 1039074: Tools exit 0 on error parsing options, should exit non-zero +# ############################################################################# + +system("$trunk/bin/pt-deadlock-logger --i-am-the-error >/dev/null 2>&1"); +my $exit_status = $CHILD_ERROR >> 8; + +is( + $exit_status, + 1, + "Non-zero exit on option error (bug 1039074)" +); + # ############################################################################# # Done. # #############################################################################