Dist-Zilla-PluginBundle-Author-ETHER

 view release on metacpan or  search on metacpan

t/lib/Helper.pm  view on Meta::CPAN

            ) if $prereq_plugin_phase and $prereq_plugin_relationship;

            if (exists $additional{$plugin}) {
                # plugin was added in via an extra option, therefore the
                # plugin should exist as a recommendation of the bundle (as some tests require it)
                cmp_deeply(
                    $pluginbundle_meta->{prereqs}{runtime}{recommends},
                    superhashof({ $plugin => $required_version }),
                    $plugin . ' is a runtime recommendation of this plugin bundle',
                ) if $pluginbundle_meta;
            }
            else {
                # plugin is a core requirement of the bundle
                cmp_deeply(
                    $pluginbundle_meta->{prereqs}{runtime}{requires},
                    superhashof({ $plugin => $required_version }),
                    $plugin . ' is a runtime prereq of this plugin bundle',
                ) if $pluginbundle_meta;
            }
        }

        pass 'this is a token test to keep things humming' if not $pluginbundle_meta;

        if (not Test::Builder->new->is_passing) {
            diag 'got distribution metadata: ', explain $dist_meta;
            diag 'got plugin bundle metadata: ', explain $pluginbundle_meta;
        }
    }
} }

# provides a temp directory that is guaranteed to not be inside a git repository
# directory is cleaned up when $tempdir goes out of scope
sub no_git_tempdir {
    my $tempdir = Path::Tiny->tempdir(CLEANUP => 1);
    mkdir $tempdir if not -d $tempdir;    # FIXME: File::Temp::newdir doesn't make the directory?!

    my $in_git = git_in_path($tempdir);
    ok(!$in_git, 'tempdir is not in a real git repository');

    return $tempdir;
}

# checks if a .git directory is in the current or any parent directory
sub git_in_path {
    my $in_git;
    my $dir = path($_[0]);
    my $count = 0;
    while (not $dir->is_rootdir) {
        # this should never happen.
        do { diag "failed to detect that $dir is at the root?!"; last } if $dir eq $dir->parent;

        my $checkdir = path($dir, '.git');
        if (-d $checkdir) {
            note "found $checkdir in $_[0]";
            $in_git = 1;
            last;
        }
        $dir = $dir->parent;
    }
    continue {
        die "too many iterations when traversing $dir!"
            if $count++ > 100;
    }
    return $in_git;
}

# TODO: replace with Test::Deep::notexists($key)
sub notexists {
    my @keys = @_;
    Test::Deep::code(sub {
        # TODO return 0 unless $self->test_reftype($_[0], 'HASH');
        return (0, 'not a HASH') if ref $_[0] ne 'HASH';
        foreach my $key (@keys) {
            return (0, "'$key' key exists") if exists $_[0]->{$key};
        }
        return 1;
    });
}

# simple Path::Tiny helper: like `find $dir -type f`
sub recursive_child_files {
    my $dir = shift;
    my @found_files;
    $dir->visit(
        sub { push @found_files, $_->relative($dir)->stringify if -f },
        { recurse => 1 },
    );
    @found_files;
}

1;



( run in 0.687 second using v1.01-cache-2.11-cpan-71847e10f99 )