App-pltest
view release on metacpan or search on metacpan
echo &Form;
}
# Form without newline
sub Form($@) {
(my $form = shift) =~ s/%\K(%|[^a-z]+)/ my $x = $1; $x =~ tr!:!$!; $x /eg; # also matches %%, todo /r
Echo sprintf $form, &Echo;
}
sub benchmark(&@) {
my( $code, $name, @args ) = @_;
local( $a, $b ) = ($a, $b);
$name //= 'anonymous';
require Benchmark;
local $SIG{__WARN__} = sub { die @_ };
if( @args ) {
say Benchmark::timestr( Benchmark::countit( 10, $code )), " $name: $_"
for @args;
} else {
say Benchmark::timestr( Benchmark::countit( 10, $code )), " $name";
}
}
# Do it 100x for very fast test code (to increase weight compared to Benchmark overhead).
sub Benchmark(&@) {
my( $code, @rest ) = @_;
benchmark { for my $i (0..99) { &$code() }} @rest;
}
sub Config(@) {
require Config;
if( @_ ) {
#{map { pairgrep { $a =~ /$_/ } %Config::Config } @_}; # needs 5.20
my %config;
while( my( $k, $v ) = each %Config::Config ) {
}
}
# trim small values from %NUMBER
sub Number(;$) {
my $n = $_[0] // 2;
$NUMBER{$_} < $n and delete $NUMBER{$_} for keys %NUMBER;
}
# Pipe command to CODE
sub piped(&$@) {
my $code = shift;
open my $fd, "-|", @_ or die "$_[0]: $!\n";
&$code() while <$fd>;
}
sub help(;$) {
if( @_ && ! defined $_[0] ) {
print <<\EOF;
usage: pltest {-{BbeE} program} [-o] [-Vversion] [-perlopt...] [--] [main program] [arg ...]
-Aprog map prog over @A (or undef) returning new @A
open $fh, Win32::ShellQuote::quote_native( $^X, '-W', '..\pltest', @_ ) . '|';
} else {
open $fh, '-|', $^X, '-W', '../pltest', @_;
}
local $/;
my $ret = <$fh>;
ok $ret eq $_, join ' ', 'pltest', map /[\s*?()[\]{}\$\\'";|&]|^$/ ? "'$_'" : $_, @_
or print "got: '$ret', expected: '$_'\n";
}
# run pltest, expect $_ altered by shift->()
sub pl_a(&@) {
local $_ = $_;
shift->();
&pltest;
}
my @files = <atom-weight-[123].csv>;
my( $B, $I, $G, $R, $E ) = map "\e[${_}m", 1, 3, 32, 31, '', '';
# Run one with Algorithm::Diff, once without
#pltest -F, --color K *.csv | pltest -pB '@c{1, 3, 32, 31, ""} = qw(B I G R E)' 's/\e\[(\d*)m/\${$c{$1}}/g'
waitpid $pid, 0;
}
# run pltest, expect shift
sub pl_e($@) {
local $_ = shift;
&pltest;
}
# run pltest, expect $_ altered by shift->()
sub pl_a(&@) {
local $_ = $_;
shift->();
&pltest;
}
1;
( run in 1.032 second using v1.01-cache-2.11-cpan-49f99fa48dc )