Coder Social home page Coder Social logo

test-mojo-commandoutputrole's Introduction

Test::Mojo::CommandOutputRole

A role to extend Test::Mojo to make mojo command output tests easy.

Travis CI tests

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

License and copyright

Copyright (c) 2019 Mirko Westermeier (@memowe, [email protected])

Released under the MIT (X11) license. See LICENSE.txt for details.

Contributors

test-mojo-commandoutputrole's People

Contributors

memowe avatar

Watchers

Mohammad Sajid Anwar avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.