Alien-Base-ModuleBuild

 view release on metacpan or  search on metacpan

t/alien_base_modulebuild.t  view on Meta::CPAN

subtest 'interpolation of version' => sub {

  my $builder = builder();

  subtest 'prior to loading version information' => sub {

    my $warn_count = warns {
      is  ( $builder->alien_interpolate('version=%v'), 'version=%v', 'version prior to setting it' );
    };
    is $warn_count, 1, 'version warning';
  };

  subtest 'after loading the version information' => sub {

    my $warn_count = warns {

      my $current_version = $builder->config_data( 'alien_version' ) ;
      my $test_version = time;
      $builder->config_data( 'alien_version', $test_version );
      is( $builder->alien_interpolate('version=%v'), "version=$test_version", 'version after setting it' );
    };

    is $warn_count, 0, 'no warnings';

  };

};


subtest 'interpolation of helpers' => sub {

  my $mock = mock 'Alien::foopatcher' => (
    add => [
      new          => sub { bless 'Alien::foopatcher', {} },
      alien_helper => sub {
        return {
          patch1 => 'join " ", qw(patch1 --binary)',
          patch2 => sub { 'patch2 --binary' },
          double => sub { 2 },
          argument_count2 => sub { scalar @_ },
        },
      }
    ],
  );

  my $builder = builder(
    alien_helper => {
      foo => ' "bar" . "baz" ',
      exception => ' die "abcd" ',
      double => '"1";',
      argument_count1 => 'scalar @_',
    },
    alien_bin_requires => {
      'Alien::foopatcher' => 0,
    },
  );

  is( $builder->alien_interpolate("|%{foo}|"), "|barbaz|", "helper" );
  is( $builder->alien_interpolate("|%{foo}|%{foo}|"), "|barbaz|barbaz|", "helper x 2" );
  eval { $builder->alien_interpolate("%{exception}") };
  like $@, qr{abcd}, "exception gets thrown";

  $builder->_alien_bin_require('Alien::foopatcher');
  is( $builder->alien_interpolate("|%{patch1}|"), "|patch1 --binary|", "helper from independent Alien module");
  is( $builder->alien_interpolate("|%{patch2}|"), "|patch2 --binary|", "helper from independent Alien module with code ref");

  eval { $builder->alien_interpolate("%{bogus}") };
  like $@, qr{no such helper: bogus}, "exception thrown with bogus helper";

  is( $builder->alien_interpolate('%{double}'), "1", "MB helper overrides AB helper");

  is( $builder->alien_interpolate('%{argument_count1}'), "0", "argument count is zero (string helper)");
  is( $builder->alien_interpolate('%{argument_count2}'), "0", "argument count is zero (code helper)");

  is( $builder->alien_interpolate('%{pkg_config}'), Alien::Base::PkgConfig->pkg_config_command, "support for %{pkg_config}");
};

subtest 'find lib' => sub {

  my $expected = {
    lib       => [ 'lib' ],
    inc       => [ 'include' ],
    lib_files => [ 'mylib' ],
  };

  my $builder = builder();

  $builder->config( so => 'so' );
  $builder->config( ext_lib => '.a' );

  subtest 'dynamic' => sub {

    my $dir = $abmb_root->child('corpus/alien_base_modulebuild__find_lib/dynamic')->stringify;

    subtest 'Find from file structure' => sub {
      local $expected->{lib_files} = [sort qw/mylib onlypostdot onlypredot otherlib prepostdot/];
      my $paths = $builder->alien_find_lib_paths($dir);
      is( $paths, $expected, "found paths from extensions only" );

      my $pc = $builder->alien_generate_manual_pkgconfig($dir);
      isa_ok($pc, 'Alien::Base::PkgConfig');

      my $libs = $pc->keyword('Libs');
      note "libs = $libs";

      like( $libs, qr/-lmylib/, "->keyword('Libs') returns mylib" );

      my ($L) = $libs =~ /-L(\S*)/g;
      ok( -d $L,  "->keyword('Libs') finds mylib directory");
      opendir(my $dh, $L);
      my @files = grep { /mylib/ } readdir $dh;
      ok( @files, "->keyword('Libs') finds mylib" );
    };

    subtest 'Find using alien_provides_libs' => sub {
      $builder->alien_provides_libs('-lmylib');
      my $paths = $builder->alien_find_lib_paths($dir);
      is( $paths, $expected, "found paths from provides" );

      my $pc = $builder->alien_generate_manual_pkgconfig($dir);
      isa_ok($pc, 'Alien::Base::PkgConfig');

      my $libs = $pc->keyword('Libs');
      note "libs = $libs";

      like( $libs, qr/-lmylib/, "->keyword('Libs') returns mylib" );

      my ($L) = $libs =~ /-L(\S*)/g;



( run in 1.068 second using v1.01-cache-2.11-cpan-d7f47b0818f )