Alien-Base-ModuleBuild

 view release on metacpan or  search on metacpan

t/alien_base_modulebuild.t  view on Meta::CPAN

    alien_helper => {
      myhelper => '"my helper text"',
    },
    alien_env => {
      FOO => 'foo1',
      BAR => '%{myhelper}',
      BAZ => undef,
    },
    alien_build_commands => [],
  );

  isa_ok $builder, 'Alien::Base::ModuleBuild';
  my($out, $err, %status) = capture { $builder->alien_do_system([$^X, -e => 'print $ENV{FOO}']) };
  is $status{stdout}, 'foo1', 'env FOO passed to process';
  ($out, $err, %status) = capture { $builder->alien_do_system([$^X, -e => 'print $ENV{BAR}']) };
  is $status{stdout}, 'my helper text', 'alien_env works with helpers';
  ($out, $err, %status) = capture { $builder->alien_do_system([$^X, -e => 'print $ENV{BAZ}||"undef"']) };
  is $status{stdout}, 'undef', 'alien_env works with helpers';
};

subtest 'cmake' => sub {

  subtest 'default' => sub {

    local $CWD = _new_temp();

    my $builder = builder(
      alien_bin_requires => { 'Alien::CMake' => 0 },
      alien_build_commands => [],
    );

    isa_ok $builder, 'Alien::Base::ModuleBuild';
    is $builder->build_requires->{"Alien::CMake"}, '0.07', 'require at least 0.07';
  };

  subtest 'more recent' => sub {

    local $CWD = _new_temp();

    my $builder = builder(
      alien_bin_requires => { 'Alien::CMake' => '0.10' },
      alien_build_commands => [],
    );

    isa_ok $builder, 'Alien::Base::ModuleBuild';
    is $builder->build_requires->{"Alien::CMake"}, '0.10', 'keep 0.10';
  };

};

subtest 'install location' => sub {

  local $CWD = _new_temp();

  my $builder = builder();
  my $path = $builder->alien_library_destination;

  # this is not good enough, I really wish I could introspect File::ShareDir, then again, I wouldn't need this test!
  my $path_to_share = "auto/share/dist/My-Test";
  $path_to_share =~ s{\\}{/}g if $^O eq 'MSWin32';
  like $path, qr/\Q$path_to_share\E/, 'path looks good';
};

subtest 'validation' => sub {

  local $CWD = _new_temp();

  my $builder = builder(
    module_name  => 'My::Test::Module',
    dist_version => '1.234.567',
  );

  ok( $builder->alien_validate_repo( {platform => undef} ), "undef validates to true");

  subtest 'windows test' => sub {
    skip_all "Windows test" unless $builder->is_windowsish();
    ok( $builder->alien_validate_repo( {platform => 'Windows'} ), "platform Windows on Windows");
    ok( ! $builder->alien_validate_repo( {platform => 'Unix'} ), "platform Unix on Windows is false");
  };

  subtest 'unix test' => sub {
    skip_all "Unix test" unless $builder->is_unixish();
    ok( $builder->alien_validate_repo( {platform => 'Unix'} ), "platform Unix on Unix");
    ok( ! $builder->alien_validate_repo( {platform => 'Windows'} ), "platform Windows on Unix is false");
  };

  subtest 'need c compiler' => sub {
    skip_all "Needs c compiler" unless $builder->have_c_compiler();
    ok( $builder->alien_validate_repo( {platform => 'src'} ), "platform src");
  };
};

subtest 'basic interpolation' => sub {

  my $builder = builder();

  is( $builder->alien_interpolate('%phello'), $builder->alien_exec_prefix . 'hello', 'prefix interpolation');
  is( $builder->alien_interpolate('%%phello'), '%phello', 'no prefix interpolation with escape');

  my $path = $builder->alien_library_destination;
  is( $builder->alien_interpolate('thing other=%s'), "thing other=$path", 'share_dir interpolation');
  is( $builder->alien_interpolate('thing other=%%s'), 'thing other=%s', 'no share_dir interpolation with escape');

  my $perl = $builder->perl;
  is( $builder->alien_interpolate('%x'), $perl, '%x is current interpreter' );
  unlike( $builder->alien_interpolate('%X'), qr{\\}, 'no backslash in %X' );
};

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 {



( run in 0.430 second using v1.01-cache-2.11-cpan-fa01517f264 )