use strict; use warnings;
use Test::More tests => 6;
-use Test::Exception;
+use Test::Fatal;
{
package MyClass;
# before fix, prints this on stderr:
#Unknown option: ?
-#usage: test1.t
+#usage: test1.t
# after fix, prints this on stderr:
#usage: test1.t [-?] [long options...]
# -? --usage --help Prints this usage information.
+my $obj = MyClass->new_with_options;
+ok($obj->meta->has_attribute('usage'), 'class has usage attribute');
+isa_ok($obj->usage, 'Getopt::Long::Descriptive::Usage');
+my $usage_text = $obj->usage->text;
+
foreach my $args ( ['--help'], ['--usage'], ['--?'], ['-?'] )
{
local @ARGV = @$args;
- throws_ok { MyClass->new_with_options() }
- qr/^usage: (?:[\d\w]+)\Q.t [-?] [long options...]\E.^\t\Q-? --usage --help Prints this usage information.\E$/ms,
+ is exception { MyClass->new_with_options() },
+ $usage_text,
'Help request detected; usage information properly printed';
}
-# now call again, and ensure we got the usage info.
-my $obj = MyClass->new_with_options();
-ok($obj->meta->has_attribute('usage'), 'class has usage attribute');
-isa_ok($obj->usage, 'Getopt::Long::Descriptive::Usage');