summaryrefslogtreecommitdiff
path: root/unittest/unit.pl
diff options
context:
space:
mode:
authorunknown <mats@mysql.com>2006-04-10 17:06:12 +0200
committerunknown <mats@mysql.com>2006-04-10 17:06:12 +0200
commit4f99f11e9c798225fd5906c23dc26da01ae4f20e (patch)
treea0aa9d8a9cbbeb9f6e3b36fb64e93e0cf337725b /unittest/unit.pl
parent3f9e35d3f350768a8d237bfd369adf63f565f81c (diff)
downloadmariadb-git-4f99f11e9c798225fd5906c23dc26da01ae4f20e.tar.gz
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''
Diffstat (limited to 'unittest/unit.pl')
-rw-r--r--unittest/unit.pl47
1 files changed, 39 insertions, 8 deletions
diff --git a/unittest/unit.pl b/unittest/unit.pl
index bc20938309a..5c45c15a5b1 100644
--- a/unittest/unit.pl
+++ b/unittest/unit.pl
@@ -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;
}
}