Commits

Toby Inkster committed 74ef110 Draft

test suite

Comments (0)

Files changed (6)

+- test for generators
+- test for introspection

lib/Exporter/Everything.pm

 
 =head2 What if I import functions like L<Scalar::Util> C<blessed> and don't want to re-export them.
 
-Then clean up your namespace with something like C<namespace::clean>.
+Then clean up your namespace with something like C<namespace::autoclean>.
 
 =head2 I need cool features like Exporter.pm's tags, or Sub::Exporter's generators.
 
 	perl_version_from m`Exporter::Everything`;
 	version_from      m`Exporter::Everything`;
 	readme_from       m`Exporter::Everything`;
-	test_requires     p`Test::More 0.61`  .
+	requires          p`Sub::Exporter 0`;
+	requires          p`Sub::Name 0`;
+	requires          p`Package::Stash 0`;
+	test_requires     p`thanks 0.001`;
+	test_requires     p`Test::Exception 0`;
+	test_requires     p`Test::More 0.61`.
 
+use Test::More tests => 66;
+
+BEGIN {
+	package Local::Exporter::Other;
+	use Exporter::Everything;
+	sub a { 'a' }
+	no thanks;
+}
+
+BEGIN {
+	package Local::Exporter;
+	use Exporter::Everything;
+	# don't want to export these constants, give them underscores!
+	use constant _SHOULD     => qw(a b C D _p _q _R _S __w __x __Y __Z);
+	use constant _SHOULD_NOT => qw(break);
+	use Local::Exporter::Other;
+	sub b { 'b' }
+	sub C { 'c' }
+	sub D { 'd' }
+	sub _p { 'p' }
+	sub _q { 'q' }
+	sub _R { 'r' }
+	sub _S { 's' }
+	sub __w { 'w' }
+	sub __x { 'x' }
+	sub __Y { 'y' }
+	sub __Z { 'z' }
+	no thanks;
+}
+
+BEGIN {
+	package Local::Importer1;
+	use Local::Exporter qw(a C _p _R);
+	use constant SHOULD     => qw(a C _p _R);
+	use constant SHOULD_NOT => qw(b D _q _S __w __x __Y __Z import);
+	no thanks;
+}
+
+BEGIN {
+	package Local::Importer2;
+	use Local::Exporter;
+	use constant SHOULD     => qw(a b C D);
+	use constant SHOULD_NOT => qw(_p _q _R _S __w __x __Y __Z import);
+	no thanks;
+}
+
+BEGIN {
+	package Local::Importer3;
+	use Local::Exporter -const;
+	use constant SHOULD     => qw(C D);
+	use constant SHOULD_NOT => qw(a b _p _q _R _S __w __x __Y __Z import);
+	no thanks;
+}
+
+BEGIN {
+	package Local::Importer4;
+	use Local::Exporter -default, '_p' => { -as => 'P'};
+	use constant SHOULD     => qw(a b C D P);
+	use constant SHOULD_NOT => qw(_p _q _R _S __w __x __Y __Z import);
+	no thanks;
+}
+
+for my $class ('Local::Exporter') {
+	for my $f ($class->_SHOULD)
+	{
+		my ($letter) = map { +lc } ($f =~ /([A-Z])/i);
+		ok($class->can($f) && $class->$f eq $letter, "'$class' defines '$f' properly");
+	}
+	for my $f ($class->_SHOULD_NOT)
+	{
+		ok(!$class->can($f), "'$class' does not define '$f'");
+	}
+}
+
+for my $n (1 .. 4)
+{
+	my $class = "Local::Importer$n";
+	for my $f ($class->SHOULD)
+	{
+		my ($letter) = map { +lc } ($f =~ /([A-Z])/i);
+		ok($class->can($f) && $class->$f eq $letter, "'$class' imports '$f' properly");
+	}
+	for my $f ($class->SHOULD_NOT)
+	{
+		ok(!$class->can($f), "'$class' does not import '$f'");
+	}
+}
+use Test::More tests => 8;
+use Test::Exception;
+
+BEGIN {
+	package Local::Exporter::Other;
+	use Exporter::Everything;
+	sub a { 'a' }
+	no thanks;
+}
+
+BEGIN {
+	package Local::Exporter;
+	use Exporter::Everything;
+	# don't want to export these constants, give them underscores!
+	use constant _SHOULD     => qw(a b C D _p _q _R _S __w __x __Y __Z);
+	use constant _SHOULD_NOT => qw(break);
+	use Local::Exporter::Other;
+	sub b { 'b' }
+	sub C { 'c' }
+	sub D { 'd' }
+	sub _p { 'p' }
+	sub _q { 'q' }
+	sub _R { 'r' }
+	sub _S { 's' }
+	sub __w { 'w' }
+	sub __x { 'x' }
+	sub __Y { 'y' }
+	sub __Z { 'z' }
+	no thanks;
+}
+
+for my $f (qw( __w __x __Y __Z these do not exist ))
+{
+	throws_ok { Local::Exporter->import($f) }
+	qr        {is not exported by the Local::Exporter module};
+}

t/04namespace_clean.t

+use Test::More;
+use Test::Exception;
+
+BEGIN {
+	eval 'require namespace::clean; 1'
+		or plan skip_all => "need namespace::clean for this test";
+	plan tests => 9;
+}
+
+BEGIN {
+	package Local::Exporter;
+	use Scalar::Util qw(blessed);
+	sub a { 'a' }
+	use namespace::clean;
+	use Exporter::Everything;
+	use Scalar::Util qw(reftype);
+	sub b { 'b' }
+	no thanks;
+}
+
+BEGIN {
+	package Local::Importer;
+	use Local::Exporter;
+	no thanks;
+}
+
+for my $class (qw(Local::Exporter Local::Importer))
+{
+	ok(!$class->can('blessed'), "$class cannot 'blessed'");
+	ok(!$class->can('a'), "$class cannot 'a'");
+	ok($class->can('reftype'), "$class can 'reftype'");
+	ok($class->can('b'), "$class can 'b'");
+}
+
+throws_ok { Local::Exporter->import('a') }
+qr        {is not exported by the Local::Exporter module};