App-Sqitch
view release on metacpan or search on metacpan
%request_params = @_;
return $self->note;
});
# Use the same plan.
my $mock_plan = Test::MockModule->new(ref $target);
$mock_plan->mock(plan => $plan);
ok my $add = App::Sqitch::Command::add->new(
sqitch => $sqitch,
change_name => 'foo',
template_directory => Path::Class::dir(qw(etc templates))
), 'Create another add with template_directory';
file_not_exists_ok($_) for ($deploy_file, $revert_file, $verify_file);
ok $add->execute, 'Execute with the --change option';
file_exists_ok($_) for ($deploy_file, $revert_file, $verify_file);
ok my $foo = $plan->get('foo'), 'Get the "foo" change';
throws_ok { $rework->execute('foo') } 'App::Sqitch::X',
'Should get an example for duplicate change';
is $@->ident, 'plan', 'Duplicate change error ident should be "plan"';
is $@->message, __x(
qq{Cannot rework "{change}" without an intervening tag.\n}
. 'Use "sqitch tag" to create a tag and try again',
change => 'foo',
), 'Fail message should say a tag is needed';
# Tag it, and *then* it should work.
ok $plan->tag( name => '@alpha' ), 'Tag it';
my $deploy_file2 = file qw(test-rework deploy foo@alpha.sql);
my $revert_file2 = file qw(test-rework revert foo@alpha.sql);
my $verify_file2 = file qw(test-rework verify foo@alpha.sql);
MockOutput->get_info;
file_not_exists_ok($_) for ($deploy_file2, $revert_file2, $verify_file2);
ok $rework->execute('foo'), 'Rework "foo"';
# The files should have been copied.
file_exists_ok($_) for ($deploy_file, $revert_file, $verify_file);
file_exists_ok($_) for ($deploy_file2, $revert_file2, $verify_file2);
file_contents_identical($deploy_file2, $deploy_file);
file_contents_identical($verify_file2, $verify_file);
file_contents_identical($revert_file, $deploy_file);
file_contents_is($revert_file2, <<'EOF', 'New revert should revert');
-- Revert empty:foo from sqlite
BEGIN;
-- XXX Add DDLs here.
COMMIT;
EOF
# The note should have been required.
is_deeply \%request_params, {
for => __ 'rework',
scripts => [$deploy_file, $revert_file, $verify_file],
}, 'It should have prompted for a note';
# The plan file should have been updated.
ok $plan->load, 'Reload the plan file';
ok my @steps = $plan->changes, 'Get the steps';
is @steps, 2, 'Should have two steps';
is $steps[0]->name, 'foo', 'First step should be "foo"';
is $steps[1]->name, 'foo', 'Second step should also be "foo"';
is_deeply [$steps[1]->requires], [dep 'foo@alpha'],
'Reworked step should require the previous step';
is_deeply +MockOutput->get_info, [
[__x(
'Added "{change}" to {file}.',
change => 'foo [foo@alpha]',
file => $target->plan_file,
)],
[__n(
'Modify this file as appropriate:',
'Modify these files as appropriate:',
3,
)],
[" * $deploy_file"],
[" * $revert_file"],
[" * $verify_file"],
], 'And the info message should suggest editing the old files';
is_deeply +MockOutput->get_debug, [
[' ', __x 'Created {file}', file => dir qw(test-rework deploy) ],
[' ', __x 'Created {file}', file => dir qw(test-rework revert) ],
[' ', __x 'Created {file}', file => dir qw(test-rework verify) ],
[__x(
'Copied {src} to {dest}',
dest => $deploy_file2,
src => $deploy_file,
)],
[__x(
'Copied {src} to {dest}',
dest => $revert_file2,
src => $revert_file,
)],
[__x(
'Copied {src} to {dest}',
dest => $verify_file2,
src => $verify_file,
)],
[__x(
'Copied {src} to {dest}',
dest => $revert_file,
src => $deploy_file,
)],
], 'Debug should show file copying';
##############################################################################
# Let's do that again. This time with more dependencies and fewer files.
$deploy_file = file qw(test-rework deploy bar.sql);
$revert_file = file qw(test-rework revert bar.sql);
$verify_file = file qw(test-rework verify bar.sql);
ok $add = App::Sqitch::Command::add->new(
sqitch => $sqitch,
template_directory => Path::Class::dir(qw(etc templates)),
with_scripts => { revert => 0, verify => 0 },
), 'Create another add with template_directory';
file_not_exists_ok($_) for ($deploy_file, $revert_file, $verify_file);
$add->execute('bar');
file_exists_ok($deploy_file);
file_not_exists_ok($_) for ($revert_file, $verify_file);
ok $plan->tag( name => '@beta' ), 'Tag it with @beta';
my $deploy_file3 = file qw(test-rework deploy bar@beta.sql);
my $revert_file3 = file qw(test-rework revert bar@beta.sql);
my $verify_file3 = file qw(test-rework verify bar@beta.sql);
MockOutput->get_info;
isa_ok $rework = App::Sqitch::Command::rework->new(
sqitch => $sqitch,
command => 'rework',
config => $config,
requires => ['foo'],
note => [qw(hi there)],
conflicts => ['dr_evil'],
), $CLASS, 'rework command with requirements and conflicts';
# Check the files.
file_not_exists_ok($_) for ($deploy_file3, $revert_file3, $verify_file3);
ok $rework->execute('bar'), 'Rework "bar"';
file_exists_ok($deploy_file);
file_not_exists_ok($_) for ($revert_file, $verify_file);
file_exists_ok($deploy_file3);
file_not_exists_ok($_) for ($revert_file3, $verify_file3);
# The note should have been required.
is_deeply \%request_params, {
for => __ 'rework',
scripts => [$deploy_file],
}, 'It should have prompted for a note';
# The plan file should have been updated.
ok $plan->load, 'Reload the plan file again';
ok @steps = $plan->changes, 'Get the steps';
is @steps, 4, 'Should have four steps';
is $steps[0]->name, 'foo', 'First step should be "foo"';
is $steps[1]->name, 'foo', 'Second step should also be "foo"';
is $steps[2]->name, 'bar', 'First step should be "bar"';
is $steps[3]->name, 'bar', 'Second step should also be "bar"';
is_deeply [$steps[3]->requires], [dep 'bar@beta', dep 'foo'],
'Requires should have been passed to reworked change';
is_deeply [$steps[3]->conflicts], [dep '!dr_evil'],
'Conflicts should have been passed to reworked change';
is $steps[3]->note, "hi\n\nthere",
'Note should have been passed as comment';
is_deeply +MockOutput->get_info, [
[__x(
'Added "{change}" to {file}.',
change => 'bar [bar@beta foo !dr_evil]',
file => $target->plan_file,
)],
[__n(
'Modify this file as appropriate:',
'Modify these files as appropriate:',
1,
)],
[" * $deploy_file"],
], 'And the info message should show only the one file to modify';
is_deeply +MockOutput->get_debug, [
[__x(
'Copied {src} to {dest}',
dest => $deploy_file3,
src => $deploy_file,
)],
[__x(
'Skipped {dest}: {src} does not exist',
dest => $revert_file3,
src => $revert_file,
)],
[__x(
'Skipped {dest}: {src} does not exist',
dest => $verify_file3,
src => $verify_file,
)],
[__x(
'Skipped {dest}: {src} does not exist',
dest => $revert_file,
src => $revert_file3, # No previous revert, no need for new revert.
)],
], 'Should have debug oputput for missing files';
# Make sure --open-editor works
MOCKSHELL: {
my $sqitch_mocker = Test::MockModule->new('App::Sqitch');
my $shell_cmd;
$sqitch_mocker->mock(shell => sub { $shell_cmd = $_[1] });
$sqitch_mocker->mock(quote_shell => sub { shift; join ' ' => @_ });
ok $rework = $CLASS->new(
sqitch => $sqitch,
( run in 2.778 seconds using v1.01-cache-2.11-cpan-5735350b133 )