~ubuntu-branches/ubuntu/precise/mysql-5.1/precise

« back to all changes in this revision

Viewing changes to unittest/unit.pl

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Tretkowski
  • Date: 2010-03-17 14:56:02 UTC
  • Revision ID: james.westby@ubuntu.com-20100317145602-x7e30l1b2sb5s6w6
Tags: upstream-5.1.45
ImportĀ upstreamĀ versionĀ 5.1.45

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl
 
2
# Copyright (C) 2006 MySQL AB
 
3
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
use Test::Harness qw(&runtests $verbose);
 
18
use File::Find;
 
19
 
 
20
use strict;
 
21
 
 
22
sub run_cmd (@);
 
23
 
 
24
my %dispatch = (
 
25
    "run" => \&run_cmd,
 
26
);
 
27
 
 
28
=head1 NAME
 
29
 
 
30
unit - Run unit tests in directory
 
31
 
 
32
=head1 SYNOPSIS
 
33
 
 
34
  unit run
 
35
 
 
36
=cut
 
37
 
 
38
my $cmd = shift;
 
39
 
 
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";
 
45
}
 
46
 
 
47
=head2 run
 
48
 
 
49
Run all unit tests in the current directory and all subdirectories.
 
50
 
 
51
=cut
 
52
 
 
53
 
 
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;
 
62
}
 
63
 
 
64
sub run_cmd (@) {
 
65
    my @files;
 
66
 
 
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);
 
73
 
 
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);
 
77
 
 
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);
 
83
    }
 
84
 
 
85
    print "Running tests: @_\n";
 
86
 
 
87
    foreach my $name (@_) {
 
88
        push(@files, _find_test_files $name) if -d $name;
 
89
        push(@files, $name) if -f $name;
 
90
    }
 
91
 
 
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;
 
97
    }
 
98
}
 
99