File: Test.pm

package info (click to toggle)
libmojolicious-perl 0.999926-1%2Bsqueeze2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,672 kB
  • ctags: 949
  • sloc: perl: 17,391; makefile: 4
file content (121 lines) | stat: -rw-r--r-- 2,676 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# Copyright (C) 2008-2010, Sebastian Riedel.

package Mojo::Command::Test;

use strict;
use warnings;

use base 'Mojo::Command';

use Cwd;
use FindBin;
use File::Spec;
use Test::Harness;

__PACKAGE__->attr(description => <<'EOF');
Run unit tests.
EOF
__PACKAGE__->attr(usage => <<"EOF");
usage: $0 test [TESTS]
EOF

# My eyes! The goggles do nothing!
sub run {
    my ($self, @tests) = @_;

    # Search tests
    unless (@tests) {
        my @base = File::Spec->splitdir(File::Spec->abs2rel($FindBin::Bin));

        # Test directory in the same directory as "mojo" (t)
        my $path = File::Spec->catdir(@base, 't');

        # Test dirctory in the directory above "mojo" (../t)
        $path = File::Spec->catdir(@base, '..', 't') unless -d $path;
        unless (-d $path) {
            print "Can't find test directory.\n";
            return;
        }

        # List test files
        my @dirs = ($path);
        while (my $dir = shift @dirs) {
            opendir(my $fh, $dir);
            for my $file (readdir($fh)) {
                next if $file eq '.';
                next if $file eq '..';
                my $fpath = File::Spec->catfile($dir, $file);
                push @dirs, File::Spec->catdir($dir, $file) if -d $fpath;
                push @tests,
                  File::Spec->abs2rel(
                    Cwd::realpath(
                        File::Spec->catfile(File::Spec->splitdir($fpath))
                    )
                  ) if (-f $fpath) && ($fpath =~ /\.t$/);
            }
            closedir $fh;
        }

        $path = Cwd::realpath($path);
        print "Running tests from '$path'.\n";
    }

    # Run tests
    runtests(@tests);

    return $self;
}

1;
__END__

=head1 NAME

Mojo::Command::Test - Test Command

=head1 SYNOPSIS

    use Mojo::Command::Test;

    my $test = Mojo::Command::Test->new;
    $test->run(@ARGV);

=head1 DESCRIPTION

L<Mojo::Command::Test> is a test script.

=head1 ATTRIBUTES

L<Mojo::Command::Test> inherits all attributes from L<Mojo::Command> and
implements the following new ones.

=head2 C<description>

    my $description = $test->description;
    $test           = $test->description('Foo!');

Short description of this command, used for the command list.

=head2 C<usage>

    my $usage = $test->usage;
    $test     = $test->usage('Foo!');

Usage information for this command, used for the help screen.

=head1 METHODS

L<Mojo::Command::Test> inherits all methods from L<Mojo::Command> and
implements the following new ones.

=head2 C<run>

    $test = $test->run(@ARGV);

Run this command.

=head1 SEE ALSO

L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>.

=cut