File: confirmrelease.t

package info (click to toggle)
libdist-zilla-perl 4.300020-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,144 kB
  • sloc: perl: 6,159; makefile: 9
file content (105 lines) | stat: -rw-r--r-- 2,085 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
use strict;
use warnings;
use Test::More 0.88;
use Test::Fatal;

use lib 't/lib';

use Test::DZil;

sub new_tzil {
  my $tzil = Builder->from_config(
    { dist_root => 'corpus/dist/DZT' },
    {
      add_files => {
        'source/dist.ini' =>
          simple_ini(qw(GatherDir ConfirmRelease FakeRelease)),
      },
    },
  );
}

sub release_happened {
  scalar grep({/Fake release happening/i} @{ shift->log_messages }),;
}

my $release_aborted = qr/aborting release/i;

{
  my $tzil = new_tzil;

  like(
    exception { $tzil->release },
    $release_aborted,
    "ConfirmRelease aborts by default",
  );

  ok(!release_happened($tzil), "release did not happen by default");
}

for my $no (qw(n no)) {
  local $ENV{DZIL_CONFIRMRELEASE_DEFAULT} = $no;

  my $tzil = new_tzil;

  like(
    exception { $tzil->release },
    $release_aborted,
    "ConfirmRelease aborts when DZIL_CONFIRMRELEASE_DEFAULT=$no",
  );

  ok(
    !release_happened($tzil),
    "release did not happen when DZIL_CONFIRMRELEASE_DEFAULT=$no",
  );
}

for my $yes (qw(y yes)) {
  local $ENV{DZIL_CONFIRMRELEASE_DEFAULT} = $yes;

  my $tzil = new_tzil;

  is(
    exception { $tzil->release },
    undef,
    "DZIL_CONFIRMRELEASE_DEFAULT=$yes no exception",
  );

  ok(
    release_happened($tzil),
    "DZIL_CONFIRMRELEASE_DEFAULT=$yes allows release",
  );
}

my $prompt = "*** Preparing to release DZT-Sample-0.001.tar.gz with FakeRelease ***\n"
           . "Do you want to continue the release process?";

for my $no (qw(n no)) {
  my $tzil = new_tzil;

  $tzil->chrome->set_response_for($prompt, $no);

  like(
    exception { $tzil->release },
    $release_aborted,
    "ConfirmRelease aborts when answering '$no'",
  );

  ok(!release_happened($tzil), "release did not happen when answering '$no'");
}

for my $yes (qw(y yes)) {
  my $tzil = new_tzil;

  $tzil->chrome->set_response_for($prompt, $yes);

  is(
    exception { $tzil->release },
    undef,
    "ConfirmRelease no exception when answering '$yes'",
  );

  ok(release_happened($tzil), "answering '$yes' allows release");
}

done_testing;