App-Term-Jump
view release on metacpan or search on metacpan
use strict ;
use warnings ;
package t::Jump ;
require Exporter ;
our @ISA = qw(Exporter) ;
our %EXPORT_TAGS = ('all' => [ qw() ]) ;
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ) ;
our @EXPORT = qw(jump_test) ;
our $VERSION = '0.5' ;
use Test::Exception ;
use Test::Warn;
use Test::NoWarnings qw(had_no_warnings);
use Test::Deep ;
use Test::More qw(no_plan) ;
use Cwd ;
use Test::MockModule ;
use Directory::Scratch ;
use File::Path::Tiny ;
use File::Spec ;
use Data::TreeDumper ;
use Data::TreeDumper::Utils qw(:all) ;
use Clone qw(clone) ;
use YAML ;
use File::Slurp ;
use App::Term::Jump ;
#------------------------------------------------------------------------------------------------------------------------
=head1
Implements I<jump_test>.
Each invocation of I<jump_test> will create a temporary directory and a structure of directories under it.
The tests listes in the call will be run sequentialy. I<jump_test> will stop at the first error an report
the error as well as all the necessary information to debug the error.
=cut
sub jump_test
{
my (%setup_arguments) = @_ ;
$setup_arguments{caller} = join(':', @{[caller()]}[1 .. 2]) ;
$setup_arguments{name} =~ s/ +/_/g ;
if(exists $setup_arguments{directories_and_db})
{
@setup_arguments{'temporary_directory_structure', 'db_start'} = get_directories_and_db($setup_arguments{directories_and_db}) ;
delete $setup_arguments{directories_and_db} ;
}
my $start_directory = cwd() ;
my $test_directory = cwd() ;
my $using_temporary_directory = 0 ;
my ($jump_options, $command_line_arguments) = App::Term::Jump::parse_command_line() ; # sets default db and config
# temporary test directory
if(exists $setup_arguments{temporary_directory_structure})
{
my $temporary_directory_root = File::Spec->tmpdir() . "/jump_test_$setup_arguments{name}_" ;
my $allowed_characters_in_directory_name = ['a' .. 'z'] ;
$test_directory = create_directory_structure($setup_arguments{temporary_directory_structure}, $temporary_directory_root, '1234', $allowed_characters_in_directory_name) ;
chdir($test_directory) or die "Error: Can't cd to temporary directory: $!\n" ;
$using_temporary_directory++ ;
# database --------------------------------------------------
my @db_interpolated ;
while (my ($k, $v) = each %{$setup_arguments{db_start}})
{
$k =~ s/TD/$test_directory/g ;
$k =~ s/TEMPORARY_DIRECTORY/$test_directory/g ;
push @db_interpolated, $k, $v ;
}
$jump_options->{db_location} = "$test_directory/temporary_jump_database" ;
App::Term::Jump::write_db($jump_options, {@db_interpolated}) ;
}
local $ENV{APP_TERM_JUMP_DB} = $jump_options->{db_location} if exists $jump_options->{db_location} ;
# tests -------------------------------------------------------
my $test_index = -1 ;
my $error ;
for my $test (@{$setup_arguments{tests}})
{
$test_index++ ;
my $test_name = $test->{name} ||= "missing name '$setup_arguments{caller}'" ;
do {diag "Skipping test '$test_name'\n"; next} if $test->{skip} ;
# configuration ----------------------------------------------
if(exists $test->{configuration})
{
$jump_options->{config_location} = "$test_directory/temporary_jump_configuration" ;
File::Slurp::write_file($jump_options->{config_location}, $test->{configuration}) or die $! ;
$test->{configuration_warning} = "temporarily overridding config!" if exists $setup_arguments{configuration} ;
( run in 2.075 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )