Alien-Build

 view release on metacpan or  search on metacpan

t/alien_build_plugin_extract_archivetar.t  view on Meta::CPAN

          unless eval { require Alien::Build::Plugin::Extract::ArchiveTar; Alien::Build::Plugin::Extract::ArchiveTar->_can_bz2 };
      }
      elsif($ext eq 'tar.gz')
      {
        skip_all 'Test requires Bzip2 support in Archive::Tar'
          unless eval { Archive::Tar->has_bzip2_support };
      }
      elsif($ext eq 'tar.xz')
      {
        skip_all 'Test requires XZ support in Archive::Tar'
          unless eval { Archive::Tar->has_xz_support };
      }

      my $archive = path("corpus/dist/foo-1.00.$ext")->absolute;

      my($out, $dir, $error) = capture_merged {
        local $build->install_prop->{download_detail}->{"$archive"} = {
          protocol => 'file',
          digest => [ FAKE => 'deadbeaf' ],
        };
        my $dir = eval { $build->extract("$archive") };
        ($dir, $@);
      };

      my($bad1, $bad2);

      $bad1 = !!$error;
      is $error, '';

      note $out if $out ne '';

      if(defined $dir)
      {
        $dir = path($dir);

        $bad2 = !ok( defined $dir && -d $dir, "directory created"   );
        note "dir = $dir";

        foreach my $name (qw( configure foo.c ))
        {
          my $file = $dir->child($name);
          ok -f $file, "$name exists";
        }
      }

      if($bad1 || $bad2)
      {
        diag "failed with extension $ext";
        diag _dump({ error => $error, dir => "$dir" });
        if($out ne '')
        {
          diag "[out]";
          diag $out;
        }
      }
    }
  }

};

subtest 'archive with pax_global_header' => sub {

  skip_all 'Test requires Archive::Tar'
    unless eval { require Archive::Tar };

  my $build = alienfile_ok q{
    use alienfile;
    use Path::Tiny qw( path );
    plugin 'Test::Mock',
      probe    => 'share',
      download => {
        'foo.tar' => path(__FILE__)->parent->parent->child('corpus/dist2/foo.tar')->slurp_raw,
      };
    share {
      plugin 'Extract::ArchiveTar';
    };

  };

  my $dir = alien_extract_ok;

  if(defined $dir)
  {
    my $file = path($dir)->child('foo.txt');
    my $content = eval { $file->slurp };
    is($content, "xx\n", "file content matches");

    unless(-f $file)
    {
      diag "listing:";
      foreach my $child (path($dir)->children)
      {
        diag $child;
      }
    }

  }

};

done_testing;



( run in 1.343 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )