Alien-Build

 view release on metacpan or  search on metacpan

t/alien_build.t  view on Meta::CPAN

      $tarpath->slurp_raw,
      'file matches',
    );
  };

  subtest 'component' => sub {

    foreach my $file_as (qw( content path ))
    {

      subtest "single download with file as $file_as" => sub {

        my($build, $meta) = $build->(
          url            => 'https://test1.test/foo/bar/baz/foo-1.00.tar.gz',
          return_file_as => $file_as,
        );

        $check->($build);

      };
    }

    foreach my $listing_as (qw( list html dir_listing ))
    {

      subtest "listing download with listing as $listing_as" => sub {

        my($build, $meta) = $build->(
          url               => 'https://test1.test/foo/bar/baz/',
          return_listing_as => $listing_as,
        );

        $check->($build);

      };

    }

  };

  subtest 'command single' => sub {

    # This test uses a fake wget, and doesn't connect to the internet
    local $ENV{ALIEN_DOWNLOAD_RULE} = 'warn';

    my $guard = system_fake
      wget => sub {
        my($url) = @_;

        # just pretend that we have some hidden files
        path('.foo')->touch;

        if($url eq 'https://test1.test/foo/bar/baz/foo-1.00.tar.gz')
        {
          print "200 found $url!\n";
          path('foo-1.00.tar.gz')->spew_raw($tarpath->slurp_raw);
          return 0;
        }
        else
        {
          print "404 not found $url\n";
          return 2;
        }
      };

    my $build = alienfile filename => 'corpus/blank/alienfile';
    my $meta = $build->meta;

    $meta->register_hook(
      download => [ "wget https://test1.test/foo/bar/baz/foo-1.00.tar.gz" ],
    );

    $check->($build);

  };

  subtest 'command no file' => sub {

    my $guard = system_fake
      true => sub {
        0;
      };

    my $build = alienfile filename => 'corpus/blank/alienfile';
    my $meta = $build->meta;

    $meta->register_hook(
      download => [ 'true' ],
    );

    my($out, $error) = capture_merged { eval { $build->download }; $@ };
    note $out;
    like $error, qr/no files downloaded/, 'diagnostic failure';

  };

  subtest 'command multiple files' => sub {

    my $guard = system_fake
      explode => sub {
        path($_)->touch for map { "$_.txt" } qw( foo bar baz );
        0;
      };

    my $build = alienfile filename => 'corpus/blank/alienfile';
    my $meta = $build->meta;

    $meta->register_hook(
      download => ['explode'],
    );

    note scalar capture_merged { $build->download };

    is(
      $build->install_prop,
      hash {
        field download => T();
        field complete => hash {
          field download => T();
          etc;
        };



( run in 2.314 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )