Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the App-Cmd CPAN distribution.

Report information
The Basics
Id: 51512
Status: resolved
Priority: 0/
Queue: App-Cmd

People
Owner: Nobody in particular
Requestors: adam.prime [...] utoronto.ca
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.301
Fixed in: (no value)



Subject: Params::Validate callbacks and App::Cmd
Attached is a patch that adds a failing test (and some passing ones) related to using a Params::Validate callback in opt_spec of an App::Cmd command. right now it throws a stack trace, it should probably do something a little bit nicer than this.
Subject: 0001-Added-test-for-failing-callback.patch
From ad4c480cfcd20a68e0f61d6d95750062929dc446 Mon Sep 17 00:00:00 2001 From: Adam Prime <aprime@oanda.com> Date: Fri, 13 Nov 2009 14:54:54 -0500 Subject: [PATCH] Added test for failing callback --- t/callback.t | 28 ++++++++++++++++++++++++++++ t/lib/Test/WithCallback.pm | 7 +++++++ t/lib/Test/WithCallback/Command/lol.pm | 19 +++++++++++++++++++ t/lib/lol.pl | 3 +++ 4 files changed, 57 insertions(+), 0 deletions(-) create mode 100644 t/callback.t create mode 100644 t/lib/Test/WithCallback.pm create mode 100644 t/lib/Test/WithCallback/Command/lol.pm create mode 100644 t/lib/lol.pl diff --git a/t/callback.t b/t/callback.t new file mode 100644 index 0000000..d8d49be --- /dev/null +++ b/t/callback.t @@ -0,0 +1,28 @@ +#!perl +use strict; +use warnings; + +use Test::More 'no_plan'; +use App::Cmd::Tester; + +use lib 't/lib'; + +my $CLASS = 'Test::WithCallback'; + +require_ok($CLASS); + +ok($CLASS->isa('App::Cmd'), "$CLASS subclasses App::Cmd"); + +my $app = $CLASS->new; + +is_deeply( + [ sort $app->command_names ], + [ sort qw(help --help -h -? commands lol) ], + "got correct list of registered command names", +); + +my $return = test_app('Test::WithCallback', [ qw(lol -e 2) ]); +is($return->stdout, 'yay', "Callback validated correctly"); + +$return = test_app('Test::WithCallback', [ qw(lol -e 1) ]); +is($return->error, 'Something other than this stack trace', "Failing Params::Validate callback prints nice error message"); diff --git a/t/lib/Test/WithCallback.pm b/t/lib/Test/WithCallback.pm new file mode 100644 index 0000000..32ab7a0 --- /dev/null +++ b/t/lib/Test/WithCallback.pm @@ -0,0 +1,7 @@ +use strict; +use warnings; + +package Test::WithCallback; +use App::Cmd::Setup -app; + +1; diff --git a/t/lib/Test/WithCallback/Command/lol.pm b/t/lib/Test/WithCallback/Command/lol.pm new file mode 100644 index 0000000..546138d --- /dev/null +++ b/t/lib/Test/WithCallback/Command/lol.pm @@ -0,0 +1,19 @@ +package Test::WithCallback::Command::lol; +use strict; +use Test::WithCallback -command; + +sub opt_spec { + return ( + [ "even|e=s", "an even number", { + callbacks => { + valid_email => sub { return !($_[0] % 2) } + } + }], + ); +} + +sub execute { + print 'yay'; +} + +1; diff --git a/t/lib/lol.pl b/t/lib/lol.pl new file mode 100644 index 0000000..ae05af6 --- /dev/null +++ b/t/lib/lol.pl @@ -0,0 +1,3 @@ +use Test::WithCallback; + +Test::WithCallback->run -- 1.6.3.1
thanks, applied -- rjbs