diff options
Diffstat (limited to 't/lib/t/Util.pm')
-rw-r--r-- | t/lib/t/Util.pm | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/t/lib/t/Util.pm b/t/lib/t/Util.pm index bb8f59e..b1312f5 100644 --- a/t/lib/t/Util.pm +++ b/t/lib/t/Util.pm @@ -8,8 +8,10 @@ use File::Slurp; use File::Spec::Functions qw(rel2abs); use File::chdir; use File::Temp qw(tempdir); +use Try::Tiny; +use Capture::Tiny qw(capture); -our @EXPORT = qw( corrupt_annexed_file device_id_issues ); +our @EXPORT = qw( corrupt_annexed_file device_id_issues run_bin ); sub corrupt_annexed_file { my ($git, $file) = @_; @@ -37,4 +39,27 @@ sub device_id_issues { return($foo_id != $bar_id); } +sub run_bin { + (my $bin = "App::" . shift) =~ tr/-/_/; + local @ARGV = @_; + my ($stdout, $stderr, $exit) = capture { + my $exit; + #<<< + # in order to simulate calling the program at the command + # line, convert exceptions into what happens when an ordinary + # perl script, invoked from the command line, calls 'die' + try { + $exit = $bin->main; + } catch { + say STDERR $_; + $exit = 255; + }; + #>>> + return $exit; + }; + my @stdout = split "\n", $stdout; + my @stderr = split "\n", $stderr; + return (\@stdout, \@stderr, $exit); +} + 1; |