Devel-DebugHooks

 view release on metacpan or  search on metacpan

t/27-cmd_e.t  view on Meta::CPAN

#!/usr/bin/env perl


use strict;
use warnings;

use Test::More 'no_plan';
use Test::Output;
use FindBin qw/ $Bin /;  my $lib =  "-I$Bin/lib -I$Bin/../lib";
use Data::Section::Simple qw/ get_data_section /;

use Test::Differences;
unified_diff();
{
	no warnings qw/ redefine prototype /;
	*is =  \&eq_or_diff;
}



sub n {
	$_ =  join '', @_;

	s#\t#  #gm;
	s#([^/]*)(?:.*?)?([^/]+\.p(?:m|l))#$1xxx/$2#gm;

	$_;
}

sub nn {
	$_ =  n( @_ );

	s#( at ).*$#$1...#gm;    # Remove file:line info

	$_;
}


my $cmd;
my $script;
my $files =  get_data_section();


($script =  <<'PERL') =~ s#^\t##gm;
	$x =  1;
	$x =  [ a => 1 ];
	$x =  { a => 1 };
	@x =  ( a => 1 );
	%x =  ( a => 1 );
	2;
PERL

$cmd =  '2+2;e;q';
is
	n( `$^X $lib -d:DbInteract='$cmd' -e '$script'` )
	,$files->{ 'last eval' }
	,'Eval last expression if none supplied';

$cmd =  's;$x;e $x;$x++;e $x;s;e $x;s;e $x;s;@x;scalar @x;e \@x;s;%x;0+keys(%x);e \%x;';
is
	n( `$^X $lib -d:DbInteract='$cmd' -e '$script'` )
	,$files->{ 'eval' }
	,'Eval expressions at user context and dump them';



($script =  <<'PERL') =~ s#^\t##gm;
	sub t {
		1;
	}
	t( 1, [], {} );
PERL



( run in 0.477 second using v1.01-cache-2.11-cpan-6aa56a78535 )