Acme-MetaSyntactic
view release on metacpan or search on metacpan
lib/Test/MetaSyntactic.pm view on Meta::CPAN
my @lines;
my $in_data;
for my $line (@_) {
$in_data++ if $line =~ /^__DATA__$/;
next if !$in_data;
push @lines, $line
if /^#/ && !/^# ?(?:names(?: +[-\w]+)*|default)\s*$/;
}
return @lines;
}
);
}
sub subtest_version {
my ($theme) = @_;
my $tb = __PACKAGE__->builder;
$tb->plan( tests => 1 );
no strict 'refs';
my $version = "Acme::MetaSyntactic::$theme"->VERSION || '';
$tb->ok( $version, "$theme version $version" );
}
# t/90up2date.t
my ($has_lwp, $has_test_diff, $has_network);
BEGIN {
$has_lwp = eval { require LWP::UserAgent; 1; };
$has_network = $has_lwp
&& LWP::UserAgent->new( timeout => 5, env_proxy => 1 )
->get('http://www.google.com/intl/en/')
->is_success;
};
sub subtest_remote {
my ($theme) = @_;
my $class = "Acme::MetaSyntactic::$theme";
# find out if we're in one of the many cases for skipping
my $why
= !$ENV{RELEASE_TESTING}
&& !$ENV{AUTHOR_TESTING} ? 'Remote list test is RELEASE_TESTING'
: $ENV{AUTOMATED_TESTING} ? "Remote list test isn't AUTOMATED_TESTING"
: !$class->has_remotelist ? "Theme $theme does not have a remote list"
: !$has_lwp ? 'Remote list test needs LWP::UserAgent'
: !$has_network ? 'Remote list test needs network'
: '';
my $tb = __PACKAGE__->builder;
my @metas = _theme_sublists($theme);
$tb->plan( tests => scalar @metas );
SKIP: {
if ($why) {
$tb->skip($why) for 1 .. @metas;
last SKIP;
}
for my $test (@metas) {
my ( $ams, $theme ) = @$test;
no warnings 'utf8';
my $current = [ sort $ams->name(0) ];
my $remote = [ sort $ams->remote_list() ];
if ( !@$remote ) {
$tb->skip("Fetching remote items for $theme probably failed");
next;
}
# compare both lists
my %seen;
$seen{$_}++ for @$remote;
$seen{$_}-- for @$current;
$tb->ok( !grep( $_, values %seen ),
"Local and remote lists are identical for $theme" )
or $tb->diag("Differences between local and remote list:");
$tb->diag( $seen{$_} > 0 ? "+ $_" : "- $_" )
for grep $seen{$_}, sort keys %seen;
}
}
}
1;
__END__
=head1 NAME
Test::MetaSyntactic - Common tests for Acme::MetaSyntactic themes
=head1 SYNOPSIS
# add this as t/meta.t
use Test::MetaSyntatic;
all_themes_ok();
=head1 DESCRIPTION
This module provides the minimum set of tests that any Acme::MetaSyntactic theme
should pass.
The goal is to make is easier for theme creators build a distribution and ensure
theirs themes will work as expected when installed.
=head1 EXPORTED FUNCTIONS
=head2 all_themes_ok( @lib )
Will find all themes under the directories listed in C<@lib>, and run C<theme_ok()>
on them.
C<@lib> is optional (it will try to find themes in F<blib/lib> or F<lib> if not provided).
=head2 theme_ok( $theme, $source )
Will run all tests on the given C<$theme>. Some tests require access to the source, but
they will be skipped if C<$source> is not provided.
If the C<subtest_load()> test fails, no further test will be run.
=head1 SUBTESTS
( run in 0.589 second using v1.01-cache-2.11-cpan-39bf76dae61 )