DB-Hooks

 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;
}
$ENV{ DEBUGGER_NO_COLOR } =  1;



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 =  'e 2+2;e;q';
is
	n( `$^X $lib -d:DbBatch='$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; scalar %x;e \%x;';
is
	n( `$^X $lib -d:DbBatch='$cmd' -e '$script'` )
	,$^V < '5.26.0'? $files->{ 'eval < 5.26.0' } : $files->{ 'eval >= 5.26.0' }
	,'Eval expressions at user context and dump them';



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



( run in 1.772 second using v1.01-cache-2.11-cpan-4ab04211f4c )