Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 82 lines (61 sloc) 1.794 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
use strict;
use warnings;

use lib 't';
use MyTestHelper;

use Test::More;

use File::Temp ();
use Cwd qw/getcwd/;

my $log = '';
open my $log_handle, '>', \$log;
{
  package MyTestClass;
  use Moo;
  with 'Moodule::Build::Role::DistInfo';
  sub log_warn { shift; print $log_handle @_ }
}

my $old = getcwd;

subtest 'get module_name from dist_name' => sub {
  my $dir = File::Temp->newdir;
  chdir $dir or die "Cannot chdir to $dir\n";

  make_file( qw/lib Not So Simple.pm/, 'Testing' );

  my $mb = MyTestClass->new(
    dist_name => 'Not-So-Simple',
    dist_version => 1,
  );

  is( $mb->module_name, "Not::So::Simple",
    "module_name guessed from dist_name"
  );

  chdir $old;
};

subtest 'cannot determine module_name' => sub {
  my $mb = MyTestClass->new( dist_name => 'Foo-Bar' );
  $mb->module_name;
  ok $log, 'warn on undetermined module_name';
};

subtest 'get module_name from dist_version_from' => sub {
  my $dir = File::Temp->newdir;
  chdir $dir or die "Cannot chdir to $dir\n";

  make_file( qw/lib Simple Name.pm/, <<'END_PACKAGE' );
package Simple::Name;
our $VERSION = 1.23;
1;
END_PACKAGE

  my $mb = MyTestClass->new(
    dist_name => 'Random-Name',
    dist_version_from => 'lib/Simple/Name.pm',
  );

  is( $mb->module_name, "Simple::Name",
    "module_name guessed from dist_version_from"
  );

  chdir $old;
};

subtest 'get dist_name from module_name' => sub {
  my $mb = MyTestClass->new( module_name => 'My::Dist' );
  is $mb->dist_name, 'My-Dist', 'dist_name from module_name';
};

subtest 'Constructor without either name' => sub {
  my $builder = MyTestClass->new;
  my $message = eval{ $builder->dist_name } ? 'Did not fail' : $@;
  like $message, qr/Can't determine distribution name/, 'dies without either dist_name or module_name';
};

done_testing;

Something went wrong with that request. Please try again.