dragonchild has asked for the wisdom of the Perl Monks concerning the following question:

Has anyone used these two modules together? I would love to have the output for Test::More, but would also like to have the features of Test::Cmd::Common. I'm not sure, though, how to structure my script, particularly my ok()/is()/isnt() calls.

------
We are the carpenters and bricklayers of the Information Age.

Don't go borrowing trouble. For programmers, this means Worry only about what you need to implement.

Please remember that I'm crufty and crochety. All opinions are purely mine and all code is untested, unless otherwise specified.

Replies are listed 'Best First'.
Re: Test::Cmd::Common and Test::More
by adrianh (Chancellor) on Jun 27, 2003 at 16:37 UTC

    You probably should use Test::Cmd if you want to integrate easily with Test::More and friends. In Test::Cmd::Common (to quote from the docs):

    All methods throw exceptions and exit on failure

    Since you want to detect failure rather than exit, use Test::Cmd instead. For example:

    use strict; use warnings; use Test::More tests => 2; use Test::Cmd; my $cmd = Test::Cmd->new( prog => '/bin/ls /etc/motd' ); is $cmd->run, 0, 'ls ran okay'; is $cmd->stdout, "/etc/motd\n", 'and gave expected output';

      You can also use Test::Exception to handle things that may or may not die. It's a handy module.

        It's a handy module

        Why thank you ;-)

        However, it's not appropriate here since Test::Cmd::Common doesn't die on test failure - it exits (see the documentation for the fail method for details.)

        T::C::C is a good fit for systems like Aegis, but not for Test::Harness folk.