Test::Mojo::CommandOutputRole
A role to extend Test::Mojo to make mojo command output tests easy.
Example
my
$t
= Test::Mojo->new->with_roles(
'Test::Mojo::CommandOutputRole'
);
# Normal web tests
$t
->get_ok(
'/'
)->content_is(
'Hello world'
);
# Test for string equality
$t
->command_output(
do_something
=> [
qw(arg1 arg2)
] =>
'Expected output'
,
'Correct do_something output'
);
# Test for regex matching
$t
->command_output(
do_something
=> [
qw(arg1 arg2)
] =>
qr/^ \s* Expected\ answer\ is\ [3-5][1-3] \.? $/
x,
'Matching do_something output'
);
# Complex test
$t
->command_output(
do_something
=> [] =>
sub
(
$output
) {
ok
defined
(
$output
),
'Output is defined'
;
is
length
(
$output
) => 42,
'Correct length'
;
},
'Output test results OK'
);
Test results:
ok 1 - GET /
ok 2 - exact match for content
# Subtest: Correct do_something output
ok 1 - Command didn't die
ok 2 - Correct output string
1..2
ok 3 - Correct do_something output
# Subtest: Matching do_something output
ok 1 - Command didn't die
ok 2 - Output regex
1..2
ok 4 - Matching do_something output
# Subtest: Output test results OK
ok 1 - Command didn't die
# Subtest: Handle command output
ok 1 - Output is defined
ok 2 - Correct length
1..2
ok 2 - Handle command output
1..2
ok 5 - Output test results OK
Dependencies
- perl 5.20
- Mojolicious 8.06
- Capture::Tiny 0.48
License and copyright
Copyright (c) 2019 Mirko Westermeier (@memowe, mirko@westermeier.de)
Released under the MIT (X11) license. See LICENSE.txt for details.
Contributors
- Renee Bäcker (@reneeb)