Module-Build

 view release on metacpan or  search on metacpan

t/extend.t  view on Meta::CPAN

  @ISA = qw(Module::Build);
  $VERSION = 0.01;

  # Add a new property.
  ok(__PACKAGE__->add_property('foo'));
  # Add a new property with a default value.
  ok(__PACKAGE__->add_property('bar', 'hey'));
  # Add a hash property.
  ok(__PACKAGE__->add_property('hash', {}));


  # Catch an exception adding an existing property.
  eval { __PACKAGE__->add_property('module_name')};
  like "$@", qr/already exists/;
}

{
  package MBSub2;
  use Test::More;
  use vars qw($VERSION @ISA);
  @ISA = qw(Module::Build);
  $VERSION = 0.01;

  # Add a new property with a different default value than MBSub has.
  ok(__PACKAGE__->add_property('bar', 'yow'));
}


{
  ok my $mb = MBSub->new( module_name => $dist->name );
  isa_ok $mb, 'Module::Build';
  isa_ok $mb, 'MBSub';
  ok $mb->valid_property('foo');
  can_ok $mb, 'module_name';

  # Check foo property.
  can_ok $mb, 'foo';
  ok ! $mb->foo;
  ok $mb->foo(1);
  ok $mb->foo;

  # Check bar property.
  can_ok $mb, 'bar';
  is $mb->bar, 'hey';
  ok $mb->bar('you');
  is $mb->bar, 'you';

  # Check hash property.
  ok $mb = MBSub->new(
		       module_name => $dist->name,
		       hash        => { foo => 'bar', bin => 'foo'}
		     );

  can_ok $mb, 'hash';
  isa_ok $mb->hash, 'HASH';
  is $mb->hash->{foo}, 'bar';
  is $mb->hash->{bin}, 'foo';

  # Check hash property passed via the command-line.
  {
    local @ARGV = (
		   '--hash', 'foo=bar',
		   '--hash', 'bin=foo',
		  );
    ok $mb = MBSub->new( module_name => $dist->name );
  }

  can_ok $mb, 'hash';
  isa_ok $mb->hash, 'HASH';
  is $mb->hash->{foo}, 'bar';
  is $mb->hash->{bin}, 'foo';

  # Make sure that a different subclass with the same named property has a
  # different default.
  ok $mb = MBSub2->new( module_name => $dist->name );
  isa_ok $mb, 'Module::Build';
  isa_ok $mb, 'MBSub2';
  ok $mb->valid_property('bar');
  can_ok $mb, 'bar';
  is $mb->bar, 'yow';
}

SKIP: {
  skip 'Need CPAN::Meta 2.142060 for Meta support', 4 if not eval { require CPAN::Meta; CPAN::Meta->VERSION(2.142060) };
  # Test the meta_add and meta_merge stuff
  ok my $mb = Module::Build->new(
				  module_name => $dist->name,
				  license => 'perl',
				  meta_add => {keywords => ['bar']},
				  conflicts => {'Foo::Barxx' => 0},
			        );
  my $data = $mb->get_metadata;
  is_deeply $data->{keywords}, ['bar'];

  $mb->meta_merge(keywords => ['baz']);
  $data = $mb->get_metadata;
  is_deeply $data->{keywords}, [qw/bar baz/];

  $mb->meta_merge(
    'meta-spec' => { version => 2 },
    prereqs => {
      test => {
        requires => {
          'Foo::Fooxx' => 0,
        }
      }
    }
  );
  $data = $mb->get_metadata;
  is_deeply $data->{prereqs}{test}{requires}, { 'Foo::Fooxx' => 0 } or diag explain $mb->meta_merge;

}

{
  # Test interactive prompting

  my $ans;
  local $ENV{PERL_MM_USE_DEFAULT};

  local $^W = 0;
  local *{Module::Build::_readline} = sub { 'y' };



( run in 1.424 second using v1.01-cache-2.11-cpan-39bf76dae61 )