App-diff_spreadsheets
view release on metacpan or search on metacpan
t/t_TestCommon.pm view on Meta::CPAN
@_ = ("TESTc FAILED: $desc", $expected, $actual);
goto &mycheckeq_literal
}
}
}
}
sub verif_eval_err(;$) { # MUST be called on same line as the 'eval'
my ($msg_regex) = @_;
my @caller = caller(0);
my $ln = $caller[2];
my $fn = $caller[1];
my $ex = $@;
confess "expected error did not occur at $fn line $ln\n",
unless $ex;
if ($ex !~ / at \Q$fn\E line $ln\.?(?:$|\R)/s) {
confess "Got UN-expected err (not ' at $fn line $ln'):\n«$ex»\n",
"\n";
}
if ($msg_regex && $ex !~ qr/$msg_regex/) {
confess "Got UN-expected err (not matching $msg_regex) at $fn line $ln'):\n«$ex»\n",
"\n";
}
verif_no_internals_mentioned($ex) if defined $testee_top_module;
dprint "Got expected err: $ex\n";
}
sub insert_loc_in_evalstr($) {
my $orig = shift;
my ($fn, $lno) = (caller(0))[1,2];
#use Data::Dumper::Interp; say dvis '###insert_loc_in_evalstr $fn $lno';
"# line $lno \"$fn\"\n".$orig
}
sub timed_run(&$@) {
my ($code, $maxcpusecs, @codeargs) = @_;
my $getcpu = eval {do{
require Time::HiRes;
() = (&Time::HiRes::clock());
\&Time::HiRes::clock;
}} // sub{ my @t = times; $t[0]+$t[1] };
dprint("Note: $@") if $@;
$@ = ""; # avoid triggering "Eval error" in mycheck();
my $startclock = &$getcpu();
my (@result, $result);
if (wantarray) {@result = &$code(@codeargs)} else {$result = &$code(@codeargs)};
my $cpusecs = &$getcpu() - $startclock;
confess "TOOK TOO LONG ($cpusecs CPU seconds vs. limit of $maxcpusecs)\n"
if $cpusecs > $maxcpusecs;
if (wantarray) {return @result} else {return $result};
}
# Copy a file if needed to prevent any possibilty of it being modified.
# Returns the original path if the file is read-only, otherwise the path
# of a temp copy.
sub tmpcopy_if_writeable($) {
my $path = shift;
confess "$path : $!" unless stat($path);
if ( (stat(_))[2] & 0222 ) {
my ($name, $suf) = (basename($path) =~ /^(.*?)((?:\.\w{1,4})?)$/);
(undef, my $tpath) =
File::Temp::tempfile(SUFFIX => $suf, UNLINK => 1);
File::Copy::copy($path, $tpath) or die "File::Copy $!";
return $tpath;
}
$path
}
sub clean_capture_output($) {
my $str = shift;
# For some reason I can not track down, tests on Windows in VirtualBox sometimes emit
# this message. I think (unproven) that this occurs because the current directory
# is a VBox host-shared directory mounted read-only. But nobody should be writing
# to the cwd!
$str =~ s/The media is write protected\S*\R//gs;
$str
}
sub my_capture(&) {
my ($out, $err, @results) = &capture($_[0]);
$out = clean_capture_output($out);
$err = clean_capture_output($err);
confess "my_capture: Must be called in list context to receive both stdout & err"
unless wantarray;
return( $out, $err, @results );
}
sub my_capture_merged(&) {
my ($merged, @results) = &capture_merged($_[0]);
$merged = clean_capture_output($merged);
return( wantarray ? ($merged, @results) : $merged );
}
sub my_tee_merged(&) {
my ($merged, @results) = &tee_merged($_[0]);
$merged = clean_capture_output($merged);
return( wantarray ? ($merged, @results) : $merged );
}
1;
( run in 0.438 second using v1.01-cache-2.11-cpan-e1769b4cff6 )