Skip to content

Commit

Permalink
initial split into t/funcs.pm
Browse files Browse the repository at this point in the history
  • Loading branch information
rsrchboy committed Feb 3, 2012
1 parent 49b5bad commit 1ba71cb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 47 deletions.
51 changes: 51 additions & 0 deletions t/funcs.pm
@@ -0,0 +1,51 @@
use strict;
use warnings;

use autodie 'system';
use IPC::System::Simple (); # for autodie && prereqs

use File::chdir;
use Path::Class;

sub make_test_repo {
my @commands = @_;

my $tempdir = tempdir;
my $repo_root = dir($tempdir)->absolute;
note "Repo being created at $repo_root";
local $CWD = "$repo_root";

unshift @commands, 'git init'
unless $commands[0] =~ /git init/;

system "($_) 2> /dev/null > /dev/null" for @commands;

return $repo_root;
}

sub _ack {
my ($fn, $text) = @_;
$text ||= 'whee';

return (
qq{echo "$text" >> $fn},
qq{git add $fn && git commit -m "ack"},
);
}

# blatantly stolen from Dist-Zilla-Plugin-CheckPrereqsIndexed-0.008/t/basic.t
# Write the log messages as diagnostics:
sub diag_log
{
my $tzil = shift;

# Output nothing if all tests passed:
my $all_passed = shift;
$all_passed &&= $_ for @_;

return if $all_passed;

diag(map { "$_\n" } @{ $tzil->log_messages });
}

!!42;
49 changes: 2 additions & 47 deletions t/plugin/correct_branch.t
@@ -1,17 +1,13 @@
use strict;
use warnings;

use autodie 'system';
use IPC::System::Simple (); # for autodie && prereqs

use File::chdir;
use Path::Class;

use Test::More;
use Test::Fatal;
use Test::Moose::More 0.004;
use Test::TempDir;

require 't/funcs.pm' unless eval { require funcs };

use Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch;

my $THING = 'Dist::Zilla::Plugin::Git::CheckFor::CorrectBranch';
Expand All @@ -29,47 +25,6 @@ validate_class $THING => (

use Test::DZil;

sub make_test_repo {
my @commands = @_;

my $tempdir = tempdir;
my $repo_root = dir($tempdir)->absolute;
note "Repo being created at $repo_root";
local $CWD = "$repo_root";

unshift @commands, 'git init'
unless $commands[0] =~ /git init/;

system "($_) 2> /dev/null > /dev/null" for @commands;

return $repo_root;
}

sub _ack {
my ($fn, $text) = @_;
$text ||= 'whee';

return (
qq{echo "$text" >> $fn},
qq{git add $fn && git commit -m "ack"},
);
}

# blatantly stolen from Dist-Zilla-Plugin-CheckPrereqsIndexed-0.008/t/basic.t
# Write the log messages as diagnostics:
sub diag_log
{
my $tzil = shift;

# Output nothing if all tests passed:
my $all_passed = shift;
$all_passed &&= $_ for @_;

return if $all_passed;

diag(map { "$_\n" } @{ $tzil->log_messages });
}

subtest 'simple repo, on wrong, divergent branch' => sub {

# make some basic commits, branch...
Expand Down

0 comments on commit 1ba71cb

Please sign in to comment.