summaryrefslogtreecommitdiff
path: root/unittest/unit.pl
diff options
context:
space:
mode:
authorunknown <mats@mysql.com>2006-04-04 18:16:15 +0200
committerunknown <mats@mysql.com>2006-04-04 18:16:15 +0200
commit6d9323ade0b057fb6e80b6473531f54993d7ecf3 (patch)
treedd8e8d7fdd3a93b877138eb5257cdc5f44ec3b13 /unittest/unit.pl
parentdfa9a7641104686b588af016aa58cf46a9db093f (diff)
downloadmariadb-git-6d9323ade0b057fb6e80b6473531f54993d7ecf3.tar.gz
WL#3206 (Add unit tests):
An implementation of the TAP framework for writing unit tests. Makefile.am: Adding directories mytap and unittest configure.in: Building Makefiles for mytap and unittest directories. mytap/Doxyfile: New BitKeeper file ``mytap/Doxyfile'' mytap/Makefile.am: New BitKeeper file ``mytap/Makefile.am'' mytap/t/basic.t.c: New BitKeeper file ``mytap/t/basic.t.c'' mytap/tap.c: New BitKeeper file ``mytap/tap.c'' mytap/tap.h: New BitKeeper file ``mytap/tap.h'' unittest/Makefile.am: New BitKeeper file ``unittest/Makefile.am'' unittest/examples/Makefile.am: New BitKeeper file ``unittest/examples/Makefile.am'' unittest/examples/no_plan.t.c: New BitKeeper file ``unittest/examples/no_plan.t.c'' unittest/examples/simple.t.c: New BitKeeper file ``unittest/examples/simple.t.c'' unittest/examples/skip.t.c: New BitKeeper file ``unittest/examples/skip.t.c'' unittest/examples/skip_all.t.c: New BitKeeper file ``unittest/examples/skip_all.t.c'' unittest/examples/todo.t.c: New BitKeeper file ``unittest/examples/todo.t.c'' unittest/mysys/Makefile.am: New BitKeeper file ``unittest/mysys/Makefile.am'' unittest/mysys/bitmap.t.c: New BitKeeper file ``unittest/mysys/bitmap.t.c'' unittest/unit.pl: New BitKeeper file ``unittest/unit.pl''
Diffstat (limited to 'unittest/unit.pl')
-rw-r--r--unittest/unit.pl77
1 files changed, 77 insertions, 0 deletions
diff --git a/unittest/unit.pl b/unittest/unit.pl
new file mode 100644
index 00000000000..bc20938309a
--- /dev/null
+++ b/unittest/unit.pl
@@ -0,0 +1,77 @@
+#!/usr/bin/perl
+
+# 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] }
+
+package main;
+
+use strict;
+use Test::Harness;
+use File::Find;
+
+sub run_cmd (@);
+
+my %dispatch = (
+ "run" => \&run_cmd,
+);
+
+=head1 NAME
+
+unit - Run unit tests in directory
+
+=head1 SYNOPSIS
+
+ unit run
+
+=cut
+
+my $cmd = shift;
+
+if (defined $cmd && exists $dispatch{$cmd}) {
+ $dispatch{$cmd}->(@ARGV);
+} else {
+ print "Unknown command", (defined $cmd ? " $cmd" : ""), ".\n";
+ print "Available commands are: ", join(", ", keys %dispatch), "\n";
+}
+
+=head2 run
+
+Run all unit tests in the current directory and all subdirectories.
+
+=cut
+
+
+sub _find_test_files (@) {
+ my @dirs = @_;
+ my @files;
+ find sub {
+ $File::Find::prune = 1 if /^SCCS$/;
+ push(@files, $File::Find::name) if -x _ && /\.t\z/;
+ }, @dirs;
+ return @files;
+}
+
+sub run_cmd (@) {
+ my @files;
+
+ push(@_, '.') if @_ == 0;
+
+ 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
+ $Test::Harness::Strap = MySQL::Straps->new;
+
+ runtests @files;
+ }
+}
+