Dist-Zilla

 view release on metacpan or  search on metacpan

t/plugins/uploadtocpan.t  view on Meta::CPAN

# config from %PAUSE stash in dist.ini:
{
  my $tzil = build_tzil(
    [ UploadToCPAN => { %safety_first } ],
    'FakeRelease',
    [ '%PAUSE' => {qw(
      username  user
      password  password
    )}],
  );

  $tzil->release;

  my $msgs = $tzil->log_messages;

  ok(grep({ /PAUSE user is user/ } @$msgs), "read username");
  ok(grep({ /PAUSE password is password/ } @$msgs), "read password");
  ok(grep({ /Uploading.*DZT-Sample/ } @$msgs), "uploaded archive");
  ok(
    grep({ /fake release happen/i } @$msgs),
    "releasing continues after upload",
  );
}

#---------------------------------------------------------------------
# Config from user input:
{
  my $tzil = build_tzil(
    [ UploadToCPAN => { %safety_first } ],
    'FakeRelease',
  );

  set_responses($tzil, qw(user password));

  $tzil->release;

  my $msgs = $tzil->log_messages;

  ok(grep({ /PAUSE user is user/ } @$msgs), "entered username");
  ok(grep({ /PAUSE password is password/ } @$msgs), "entered password");
  ok(grep({ /Uploading.*DZT-Sample/ } @$msgs), "uploaded archive manually");
  ok(
    grep({ /fake release happen/i } @$msgs),
    "releasing continues after manual upload",
  );
}

#---------------------------------------------------------------------
# No config at all:
{
  my $tzil = build_tzil(
    'FakeRelease',
    [ UploadToCPAN => { %safety_first } ],
  );

  # Pretend user just hits Enter at the prompts:
  set_responses($tzil, '', '');

  like( exception { $tzil->release },
        qr/No username was provided/,
        "release without credentials fails");

  my $msgs = $tzil->log_messages;

  ok(grep({ /No username was provided/} @$msgs), "insist on username");
  ok(!grep({ /Uploading.*DZT-Sample/ } @$msgs), "no upload without credentials");
  ok(
    !grep({ /fake release happen/i } @$msgs),
    "no release without credentials"
  );
}

#---------------------------------------------------------------------
# No config at all, but enter username:
{
  my $tzil = build_tzil(
    'FakeRelease',
    [ UploadToCPAN => { %safety_first } ],
  );

  # Pretend user just hits Enter at the password prompt:
  set_responses($tzil, 'user', '');

  like( exception { $tzil->release },
        qr/No password was provided/,
        "release without password fails");

  my $msgs = $tzil->log_messages;

  ok(grep({ /No password was provided/} @$msgs), "insist on password");
  ok(!grep({ /Uploading.*DZT-Sample/ } @$msgs), "no upload without password");
  ok(
    !grep({ /fake release happen/i } @$msgs),
    "no release without password"
  );
}

# Config from dist.ini
{
  my $tzil = build_tzil(
    'FakeRelease',
    [ UploadToCPAN => {
        %safety_first,
        username => 'me',
        password => 'ohhai',
      }
    ],
  );

  like( exception { $tzil->release },
        qr/Couldn't figure out password/,
        "password set in dist.ini is ignored");
}



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