Last active
August 29, 2015 14:14
-
-
Save aereal/313e3e256e18eb199bf3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use IPC::Run (); | |
use List::Util qw(reduce); | |
sub run { | |
my (@cmd) = @_; | |
my $success = IPC::Run::run(\@cmd, \undef, \my $stdout, \my $stderr); | |
return +{ | |
cmd => \@cmd, | |
success => $success, | |
stdout => $stdout, | |
stderr => $stderr, | |
}; | |
} | |
sub seq_run { | |
my (@cmd_array) = @_; | |
my $aggregated = reduce { | |
my ($results, $cmds) = ($a, $b); | |
my $last_result = $results->[scalar(@$results) - 1]; | |
$last_result->{success} ? [@$results, run(@$cmds)] : $results; | |
} [ { success => 1 } ], @cmd_array; | |
shift @$aggregated; | |
return $aggregated; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use List::Util qw(reduce); | |
use Test::More; | |
sub run { | |
my $rc = system(@_); | |
return +{ success => ($rc == 0), cmd => \@_, run => 1 }; | |
} | |
sub seq_run { | |
my $aggregated = reduce { | |
my ($results, $cmd_array) = ($a, $b); | |
my $last_result = $results->[scalar(@$results) - 1]; | |
$last_result->{success} ? [@$results, run(@$cmd_array)] : $results; | |
} [ { success => 1 } ], @_; | |
shift @$aggregated; | |
return $aggregated; | |
} | |
my $results = seq_run( | |
['true'], | |
['false'], | |
['echo', 'will not run'], | |
['echo', 'will not run'], | |
); | |
ok $results; | |
diag explain $results; | |
done_testing; | |
__END__ | |
ok 1 | |
# [ | |
# { | |
# 'cmd' => [ | |
# 'true' | |
# ], | |
# 'run' => 1, | |
# 'success' => 1 | |
# }, | |
# { | |
# 'cmd' => [ | |
# 'false' | |
# ], | |
# 'run' => 1, | |
# 'success' => '' | |
# } | |
# ] | |
1..1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment