This file is indexed.

/usr/share/perl5/Test/Unit/TestSuite.pm is in libtest-unit-perl 0.25-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
package Test::Unit::TestSuite;
use strict;

=head1 NAME

Test::Unit::TestSuite - unit testing framework base class

=cut

use base 'Test::Unit::Test';

use Carp;

use Test::Unit::Debug qw(debug);
use Test::Unit::TestCase;
use Test::Unit::Loader;
use Test::Unit::Warning;

=head1 SYNOPSIS

    package MySuite;

    use base qw(Test::Unit::TestSuite);

    sub name { 'My very own test suite' } 
    sub include_tests { qw(MySuite1 MySuite2 MyTestCase1 ...) }

This is the easiest way of building suites; there are many more.  Read on ...

=head1 DESCRIPTION

This class provides the functionality for building test suites in
several different ways.

Any module can be a test suite runnable by the framework if it
provides a C<suite()> method which returns a C<Test::Unit::TestSuite>
object, e.g.

    use Test::Unit::TestSuite;

    # more code here ...

    sub suite {
	my $class = shift;

	# Create an empty suite.
	my $suite = Test::Unit::TestSuite->empty_new("A Test Suite");
	# Add some tests to it via $suite->add_test() here

	return $suite;
    }

This is useful if you want your test suite to be contained in the module
it tests, for example.

Alternatively, you can have "standalone" test suites, which inherit directly
from C<Test::Unit::TestSuite>, e.g.:

    package MySuite;

    use base qw(Test::Unit::TestSuite);

    sub new {
        my $class = shift;
        my $self = $class->SUPER::empty_new();
        # Build your suite here
        return $self;
    }

    sub name { 'My very own test suite' }

or if your C<new()> is going to do nothing more interesting than add
tests from other suites and testcases via C<add_test()>, you can use the
C<include_tests()> method as shorthand:

    package MySuite;

    use base qw(Test::Unit::TestSuite);

    sub name { 'My very own test suite' } 
    sub include_tests { qw(MySuite1 MySuite2 MyTestCase1 ...) }

This is the easiest way of building suites.

=head1 CONSTRUCTORS

=head2 empty_new ([NAME])

    my $suite = Test::Unit::TestSuite->empty_new('my suite name');

Creates a fresh suite with no tests.

=cut

sub empty_new {
    my $this = shift;
    my $classname = ref $this || $this;
    my $name = shift || '';
    
    my $self = {
        _Tests => [],
        _Name => $name,
    };
    bless $self, $classname;
    
    debug(ref($self), "::empty_new($name) called\n");
    return $self;
}

=head2 new ([ CLASSNAME | TEST ])

If a test suite is provided as the argument, it merely returns that
suite.  If a test case is provided, it extracts all test case methods
from the test case (see L<Test::Unit::TestCase/list_tests>) into a new
test suite.

If the class this method is being run in has an C<include_tests> method
which returns an array of class names, it will also automatically add
the tests from those classes into the newly constructed suite object.

=cut

sub new {
    my $class = shift;
    my $classname = shift || ''; # Avoid a warning
    debug("$class\::new($classname) called\n");

    my $self = $class->empty_new();

    if ($classname) {
        Test::Unit::Loader::compile_class($classname);
        if (eval { $classname->isa('Test::Unit::TestCase') }) {
            $self->{_Name} = "suite extracted from $classname";
            my @testcases = Test::Unit::Loader::extract_testcases($classname);
            foreach my $testcase (@testcases) {
                $self->add_test($testcase);
            }
        }
        elsif (eval { $classname->can('suite') }) {
            return $classname->suite();
        }
        else {
            my $error = "Class $classname was not a test case or test suite.\n";
            #$self->add_warning($error);
            die $error;
        }
    }

    if ($self->can('include_tests')) {
        foreach my $test ($self->include_tests()) {
            $self->add_test($test);
        }
    }

    return $self;
}

=head1 METHODS

=cut

sub suite {
    my $class = shift;
    croak "suite() is not an instance method" if ref $class;
    $class->new(@_);
}

=head2 name()

Returns the suite's human-readable name.

=cut

sub name {
    my $self = shift;
    croak "Override name() in subclass to set name\n" if @_;
    return $self->{_Name};
}

=head2 names()

Returns an arrayref of the names of all tests in the suite.

=cut

sub names {
    my $self = shift;
    my @test_list = @{$self->tests};
    return [ map {$_->name} @test_list ] if @test_list;
}

=head2 list (SHOW_TESTCASES)

Produces a human-readable indented lists of the suite and the subsuites
it contains.  If the first parameter is true, also lists any testcases
contained in the suite and its subsuites.

=cut

sub list {
    my $self = shift;
    my $show_testcases = shift;
    my $first = ($self->name() || 'anonymous Test::Unit::TestSuite');
    $first .= " - " . ref($self) unless ref($self) eq __PACKAGE__;
    $first .= "\n";
    my @lines = ( $first );
    foreach my $test (@{ $self->tests() }) {
        push @lines, map "   $_", @{ $test->list($show_testcases) };
    }
    return \@lines;
}

=head2 add_test (TEST_CLASSNAME | TEST_OBJECT)

You can add a test object to a suite with this method, by passing
either its classname, or the object itself as the argument.

Of course, there are many ways of getting the object too ...

    # Get and add an existing suite.
    $suite->add_test('MySuite1');

    # This is exactly equivalent:
    $suite->add_test(Test::Unit::TestSuite->new('MySuite1'));

    # So is this, provided MySuite1 inherits from Test::Unit::TestSuite.
    use MySuite1;
    $suite->add_test(MySuite1->new());

    # Extract yet another suite by way of suite() method and add it to
    # $suite.
    use MySuite2;
    $suite->add_test(MySuite2->suite());
    
    # Extract test case methods from MyModule::TestCase into a
    # new suite and add it to $suite.
    $suite->add_test(Test::Unit::TestSuite->new('MyModule::TestCase'));

=cut

sub add_test {
    my $self = shift;
    my ($test) = @_;
    debug('+ ', ref($self), "::add_test($test) called\n");
    $test = Test::Unit::Loader::load_test($test) unless ref $test;
    croak "`$test' could not be interpreted as a Test::Unit::Test object"
        unless eval { $test->isa('Test::Unit::Test') };
    push @{$self->tests}, $test;
}

sub count_test_cases {
    my $self = shift;
    my $count;
    $count += $_->count_test_cases for @{$self->tests};
    return $count;
}

sub run {
    my $self = shift;
    my ($result, $runner) = @_;

    debug("$self\::run($result, ", $runner || 'undef', ") called\n");

    $result ||= create_result();
    $result->tell_listeners(start_suite => $self);

    $self->add_warning("No tests found in " . $self->name())
        unless @{ $self->tests() };

    for my $t (@{$self->tests()}) {
        if ($runner && $self->filter_test($runner, $t)) {
            debug(sprintf "+ skipping '%s'\n", $t->name());
            next;
        }
        debug(sprintf "+ didn't skip '%s'\n", $t->name());
 
        last if $result->should_stop();
        $t->run($result, $runner);
    }

    $result->tell_listeners(end_suite => $self);

    return $result;
}
    
sub filter_test {
    my $self = shift;
    my ($runner, $test) = @_;

    debug(sprintf "checking whether to filter '%s'\n", $test->name);

    my @filter_tokens = $runner->filter();

    foreach my $token (@filter_tokens) {
        my $filtered = $test->filter_method($token);
        debug("  - by token $token? ", $filtered ? 'yes' : 'no', "\n");
        return 1 if $filtered;
    }

    return 0;
}

sub test_at {
    my $self = shift;
    my ($index) = @_;
    return $self->tests()->[$index];
}

sub test_count {
    my $self = shift;
    return scalar @{$self->tests()};
}

sub tests {
    my $self = shift;
    return $self->{_Tests};
}

sub to_string {
    my $self = shift;
    return $self->name();
}

sub add_warning {
    my $self = shift;
    $self->add_test(Test::Unit::Warning->new(join '', @_));
}

1;
__END__

=head1 AUTHOR

Copyright (c) 2000-2002, 2005 the PerlUnit Development Team
(see L<Test::Unit> or the F<AUTHORS> file included in this
distribution).

All rights reserved. This program is free software; you can
redistribute it and/or modify it under the same terms as Perl itself.

=head1 SEE ALSO

=over 4

=item *

L<Test::Unit::TestRunner>

=item *

L<Test::Unit::TkTestRunner>

=item *

For further examples, take a look at the framework self test
collection (t::tlib::AllTests).

=back

=cut