mySQL 5.0.11 sources for tomato
[tomato.git] / release / src / router / mysql / unittest / unit.pl
blob9d328985012166ad9e921e7370c00be711d8c728
1 #!/usr/bin/perl
2 # Copyright (C) 2006 MySQL AB
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; version 2 of the License.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software
15 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 use Test::Harness qw(&runtests $verbose);
18 use File::Find;
20 use strict;
22 sub run_cmd (@);
24 my %dispatch = (
25 "run" => \&run_cmd,
28 =head1 NAME
30 unit - Run unit tests in directory
32 =head1 SYNOPSIS
34 unit run
36 =cut
38 my $cmd = shift;
40 if (defined $cmd && exists $dispatch{$cmd}) {
41 $dispatch{$cmd}->(@ARGV);
42 } else {
43 print "Unknown command", (defined $cmd ? " $cmd" : ""), ".\n";
44 print "Available commands are: ", join(", ", keys %dispatch), "\n";
47 =head2 run
49 Run all unit tests in the current directory and all subdirectories.
51 =cut
54 sub _find_test_files (@) {
55 my @dirs = @_;
56 my @files;
57 find sub {
58 $File::Find::prune = 1 if /^SCCS$/;
59 push(@files, $File::Find::name) if -x _ && /-t\z/;
60 }, @dirs;
61 return @files;
64 sub run_cmd (@) {
65 my @files;
67 # If no directories were supplied, we add all directories in the
68 # current directory except 'mytap' since it is not part of the
69 # test suite.
70 if (@_ == 0) {
71 # Ignore these directories
72 my @ignore = qw(mytap SCCS);
74 # Build an expression from the directories above that tests if a
75 # directory should be included in the list or not.
76 my $ignore = join(' && ', map { '$_ ne ' . "'$_'"} @ignore);
78 # Open and read the directory. Filter out all files, hidden
79 # directories, and directories named above.
80 opendir(DIR, ".") or die "Cannot open '.': $!\n";
81 @_ = grep { -d $_ && $_ !~ /^\..*/ && eval $ignore } readdir(DIR);
82 closedir(DIR);
85 print "Running tests: @_\n";
87 foreach my $name (@_) {
88 push(@files, _find_test_files $name) if -d $name;
89 push(@files, $name) if -f $name;
92 if (@files > 0) {
93 # Removing the first './' from the file names
94 foreach (@files) { s!^\./!! }
95 $ENV{'HARNESS_PERL_SWITCHES'} .= q" -e 'exec @ARGV'";
96 runtests @files;