Skip to content

Commit

Permalink
Started cleaning up t/Helper.pm.
Browse files Browse the repository at this point in the history
  • Loading branch information
shlomif committed Oct 30, 2011
1 parent b64ddf6 commit 7956382
Showing 1 changed file with 30 additions and 4 deletions.
34 changes: 30 additions & 4 deletions t/Helper.pm
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -14,24 +14,50 @@ require Test::More;
my $trepanpl = File::Spec->catfile(dirname(__FILE__), qw(.. bin trepanpl)); my $trepanpl = File::Spec->catfile(dirname(__FILE__), qw(.. bin trepanpl));
my $debug = $^W; my $debug = $^W;


sub _slurp
{
my ($filename) = @_;

open my $in, '<', $filename
or die "Cannot open '$filename' for slurping - $!";

local $/;
my $contents = <$in>;

close($in);

return $contents;
}

sub run_debugger($$;$$) sub run_debugger($$;$$)
{ {
my ($test_invoke, $cmdfile, $rightfile, $opts) = @_; my ($test_invoke, $cmdfile, $rightfile, $opts) = @_;

$opts //= {}; $opts //= {};

Test::More::note( "running $test_invoke with $cmdfile" ); Test::More::note( "running $test_invoke with $cmdfile" );

my $run_opts = $opts->{run_opts} || "--basename --nx --no-highlight"; my $run_opts = $opts->{run_opts} || "--basename --nx --no-highlight";
my $full_cmdfile = File::Spec->catfile(dirname(__FILE__), 'data', $cmdfile); my $full_cmdfile = File::Spec->catfile(dirname(__FILE__), 'data', $cmdfile);
$run_opts .= " --command $full_cmdfile" unless ($opts->{no_cmdfile}); $run_opts .= " --command $full_cmdfile" unless ($opts->{no_cmdfile});
($rightfile = $full_cmdfile) =~ s/\.cmd/.right/ unless defined($rightfile);
if (!defined($rightfile))
{
($rightfile = $full_cmdfile) =~ s/\.cmd\z/.right/;
}

my $cmd = "$EXECUTABLE_NAME $trepanpl $run_opts $test_invoke"; my $cmd = "$EXECUTABLE_NAME $trepanpl $run_opts $test_invoke";
print $cmd, "\n" if $debug; print $cmd, "\n" if $debug;

my $output = `$cmd`; my $output = `$cmd`;
print $output if $debug;
my $rc = $? >> 8; my $rc = $? >> 8;

print $output if $debug;
Test::More::is($rc, 0); Test::More::is($rc, 0);
open(RIGHT_FH, "<$rightfile");
my $right_string = _slurp($rightfile);

undef $INPUT_RECORD_SEPARATOR; undef $INPUT_RECORD_SEPARATOR;
my $right_string = <RIGHT_FH>;
($output, $right_string) = $opts->{filter}->($output, $right_string) if $opts->{filter}; ($output, $right_string) = $opts->{filter}->($output, $right_string) if $opts->{filter};
my $gotfile; my $gotfile;
($gotfile = $full_cmdfile) =~ s/\.cmd/.got/; ($gotfile = $full_cmdfile) =~ s/\.cmd/.got/;
Expand Down

0 comments on commit 7956382

Please sign in to comment.