Sign in to PrePAN

App::Cmd::Tester::Untied Capture the result of running an App::Cmd application using Capture::Tiny



use Test::More tests => 4;
use App::Cmd::Tester::Untied;

use YourApp;

# Separate output from STDOUT and STDERR
my $result = test_app(YourApp => [ qw(command --opt value) ]);

like($result->stdout, qr/expected output/, 'printed what we expected');

is($result->stderr, '', 'nothing sent to sderr');

is($result->error, undef, 'threw no exceptions');

# Merged output from STDOUT and STDERR
my $result = test_app_merged(YourApp => [ qw(command --opt value --quiet) ]);

is($result->output, '', 'absolutely no output with --quiet');


One of the reasons that user-executed programs are so often poorly tested is that they are hard to test. App::Cmd::Tester is one of the tools App-Cmd provides to help make it easy to test App::Cmd-based programs.

App::Cmd::Tester::Untied modifies the original to use Capture::Tiny in those extremely rare cases where using tie() on STDOUT and STDERR breaks the application.


or... Why use this module instead of App::Cmd::Tester?


Git::Repository is a module for running git(1). It uses the System::Command module to run a Git command and capture all the output. Git's plumbing commands are ideal for scripting and automation, and Perl's text-processing utilities make it perfect for parsing and interpreting Git's plumbing command output.

When System::Command runs a command, it uses IPC::Open3 on Linux. IPC::Open3 will do some things to make sure that its environment is sane, one of which is to remove any tie() on STDOUT and STDERR.

App::Cmd::Tester does exactly what it sounds like: It tests App::Cmd apps. In order to get the most coverage, it tests from the front-end, localizing @ARGV, overriding exit(), and capturing the regular STDOUT and STDERR using IO::TieCombine, which again does exactly what it sounds like (uses tie() and combines multiple IO handles).

App::Cmd::Tester captures STDOUT and STDERR by tie(). IPC::Open3 removes tie() on STDOUT and STDERR. This breaks Git::Repository, causing it to think there is no .git directory, so it dies with an error.


  • Should I release this or try to get it merged into the main App::Cmd repository?


Already did that. See and see if it does what you need. If not, you could probably patch it.
Of course. Glad I posted this here before uploading the exact same module. Now to make a doc update to App::Cmd::Tester.

Please sign up to post a review.