App-Framework-Lite

 view release on metacpan or  search on metacpan

t/10-Feature-Run.t  view on Meta::CPAN

plan tests => $num_tests ;

	my $expected ;
	my $delay ;

	my $app = App::Framework::Lite->new('exit_type'=>'die');
	$app->go() ;


#=================================================================================
# SUBROUTINES EXECUTED BY APP
#=================================================================================

#----------------------------------------------------------------------
# Main execution
#
sub app
{
	my ($app) = @_ ;


	my $run1 = $app->feature("run") ;
	my $class1 = ref($run1) ;
	
	is($class1, 'App::Framework::Lite', 'Run feature class check') ;
	
	my $run = $app->run ;
	my $class = ref($run) ;
	is($run, $run1, 'Run object check') ;

	my $run2 = $app->Run ;
	is($run, $run2, 'Run object check (access alias)') ;

	is($run->on_error, 'fatal', 'Default on_error setting') ;

	if ($App::Framework::Lite::AVAILABLE_MOD{'File::Which'})
	{
		$run->on_error('fatal') ;
		eval{$run->required({ %progs }) ;} ;
		ok ($@, "Expected failure to find non-existent program") ;
	}
	else
	{
		# skip this test
		pass() ;
	}
	
	$run->on_error('status') ;
	my $required = $run->required({ %progs }) ;
$app->prt_data("Required stats=", $required) ;	
	foreach my $exe (keys %progs)
	{
		if ($App::Framework::Lite::AVAILABLE_MOD{'File::Which'})
		{
			if ($exe eq 'not-there')
			{
				is($required->{$exe}, undef, "$exe status") ;
			}
			else
			{
				## if we can find it then the framework should find it
				if (which($exe))
				{
					ok ($required->{$exe}, "Expected to find $exe") ;
				}
				else
				{
					is($required->{$exe}, undef, "Expected not to find $exe") ;
				}
			}
		}
		else
		{
			# skip this test
			pass() ;
		}
	}	

	my $idx = 1 ;
	foreach my $test_href (@expected_array)
	{
$app->prt_data("Test HASH=", $test_href) ;
		$expected = $test_href->{expected} ;
		$delay = $test_href->{delay} ;
		my $results_aref ;
		
		## feature run
		$app->run( @{$test_href->{args}} ) ;

		# results
		$results_aref = $app->run->results() ;
		if (ref($test_href->{expected}) eq 'ARRAY')
		{
			is_deeply($results_aref, $test_href->{expected}, "$idx : Test array results") ;
		}
		else
		{
			is($results_aref->[0], $test_href->{expected}, "$idx : Test scalar results") ;
		}
		
		## direct object access
		$run->run( @{$test_href->{args}} ) ;
		
		# results
		$results_aref = $run->results() ;
		if (ref($test_href->{expected}) eq 'ARRAY')
		{
			is_deeply($results_aref, $test_href->{expected}, "$idx : Test direct array results") ;
		}
		else
		{
			is($results_aref->[0], $test_href->{expected}, "$idx : Test direct scalar results") ;
		}
		
		++$idx ;
	}

	
}

#=================================================================================



( run in 0.628 second using v1.01-cache-2.11-cpan-e1769b4cff6 )