earlier error reporting, with tests
[p5sagit/Package-Variant.git] / t / 01simple.t
index 1520886..e41d27f 100644 (file)
@@ -36,9 +36,11 @@ BEGIN {
   $INC{'TestVariable.pm'} = __FILE__;
 }
 
-use TestVariable;
-
-my $variant = TestVariable(3..7);
+my $variant = do {
+    package TestScopeA;
+    use TestVariable;
+    TestVariable(3..7);
+};
 
 ok defined($variant), 'new variant is a defined value';
 ok length($variant), 'new variant has length';
@@ -53,4 +55,46 @@ is_deeply shift(@DECLARED), [class => 'TestVariable'],
   'class method resolution';
 is scalar(@DECLARED), 0, 'proxy sub called right amount of times';
 
+use TestVariable as => 'RenamedVar';
+is exception {
+  my $renamed = RenamedVar(9..12);
+  is_deeply $renamed->args, [9..12], 'imported generator can be renamed';
+}, undef, 'no errors for renamed usage';
+
+my @imported;
+BEGIN {
+  package TestImportableA;
+  sub import { push @imported, shift }
+  $INC{'TestImportableA.pm'} = __FILE__;
+  package TestImportableB;
+  sub import { push @imported, shift }
+  $INC{'TestImportableB.pm'} = __FILE__;
+  package TestArrayImports;
+  use Package::Variant
+    importing => [
+      'TestImportableA',
+      'TestImportableB',
+    ];
+  sub make_variant { }
+  $INC{'TestArrayImports.pm'} = __FILE__;
+}
+
+use TestArrayImports;
+TestArrayImports(23);
+
+is_deeply [@imported], [qw( TestImportableA TestImportableB )],
+  'multiple imports in the right order';
+
+like exception {
+  Package::Variant->import(
+    importing => \'foo', subs => [qw( foo )],
+  );
+}, qr/importing.+option.+hash.+array/i, 'invalid "importing" option';
+
+like exception {
+  Package::Variant->import(
+    importing => { foo => \'bar' }, subs => [qw( bar )],
+  );
+}, qr/import.+argument.+not.+array/i, 'invalid import argument list';
+
 done_testing;