App-Framework

 view release on metacpan or  search on metacpan

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

#   tests -> 1 test per test
# }
# 3 object tests
# progs test
plan tests => $no_data_tests * 1 * 2
	+ $data_tests * scalar(@data) * 2
	+ scalar(@expected_array) * 2
	+ 3 
	+ 1 + 1 + scalar(keys %progs) ;


	my $expected ;
	my $delay ;

	my $app = App::Framework->new();
	$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::Feature::Run', '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') ;


	$run->on_error('fatal') ;
	eval{$run->required({ %progs }) ;} ;
	ok ($@, "Expected failure to find non-existent program") ;

	$run->on_error('status') ;
	my $required = $run->required({ %progs }) ;
$app->prt_data("Required stats=", $required) ;	
	foreach my $exe (keys %progs)
	{
		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") ;
			}
		}
	}	

	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 ;
	}

	
}

#=================================================================================
# SUBROUTINES
#=================================================================================

#---------------------------------------------------------------------------------
sub progress
{



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