App-GitGot

 view release on metacpan or  search on metacpan

t/00-compile.t  view on Meta::CPAN

use File::Spec;
use IPC::Open3;
use IO::Handle;

open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!";

my @warnings;
for my $lib (@module_files)
{
    # see L<perlfaq8/How can I capture STDERR from an external command?>
    my $stderr = IO::Handle->new;

    diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
            $^X, @switches, '-e', "require q[$lib]"))
        if $ENV{PERL_COMPILE_TEST_DEBUG};

    my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]");
    binmode $stderr, ':crlf' if $^O eq 'MSWin32';
    my @_warnings = <$stderr>;
    waitpid($pid, 0);
    is($?, 0, "$lib loaded ok");

    shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
        and not eval { +require blib; blib->VERSION('1.01') };

    if (@_warnings)
    {
        warn @_warnings;
        push @warnings, @_warnings;

t/00-compile.t  view on Meta::CPAN

{ SKIP: {
    open my $fh, '<', $file or warn("Unable to open $file: $!"), next;
    my $line = <$fh>;

    close $fh and skip("$file isn't perl", 1) unless $line =~ /^#!\s*(?:\S*perl\S*)((?:\s+-\w*)*)(?:\s*#.*)?$/;
    @switches = (@switches, split(' ', $1)) if $1;

    close $fh and skip("$file uses -T; not testable with PERL5LIB", 1)
        if grep { $_ eq '-T' } @switches and $ENV{PERL5LIB};

    my $stderr = IO::Handle->new;

    diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'} . $str . q{'} }
            $^X, @switches, '-c', $file))
        if $ENV{PERL_COMPILE_TEST_DEBUG};

    my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-c', $file);
    binmode $stderr, ':crlf' if $^O eq 'MSWin32';
    my @_warnings = <$stderr>;
    waitpid($pid, 0);
    is($?, 0, "$file compiled ok");

    shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/
        and not eval { +require blib; blib->VERSION('1.01') };

    # in older perls, -c output is simply the file portion of the path being tested
    if (@_warnings = grep { !/\bsyntax OK$/ }
        grep { chomp; $_ ne (File::Spec->splitpath($file))[2] } @_warnings)
    {

t/02-add.t  view on Meta::CPAN

use Class::Load                 qw/ try_load_class /;
use Cwd;
use YAML                        qw/ LoadFile /;

my $dir = Test::BASE::create_tempdir_and_chdir();

{
  my $result = test_app( 'App::GitGot' => [ 'add' ]);

  is   $result->stdout    , ''                              , 'empty STDOUT';
  like $result->stderr    , qr/Non-git repos not supported/ , 'expected error on STDERR';
  is   $result->exit_code , 1                               , 'exit with 1';
}

my $config = "$dir/gitgot";
file_not_exists_ok $config , 'no config';

Test::BASE::build_fake_git_repo();

{
  my $result = test_app( 'App::GitGot' => [ 'add' , '-f' , $config  , '-D' ]);

  like $result->stdout, qr/
        Add \s repository \s at \s '.*?'\? \s+ \(y\/n\) \s \[y\]: \s y \s+
        Name\? \s+ \[foo.git\]: \s+ foo.git \s+
        Tracking \s remote\? \s+  : \s+
        Tags\? \s+  \[\]:
   /x, 'interaction auto-filled';

  my $err = $result->stderr;
  $err =~ s/-\w on unopened filehandle STDOUT.*?\n//g; # test_app mess with STDOUT
  is $err    , '' , 'nothing on stderr';
  is $result->exit_code , 0  , 'exit with 0';

  file_exists_ok $config , 'config exists';

  my $entry = LoadFile( $config );
  is( $entry->[0]{name} , 'foo.git' , 'expected name' );
  is( $entry->[0]{type} , 'git'     , 'expected type' );
  is( $entry->[0]{path} , getcwd()  , 'expected path' );
}

{
  my $result = test_app( 'App::GitGot' => [ 'add' , '-f' , $config  , '-D' ]);

  is   $result->stdout    , '' , 'empty STDOUT';
  like $result->stderr    ,
    qr/Repository at '.+' already registered with Got, skipping/,
    'msg that cannot add same repo twice on STDERR';
  is   $result->exit_code , 0, 'exit with 0';
}

chdir('/'); ## clean up tempfiles

subtest 'recursive behavior' => sub {
 SKIP:
  {

t/03-chdir.t  view on Meta::CPAN


use App::Cmd::Tester;
use App::GitGot;

my( $config , $dir ) = Test::BASE::write_fake_config();

{
  my $result = test_app( 'App::GitGot' => [ 'chdir' , '-f' , $config ]);

  is   $result->stdout    , '' , 'nothing on STDOUT';
  like $result->stderr    ,
    qr/ERROR: You need to select a single repo/ ,
    'need to select a repo';
  is   $result->exit_code , 1  , 'exit with 1';
}

{
  my $result = test_app( 'App::GitGot' => [ 'chdir' , '-f' , $config , 2 ]);

  is   $result->stdout    , ''                          , 'no output';
  like $result->stderr    , qr/Failed to chdir to repo/ , 'msg about non-existant dir';
  is   $result->exit_code , 1                           , 'exit with 1';
}

chdir('/'); ## clean up tempfiles
done_testing();

t/04-clone.t  view on Meta::CPAN

my $dir    = Test::BASE::create_tempdir_and_chdir();
my $config = path( "$dir/gitgot" );
file_not_exists_ok $config , 'config does not exist';

$ENV{GITGOT_FAKE_GIT_WRAPPER} = 1;

{
  my $result = test_app( 'App::GitGot' => [ 'clone' , '-f' , $config ]);

  is   $result->stdout    , '' , 'nothing on STDOUT';
  like $result->stderr    ,
    qr/ERROR: Need the URL to clone/ ,
    'need to give a URL';
  is   $result->exit_code , 1  , 'exit with 1';

  file_not_exists_ok $config , 'failed command does not create config';
}

{
  my $result = test_app( 'App::GitGot' => [ 'clone' , '-f' , $config , '-Dq' ,
                                            'http://genehack.org/fake-git-repo.git' ]);

  is $result->stdout    , '' , 'no output';
  is $result->stderr    , '' , 'nothing on STDERR';
  is $result->exit_code , 0  , 'exit with 0';

  file_exists_ok $config , 'now config exists';

  my $entry = LoadFile( $config );
  is( $entry->[0]{name} , 'fake-git-repo'              , 'expected name' );
  is( $entry->[0]{type} , 'git'                        , 'expected type' );
  is( $entry->[0]{path} , path( "$dir/fake-git-repo" ) , 'expected path' );
}

t/05-fork.t  view on Meta::CPAN

my $dir    = Test::BASE::create_tempdir_and_chdir();
my $config = path( "$dir/gitgot" );
file_not_exists_ok $config , 'config does not exist';

$ENV{HOME} = $dir;

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config ]);

  is   $result->stdout    , '' , 'nothing on STDOUT';
  like $result->stderr    ,
    qr/ERROR: Need the URL of a repo to fork/ ,
    'need to give a URL';
  is   $result->exit_code , 1  , 'exit with 1';

  file_not_exists_ok $config , 'failed command does not create config';
}

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config ,
                                            'http://not.github.org/' ]);
  is   $result->stdout    , '' , 'nothing on STDOUT';
  like $result->stderr    ,
    qr|ERROR: Can't parse 'http://not.github.org/'| ,
      'need repo URL';
  is   $result->exit_code , 1  , 'exit with 1';

  file_not_exists_ok $config , 'failed command does not create config';
}

Test::BASE::create_github_identity_file();

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config , 'http://not.github.org/' ]);

  is $result->stdout , '' , 'nothing on STDOUT';
  like $result->stderr ,
    qr|ERROR: Can't parse 'http://not.github.org| ,
      'need to give a *github* URL';
  is $result->exit_code , 1 , 'exit with 1';

  file_not_exists_ok $config , 'failed command does not create config';
}

{
  my $result = test_app( 'App::GitGot' => [ 'fork' , '-f' , $config , '--noclone' , '-q' ,
                                            'http://github.com/genehack/fake-git-repo.git' ]);

  is $result->stdout    , '' , 'no output';
  is $result->stderr    , '' , 'nothing on STDERR';
  is $result->exit_code , 0  , 'exit with 0';

  file_exists_ok $config , 'now config exists';

  my $entry = LoadFile( $config );
  is( $entry->[0]{name} , 'fake-git-repo'              , 'expected name' );
  is( $entry->[0]{type} , 'git'                        , 'expected type' );
  is( $entry->[0]{path} , path( "$dir/fake-git-repo" ) , 'expected path' );
}

t/06-list.t  view on Meta::CPAN


  like $result->stdout ,
    qr|2\)\s*bargle\.git\s*git\s*github\@github\.com:genehack/bargle\.git\s*\(Not checked out\)| ,
    'second repo';


  like $result->stdout ,
    qr|3\)\s*foo\.git\s*git\s*ERROR: No remote and no repo\?\!| ,
    'second repo';

  is $result->stderr    , '' , 'nothing on STDERR';
  is $result->exit_code , 0  , 'exit with 0';
}

{
  my $result = test_app( 'App::GitGot' => [ 'list' , '-f' , $config , '-q' ]);

  like $result->stdout , qr|1\)\s*bar\.git|    , 'first repo';
  like $result->stdout , qr|2\)\s*bargle\.git| , 'second repo';
  like $result->stdout , qr|3\)\s*foo\.git|    , 'third repo';

  is $result->stderr    , '' , 'nothing on STDERR';
  is $result->exit_code , 0  , 'exit with 0';
}

{
  my $result = test_app( 'App::GitGot' => [ 'list' , '-f' , $config , '-v' ]);

  like $result->stdout ,
    qr|1\)\s*bar\.git\s*git\s*github\@github.com:genehack/bar.git|,
    'first repo';

  like $result->stdout ,
    qr|3\)\s*foo\.git\s*git\s*ERROR: No remote and no repo\?\!| ,
    'third repo';

  is $result->stderr    , '' , 'nothing on STDERR';
  is $result->exit_code , 0  , 'exit with 0';
}

chdir('/'); ## clean up temp files
done_testing();

t/07-remove.t  view on Meta::CPAN

use App::Cmd::Tester;
use App::GitGot;
use YAML              qw/ DumpFile LoadFile /;

my( $config , $dir ) = Test::BASE::write_fake_config();

{
  my $result = test_app( 'App::GitGot' => [ 'remove' , '-f' , $config ]);

  is   $result->stdout    , '' , 'nothing on STDOUT';
  like $result->stderr    ,
    qr/ERROR: You need to select one or more repos to remove/ ,
    'need to give some repos';
  is   $result->exit_code , 1  , 'exit with 1';
}

{
  my $result = test_app( 'App::GitGot' => [ 'remove' , '-f' , $config , 1 , '--force' ]);

  is $result->stdout    , '' , 'nothing on STDOUT';
  is $result->stderr    , '' , 'nothing on STDERR';
  is $result->exit_code , 0  , 'exit with 0';

  my $config   = LoadFile( $config );
  my $expected = [{
    name => 'bargle.git' ,
    path => "$dir/bargle.git" ,
    repo => 'github@github.com:genehack/bargle.git' ,
    type => 'git' ,
  },{
    name => 'foo.git' ,

t/07-remove.t  view on Meta::CPAN

    path => "$dir/xxx.git" ,
    type => 'git'
  }];
  is_deeply( $config , $expected , 'deleted repo' );
}

{
  my $result = test_app( 'App::GitGot' => [ 'remove' , '-f' , $config , 2 , '--force' , '-v' ]);

  like $result->stdout    , qr/^Removed repo 'foo\.git'/ , 'expected on STDOUT';
  is   $result->stderr    , ''                           , 'nothing on STDERR';
  is   $result->exit_code , 0                            , 'exit with 0';

  my $config = LoadFile( $config );
  my $expected = [{
    name => 'bargle.git' ,
    path => "$dir/bargle.git" ,
    repo => 'github@github.com:genehack/bargle.git' ,
    type => 'git' ,
  },{
    name => 'xxx.git' ,

t/08-status.t  view on Meta::CPAN


$ENV{GITGOT_FAKE_GIT_WRAPPER} = 1;

{
  my $result = test_app( 'App::GitGot' => [ 'status' , '-f' , $config , '-C' ]);

  like $result->stdout , qr|1\)\s+bar\.git\s+\:\s+OK| , 'repo 1';
  like $result->stdout , qr|3\)\s+foo\.git\s+\:\s+ERROR: repo 'foo.git' does not exist| , 'repo 3';
  like $result->stdout , qr|4\)\s+xxx\.git\s+\:\s+OK| , 'repo 4';

  is   $result->stderr    , '' , 'nothing on STDERR';
  is   $result->exit_code , 0  , 'exit with 0';
}

{
  my $result = test_app( 'App::GitGot' => [ 'status' , '-f' , $config , '-C' , '-v' ]);

  like $result->stdout , qr|1\)\s+bar\.git\s+\:\s+OK| , 'repo 1';
  like $result->stdout , qr|3\)\s+foo\.git\s+\:\s+ERROR: repo 'foo.git' does not exist| , 'repo 3';
  like $result->stdout , qr|4\)\s+xxx\.git\s+\:\s+OK| , 'repo 4';

  is   $result->stderr    , '' , 'nothing on STDERR';
  is   $result->exit_code , 0  , 'exit with 0';
}

{
  my $result = test_app( 'App::GitGot' => [ 'status' , '-f' , $config , '-C' , '--show-branch' ]);

  like $result->stdout , qr|1\)\s+bar\.git\s+\:\s+OK\s+\[1\]| , 'repo 1';
  like $result->stdout , qr|3\)\s+foo\.git\s+\:\s+ERROR: repo 'foo.git' does not exist| , 'repo 3';
  like $result->stdout , qr|4\)\s+xxx\.git\s+\:\s+OK\s\[1\]| , 'repo 4';

  is   $result->stderr    , '' , 'nothing on STDERR';
  is   $result->exit_code , 0  , 'exit with 0';
}

chdir('/'); ## clean up temp files
done_testing();

t/09-update.t  view on Meta::CPAN


my( $config , $dir ) = Test::BASE::write_fake_config();

$ENV{GITGOT_FAKE_GIT_WRAPPER} = 1;

{
  my $result = test_app( 'App::GitGot' => [ 'update' , '-f' , $config , '-C' ]);

  like $result->stdout    , qr|1\)\s+bar\.git\s+\:\s+Updated| , 'repo 1';
  like $result->stdout    , qr|2\)\s+bargle\.git\s+\:\s+Checked out| , 'repo 2';
  is   $result->stderr    , '' , 'nothing on STDERR';
  is   $result->exit_code , 0  , 'exit with 0';
}

chdir('/'); ## clean up temp files
done_testing();

t/10-gc.t  view on Meta::CPAN


my( $config , $dir ) = Test::BASE::write_fake_config();

$ENV{GITGOT_FAKE_GIT_WRAPPER} = 1;

{
  my $result = test_app( 'App::GitGot' => [ 'gc' , '-f' , $config , '-C' ]);

  like $result->stdout    , qr|1\)\s+bar\.git\s+\:\s+COLLECTED| , 'repo 1';
  like $result->stdout    , qr|2\)\s+bargle\.git\s+\:\s+COLLECTED| , 'repo 2';
  is   $result->stderr    , '' , 'nothing on STDERR';
  is   $result->exit_code , 0  , 'exit with 0';
}

{
  my $result = test_app( 'App::GitGot' => [ 'gc' , '-f' , $config , '-C' , '-q' ]);

  is $result->stdout    , '' , 'nothing on STDOUT';
  is $result->stderr    , '' , 'nothing on STDERR';
  is $result->exit_code , 0  , 'exit with 0';
}

chdir('/'); ## clean up temp files
done_testing();

t/11-push.t  view on Meta::CPAN


my( $config , $dir ) = Test::BASE::write_fake_config();

$ENV{GITGOT_FAKE_GIT_WRAPPER} = 1;

{
  my $result = test_app( 'App::GitGot' => [ 'push' , '-f' , $config , '-C' ]);

  like $result->stdout    , qr|1\)\s+bar\.git\s+\:\s+Nothing to push| , 'repo 1';
  like $result->stdout    , qr|2\)\s+bargle\.git\s+\:\s+Nothing to push| , 'repo 2';
  is   $result->stderr    , '' , 'nothing on STDERR';
  is   $result->exit_code , 0  , 'exit with 0';
}

{
  my $result = test_app( 'App::GitGot' => [ 'push' , '-f' , $config , '-C' , '-q' ]);

  is $result->stdout    , '' , 'nothing on STDOUT';
  is $result->stderr    , '' , 'nothing on STDERR';
  is $result->exit_code , 0  , 'exit with 0';
}

chdir('/'); ## clean up temp files
done_testing();

t/12-fetch.t  view on Meta::CPAN


my( $config , $dir ) = Test::BASE::write_fake_config();

$ENV{GITGOT_FAKE_GIT_WRAPPER} = 1;

{
  my $result = test_app( 'App::GitGot' => [ 'fetch' , '-f' , $config , '-C' ]);

  like $result->stdout    , qr|1\)\s+bar\.git\s+\:\s+Up to date| , 'repo 1';
  like $result->stdout    , qr|2\)\s+bargle\.git\s+\:\s+Checked out| , 'repo 2';
  is   $result->stderr    , '' , 'nothing on STDERR';
  is   $result->exit_code , 0  , 'exit with 0';
}

chdir('/'); ## clean up temp files
done_testing();

t/13-do.t  view on Meta::CPAN

      and diag("App::GitGot add -f $config -D failed: " . $result->error);
    open my $fh, '>', "$repo.txt";
    print $fh "test";
    chdir '..';
}

my $cmd = $^O eq 'MSWin32' ? 'dir' : 'ls';

@ARGV = ( qw/ do -f /, $config, '--command' , $cmd , '--all' );

my( $stdout, $stderr, $exit ) = capture {
    App::GitGot->run;
};

like $stdout  , qr/##.*alpha.*alpha\.txt/s, 'alpha is listed';
like $stdout  , qr/##.*beta.*beta\.txt/s, 'beta is listed';
is $stderr    , '' , 'nothing on stderr';

@ARGV = ( qw/ do -f /, $config, '--with_repo' , '--command' , $cmd , '--all' );

( $stdout, $stderr, $exit ) = capture {
    App::GitGot->run;
};

like $stdout  , qr/alpha: .*alpha\.txt/, 'output preprended with repo name';


chdir('/'); ## clean up temp files
done_testing();

t/16-checkout.t  view on Meta::CPAN


my( $config , $dir ) = Test::BASE::write_fake_config();

$ENV{GITGOT_FAKE_GIT_WRAPPER} = 1;

{
  my $result = test_app( 'App::GitGot' => [ 'checkout' , '-f' , $config , '-C', '--branch', 'master' ]);

  like $result->stdout    , qr|1\)\s+bar\.git\s+\:\s+OK| , 'repo 1';
  like $result->stdout    , qr|2\)\s+bargle\.git\s+\:\s+OK| , 'repo 2';
  is   $result->stderr    , '' , 'nothing on STDERR';
  is   $result->exit_code , 0  , 'exit with 0';
}

chdir('/'); ## clean up temp files
done_testing();



( run in 0.610 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )