From 8338bbafc73eefb3377642b5914b42233e2a327d Mon Sep 17 00:00:00 2001 From: "David E. Wheeler" Date: Sun, 24 Jul 2022 21:46:43 -0400 Subject: [PATCH] Increase command, engine coverage --- lib/App/Sqitch/Command.pm | 2 +- lib/App/Sqitch/Engine.pm | 2 +- t/command.t | 6 ++++- t/engine.t | 51 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/lib/App/Sqitch/Command.pm b/lib/App/Sqitch/Command.pm index 4f6f4150..2e9ccc4b 100644 --- a/lib/App/Sqitch/Command.pm +++ b/lib/App/Sqitch/Command.pm @@ -240,7 +240,7 @@ sub parse_args { $seen{$target->name}++; } - # Iterate over the argsx to look for changes, engines, plans, or targets. + # Iterate over the args to look for changes, engines, plans, or targets. my %engines = map { $_ => 1 } ENGINES; for my $arg (@{ $p{args} }) { if ( !$p{no_changes} && $target && -e $target->plan_file && $target->plan->contains($arg) ) { diff --git a/lib/App/Sqitch/Engine.pm b/lib/App/Sqitch/Engine.pm index 238eea57..616dc2a2 100644 --- a/lib/App/Sqitch/Engine.pm +++ b/lib/App/Sqitch/Engine.pm @@ -896,7 +896,7 @@ sub _deploy_all { push @run => $change; } } catch { - if (my $ident = eval { $_->ident }) { + if (my $ident = try { $_->ident }) { $self->sqitch->vent($_->message) unless $ident eq 'private' } else { $self->sqitch->vent($_); diff --git a/t/command.t b/t/command.t index b105fdcb..140da2b9 100644 --- a/t/command.t +++ b/t/command.t @@ -4,7 +4,7 @@ use strict; use warnings; use 5.010; use utf8; -use Test::More tests => 195; +use Test::More tests => 198; #use Test::More 'no_plan'; use Test::NoWarnings; use List::Util qw(first); @@ -407,6 +407,10 @@ ARGS: { 'Single unknown arg raise an error'; is $@->ident, 'whu', 'Unknown error ident should be "whu"'; is $@->message, $msg->('foo'), 'Unknown error message should be correct'; + throws_ok { $parsem->( args => ['Changes'] ) } 'App::Sqitch::X', + 'Single invavlid fiile arg raise an error'; + is $@->ident, 'whu', 'Unknown error ident should be "whu"'; + is $@->message, $msg->('Changes'), 'Unknown file error message should be correct'; is_deeply $parsem->( args => ['hey'] ), [['devdb'], ['hey']], 'Single change should be recognized as change'; is_deeply $parsem->( args => ['devdb'] ), [['devdb'], []], diff --git a/t/engine.t b/t/engine.t index 9828de6f..a474d58b 100644 --- a/t/engine.t +++ b/t/engine.t @@ -4,7 +4,7 @@ use strict; use warnings; use 5.010; use utf8; -use Test::More tests => 721; +use Test::More tests => 731; # use Test::More 'no_plan'; use App::Sqitch; use App::Sqitch::Plan; @@ -1679,6 +1679,47 @@ is_deeply +MockOutput->get_vent, [ ['ROFL'], [__x 'Reverting to {change}', change => '@alpha'], ], 'Should notifiy user of error and rollback to @alpha'; + +# Die with a string rather than an exception. +$plan->position(2); +$engine->start_at('@alpha'); +$mock_whu->mock(run_file => sub { die 'Oops' if $_[1]->basename eq 'dr_evil.sql' }); +throws_ok { $engine->_deploy_all($plan, $plan->count -1 ) } 'App::Sqitch::X', + 'Die in _deploy_all on the last change'; +is $@->message, __('Deploy failed'), 'Should once again get final deploy failure message'; +is_deeply $engine->seen, [ + [log_deploy_change => $changes[3]], + [log_deploy_change => $changes[4]], + [log_deploy_change => $changes[5]], + [log_fail_change => $changes[6]], + [log_revert_change => $changes[5]], + [log_revert_change => $changes[4]], + [log_revert_change => $changes[3]], +], 'Should have deployed to dr_evil and revered down to @alpha'; + +is_deeply +MockOutput->get_info_literal, [ + [' + lolz ..', '.........', ' '], + [' + tacos ..', '........', ' '], + [' + curry ..', '........', ' '], + [' + dr_evil ..', '......', ' '], + [' - curry ..', '........', ' '], + [' - tacos ..', '........', ' '], + [' - lolz ..', '.........', ' '], +], 'Should see changes revert back to @alpha'; +is_deeply +MockOutput->get_info, [ + [__ 'ok' ], + [__ 'ok' ], + [__ 'ok' ], + [__ 'not ok' ], + [__ 'ok' ], + [__ 'ok' ], + [__ 'ok' ], +], 'Output should reflect deploy successes and failures'; +$vented = MockOutput->get_vent; +is @{ $vented }, 2, 'Should have two vented items'; +like $vented->[0][0], qr/Oops/, 'First vented should be the error'; +is_deeply $vented->[1], [__x 'Reverting to {change}', change => '@alpha'], + 'Should notifiy user of rollback to @alpha'; $mock_whu->unmock_all; ############################################################################## @@ -2512,6 +2553,14 @@ CHECK_REVERT_DEPEND: { plan => $plan, ); + # First test with no dependencies. + @requiring = []; + ok $engine->check_revert_dependencies($change), + 'Should get no error with no dependencies'; + is_deeply $engine->seen, [ + [changes_requiring_change => $change ], + ], 'It should have check for requiring changes'; + # Have revert change fail with requiring changes. my $req = { change_id => '23234234',