Test-Apocalypse

 view release on metacpan or  search on metacpan

lib/Test/Apocalypse.pm  view on Meta::CPAN

	);

	# loop through our plugins ( in alphabetical order! )
	foreach my $t ( sort { $a cmp $b } __PACKAGE__->plugins() ) {
		my $plugin = $t;
		$plugin =~ s/^Test::Apocalypse:://;

		# Do we want this test?
		# PERL_APOCALYPSE=1 means run all tests, =0 means default behavior
		if ( ! exists $ENV{PERL_APOCALYPSE} or ! $ENV{PERL_APOCALYPSE} ) {
			if ( exists $opt{'allow'} ) {
				if ( $t =~ /^Test::Apocalypse::(.+)$/ ) {
					if ( $1 !~ $opt{'allow'} ) {
						diag( "Skipping $plugin ( via allow policy )..." );
						next;
					}
				}
			} elsif ( exists $opt{'deny'} ) {
				if ( $t =~ /^Test::Apocalypse::(.+)$/ ) {
					if ( $1 =~ $opt{'deny'} ) {
						diag( "Skipping $plugin ( via deny policy )..." );
						next;
					}
				}
			}
		}

		# Load it, and look for errors
		eval "use $t";
		if ( $@ ) {
			# TODO smarter error detection - missing module, bla bla
			my $error = "Unable to load $plugin -> $@";

			if ( $ENV{RELEASE_TESTING} or $ENV{PERL_APOCALYPSE} ) {
				die $error;
			} else {
				diag( $error );
			}

			next;
		}

		# Is this plugin disabled?
		if ( $t->can( '_is_disabled' ) and ! $ENV{PERL_APOCALYPSE} ) {
			my $ret = $t->_is_disabled;
			if ( $ret ) {
				diag( "Skipping $plugin => $ret" );
				next;
			}
		}

		# Check for AUTOMATED_TESTING
		if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_APOCALYPSE} and $t->can( '_do_automated' ) and ! $t->_do_automated() ) {
			diag( "Skipping $plugin ( for RELEASE_TESTING only )..." );
			next;
		}

		# run it!
		subtest $plugin => sub {
			eval {
				# TODO ignore annoying gpg warnings like 'WARNING: This key is not certified with a trusted signature!' at /usr/local/share/perl/5.18.2/Module/Signature.pm line 265.
				no warnings qw(once);
				local @Test::FailWarnings::ALLOW_FROM = ( 'Module::Signature' );

				local $SIG{__WARN__} = \&Test::FailWarnings::handler;
				$t->do_test();
			};
			if ( $@ ) {
				# Sometimes we get a plain string, sometimes we get
				# Error running Kwalitee: Test::Builder::Exception=HASH(0x3fa6078)
				my $err = $@;
				if ( $err->isa( 'Test::Builder::Exception' ) ) {
					# TODO reach into T::B to get the actual skip reason
					$err = Test::Builder->new->{Skip_All};
				}

				if ( $ENV{RELEASE_TESTING} or $ENV{PERL_APOCALYPSE} ) {
					die "Error running $plugin: $err";
				} else {
					diag( "Error running $plugin: $err" );
				}

				# we need to manually intervene or we'll get this:
				# Running DOSnewline...
				# Running Dependencies...
					# Child (Dependencies) exited without calling finalize()
					#   Failed test 'Dependencies'
					#   at /usr/local/share/perl/5.18.2/Test/Apocalypse.pm line 134.
					# Error running Dependencies: Can't locate object method "new" via package "Version::Requirements" (perhaps you forgot to load "Version::Requirements"?) at /usr/local/share/perl/5.18.2/Test/Apocalypse/Dependencies.pm line 59.
				# Running DirChecks...
				# Error running DirChecks: You already have a child named (Dependencies) running at /usr/local/share/perl/5.18.2/Test/More.pm line 771.
				done_testing();
			}
		};
	}

	done_testing();
	return 1;
}

1;

__END__

=pod

=encoding UTF-8

=for :stopwords Apocalypse Niebur Ryan cpan testmatrix url annocpan anno bugtracker rt
cpants kwalitee diff irc mailto metadata placeholders metacpan apocal CPAN
AUTHORs al backend debian distro distros dists env hackish plugins
testsuite yml pm yay unicode blog precompiled =for stopwords ap cyclomatic
cal dist homebrew imo internet perltidy prefs prereq testrun

=head1 NAME

Test::Apocalypse - Apocalypse's favorite tests bundled into a simple interface

=head1 VERSION

  This document describes v1.006 of Test::Apocalypse - released October 25, 2014 as part of Test-Apocalypse.



( run in 1.062 second using v1.01-cache-2.11-cpan-df04353d9ac )