summaryrefslogtreecommitdiff
path: root/t
diff options
context:
space:
mode:
Diffstat (limited to 't')
-rw-r--r--t/00-report-prereqs.dd128
-rw-r--r--t/00-report-prereqs.t183
-rw-r--r--t/RT42725_deparse.t14
-rw-r--r--t/RT96893_perlcc.t30
-rw-r--r--t/smoke.t44
5 files changed, 399 insertions, 0 deletions
diff --git a/t/00-report-prereqs.dd b/t/00-report-prereqs.dd
new file mode 100644
index 0000000..520350c
--- /dev/null
+++ b/t/00-report-prereqs.dd
@@ -0,0 +1,128 @@
+do { my $x = {
+ 'configure' => {
+ 'requires' => {
+ 'ExtUtils::MakeMaker' => '0',
+ 'perl' => '5.006'
+ }
+ },
+ 'develop' => {
+ 'recommends' => {
+ 'Dist::Zilla::PluginBundle::Author::ETHER' => '0.092'
+ },
+ 'requires' => {
+ 'Devel::PPPort' => '3.23',
+ 'Dist::Zilla' => '5',
+ 'Dist::Zilla::Plugin::Authority' => '0',
+ 'Dist::Zilla::Plugin::AuthorityFromModule' => '0.002',
+ 'Dist::Zilla::Plugin::AutoMetaResources' => '0',
+ 'Dist::Zilla::Plugin::AutoPrereqs' => '0',
+ 'Dist::Zilla::Plugin::BumpVersionAfterRelease::Transitional' => '0.004',
+ 'Dist::Zilla::Plugin::CheckIssues' => '0',
+ 'Dist::Zilla::Plugin::CheckPrereqsIndexed' => '0',
+ 'Dist::Zilla::Plugin::CheckSelfDependency' => '0',
+ 'Dist::Zilla::Plugin::CheckStrictVersion' => '0',
+ 'Dist::Zilla::Plugin::ConfirmRelease' => '0',
+ 'Dist::Zilla::Plugin::CopyFilesFromRelease' => '0',
+ 'Dist::Zilla::Plugin::ExecDir' => '0',
+ 'Dist::Zilla::Plugin::FileFinder::ByName' => '0',
+ 'Dist::Zilla::Plugin::GenerateFile::ShareDir' => '0',
+ 'Dist::Zilla::Plugin::Git::Check' => '2.025',
+ 'Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch' => '0.004',
+ 'Dist::Zilla::Plugin::Git::CheckFor::MergeConflicts' => '0',
+ 'Dist::Zilla::Plugin::Git::Commit' => '2.020',
+ 'Dist::Zilla::Plugin::Git::Contributors' => '0.004',
+ 'Dist::Zilla::Plugin::Git::Describe' => '0.004',
+ 'Dist::Zilla::Plugin::Git::GatherDir' => '2.016',
+ 'Dist::Zilla::Plugin::Git::Push' => '0',
+ 'Dist::Zilla::Plugin::Git::Remote::Check' => '0',
+ 'Dist::Zilla::Plugin::Git::Tag' => '0',
+ 'Dist::Zilla::Plugin::GitHub::Update' => '0.40',
+ 'Dist::Zilla::Plugin::GithubMeta' => '0',
+ 'Dist::Zilla::Plugin::InstallGuide' => '0',
+ 'Dist::Zilla::Plugin::Keywords' => '0.004',
+ 'Dist::Zilla::Plugin::License' => '0',
+ 'Dist::Zilla::Plugin::MakeMaker' => '0',
+ 'Dist::Zilla::Plugin::Manifest' => '0',
+ 'Dist::Zilla::Plugin::MetaConfig' => '0',
+ 'Dist::Zilla::Plugin::MetaJSON' => '0',
+ 'Dist::Zilla::Plugin::MetaNoIndex' => '0',
+ 'Dist::Zilla::Plugin::MetaProvides::Package' => '1.15000002',
+ 'Dist::Zilla::Plugin::MetaTests' => '0',
+ 'Dist::Zilla::Plugin::MetaYAML' => '0',
+ 'Dist::Zilla::Plugin::MinimumPerl' => '1.006',
+ 'Dist::Zilla::Plugin::MojibakeTests' => '0',
+ 'Dist::Zilla::Plugin::NextRelease' => '5.033',
+ 'Dist::Zilla::Plugin::PPPort' => '0',
+ 'Dist::Zilla::Plugin::PodCoverageTests' => '0',
+ 'Dist::Zilla::Plugin::PodSyntaxTests' => '0',
+ 'Dist::Zilla::Plugin::PodWeaver' => '4.005',
+ 'Dist::Zilla::Plugin::Prereqs' => '0',
+ 'Dist::Zilla::Plugin::Prereqs::AuthorDeps' => '0',
+ 'Dist::Zilla::Plugin::PromptIfStale' => '0',
+ 'Dist::Zilla::Plugin::Readme' => '0',
+ 'Dist::Zilla::Plugin::ReadmeAnyFromPod' => '0.142180',
+ 'Dist::Zilla::Plugin::RewriteVersion::Transitional' => '0.004',
+ 'Dist::Zilla::Plugin::Run::AfterBuild' => '0.028',
+ 'Dist::Zilla::Plugin::Run::AfterRelease' => '0.031',
+ 'Dist::Zilla::Plugin::RunExtraTests' => '0.024',
+ 'Dist::Zilla::Plugin::ShareDir' => '0',
+ 'Dist::Zilla::Plugin::Test::CPAN::Changes' => '0.008',
+ 'Dist::Zilla::Plugin::Test::ChangesHasContent' => '0',
+ 'Dist::Zilla::Plugin::Test::CleanNamespaces' => '0.006',
+ 'Dist::Zilla::Plugin::Test::Compile' => '2.039',
+ 'Dist::Zilla::Plugin::Test::EOL' => '0.14',
+ 'Dist::Zilla::Plugin::Test::Kwalitee' => '2.06',
+ 'Dist::Zilla::Plugin::Test::MinimumVersion' => '2.000003',
+ 'Dist::Zilla::Plugin::Test::NoTabs' => '0.08',
+ 'Dist::Zilla::Plugin::Test::Pod::No404s' => '0',
+ 'Dist::Zilla::Plugin::Test::PodSpelling' => '2.006001',
+ 'Dist::Zilla::Plugin::Test::Portability' => '0',
+ 'Dist::Zilla::Plugin::Test::ReportPrereqs' => '0.019',
+ 'Dist::Zilla::Plugin::TestRelease' => '0',
+ 'Dist::Zilla::Plugin::UploadToCPAN' => '0',
+ 'Dist::Zilla::PluginBundle::Author::ETHER' => '0.091',
+ 'File::Spec' => '0',
+ 'IO::Handle' => '0',
+ 'IPC::Open3' => '0',
+ 'Pod::Coverage::TrustPod' => '0',
+ 'Pod::Weaver::Section::Contributors' => '0.008',
+ 'Test::CPAN::Changes' => '0.19',
+ 'Test::CPAN::Meta' => '0',
+ 'Test::CleanNamespaces' => '0.15',
+ 'Test::EOL' => '0',
+ 'Test::Kwalitee' => '1.21',
+ 'Test::More' => '0.94',
+ 'Test::NoTabs' => '0',
+ 'Test::Pod' => '1.41',
+ 'Test::Pod::Coverage' => '1.08',
+ 'Test::Spelling' => '0.12'
+ }
+ },
+ 'runtime' => {
+ 'requires' => {
+ 'Exporter' => '5.57',
+ 'XSLoader' => '0',
+ 'perl' => '5.006',
+ 'strict' => '0',
+ 'warnings' => '0'
+ }
+ },
+ 'test' => {
+ 'recommends' => {
+ 'CPAN::Meta' => '2.120900'
+ },
+ 'requires' => {
+ 'B::Deparse' => '0',
+ 'ExtUtils::MakeMaker' => '0',
+ 'File::Spec' => '0',
+ 'Test::More' => '0.88',
+ 'perl' => '5.006'
+ },
+ 'suggests' => {
+ 'B::C' => '1.48',
+ 'Devel::CheckBin' => '0'
+ }
+ }
+ };
+ $x;
+ } \ No newline at end of file
diff --git a/t/00-report-prereqs.t b/t/00-report-prereqs.t
new file mode 100644
index 0000000..f711380
--- /dev/null
+++ b/t/00-report-prereqs.t
@@ -0,0 +1,183 @@
+#!perl
+
+use strict;
+use warnings;
+
+# This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.021
+
+use Test::More tests => 1;
+
+use ExtUtils::MakeMaker;
+use File::Spec;
+
+# from $version::LAX
+my $lax_version_re =
+ qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )?
+ |
+ (?:\.[0-9]+) (?:_[0-9]+)?
+ ) | (?:
+ v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )?
+ |
+ (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)?
+ )
+ )/x;
+
+# hide optional CPAN::Meta modules from prereq scanner
+# and check if they are available
+my $cpan_meta = "CPAN::Meta";
+my $cpan_meta_pre = "CPAN::Meta::Prereqs";
+my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic
+
+# Verify requirements?
+my $DO_VERIFY_PREREQS = 1;
+
+sub _max {
+ my $max = shift;
+ $max = ( $_ > $max ) ? $_ : $max for @_;
+ return $max;
+}
+
+sub _merge_prereqs {
+ my ($collector, $prereqs) = @_;
+
+ # CPAN::Meta::Prereqs object
+ if (ref $collector eq $cpan_meta_pre) {
+ return $collector->with_merged_prereqs(
+ CPAN::Meta::Prereqs->new( $prereqs )
+ );
+ }
+
+ # Raw hashrefs
+ for my $phase ( keys %$prereqs ) {
+ for my $type ( keys %{ $prereqs->{$phase} } ) {
+ for my $module ( keys %{ $prereqs->{$phase}{$type} } ) {
+ $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module};
+ }
+ }
+ }
+
+ return $collector;
+}
+
+my @include = qw(
+ Pod::Coverage
+);
+
+my @exclude = qw(
+
+);
+
+# Add static prereqs to the included modules list
+my $static_prereqs = do 't/00-report-prereqs.dd';
+
+# Merge all prereqs (either with ::Prereqs or a hashref)
+my $full_prereqs = _merge_prereqs(
+ ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ),
+ $static_prereqs
+);
+
+# Add dynamic prereqs to the included modules list (if we can)
+my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml';
+if ( $source && $HAS_CPAN_META ) {
+ if ( my $meta = eval { CPAN::Meta->load_file($source) } ) {
+ $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs);
+ }
+}
+else {
+ $source = 'static metadata';
+}
+
+my @full_reports;
+my @dep_errors;
+my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs;
+
+# Add static includes into a fake section
+for my $mod (@include) {
+ $req_hash->{other}{modules}{$mod} = 0;
+}
+
+for my $phase ( qw(configure build test runtime develop other) ) {
+ next unless $req_hash->{$phase};
+ next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING});
+
+ for my $type ( qw(requires recommends suggests conflicts modules) ) {
+ next unless $req_hash->{$phase}{$type};
+
+ my $title = ucfirst($phase).' '.ucfirst($type);
+ my @reports = [qw/Module Want Have/];
+
+ for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) {
+ next if $mod eq 'perl';
+ next if grep { $_ eq $mod } @exclude;
+
+ my $file = $mod;
+ $file =~ s{::}{/}g;
+ $file .= ".pm";
+ my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC;
+
+ my $want = $req_hash->{$phase}{$type}{$mod};
+ $want = "undef" unless defined $want;
+ $want = "any" if !$want && $want == 0;
+
+ my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required";
+
+ if ($prefix) {
+ my $have = MM->parse_version( File::Spec->catfile($prefix, $file) );
+ $have = "undef" unless defined $have;
+ push @reports, [$mod, $want, $have];
+
+ if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) {
+ if ( $have !~ /\A$lax_version_re\z/ ) {
+ push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)";
+ }
+ elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) {
+ push @dep_errors, "$mod version '$have' is not in required range '$want'";
+ }
+ }
+ }
+ else {
+ push @reports, [$mod, $want, "missing"];
+
+ if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) {
+ push @dep_errors, "$mod is not installed ($req_string)";
+ }
+ }
+ }
+
+ if ( @reports ) {
+ push @full_reports, "=== $title ===\n\n";
+
+ my $ml = _max( map { length $_->[0] } @reports );
+ my $wl = _max( map { length $_->[1] } @reports );
+ my $hl = _max( map { length $_->[2] } @reports );
+
+ if ($type eq 'modules') {
+ splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl];
+ push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports;
+ }
+ else {
+ splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl];
+ push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports;
+ }
+
+ push @full_reports, "\n";
+ }
+ }
+}
+
+if ( @full_reports ) {
+ diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports;
+}
+
+if ( @dep_errors ) {
+ diag join("\n",
+ "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n",
+ "The following REQUIRED prerequisites were not satisfied:\n",
+ @dep_errors,
+ "\n"
+ );
+}
+
+pass;
+
+# vim: ts=4 sts=4 sw=4 et:
diff --git a/t/RT42725_deparse.t b/t/RT42725_deparse.t
new file mode 100644
index 0000000..a10ce82
--- /dev/null
+++ b/t/RT42725_deparse.t
@@ -0,0 +1,14 @@
+use strict;
+use warnings;
+
+use Test::More tests => 2;
+use Sub::Name;
+use B::Deparse;
+
+my $source = eval {
+ B::Deparse->new->coderef2text(subname foo => sub{ @_ });
+};
+
+ok !$@;
+
+like $source, qr/\@\_/;
diff --git a/t/RT96893_perlcc.t b/t/RT96893_perlcc.t
new file mode 100644
index 0000000..6a35357
--- /dev/null
+++ b/t/RT96893_perlcc.t
@@ -0,0 +1,30 @@
+use strict;
+use warnings;
+
+use Test::More 0.88;
+
+plan skip_all => 'B::C required for testing perlcc -O3'
+ unless eval "require B::C;";
+
+plan skip_all => "B::C is too old (require 1.48, have $B::C::VERSION)"
+ unless eval { B::C->VERSION('1.48') };
+
+plan skip_all => 'Devel::CheckBin required for looking for a perlcc executable'
+ unless eval 'require Devel::CheckBin';
+
+plan skip_all => 'perlcc required' unless Devel::CheckBin::can_run('perlcc');
+
+plan tests => 1;
+
+my $f = "t/rt96893x.pl";
+open my $fh, ">", $f; END { unlink $f if $f }
+print $fh 'use Sub::Name; subname("main::bar", sub{42}); print "# successfully ran subname() with perlcc\n";';
+close $fh;
+
+system($^X, qw(-Mblib -S perlcc -O3 -UCarp -UConfig -r), $f);
+
+local $TODO = 'experimental, for informational purposes only';
+is($? >> 8, 0, 'executable completed successfully');
+
+unlink "t/rt96893x", "t/rt96893x.exe";
+# vim: ft=perl
diff --git a/t/smoke.t b/t/smoke.t
new file mode 100644
index 0000000..763abcc
--- /dev/null
+++ b/t/smoke.t
@@ -0,0 +1,44 @@
+use strict;
+use warnings;
+
+BEGIN { $^P |= 0x210 }
+
+use Test::More 0.88;
+use Sub::Name;
+
+my $x = subname foo => sub { (caller 0)[3] };
+my $line = __LINE__ - 1;
+my $file = __FILE__;
+my $anon = $DB::sub{"main::__ANON__[${file}:${line}]"};
+
+is($x->(), "main::foo");
+
+package Blork;
+
+use Sub::Name;
+
+subname " Bar!", $x;
+::is($x->(), "Blork:: Bar!");
+
+subname "Foo::Bar::Baz", $x;
+::is($x->(), "Foo::Bar::Baz");
+
+subname "subname (dynamic $_)", \&subname for 1 .. 3;
+
+for (4 .. 5) {
+ subname "Dynamic $_", $x;
+ ::is($x->(), "Blork::Dynamic $_");
+}
+
+::is($DB::sub{"main::foo"}, $anon);
+
+for (4 .. 5) {
+ ::is($DB::sub{"Blork::Dynamic $_"}, $anon);
+}
+
+for ("Blork:: Bar!", "Foo::Bar::Baz") {
+ ::is($DB::sub{$_}, $anon);
+}
+
+::done_testing;
+# vim: ft=perl