App-git-ship

 view release on metacpan or  search on metacpan

t/Util.pm  view on Meta::CPAN


  diag "Workdir is $base/$workdir";
}

sub test_file {
  my ($class, $file, @rules) = @_;
  my ($FH, $txt);

  unless (open $FH, '<', $file) {
    ok 0, "The file $file is missing";
    return;
  }

  $txt = do { local $/; <$FH>; };
  for my $rule (@rules) {
    like $txt, $rule, "File $file match $rule";
  }
}

sub test_file_lines {
  my ($class, $file) = (shift, shift);
  my ($FH, @extra, @re);
  my %lines = map { $_ => 1 } grep { ref $_ ? (push @re, $_)[2] : $_ } @_;

  unless (open $FH, '<', $file) {
    ok 0, "The file $file is missing";
    return;
  }

LINE:
  while (<$FH>) {
    chomp;
    for my $re (@re) { next LINE if $_ =~ $re; }
    delete $lines{$_} or push @extra, $_;
  }

  is_deeply \@extra, [], "The file $file has no extra lines" or diag join ', ', @extra;
  is_deeply [keys %lines], [], "The file $file has no missing lines"
    or diag join ', ', sort keys %lines;
}

sub test_git {
  my ($class, $git) = @_;
  my $output;

  $output = qx{$git --version 2>/dev/null};
  $output =~ s![\n\r]!!g;
  plan skip_all => "Invalid git: $output" unless $output =~ qr{\b\s+version\s+\d};
  plan skip_all => "Unsupported git version: $output" if $output =~ qr{\s1\.4};
  diag "git --version: $output" unless $output =~ /\b(1\.9|2\.[0123])/;
  $output = qx{git config --global --get-regexp user.* 2>/dev/null};
  $output =~ s![\n\r]!!g;
  plan skip_all => "Cannot run with unknown git user: $output"
    unless $output =~ /user\.email/ and $output =~ /user\.name/;
}

sub import {
  my $class  = shift;
  my $caller = caller;

  strict->import;
  warnings->import;
  eval "package $caller; use Test::More;1" or die $@;
}

1;



( run in 1.677 second using v1.01-cache-2.11-cpan-e93a5daba3e )