mirror of
https://github.com/MariaDB/server.git
synced 2025-07-30 16:24:05 +03:00
WL#3206 (Adding unit tests):
Added 'test' target to build and run tests. Added documentation. Added README.txt files. Fixing problem with initialization of the Test::Harness::Straps replacement. Added code to filter out non- test directories. unittest/Makefile.am: Adding 'test' target to build and run tests. unittest/examples/skip.t.c: Changing text for skip reason. unittest/examples/skip_all.t.c: Changing text for skip reason. unittest/mytap/tap.c: Adding copyright. Adding documentation. Minor code changes. unittest/mytap/tap.h: Adding copyright. Adding documentation. unittest/unit.pl: Initializing replacement Test::Harness::Straps properly. Adding code to filter non-test directories from default directories to use. unittest/README.txt: New BitKeeper file ``unittest/README.txt''
This commit is contained in:
@ -3,15 +3,22 @@
|
||||
# Override _command_line in the standard Perl test harness to prevent
|
||||
# it from using "perl" to run the test scripts.
|
||||
package MySQL::Straps;
|
||||
|
||||
use base qw(Test::Harness::Straps);
|
||||
sub _command_line { return $_[1] }
|
||||
|
||||
use strict;
|
||||
|
||||
sub _command_line {
|
||||
return $_[1]
|
||||
}
|
||||
|
||||
package main;
|
||||
|
||||
use strict;
|
||||
use Test::Harness;
|
||||
use Test::Harness qw(&runtests $verbose);
|
||||
use File::Find;
|
||||
|
||||
use strict;
|
||||
|
||||
sub run_cmd (@);
|
||||
|
||||
my %dispatch = (
|
||||
@ -30,6 +37,9 @@ unit - Run unit tests in directory
|
||||
|
||||
my $cmd = shift;
|
||||
|
||||
# $Test::Harness::Verbose = 1;
|
||||
# $Test::Harness::Debug = 1;
|
||||
|
||||
if (defined $cmd && exists $dispatch{$cmd}) {
|
||||
$dispatch{$cmd}->(@ARGV);
|
||||
} else {
|
||||
@ -57,20 +67,41 @@ sub _find_test_files (@) {
|
||||
sub run_cmd (@) {
|
||||
my @files;
|
||||
|
||||
push(@_, '.') if @_ == 0;
|
||||
# If no directories were supplied, we add all directories in the
|
||||
# current directory except 'mytap' since it is not part of the
|
||||
# test suite.
|
||||
if (@_ == 0) {
|
||||
# Ignore these directories
|
||||
my @ignore = qw(mytap SCCS);
|
||||
|
||||
# Build an expression from the directories above that tests if a
|
||||
# directory should be included in the list or not.
|
||||
my $ignore = join(' && ', map { '$_ ne ' . "'$_'"} @ignore);
|
||||
|
||||
# Open and read the directory. Filter out all files, hidden
|
||||
# directories, and directories named above.
|
||||
opendir(DIR, ".") or die "Cannot open '.': $!\n";
|
||||
@_ = grep { -d $_ && $_ !~ /^\..*/ && eval $ignore } readdir(DIR);
|
||||
closedir(DIR);
|
||||
}
|
||||
|
||||
print "Running tests: @_\n";
|
||||
|
||||
foreach my $name (@_) {
|
||||
push(@files, _find_test_files $name) if -d $name;
|
||||
push(@files, $name) if -f $name;
|
||||
}
|
||||
|
||||
|
||||
if (@files > 0) {
|
||||
# Removing the first './' from the file names
|
||||
foreach (@files) { s!^\./!! }
|
||||
|
||||
# Install the strap above instead of the default strap
|
||||
|
||||
# Install the strap above instead of the default strap. Since
|
||||
# we are replacing the straps under the feet of Test::Harness,
|
||||
# we need to do some basic initializations in the new straps.
|
||||
$Test::Harness::Strap = MySQL::Straps->new;
|
||||
|
||||
$Test::Harness::Strap->{callback} = \&Test::Harness::strap_callback;
|
||||
|
||||
runtests @files;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user