App-Sqitch

 view release on metacpan or  search on metacpan

t/plan.t  view on Meta::CPAN

    [qw(hey hey-there)], 'Search by change name should work as a regex';

is_deeply $get_all_names->( $plan->search_changes( name => '[-/]')),
    [qw(this/rocks hey-there)],
    'Search by change name should with a character class';

# Try planner name.
is_deeply $get_all_names->( $plan->search_changes( planner => 'Barack' ) ),
    [qw(this/rocks hey-there)], 'Search by planner should work';

is_deeply $get_all_names->( $plan->search_changes( planner => 'a..a' ) ),
    [qw(you)], 'Search by planner should work as a regex';

# Search by operation.
is_deeply $get_all_names->( $plan->search_changes( operation => 'deploy' ) ),
    [qw(hey you this/rocks hey-there)], 'Search by operation "deploy" should work';

is_deeply $get_all_names->( $plan->search_changes( operation => 'revert' ) ),
    [], 'Search by operation "rever" should return nothing';

# Fake out an operation.
my $mock_change = Test::MockModule->new('App::Sqitch::Plan::Change');
$mock_change->mock( operator => sub { return shift->name =~ /hey/ ? '-' : '+' });

is_deeply $get_all_names->( $plan->search_changes( operation => 'DEPLOY' ) ),
    [qw(you this/rocks)], 'Search by operation "DEPLOY" should now return two changes';

is_deeply $get_all_names->( $plan->search_changes( operation => 'REVERT' ) ),
    [qw(hey hey-there)], 'Search by operation "REVERT" should return the other two';

$mock_change->unmock_all;

# Make sure we test only for legal operations.
throws_ok { $plan->search_changes( operation => 'foo' ) } 'App::Sqitch::X',
    'Should get an error for unknown operation';
is $@->ident, 'DEV', 'Unknown operation error ident should be "DEV"';
is $@->message, 'Unknown change operation "foo"',
    'Unknown operation error message should be correct';

# Test offset and limit.
is_deeply $get_all_names->( $plan->search_changes( offset => 2 ) ),
    [qw(this/rocks hey-there)], 'Search with offset 2 should work';

is_deeply $get_all_names->( $plan->search_changes( offset => 2, limit => 1 ) ),
    [qw(this/rocks)], 'Search with offset 2, limit 1 should work';

is_deeply $get_all_names->( $plan->search_changes( offset => 3, direction => 'desc' ) ),
    [qw(hey)], 'Search with offset 3 and direction "desc" should work';

is_deeply $get_all_names->( $plan->search_changes( offset => 2, limit => 1, direction => 'desc' ) ),
    [qw(you)], 'Search with offset 2, limit 1, direction "desc" should work';

is_deeply $get_all_names->( $plan->search_changes( limit => 3, direction => 'desc' ) ),
    [qw(hey-there this/rocks you)], 'Search with limit 3, direction "desc" should work';

##############################################################################
# Test writing the plan.
can_ok $plan, 'write_to';
my $to = file 'plan.out';
END { unlink $to }
file_not_exists_ok $to;
ok $plan->write_to($to), 'Write out the file';
file_exists_ok $to;
my $v = App::Sqitch->VERSION;
file_contents_is $to,
    '%syntax-version=' . App::Sqitch::Plan::SYNTAX_VERSION . "\n"
    . $file->slurp(iomode => '<:utf8_strict'),
    'The contents should look right';

# Make sure it will start from a certain point.
ok $plan->write_to($to, 'this/rocks'), 'Write out the file from "this/rocks"';
file_contents_is $to,
    '%syntax-version=' . App::Sqitch::Plan::SYNTAX_VERSION . "\n"
    . '%project=multi' . "\n"
    . '# This is a note' . "\n"
    . "\n"
    . $plan->find('this/rocks')->as_string . "\n"
    . $plan->find('hey-there')->as_string . "\n"
    . join( "\n", map { $_->as_string } $plan->find('hey-there')->tags ) . "\n",
    'Plan should have been written from "this/rocks" through tags at end';

# Make sure it ends at a certain point.
ok $plan->write_to($to, undef, 'you'), 'Write the file up to "you"';
file_contents_is $to,
    '%syntax-version=' . App::Sqitch::Plan::SYNTAX_VERSION . "\n"
    . '%project=multi' . "\n"
    . '# This is a note' . "\n"
    . "\n"
    . '# And there was a blank line.' . "\n"
    . "\n"
    . $plan->find('hey')->as_string . "\n"
    . $plan->find('you')->as_string . "\n"
    . join( "\n", map { $_->as_string } $plan->find('you')->tags ) . "\n",
    'Plan should have been written through "you" and its tags';

# Try both.
ok $plan->write_to($to, '@foo', 'this/rocks'),
    'Write from "@foo" to "this/rocks"';
file_contents_is $to,
    '%syntax-version=' . App::Sqitch::Plan::SYNTAX_VERSION . "\n"
    . '%project=multi' . "\n"
    . '# This is a note' . "\n"
    . "\n"
    . $plan->find('you')->as_string . "\n"
    . join( "\n", map { $_->as_string } $plan->find('you')->tags ) . "\n"
    . '   ' . "\n"
    . $plan->find('this/rocks')->as_string . "\n",
    'Plan should have been written from "@foo" to "this/rocks"';

# End with a tag.
ok $plan->write_to($to, 'hey', '@foo'), 'Write from "hey" to "@foo"';
file_contents_is $to,
    '%syntax-version=' . App::Sqitch::Plan::SYNTAX_VERSION . "\n"
    . '%project=multi' . "\n"
    . '# This is a note' . "\n"
    . "\n"
    . $plan->find('hey')->as_string . "\n"
    . $plan->find('you')->as_string . "\n"
    . join( "\n", map { $_->as_string } $plan->find('you')->tags ) . "\n",
    'Plan should have been written from "hey" through "@foo"';



( run in 1.664 second using v1.01-cache-2.11-cpan-5a3173703d6 )