Archive-Ar-Libarchive

 view release on metacpan or  search on metacpan

t/write.t  view on Meta::CPAN

subtest 'write string' => sub {
  plan tests => 2;

  my $content = before()->write;

  note "size = " . length $content;
  ok defined $content, 'write';


  my $ar = Archive::Ar::Libarchive->new;
  $ar->read_memory($content);

  check_content($ar);
};

subtest 'write bsd' => sub {
  plan tests => 2;

  my $ar = before();
  #$ar->set_output_format_bsd;
  $ar->set_opt(type => BSD);
  my $fn = File::Spec->catfile($dir, "libfoo.a");

  my $size = $ar->write($fn);
  note "size = $size";
  ok $size, 'write';

  undef $ar;

  check_content(Archive::Ar::Libarchive->new($fn));
};

subtest 'write svr4' => sub {
  plan tests => 2;

  my $ar = before();
  #$ar->set_output_format_svr4;
  $ar->set_opt(type => COMMON);
  my $fn = File::Spec->catfile($dir, "libfoo.a");

  my $size = $ar->write($fn);
  note "size = $size";
  ok $size, 'write';

  undef $ar;

  check_content(Archive::Ar::Libarchive->new($fn));
};

sub before
{
  my $ar = Archive::Ar::Libarchive->new;
  $ar->add_data("foo.txt", "foo content", {
    uid  => 101,
    gid  => 202,
    date => 12345679,
    mode => 0100640,
  });
  $ar->add_data("bar.txt", "bar content\nbar content\n", {
    uid  => 303,
    gid  => 404,
    date => 123456798,
    mode => 0100600,
  });
  $ar;
}

sub check_content
{
  my $ar = shift;

  subtest 'content' => sub {
    plan tests => 3;
    is_deeply scalar $ar->list_files, [qw( foo.txt bar.txt )], 'contains files foo and bar';
    is_deeply $ar->get_content('foo.txt'), { name => 'foo.txt', date => 12345679, uid => 101, gid => 202, mode => 0100640, data => "foo content", size => 11 }, "foo content";
    is_deeply $ar->get_content('bar.txt'), { name => 'bar.txt', date => 123456798, uid => 303, gid => 404, mode => 0100600, data => "bar content\nbar content\n", size => 24 }, "bar content";
  };
}



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