Implements feature suggestion RT#58715 by storing the Usage object, fixes
[gitmo/MooseX-Getopt.git] / t / 108_usage_attr.t
diff --git a/t/108_usage_attr.t b/t/108_usage_attr.t
new file mode 100644 (file)
index 0000000..c0286c5
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/env perl
+
+# Re RT#58715 and the claim in the documentation:
+#   If you have Getopt::Long::Descriptive the usage param is also passed to new.
+
+# This tests the fix (that fulfills the documentation claim).
+
+use strict; use warnings;
+use Test::More tests => 3;
+
+{
+    package MyClass;
+    use strict; use warnings;
+    use Moose;
+    with 'MooseX::Getopt';
+}
+
+Moose::Meta::Class->create('MyClassWithBasic',
+    superclasses => ['MyClass'],
+    roles => [ 'MooseX::Getopt::Basic' ],
+);
+
+my $basic_obj = MyClassWithBasic->new_with_options();
+ok(!$basic_obj->meta->has_attribute('usage'), 'basic class has no usage attribute');
+
+Moose::Meta::Class->create('MyClassWithGLD',
+    superclasses => ['MyClass'],
+    roles => [ 'MooseX::Getopt' ],
+);
+
+my $gld_obj = MyClassWithGLD->new_with_options();
+
+ok($gld_obj->meta->has_attribute('usage'), 'class has usage attribute');
+isa_ok($gld_obj->usage, 'Getopt::Long::Descriptive::Usage');
+