Advanced-Config

 view release on metacpan or  search on metacpan

t/40-validate-modifiers.t  view on Meta::CPAN

   DBUG_VOID_RETURN ();
}


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

# --------------------------------------
# Start of the main program!
# --------------------------------------
{
   # Turn fish on ...
   DBUG_PUSH ( $fish );

   DBUG_ENTER_FUNC (@ARGV);

   # Set for one of the test cases!
   $ENV{yuck} = 1;
   $ENV{Yams} = 1;

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

   my $ropts = Advanced::Config::Options::get_read_opts ( { Croak => 1, dbug_test_use_case_parse_override => 1} );
   my $gopts = Advanced::Config::Options::get_get_opts ( { } );
   # print_opts_hash ( "The Read Options", $ropts );
   # print_opts_hash ( "The Get Options",  $gopts );

   my $file = File::Spec->catfile ("t", "config", "40-validate-modifiers.cfg");
   my $cfg;
   eval {
      $cfg = Advanced::Config->new ($file, $ropts, $gopts);
      dbug_isa_ok ($cfg, 'Advanced::Config');
      my $ldr = $cfg->load_config ();
      dbug_ok (defined $ldr, "Advanced::Config contents have been loaded into memory!");
   };
   if ( $@ ) {
      unless (defined $cfg) {
         dbug_isa_ok ($cfg, 'Advanced::Config');
      }
      dbug_ok (0, "Advanced::Config contents have been loaded into memory!");
      DBUG_LEAVE (3);
   }

   # So can tell when the config file was loaded in fish ...
   DBUG_PRINT ("====", "%s", "="x50);

   print_opts_hash ( "The Read Options", $ropts );
   print_opts_hash ( "The Get Options",  $gopts );

   # Builds the hash to validate the config file against ...
   my ($total, $validate) = init_validation_hash ();

   my $val = $cfg->get_value ( "msg" );
   dbug_cmp_ok ( $val, 'eq', $validate->{msg}, "The test phrases are the same!");

   DBUG_PRINT ("----", "%s", "-"x50);

   my @sections = $cfg->find_sections ();
   my $cnt = @sections;
   dbug_is ($cnt, 1, "The config file doesn't define any sections!");

   my @tag_list = $cfg->find_tags ();
   $cnt = @tag_list;
   dbug_is ($cnt, $total, "Found the expected number of tags in config file ($total)");

   DBUG_PRINT ("----", "%s", "-"x50);

   $cnt = 0;
   foreach ( @tag_list ) {
      unless ( exists $validate->{$_} ) {
         dbug_ok (0, "Tag \"$_\" exists in the validation hash!");
         ++$cnt;
      }
   }
   dbug_is ($cnt, 0, "All tags were accounted for in the validation hash!");

   dbug_ok (1, "-"x60);

   foreach ( sort keys %{$validate} ) {
      my $val1 = $validate->{$_};
      my $val2 = $cfg->get_value ( $_ );
      my $val3 = (defined $val2) ? $val2 : "";
      my $chk  = (defined $val2) && $val1 eq $val2;
      dbug_ok ( $chk, "Validating tag \"$_\" matches config file.  ($val3)" );
      unless ( $chk ) {
         DBUG_PRINT ("ERROR", "Value should have been: %s", $val1);
      }
   }

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

# ====================================================================
# All tags defined in the config file must be initialized below!
# The config file is: t/config/40-validate-modifiers.cfg

# NOTE: No tag may have undef as a value!
#       That can't happen in this module if a tag is defined!
#       Undef means the tag doesn't exist instead!

sub init_validation_hash
{
   DBUG_ENTER_FUNC (@_);

   my $Msg  = "Be liberal in what you accept, and conservative in what you send.";
   my $aMsg = "liberal in what you accept, and conservative in what you send.";
   my $bMsg = "send.";
   my $cMsg = "Be liberal in what you accept, and conservative in what you";
   my $dMsg = "Be";

   my $a2Msg = "in what you accept, and conservative in what you send.";
   my $c2Msg = "Be liberal in what you accept, and conservative in what";
   my $e2Msg = "liberal";

   my $sub1 = $Msg;   $sub1 =~ s/in/by/;
   my $sub2 = $Msg;   $sub2 =~ s/in/by/g;



( run in 0.701 second using v1.01-cache-2.11-cpan-39bf76dae61 )