mtr_cases.pm 34.3 KB
Newer Older
unknown's avatar
unknown committed
1
# -*- cperl -*-
unknown's avatar
unknown committed
2
# Copyright (C) 2005-2006 MySQL AB
unknown's avatar
unknown committed
3
#
unknown's avatar
unknown committed
4 5 6
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
unknown's avatar
unknown committed
7
#
unknown's avatar
unknown committed
8 9 10 11
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
unknown's avatar
unknown committed
12
#
unknown's avatar
unknown committed
13 14 15
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
unknown's avatar
unknown committed
16 17 18 19 20

# This is a library file used by the Perl version of mysql-test-run,
# and is part of the translation of the Bourne shell script with the
# same name.

unknown's avatar
unknown committed
21
package mtr_cases;
unknown's avatar
unknown committed
22 23
use strict;

unknown's avatar
unknown committed
24 25 26
use base qw(Exporter);
our @EXPORT= qw(collect_option collect_test_cases);

27
use mtr_report;
28
use mtr_match;
29

unknown's avatar
unknown committed
30 31 32 33 34 35
# Options used for the collect phase
our $start_from;
our $print_testcases;
our $skip_rpl;
our $do_test;
our $skip_test;
36
our $skip_combinations;
37
our $binlog_format;
unknown's avatar
unknown committed
38 39 40 41 42
our $enable_disabled;
our $default_storage_engine;
our $opt_with_ndbcluster_only;
our $defaults_file;
our $defaults_extra_file;
43
our $reorder= 1;
44
our $quick_collect;
unknown's avatar
unknown committed
45 46 47 48

sub collect_option {
  my ($opt, $value)= @_;

49 50 51
  # Evaluate $opt as string to use "Getopt::Long::Callback legacy API"
  my $opt_name = "$opt";

unknown's avatar
unknown committed
52
  # Convert - to _ in option name
53
  $opt_name =~ s/-/_/g;
unknown's avatar
unknown committed
54
  no strict 'refs';
55
  ${$opt_name}= $value;
unknown's avatar
unknown committed
56
}
57

unknown's avatar
unknown committed
58
use File::Basename;
59
use File::Spec::Functions qw / splitdir /;
unknown's avatar
unknown committed
60 61
use IO::File();
use My::Config;
unknown's avatar
unknown committed
62
use My::Platform;
63
use My::Test;
64
use My::Find;
unknown's avatar
unknown committed
65

unknown's avatar
unknown committed
66
require "mtr_misc.pl";
unknown's avatar
unknown committed
67

unknown's avatar
unknown committed
68 69 70
# Precompiled regex's for tests to do or skip
my $do_test_reg;
my $skip_test_reg;
71

72 73 74 75
# Related to adding InnoDB plugin combinations
my $lib_innodb_plugin;
my $do_innodb_plugin;

76 77 78
# If "Quick collect", set to 1 once a test to run has been found.
my $some_test_found;

79 80
sub init_pattern {
  my ($from, $what)= @_;
unknown's avatar
unknown committed
81 82 83 84
  return undef unless defined $from;
  if ( $from =~ /^[a-z0-9\.]*$/ ) {
    # Does not contain any regex (except . that we allow as
    # separator betwen suite and testname), make the pattern match
85 86
    # beginning of string
    $from= "^$from";
unknown's avatar
unknown committed
87
    mtr_verbose("$what='$from'");
88
  }
unknown's avatar
unknown committed
89 90 91
  # Check that pattern is a valid regex
  eval { "" =~/$from/; 1 } or
    mtr_error("Invalid regex '$from' passed to $what\nPerl says: $@");
92 93 94 95
  return $from;
}


unknown's avatar
unknown committed
96 97
##############################################################################
#
unknown's avatar
unknown committed
98
#  Collect information about test cases to be run
unknown's avatar
unknown committed
99 100 101
#
##############################################################################

102
sub collect_test_cases ($$) {
103
  my $suites= shift; # Semicolon separated list of test suites
104
  my $opt_cases= shift;
unknown's avatar
unknown committed
105 106 107 108
  my $cases= []; # Array of hash(one hash for each testcase)

  $do_test_reg= init_pattern($do_test, "--do-test");
  $skip_test_reg= init_pattern($skip_test, "--skip-test");
109

110 111 112 113 114 115 116 117 118 119 120
  $lib_innodb_plugin=
    my_find_file($::basedir,
		 ["storage/innodb_plugin", "storage/innodb_plugin/.libs",
		  "lib/mysql/plugin", "lib/plugin"],
		 ["ha_innodb_plugin.dll", "ha_innodb_plugin.so",
		  "ha_innodb_plugin.sl"],
		 NOT_REQUIRED);
  $do_innodb_plugin= ($::mysql_version_id >= 50100 &&
		      !(IS_WINDOWS && $::opt_embedded_server) &&
		      $lib_innodb_plugin);

121 122
  foreach my $suite (split(",", $suites))
  {
123
    push(@$cases, collect_one_suite($suite, $opt_cases));
124
    last if $some_test_found;
125 126
  }

127
  if ( @$opt_cases )
128
  {
unknown's avatar
unknown committed
129
    # A list of tests was specified on the command line
130 131
    # Check that the tests specified was found
    # in at least one suite
132
    foreach my $test_name_spec ( @$opt_cases )
133 134
    {
      my $found= 0;
135
      my ($sname, $tname, $extension)= split_testname($test_name_spec);
136 137
      foreach my $test ( @$cases )
      {
138 139
	# test->{name} is always in suite.name format
	if ( $test->{name} =~ /.*\.$tname/ )
140 141
	{
	  $found= 1;
142
	  last;
143 144 145 146
	}
      }
      if ( not $found )
      {
147 148 149 150 151 152 153 154 155 156 157
	mtr_error("Could not find '$tname' in '$suites' suite(s)") unless $sname;
	# If suite was part of name, find it there
	my ($this_case) = collect_one_suite($sname, [ $tname ]);
	if ($this_case)
        {
	  push (@$cases, $this_case);
	}
	else
	{
	  mtr_error("Could not find '$tname' in '$sname' suite");
        }
158 159 160 161
      }
    }
  }

162
  if ( $reorder && !$quick_collect)
163 164 165 166 167 168
  {
    # Reorder the test cases in an order that will make them faster to run
    my %sort_criteria;

    # Make a mapping of test name to a string that represents how that test
    # should be sorted among the other tests.  Put the most important criterion
unknown's avatar
unknown committed
169
    # first, then a sub-criterion, then sub-sub-criterion, etc.
170 171 172 173
    foreach my $tinfo (@$cases)
    {
      my @criteria = ();

174 175 176 177 178 179 180 181
      #
      # Append the criteria for sorting, in order of importance.
      #
      push(@criteria, "ndb=" . ($tinfo->{'ndb_test'} ? "A" : "B"));
      # Group test with equal options together.
      # Ending with "~" makes empty sort later than filled
      my $opts= $tinfo->{'master_opt'} ? $tinfo->{'master_opt'} : [];
      push(@criteria, join("!", sort @{$opts}) . "~");
182

183
      $sort_criteria{$tinfo->{name}} = join(" ", @criteria);
184 185 186 187 188 189
    }

    @$cases = sort {
      $sort_criteria{$a->{'name'}} . $a->{'name'} cmp
	$sort_criteria{$b->{'name'}} . $b->{'name'}; } @$cases;

unknown's avatar
unknown committed
190 191 192 193 194 195 196 197 198 199 200
    # For debugging the sort-order
    # foreach my $tinfo (@$cases)
    # {
    #   print("$sort_criteria{$tinfo->{'name'}} -> \t$tinfo->{'name'}\n");
    # }

  }

  if (defined $print_testcases){
    print_testcases(@$cases);
    exit(1);
201 202 203 204 205 206
  }

  return $cases;

}

207 208 209 210 211 212 213 214 215 216 217 218 219 220 221

# Returns (suitename, testname, extension)
sub split_testname {
  my ($test_name)= @_;

  # Get rid of directory part and split name on .'s
  my @parts= split(/\./, basename($test_name));

  if (@parts == 1){
    # Only testname given, ex: alias
    return (undef , $parts[0], undef);
  } elsif (@parts == 2) {
    # Either testname.test or suite.testname given
    # Ex. main.alias or alias.test

unknown's avatar
unknown committed
222
    if ($parts[1] eq "test")
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
    {
      return (undef , $parts[0], $parts[1]);
    }
    else
    {
      return ($parts[0], $parts[1], undef);
    }

  } elsif (@parts == 3) {
    # Fully specified suitename.testname.test
    # ex main.alias.test
    return ( $parts[0], $parts[1], $parts[2]);
  }

  mtr_error("Illegal format of test name: $test_name");
}


241
sub collect_one_suite($)
242 243
{
  my $suite= shift;  # Test suite name
244
  my $opt_cases= shift;
unknown's avatar
unknown committed
245
  my @cases; # Array of hash
246 247

  mtr_verbose("Collecting: $suite");
unknown's avatar
unknown committed
248

249 250
  my $suitedir= "$::glob_mysql_test_dir"; # Default
  if ( $suite ne "main" )
unknown's avatar
unknown committed
251
  {
252 253 254
    # Allow suite to be path to "some dir" if $suite has at least
    # one directory part
    if ( -d $suite and splitdir($suite) > 1 ){
255
      $suitedir= $suite;
256 257
      mtr_report(" - from '$suitedir'");

258 259 260 261 262 263 264 265 266 267 268
    }
    else
    {
      $suitedir= my_find_dir($::basedir,
			     ["mysql-test/suite",
			      "mysql-test",
			      # Look in storage engine specific suite dirs
			      "storage/*/mysql-test-suites"
			     ],
			     [$suite]);
    }
269
    mtr_verbose("suitedir: $suitedir");
unknown's avatar
unknown committed
270 271
  }

272 273 274
  my $testdir= "$suitedir/t";
  my $resdir=  "$suitedir/r";

unknown's avatar
unknown committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300
  # Check if t/ exists
  if (-d $testdir){
    # t/ exists

    if ( -d $resdir )
    {
      # r/exists
    }
    else
    {
      # No r/, use t/ as result dir
      $resdir= $testdir;
    }

  }
  else {
    # No t/ dir => there can' be any r/ dir
    mtr_error("Can't have r/ dir without t/") if -d $resdir;

    # No t/ or r/ => use suitedir
    $resdir= $testdir= $suitedir;
  }

  mtr_verbose("testdir: $testdir");
  mtr_verbose("resdir: $resdir");

unknown's avatar
unknown committed
301
  # ----------------------------------------------------------------------
302
  # Build a hash of disabled testcases for this suite
unknown's avatar
unknown committed
303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
  # ----------------------------------------------------------------------
  my %disabled;
  if ( open(DISABLED, "$testdir/disabled.def" ) )
  {
    while ( <DISABLED> )
      {
        chomp;
        if ( /^\s*(\S+)\s*:\s*(.*?)\s*$/ )
          {
            $disabled{$1}= $2;
          }
      }
    close DISABLED;
  }

318 319 320 321 322
  # Read suite.opt file
  my $suite_opt_file=  "$testdir/suite.opt";
  my $suite_opts= [];
  if ( -f $suite_opt_file )
  {
unknown's avatar
unknown committed
323
    $suite_opts= opts_from_file($suite_opt_file);
324 325
  }

326
  if ( @$opt_cases )
unknown's avatar
unknown committed
327
  {
328
    # Collect in specified order
329
    foreach my $test_name_spec ( @$opt_cases )
330
    {
331
      my ($sname, $tname, $extension)= split_testname($test_name_spec);
unknown's avatar
unknown committed
332

333 334 335 336
      # The test name parts have now been defined
      #print "  suite_name: $sname\n";
      #print "  tname:      $tname\n";
      #print "  extension:  $extension\n";
unknown's avatar
unknown committed
337

338 339
      # Check cirrect suite if suitename is defined
      next if (defined $sname and $suite ne $sname);
unknown's avatar
unknown committed
340

341
      if ( defined $extension )
unknown's avatar
unknown committed
342
      {
343 344 345
	my $full_name= "$testdir/$tname.$extension";
	# Extension was specified, check if the test exists
        if ( ! -f $full_name)
unknown's avatar
unknown committed
346
        {
347 348 349 350 351 352
	  # This is only an error if suite was specified, otherwise it
	  # could exist in another suite
          mtr_error("Test '$full_name' was not found in suite '$sname'")
	    if $sname;

	  next;
unknown's avatar
unknown committed
353 354 355
        }
      }
      else
unknown's avatar
unknown committed
356
      {
unknown's avatar
unknown committed
357 358 359
	# No extension was specified, use default
	$extension= "test";
	my $full_name= "$testdir/$tname.$extension";
unknown's avatar
unknown committed
360

361
	# Test not found here, could exist in other suite
unknown's avatar
unknown committed
362
	next if ( ! -f $full_name );
unknown's avatar
unknown committed
363
      }
unknown's avatar
unknown committed
364

unknown's avatar
unknown committed
365 366 367 368 369 370 371 372 373
      push(@cases,
	   collect_one_test_case($suitedir,
				 $testdir,
				 $resdir,
				 $suite,
				 $tname,
				 "$tname.$extension",
				 \%disabled,
				 $suite_opts));
unknown's avatar
unknown committed
374 375 376 377
    }
  }
  else
  {
378 379
    opendir(TESTDIR, $testdir) or mtr_error("Can't open dir \"$testdir\": $!");

380 381
    foreach my $elem ( sort readdir(TESTDIR) )
    {
unknown's avatar
unknown committed
382
      my $tname= mtr_match_extension($elem, 'test');
unknown's avatar
unknown committed
383

unknown's avatar
unknown committed
384
      next unless defined $tname;
385

386
      # Skip tests that does not match the --do-test= filter
unknown's avatar
unknown committed
387 388 389 390 391 392 393 394 395 396 397
      next if ($do_test_reg and not $tname =~ /$do_test_reg/o);

      push(@cases,
	   collect_one_test_case($suitedir,
				 $testdir,
				 $resdir,
				 $suite,
				 $tname,
				 $elem,
				 \%disabled,
				 $suite_opts));
unknown's avatar
unknown committed
398 399 400 401
    }
    closedir TESTDIR;
  }

402 403 404
  #  Return empty list if no testcases found
  return if (@cases == 0);

405
  # ----------------------------------------------------------------------
406 407
  # Read combinations for this suite and build testcases x combinations
  # if any combinations exists
408
  # ----------------------------------------------------------------------
409
  if ( ! $skip_combinations && ! $quick_collect )
410 411 412 413 414
  {
    my @combinations;
    my $combination_file= "$suitedir/combinations";
    #print "combination_file: $combination_file\n";
    if (@::opt_combinations)
415
    {
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
      # take the combination from command-line
      mtr_verbose("Take the combination from command line");
      foreach my $combination (@::opt_combinations) {
	my $comb= {};
	$comb->{name}= $combination;
	push(@{$comb->{comb_opt}}, $combination);
	push(@combinations, $comb);
      }
    }
    elsif (-f $combination_file )
    {
      # Read combinations file in my.cnf format
      mtr_verbose("Read combinations file");
      my $config= My::Config->new($combination_file);
      foreach my $group ($config->groups()) {
	my $comb= {};
	$comb->{name}= $group->name();
        foreach my $option ( $group->options() ) {
434
	  push(@{$comb->{comb_opt}}, $option->option());
435 436
	}
	push(@combinations, $comb);
437 438
      }
    }
439 440 441

    if (@combinations)
    {
442
      print " - adding combinations for $suite\n";
443 444 445 446
      #print_testcases(@cases);

      my @new_cases;
      foreach my $comb (@combinations)
447
      {
448 449 450
	foreach my $test (@cases)
	{

451 452
	  next if ( $test->{'skip'} );

453 454 455 456 457 458
	  # Skip this combination if the values it provides
	  # already are set in master_opt or slave_opt
	  if (My::Options::is_set($test->{master_opt}, $comb->{comb_opt}) &&
	      My::Options::is_set($test->{slave_opt}, $comb->{comb_opt}) ){
	    next;
	  }
459

460
	  # Copy test options
461
	  my $new_test= My::Test->new();
462 463 464 465 466 467 468 469 470 471 472 473
	  while (my ($key, $value) = each(%$test)) {
	    if (ref $value eq "ARRAY") {
	      push(@{$new_test->{$key}}, @$value);
	    } else {
	      $new_test->{$key}= $value;
	    }
	  }

	  # Append the combination options to master_opt and slave_opt
	  push(@{$new_test->{master_opt}}, @{$comb->{comb_opt}});
	  push(@{$new_test->{slave_opt}}, @{$comb->{comb_opt}});

unknown's avatar
unknown committed
474
	  # Add combination name short name
475 476 477 478 479 480
	  $new_test->{combination}= $comb->{name};

	  # Add the new test to new test cases list
	  push(@new_cases, $new_test);
	}
      }
481 482 483 484 485 486 487 488 489 490 491 492

      # Add the plain test if it was not already added
      # as part of a combination
      my %added;
      foreach my $new_test (@new_cases){
	$added{$new_test->{name}}= 1;
      }
      foreach my $test (@cases){
	push(@new_cases, $test) unless $added{$test->{name}};
      }


493 494 495 496
      #print_testcases(@new_cases);
      @cases= @new_cases;
      #print_testcases(@cases);
    }
497
  }
498 499 500 501

  # ----------------------------------------------------------------------
  # Testing InnoDB plugin.
  # ----------------------------------------------------------------------
502
  if ($do_innodb_plugin)
503 504
  {
    my @new_cases;
505
    my $sep= (IS_WINDOWS) ? ';' : ':';
506 507 508

    foreach my $test (@cases)
    {
509 510 511
      next if (!$test->{'innodb_test'});
      # If skipped due to no builtin innodb, we can still run it with plugin
      next if ($test->{'skip'} && $test->{comment} ne "No innodb support");
512 513
      # Exceptions
      next if ($test->{'name'} eq 'main.innodb'); # Failed with wrong errno (fk)
514
      next if ($test->{'name'} eq 'main.index_merge_innodb'); # Explain diff
515 516 517 518 519 520
      # innodb_file_per_table is rw with innodb_plugin
      next if ($test->{'name'} eq 'sys_vars.innodb_file_per_table_basic');
      # innodb_lock_wait_timeout is rw with innodb_plugin
      next if ($test->{'name'} eq 'sys_vars.innodb_lock_wait_timeout_basic');
      # Diff around innodb_thread_concurrency variable
      next if ($test->{'name'} eq 'sys_vars.innodb_thread_concurrency_basic');
521
      # Can't work with InnoPlug. Test framework needs to be re-designed.
522
      next if ($test->{'name'} eq 'main.innodb_bug46000');
523 524
      # Fails with innodb plugin
      next if ($test->{'name'} eq 'main.innodb-autoinc');
525 526
      # Fails with innodb plugin: r6185 Testcases changes not included
      next if ($test->{'name'} eq 'main.innodb_bug44369');
527 528 529 530 531 532 533 534 535 536
      # Copy test options
      my $new_test= My::Test->new();
      while (my ($key, $value) = each(%$test))
      {
        if (ref $value eq "ARRAY")
        {
          push(@{$new_test->{$key}}, @$value);
        }
        else
        {
537
          $new_test->{$key}= $value unless ($key eq 'skip');
538 539 540
        }
      }
      my $plugin_filename= basename($lib_innodb_plugin);
541
      my $plugin_list= "innodb=$plugin_filename" . $sep . "innodb_locks=$plugin_filename";
542 543
      push(@{$new_test->{master_opt}}, '--ignore-builtin-innodb');
      push(@{$new_test->{master_opt}}, '--plugin-dir=' . dirname($lib_innodb_plugin));
544
      push(@{$new_test->{master_opt}}, "--plugin_load=$plugin_list");
545 546
      push(@{$new_test->{slave_opt}}, '--ignore-builtin-innodb');
      push(@{$new_test->{slave_opt}}, '--plugin-dir=' . dirname($lib_innodb_plugin));
547
      push(@{$new_test->{slave_opt}}, "--plugin_load=$plugin_list");
548 549
      if ($new_test->{combination})
      {
550
        $new_test->{combination}.= '+innodb_plugin';
551 552 553
      }
      else
      {
554
        $new_test->{combination}= 'innodb_plugin';
555 556 557 558 559 560 561 562
      }
      push(@new_cases, $new_test);
    }
    push(@cases, @new_cases);
  }
  # ----------------------------------------------------------------------
  # End of testing InnoDB plugin.
  # ----------------------------------------------------------------------
563 564 565 566 567 568 569
  optimize_cases(\@cases);
  #print_testcases(@cases);

  return @cases;
}


unknown's avatar
unknown committed
570

571 572 573 574 575 576 577 578 579 580
#
# Loop through all test cases
# - optimize which test to run by skipping unnecessary ones
# - update settings if necessary
#
sub optimize_cases {
  my ($cases)= @_;

  foreach my $tinfo ( @$cases )
  {
581 582 583
    # Skip processing if already marked as skipped
    next if $tinfo->{skip};

unknown's avatar
unknown committed
584 585 586 587 588
    # =======================================================
    # If a special binlog format was selected with
    # --mysqld=--binlog-format=x, skip all test that does not
    # support it
    # =======================================================
589
    #print "binlog_format: $binlog_format\n";
unknown's avatar
unknown committed
590
    if (defined $binlog_format )
591 592
    {
      # =======================================================
unknown's avatar
unknown committed
593
      # Fixed --binlog-format=x specified on command line
594
      # =======================================================
unknown's avatar
unknown committed
595
      if ( defined $tinfo->{'binlog_formats'} )
596
      {
597 598
	#print "binlog_formats: ". join(", ", @{$tinfo->{binlog_formats}})."\n";

unknown's avatar
unknown committed
599 600
	# The test supports different binlog formats
	# check if the selected one is ok
601
	my $supported=
unknown's avatar
unknown committed
602
	  grep { $_ eq $binlog_format } @{$tinfo->{'binlog_formats'}};
603 604 605 606
	if ( !$supported )
	{
	  $tinfo->{'skip'}= 1;
	  $tinfo->{'comment'}=
unknown's avatar
unknown committed
607
	    "Doesn't support --binlog-format='$binlog_format'";
608 609
	}
      }
unknown's avatar
unknown committed
610 611 612
    }
    else
    {
613
      # =======================================================
unknown's avatar
unknown committed
614
      # Use dynamic switching of binlog format
615
      # =======================================================
unknown's avatar
unknown committed
616 617 618 619 620 621

      # Get binlog-format used by this test from master_opt
      my $test_binlog_format;
      foreach my $opt ( @{$tinfo->{master_opt}} ) {
	$test_binlog_format=
	  mtr_match_prefix($opt, "--binlog-format=") || $test_binlog_format;
622 623
      }

624 625
      if (defined $test_binlog_format and
	  defined $tinfo->{binlog_formats} )
unknown's avatar
unknown committed
626
      {
627 628 629
	my $supported=
	  grep { $_ eq $test_binlog_format } @{$tinfo->{'binlog_formats'}};
	if ( !$supported )
unknown's avatar
unknown committed
630
	{
631 632 633 634
	  $tinfo->{'skip'}= 1;
	  $tinfo->{'comment'}=
	    "Doesn't support --binlog-format='$test_binlog_format'";
	  next;
unknown's avatar
unknown committed
635 636
	}
      }
637
    }
638 639 640 641 642

    # =======================================================
    # Check that engine selected by
    # --default-storage-engine=<engine> is supported
    # =======================================================
643 644
    my %builtin_engines = ('myisam' => 1, 'memory' => 1);

645 646 647 648 649 650
    foreach my $opt ( @{$tinfo->{master_opt}} ) {
      my $default_engine=
	mtr_match_prefix($opt, "--default-storage-engine=");

      if (defined $default_engine){

651 652 653 654 655 656 657 658 659 660 661 662
	#print " $tinfo->{name}\n";
	#print " - The test asked to use '$default_engine'\n";

	#my $engine_value= $::mysqld_variables{$default_engine};
	#print " - The mysqld_variables says '$engine_value'\n";

	if ( ! exists $::mysqld_variables{$default_engine} and
	     ! exists $builtin_engines{$default_engine} )
	{
	  $tinfo->{'skip'}= 1;
	  $tinfo->{'comment'}=
	    "'$default_engine' not supported";
663
	}
664 665 666 667 668

	$tinfo->{'ndb_test'}= 1
	  if ( $default_engine =~ /^ndb/i );
	$tinfo->{'innodb_test'}= 1
	  if ( $default_engine =~ /^innodb/i );
669 670
      }
    }
671 672 673 674 675 676

    if ($quick_collect && ! $tinfo->{'skip'})
    {
      $some_test_found= 1;
      return;
    }
677
  }
unknown's avatar
unknown committed
678 679 680 681
}


#
unknown's avatar
unknown committed
682 683
# Read options from the given opt file and append them as an array
# to $tinfo->{$opt_name}
unknown's avatar
unknown committed
684
#
unknown's avatar
unknown committed
685 686
sub process_opts_file {
  my ($tinfo, $opt_file, $opt_name)= @_;
unknown's avatar
unknown committed
687

unknown's avatar
unknown committed
688
  if ( -f $opt_file )
unknown's avatar
unknown committed
689
  {
unknown's avatar
unknown committed
690
    my $opts= opts_from_file($opt_file);
unknown's avatar
unknown committed
691

unknown's avatar
unknown committed
692
    foreach my $opt ( @$opts )
693 694
    {
      my $value;
unknown's avatar
unknown committed
695

696 697 698
      # The opt file is used both to send special options to the mysqld
      # as well as pass special test case specific options to this
      # script
unknown's avatar
unknown committed
699

700 701 702 703 704 705
      $value= mtr_match_prefix($opt, "--timezone=");
      if ( defined $value )
      {
	$tinfo->{'timezone'}= $value;
	next;
      }
unknown's avatar
unknown committed
706

707 708 709 710 711 712 713 714
      $value= mtr_match_prefix($opt, "--result-file=");
      if ( defined $value )
      {
	# Specifies the file mysqltest should compare
	# output against
	$tinfo->{'result_file'}= "r/$value.result";
	next;
      }
unknown's avatar
unknown committed
715

unknown's avatar
unknown committed
716 717 718 719 720 721 722 723
      $value= mtr_match_prefix($opt, "--config-file-template=");
      if ( defined $value)
      {
	# Specifies the configuration file to use for this test
	$tinfo->{'template_path'}= dirname($tinfo->{path})."/$value";
	next;
      }

724 725 726 727
      # If we set default time zone, remove the one we have
      $value= mtr_match_prefix($opt, "--default-time-zone=");
      if ( defined $value )
      {
728 729 730
	# Set timezone for this test case to something different
	$tinfo->{'timezone'}= "GMT-8";
	# Fallthrough, add the --default-time-zone option
731
      }
unknown's avatar
unknown committed
732

733 734 735 736 737 738 739 740
      # The --restart option forces a restart even if no special
      # option is set. If the options are the same as next testcase
      # there is no need to restart after the testcase
      # has completed
      if ( $opt eq "--force-restart" )
      {
	$tinfo->{'force_restart'}= 1;
	next;
unknown's avatar
unknown committed
741
      }
unknown's avatar
unknown committed
742

743
      # Ok, this was a real option, add it
unknown's avatar
unknown committed
744
      push(@{$tinfo->{$opt_name}}, $opt);
unknown's avatar
unknown committed
745 746
    }
  }
unknown's avatar
unknown committed
747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763
}

##############################################################################
#
#  Collect information about a single test case
#
##############################################################################

sub collect_one_test_case {
  my $suitedir=   shift;
  my $testdir=    shift;
  my $resdir=     shift;
  my $suitename=  shift;
  my $tname=      shift;
  my $filename=   shift;
  my $disabled=   shift;
  my $suite_opts= shift;
unknown's avatar
unknown committed
764

unknown's avatar
unknown committed
765 766 767 768 769 770 771 772 773
  #print "collect_one_test_case\n";
  #print " suitedir: $suitedir\n";
  #print " testdir: $testdir\n";
  #print " resdir: $resdir\n";
  #print " suitename: $suitename\n";
  #print " tname: $tname\n";
  #print " filename: $filename\n";

  # ----------------------------------------------------------------------
774
  # Check --start-from
unknown's avatar
unknown committed
775
  # ----------------------------------------------------------------------
776
  if ( $start_from )
unknown's avatar
unknown committed
777
  {
778 779 780 781 782 783 784 785 786
    # start_from can be specified as [suite.].testname_prefix
    my ($suite, $test, $ext)= split_testname($start_from);

    if ( $suite and $suitename lt $suite){
      return; # Skip silently
    }
    if ( $tname lt $test ){
      return; # Skip silently
    }
unknown's avatar
unknown committed
787
  }
unknown's avatar
unknown committed
788

unknown's avatar
unknown committed
789 790 791
  # ----------------------------------------------------------------------
  # Set defaults
  # ----------------------------------------------------------------------
792 793 794
  my $tinfo= My::Test->new
    (
     name          => "$suitename.$tname",
Serge Kozlov's avatar
Serge Kozlov committed
795
     shortname     => $tname,
796
     path          => "$testdir/$filename",
unknown's avatar
unknown committed
797

798
    );
unknown's avatar
unknown committed
799

800 801 802 803 804 805 806
  my $result_file= "$resdir/$tname.result";
  if (-f $result_file) {
    # Allow nonexistsing result file
    # in that case .test must issue "exit" otherwise test
    # should fail by default
    $tinfo->{result_file}= $result_file;
  }
807 808 809 810 811 812
  else {
    # No .result file exist
    # Remember the path  where it should be
    # saved in case of --record
    $tinfo->{record_file}= $result_file;
  }
813

unknown's avatar
unknown committed
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838
  # ----------------------------------------------------------------------
  # Skip some tests but include in list, just mark them as skipped
  # ----------------------------------------------------------------------
  if ( $skip_test_reg and $tname =~ /$skip_test_reg/o )
  {
    $tinfo->{'skip'}= 1;
    return $tinfo;
  }

  # ----------------------------------------------------------------------
  # Check for disabled tests
  # ----------------------------------------------------------------------
  my $marked_as_disabled= 0;
  if ( $disabled->{$tname} )
  {
    # Test was marked as disabled in suites disabled.def file
    $marked_as_disabled= 1;
    $tinfo->{'comment'}= $disabled->{$tname};
  }

  my $disabled_file= "$testdir/$tname.disabled";
  if ( -f $disabled_file )
  {
    $marked_as_disabled= 1;
    $tinfo->{'comment'}= mtr_fromfile($disabled_file);
unknown's avatar
unknown committed
839 840
  }

unknown's avatar
unknown committed
841
  if ( $marked_as_disabled )
unknown's avatar
unknown committed
842
  {
unknown's avatar
unknown committed
843 844 845 846 847 848 849 850 851 852 853 854
    if ( $enable_disabled )
    {
      # User has selected to run all disabled tests
      mtr_report(" - $tinfo->{name} wil be run although it's been disabled\n",
		 "  due to '$tinfo->{comment}'");
    }
    else
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'disable'}= 1;   # Sub type of 'skip'
      return $tinfo;
    }
unknown's avatar
unknown committed
855 856
  }

unknown's avatar
unknown committed
857 858 859 860 861 862
  # ----------------------------------------------------------------------
  # Append suite extra options to both master and slave
  # ----------------------------------------------------------------------
  push(@{$tinfo->{'master_opt'}}, @$suite_opts);
  push(@{$tinfo->{'slave_opt'}}, @$suite_opts);

863 864 865 866 867 868 869 870
  #-----------------------------------------------------------------------
  # Check for test specific config file
  #-----------------------------------------------------------------------
  my $test_cnf_file= "$testdir/$tname.cnf";
  if ( -f $test_cnf_file) {
    # Specifies the configuration file to use for this test
    $tinfo->{'template_path'}= $test_cnf_file;
  }
unknown's avatar
unknown committed
871

872 873 874 875 876 877 878 879 880
  # ----------------------------------------------------------------------
  # Check for test specific config file
  # ----------------------------------------------------------------------
  my $test_cnf_file= "$testdir/$tname.cnf";
  if ( -f $test_cnf_file ) {
    # Specifies the configuration file to use for this test
    $tinfo->{'template_path'}= $test_cnf_file;
  }

unknown's avatar
unknown committed
881 882 883 884
  # ----------------------------------------------------------------------
  # master sh
  # ----------------------------------------------------------------------
  my $master_sh= "$testdir/$tname-master.sh";
unknown's avatar
unknown committed
885 886
  if ( -f $master_sh )
  {
unknown's avatar
unknown committed
887
    if ( IS_WIN32PERL )
unknown's avatar
unknown committed
888 889
    {
      $tinfo->{'skip'}= 1;
unknown's avatar
unknown committed
890
      $tinfo->{'comment'}= "No tests with sh scripts on Windows";
unknown's avatar
unknown committed
891
      return $tinfo;
unknown's avatar
unknown committed
892 893 894 895 896 897 898
    }
    else
    {
      $tinfo->{'master_sh'}= $master_sh;
    }
  }

unknown's avatar
unknown committed
899 900 901 902
  # ----------------------------------------------------------------------
  # slave sh
  # ----------------------------------------------------------------------
  my $slave_sh= "$testdir/$tname-slave.sh";
unknown's avatar
unknown committed
903 904
  if ( -f $slave_sh )
  {
unknown's avatar
unknown committed
905
    if ( IS_WIN32PERL )
unknown's avatar
unknown committed
906 907
    {
      $tinfo->{'skip'}= 1;
unknown's avatar
unknown committed
908
      $tinfo->{'comment'}= "No tests with sh scripts on Windows";
unknown's avatar
unknown committed
909
      return $tinfo;
unknown's avatar
unknown committed
910 911 912 913 914 915 916
    }
    else
    {
      $tinfo->{'slave_sh'}= $slave_sh;
    }
  }

unknown's avatar
unknown committed
917 918 919 920 921 922 923 924 925 926
  # ----------------------------------------------------------------------
  # <tname>.slave-mi
  # ----------------------------------------------------------------------
  mtr_error("$tname: slave-mi not supported anymore")
    if ( -f "$testdir/$tname.slave-mi");


  tags_from_test_file($tinfo,"$testdir/${tname}.test");

  if ( defined $default_storage_engine )
unknown's avatar
unknown committed
927
  {
unknown's avatar
unknown committed
928 929 930 931 932 933 934 935
    # Different default engine is used
    # tag test to require that engine
    $tinfo->{'ndb_test'}= 1
      if ( $default_storage_engine =~ /^ndb/i );

    $tinfo->{'innodb_test'}= 1
      if ( $default_storage_engine =~ /^innodb/i );

unknown's avatar
unknown committed
936 937
  }

unknown's avatar
unknown committed
938
  if ( $tinfo->{'big_test'} and ! $::opt_big_test )
unknown's avatar
unknown committed
939
  {
unknown's avatar
unknown committed
940
    $tinfo->{'skip'}= 1;
941
    $tinfo->{'comment'}= "Test needs 'big-test' option";
unknown's avatar
unknown committed
942
    return $tinfo
unknown's avatar
unknown committed
943 944
  }

unknown's avatar
unknown committed
945
  if ( $tinfo->{'need_debug'} && ! $::debug_compiled_binaries )
unknown's avatar
unknown committed
946
  {
unknown's avatar
unknown committed
947
    $tinfo->{'skip'}= 1;
948
    $tinfo->{'comment'}= "Test needs debug binaries";
unknown's avatar
unknown committed
949
    return $tinfo
unknown's avatar
unknown committed
950 951
  }

unknown's avatar
unknown committed
952
  if ( $tinfo->{'ndb_test'} )
unknown's avatar
unknown committed
953
  {
unknown's avatar
unknown committed
954
    # This is a NDB test
955
    if ( $::opt_skip_ndbcluster == 2 )
unknown's avatar
unknown committed
956
    {
unknown's avatar
unknown committed
957
      # Ndb is not supported, skip it
unknown's avatar
unknown committed
958
      $tinfo->{'skip'}= 1;
unknown's avatar
unknown committed
959 960
      $tinfo->{'comment'}= "No ndbcluster support";
      return $tinfo;
unknown's avatar
unknown committed
961
    }
unknown's avatar
unknown committed
962
    elsif ( $::opt_skip_ndbcluster )
unknown's avatar
unknown committed
963
    {
unknown's avatar
unknown committed
964
      # All ndb test's should be skipped
unknown's avatar
unknown committed
965
      $tinfo->{'skip'}= 1;
unknown's avatar
unknown committed
966 967
      $tinfo->{'comment'}= "No ndbcluster tests(--skip-ndbcluster)";
      return $tinfo;
unknown's avatar
unknown committed
968 969 970 971
    }
  }
  else
  {
unknown's avatar
unknown committed
972 973
    # This is not a ndb test
    if ( $opt_with_ndbcluster_only )
unknown's avatar
unknown committed
974
    {
unknown's avatar
unknown committed
975
      # Only the ndb test should be run, all other should be skipped
unknown's avatar
unknown committed
976
      $tinfo->{'skip'}= 1;
unknown's avatar
unknown committed
977 978
      $tinfo->{'comment'}= "Only ndbcluster tests";
      return $tinfo;
unknown's avatar
unknown committed
979
    }
unknown's avatar
unknown committed
980
  }
unknown's avatar
unknown committed
981

Magnus Svensson's avatar
Merge  
Magnus Svensson committed
982 983
  if ($tinfo->{'federated_test'})
  {
984
    # This is a test that needs federated, enable it
Magnus Svensson's avatar
Merge  
Magnus Svensson committed
985 986 987 988
    push(@{$tinfo->{'master_opt'}}, "--loose-federated");
    push(@{$tinfo->{'slave_opt'}}, "--loose-federated");
  }

unknown's avatar
unknown committed
989 990
  if ( $tinfo->{'innodb_test'} )
  {
991
    # This is a test that needs innodb
992 993
    if ( $::mysqld_variables{'innodb'} eq "OFF" ||
         ! exists $::mysqld_variables{'innodb'} )
unknown's avatar
unknown committed
994
    {
unknown's avatar
unknown committed
995
      # innodb is not supported, skip it
unknown's avatar
unknown committed
996
      $tinfo->{'skip'}= 1;
997 998
      # This comment is checked for running with innodb plugin (see above),
      # please keep that in mind if changing the text.
unknown's avatar
unknown committed
999
      $tinfo->{'comment'}= "No innodb support";
1000 1001
      # But continue processing if we may run it with innodb plugin
      return $tinfo unless $do_innodb_plugin;
unknown's avatar
unknown committed
1002
    }
unknown's avatar
unknown committed
1003 1004 1005 1006 1007 1008
  }
  else
  {
    push(@{$tinfo->{'master_opt'}}, "--loose-skip-innodb");
    push(@{$tinfo->{'slave_opt'}}, "--loose-skip-innodb");
  }
unknown's avatar
unknown committed
1009

unknown's avatar
unknown committed
1010 1011 1012
  if ( $tinfo->{'need_binlog'} )
  {
    if (grep(/^--skip-log-bin/,  @::opt_extra_mysqld_opt) )
unknown's avatar
unknown committed
1013 1014
    {
      $tinfo->{'skip'}= 1;
1015
      $tinfo->{'comment'}= "Test needs binlog";
unknown's avatar
unknown committed
1016
      return $tinfo;
unknown's avatar
unknown committed
1017
    }
unknown's avatar
unknown committed
1018 1019 1020 1021 1022 1023 1024 1025
  }
  else
  {
    # Test does not need binlog, add --skip-binlog to
    # the options used when starting
    push(@{$tinfo->{'master_opt'}}, "--loose-skip-log-bin");
    push(@{$tinfo->{'slave_opt'}}, "--loose-skip-log-bin");
  }
unknown's avatar
unknown committed
1026

unknown's avatar
unknown committed
1027 1028 1029
  if ( $tinfo->{'rpl_test'} )
  {
    if ( $skip_rpl )
unknown's avatar
unknown committed
1030 1031
    {
      $tinfo->{'skip'}= 1;
unknown's avatar
unknown committed
1032 1033
      $tinfo->{'comment'}= "No replication tests(--skip-rpl)";
      return $tinfo;
1034
    }
unknown's avatar
unknown committed
1035
  }
1036

1037 1038 1039 1040 1041 1042 1043 1044 1045 1046
  if ( $::opt_embedded_server )
  {
    if ( $tinfo->{'not_embedded'} )
    {
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "Not run for embedded server";
      return $tinfo;
    }
  }

1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057
  if ( $tinfo->{'need_ssl'} )
  {
    # This is a test that needs ssl
    if ( ! $::opt_ssl_supported ) {
      # SSL is not supported, skip it
      $tinfo->{'skip'}= 1;
      $tinfo->{'comment'}= "No SSL support";
      return $tinfo;
    }
  }

unknown's avatar
unknown committed
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
  # ----------------------------------------------------------------------
  # Find config file to use if not already selected in <testname>.opt file
  # ----------------------------------------------------------------------
  if (defined $defaults_file) {
    # Using same config file for all tests
    $tinfo->{template_path}= $defaults_file;
  }
  elsif (! $tinfo->{template_path} )
  {
    my $config= "$suitedir/my.cnf";
    if (! -f $config )
1069
    {
1070
      # assume default.cnf will be used
unknown's avatar
unknown committed
1071
      $config= "include/default_my.cnf";
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082

      # Suite has no config, autodetect which one to use
      if ( $tinfo->{rpl_test} ){
	$config= "suite/rpl/my.cnf";
	if ( $tinfo->{ndb_test} ){
	  $config= "suite/rpl_ndb/my.cnf";
	}
      }
      elsif ( $tinfo->{ndb_test} ){
	$config= "suite/ndb/my.cnf";
      }
1083
    }
unknown's avatar
unknown committed
1084 1085
    $tinfo->{template_path}= $config;
  }
1086

unknown's avatar
unknown committed
1087 1088 1089
  # Set extra config file to use
  if (defined $defaults_extra_file) {
    $tinfo->{extra_template_path}= $defaults_extra_file;
unknown's avatar
unknown committed
1090
  }
unknown's avatar
unknown committed
1091

1092 1093 1094 1095 1096 1097
  # ----------------------------------------------------------------------
  # Append mysqld extra options to both master and slave
  # ----------------------------------------------------------------------
  push(@{$tinfo->{'master_opt'}}, @::opt_extra_mysqld_opt);
  push(@{$tinfo->{'slave_opt'}}, @::opt_extra_mysqld_opt);

1098 1099 1100 1101 1102 1103 1104 1105 1106 1107
  # ----------------------------------------------------------------------
  # Add master opts, extra options only for master
  # ----------------------------------------------------------------------
  process_opts_file($tinfo, "$testdir/$tname-master.opt", 'master_opt');

  # ----------------------------------------------------------------------
  # Add slave opts, list of extra option only for slave
  # ----------------------------------------------------------------------
  process_opts_file($tinfo, "$testdir/$tname-slave.opt", 'slave_opt');

unknown's avatar
unknown committed
1108
  return $tinfo;
unknown's avatar
unknown committed
1109 1110 1111
}


unknown's avatar
unknown committed
1112 1113
# List of tags in the .test files that if found should set
# the specified value in "tinfo"
unknown's avatar
unknown committed
1114
my @tags=
unknown's avatar
unknown committed
1115
(
unknown's avatar
unknown committed
1116 1117 1118
 ["include/have_binlog_format_row.inc", "binlog_formats", ["row"]],
 ["include/have_binlog_format_statement.inc", "binlog_formats", ["statement"]],
 ["include/have_binlog_format_mixed.inc", "binlog_formats", ["mixed"]],
1119
 ["include/have_binlog_format_mixed_or_row.inc",
unknown's avatar
unknown committed
1120
  "binlog_formats", ["mixed", "row"]],
1121
 ["include/have_binlog_format_mixed_or_statement.inc",
unknown's avatar
unknown committed
1122
  "binlog_formats", ["mixed", "statement"]],
1123
 ["include/have_binlog_format_row_or_statement.inc",
unknown's avatar
unknown committed
1124 1125 1126 1127 1128
  "binlog_formats", ["row", "statement"]],

 ["include/have_log_bin.inc", "need_binlog", 1],

 ["include/have_innodb.inc", "innodb_test", 1],
unknown's avatar
unknown committed
1129 1130
 ["include/big_test.inc", "big_test", 1],
 ["include/have_debug.inc", "need_debug", 1],
1131
 ["include/have_ndb.inc", "ndb_test", 1],
1132
 ["include/have_multi_ndb.inc", "ndb_test", 1],
unknown's avatar
unknown committed
1133 1134
 ["include/master-slave.inc", "rpl_test", 1],
 ["include/ndb_master-slave.inc", "rpl_test", 1],
1135
 ["include/ndb_master-slave.inc", "ndb_test", 1],
Magnus Svensson's avatar
Merge  
Magnus Svensson committed
1136
 ["federated.inc", "federated_test", 1],
1137
 ["include/not_embedded.inc", "not_embedded", 1],
1138
 ["include/have_ssl.inc", "need_ssl", 1],
unknown's avatar
unknown committed
1139 1140
);

unknown's avatar
unknown committed
1141 1142

sub tags_from_test_file {
unknown's avatar
unknown committed
1143 1144 1145 1146 1147 1148 1149
  my $tinfo= shift;
  my $file= shift;
  #mtr_verbose("$file");
  my $F= IO::File->new($file) or mtr_error("can't open file \"$file\": $!");

  while ( my $line= <$F> )
  {
1150 1151 1152 1153

    # Skip line if it start's with #
    next if ( $line =~ /^#/ );

unknown's avatar
unknown committed
1154 1155 1156 1157 1158
    # Match this line against tag in "tags" array
    foreach my $tag (@tags)
    {
      if ( index($line, $tag->[0]) >= 0 )
      {
unknown's avatar
unknown committed
1159 1160
	# Tag matched, assign value to "tinfo"
	$tinfo->{"$tag->[1]"}= $tag->[2];
unknown's avatar
unknown committed
1161 1162 1163 1164
      }
    }

    # If test sources another file, open it as well
1165 1166
    if ( $line =~ /^\-\-([[:space:]]*)source(.*)$/ or
	 $line =~ /^([[:space:]]*)source(.*);$/ )
unknown's avatar
unknown committed
1167 1168 1169 1170 1171
    {
      my $value= $2;
      $value =~ s/^\s+//;  # Remove leading space
      $value =~ s/[[:space:]]+$//;  # Remove ending space

1172 1173 1174 1175
      # Sourced file may exist relative to test or
      # in global location
      foreach my $sourced_file (dirname($file). "/$value",
				"$::glob_mysql_test_dir/$value")
1176
      {
1177 1178 1179 1180 1181 1182 1183 1184
	if ( -f $sourced_file )
	{
	  # Only source the file if it exists, we may get
	  # false positives in the regexes above if someone
	  # writes "source nnnn;" in a test case(such as mysqltest.test)
	  tags_from_test_file($tinfo, $sourced_file);
	  last;
	}
1185
      }
unknown's avatar
unknown committed
1186
    }
unknown's avatar
unknown committed
1187

1188 1189 1190
  }
}

unknown's avatar
unknown committed
1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
sub unspace {
  my $string= shift;
  my $quote=  shift;
  $string =~ s/[ \t]/\x11/g;
  return "$quote$string$quote";
}


sub opts_from_file ($) {
  my $file=  shift;

  open(FILE,"<",$file) or mtr_error("can't open file \"$file\": $!");
  my @args;
  while ( <FILE> )
  {
    chomp;

    #    --set-variable=init_connect=set @a='a\\0c'
    s/^\s+//;                           # Remove leading space
    s/\s+$//;                           # Remove ending space

    # This is strange, but we need to fill whitespace inside
    # quotes with something, to remove later. We do this to
    # be able to split on space. Else, we have trouble with
    # options like
    #
    #   --someopt="--insideopt1 --insideopt2"
    #
    # But still with this, we are not 100% sure it is right,
    # we need a shell to do it right.

    s/\'([^\'\"]*)\'/unspace($1,"\x0a")/ge;
    s/\"([^\'\"]*)\"/unspace($1,"\x0b")/ge;
    s/\'([^\'\"]*)\'/unspace($1,"\x0a")/ge;
    s/\"([^\'\"]*)\"/unspace($1,"\x0b")/ge;

    foreach my $arg (split(/[ \t]+/))
    {
      $arg =~ tr/\x11\x0a\x0b/ \'\"/;     # Put back real chars
      # The outermost quotes has to go
      $arg =~ s/^([^\'\"]*)\'(.*)\'([^\'\"]*)$/$1$2$3/
        or $arg =~ s/^([^\'\"]*)\"(.*)\"([^\'\"]*)$/$1$2$3/;
      $arg =~ s/\\\\/\\/g;

      # Do not pass empty string since my_getopt is not capable to handle it.
      if (length($arg)) {
	push(@args, $arg);
      }
    }
  }
  close FILE;
  return \@args;
}
1244 1245 1246

sub print_testcases {
  my (@cases)= @_;
unknown's avatar
unknown committed
1247

1248 1249
  print "=" x 60, "\n";
  foreach my $test (@cases){
1250
    $test->print_test();
unknown's avatar
unknown committed
1251
  }
1252
  print "=" x 60, "\n";
unknown's avatar
unknown committed
1253 1254
}

1255

unknown's avatar
unknown committed
1256
1;