1 | package Mojolicious::Command::test;
|
---|
2 | use Mojo::Base 'Mojolicious::Command';
|
---|
3 |
|
---|
4 | use Mojo::Util 'getopt';
|
---|
5 |
|
---|
6 | has description => 'Run tests';
|
---|
7 | has usage => sub { shift->extract_usage };
|
---|
8 |
|
---|
9 | sub run {
|
---|
10 | my ($self, @args) = @_;
|
---|
11 |
|
---|
12 | getopt \@args, 'v|verbose' => \$ENV{HARNESS_VERBOSE};
|
---|
13 |
|
---|
14 | if (!@args && (my $tests = $self->app->home->child('t'))) {
|
---|
15 | die "Can't find test directory.\n" unless -d $tests;
|
---|
16 | @args = $tests->list_tree->grep(qr/\.t$/)->map('to_string')->each;
|
---|
17 | say qq{Running tests from "$tests".};
|
---|
18 | }
|
---|
19 |
|
---|
20 | $ENV{HARNESS_OPTIONS} //= 'c';
|
---|
21 | require Test::Harness;
|
---|
22 | local $Test::Harness::switches = '';
|
---|
23 | Test::Harness::runtests(sort @args);
|
---|
24 | }
|
---|
25 |
|
---|
26 | 1;
|
---|
27 |
|
---|
28 | =encoding utf8
|
---|
29 |
|
---|
30 | =head1 NAME
|
---|
31 |
|
---|
32 | Mojolicious::Command::test - Test command
|
---|
33 |
|
---|
34 | =head1 SYNOPSIS
|
---|
35 |
|
---|
36 | Usage: APPLICATION test [OPTIONS] [TESTS]
|
---|
37 |
|
---|
38 | ./myapp.pl test
|
---|
39 | ./myapp.pl test t/foo.t
|
---|
40 | ./myapp.pl test -v t/foo/*.t
|
---|
41 |
|
---|
42 | Options:
|
---|
43 | -h, --help Show this summary of available options
|
---|
44 | -v, --verbose Print verbose debug information to STDERR
|
---|
45 |
|
---|
46 | =head1 DESCRIPTION
|
---|
47 |
|
---|
48 | L<Mojolicious::Command::test> runs application tests from the C<t> directory.
|
---|
49 |
|
---|
50 | This is a core command, that means it is always enabled and its code a good
|
---|
51 | example for learning to build new commands, you're welcome to fork it.
|
---|
52 |
|
---|
53 | See L<Mojolicious::Commands/"COMMANDS"> for a list of commands that are
|
---|
54 | available by default.
|
---|
55 |
|
---|
56 | =head1 ATTRIBUTES
|
---|
57 |
|
---|
58 | L<Mojolicious::Command::test> inherits all attributes from
|
---|
59 | L<Mojolicious::Command> and implements the following new ones.
|
---|
60 |
|
---|
61 | =head2 description
|
---|
62 |
|
---|
63 | my $description = $test->description;
|
---|
64 | $test = $test->description('Foo');
|
---|
65 |
|
---|
66 | Short description of this command, used for the command list.
|
---|
67 |
|
---|
68 | =head2 usage
|
---|
69 |
|
---|
70 | my $usage = $test->usage;
|
---|
71 | $test = $test->usage('Foo');
|
---|
72 |
|
---|
73 | Usage information for this command, used for the help screen.
|
---|
74 |
|
---|
75 | =head1 METHODS
|
---|
76 |
|
---|
77 | L<Mojolicious::Command::test> inherits all methods from L<Mojolicious::Command>
|
---|
78 | and implements the following new ones.
|
---|
79 |
|
---|
80 | =head2 run
|
---|
81 |
|
---|
82 | $test->run(@ARGV);
|
---|
83 |
|
---|
84 | Run this command.
|
---|
85 |
|
---|
86 | =head1 SEE ALSO
|
---|
87 |
|
---|
88 | L<Mojolicious>, L<Mojolicious::Guides>, L<https://mojolicious.org>.
|
---|
89 |
|
---|
90 | =cut
|
---|