Advanced-Config

 view release on metacpan or  search on metacpan

t/65-rule-config.t  view on Meta::CPAN


use Test::More;
use File::Basename;
use File::Spec;
use Sys::Hostname;
use Fred::Fish::DBUG 2.09 qw / on /;
use Fred::Fish::DBUG::Test 2.09;
use Fred::Fish::DBUG::TIE;

# How to find the helper module ...
BEGIN { push (@INC, File::Spec->catdir (".", "t", "test-helper")); }
use helper1234;

my $fish;

BEGIN 
{
   $fish = turn_fish_on_off_for_advanced_config ();

   unlink ( $fish );

   DBUG_ENTER_FUNC ();

   use_ok ("Advanced::Config");
   use_ok ("Advanced::Config::Options");

   DBUG_VOID_RETURN ();
}

END {
   DBUG_ENTER_FUNC ();
   # Don't do any tests in the END block ...
   DBUG_VOID_RETURN ();
}

# --------------------------------------
# Start of the main program!
# --------------------------------------
{
   DBUG_TIE_STDERR ();

   # Turn fish on ...
   DBUG_PUSH ( $fish );

   DBUG_ENTER_FUNC (@ARGV);

   dbug_ok (1, "In the MAIN program ...");

   bad_test_rules ( build_filename ("65-bad-rule-config.cfg") );

   my $rCfg = test_rules ( build_filename ("65-good-rule-config.cfg") );

   dump_section_rules ( $rCfg, "tom*.cfg" );

   my $f = build_filename ( "65-my-config-file.cfg" );
   my $cfg1 = Advanced::Config->new ($f)->set_config_rules ($rCfg);
   dbug_ok ( (defined $cfg1), "Config Object created using rules." );
   test_using_rules ( $cfg1 );

   my $cfg2 = Advanced::Config->new ($f)->copy_opts_from_cfg ( $cfg1 );
   dbug_ok ( (defined $cfg2), "Config Object created using copy cfg logic." );
   test_using_rules ( $cfg2 );

   DBUG_UNTIE_STDERR ();
   verify_ruleCfg_is_ReadOnly ( $rCfg );
   
   # Since I didn't count the test cases, must end my program
   # with a call to this method.  Can't do tests in END anymore!
   done_testing ();

   DBUG_LEAVE (0);
}

sub test_using_rules
{
   DBUG_ENTER_FUNC (@_);
   my $cfg  = shift;

   # DBUG_SET_FILTER_COLOR ( DBUG_FILTER_LEVEL_OTHER, "red" );

   DBUG_PRINT ("DBUG", '+'x60);
   $cfg->load_config ();
   DBUG_PRINT ("DBUG", '@'x60);

   # DBUG_SET_FILTER_COLOR ( DBUG_FILTER_LEVEL_OTHER, "black" );

   my $total = 0;
   foreach my $tag ( $cfg->find_tags () ) {
      if ( $tag =~ m/^tag_(.*)$/ ) {
	  my $expected = $1;
	  my $val = $cfg->get_value ( $tag );
	  dbug_cmp_ok ($val, "eq", $expected, "Tag '$tag' has correct value.");
	  ++$total;
      } else {
	  dbug_ok ( 0, "Expected tag '$tag'." );
      }
   }
   dbug_cmp_ok ( $total, "==", 5, "Got the expected number of tags!" );

   DBUG_VOID_RETURN ();
}

sub build_filename
{
   DBUG_ENTER_FUNC (@_);
   my $file  = shift;
   $file = File::Spec->catfile ("t", "config", $file);
   DBUG_RETURN ($file);
}

sub test_rules
{
   DBUG_ENTER_FUNC (@_);
   my $file = shift;

   my $ruleCfg = Advanced::Config->newDefineConfigRules ( $file );
   dbug_ok ( (defined $ruleCfg), "Rule Config Object created" );

   DBUG_PRINT ("DBUG", '='x60);

   # Testing rule config internals ...



( run in 2.376 seconds using v1.01-cache-2.11-cpan-9789f410c06 )