This file is indexed.

/usr/share/perl5/Test/Script.pm is in libtest-script-perl 1.07-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
package Test::Script;

=pod

=head1 NAME

Test::Script - Basic cross-platform tests for scripts

=head1 DESCRIPTION

The intent of this module is to provide a series of basic tests for 80%
of the testing you will need to do for scripts in the F<script> (or F<bin>
as is also commonly used) paths of your Perl distribution.

Further, it aims to provide this functionality with perfect
platform-compatibility, and in a way that is as unobtrusive as possible.

That is, if the program works on a platform, then B<Test::Script>
should always work on that platform as well. Anything less than 100% is
considered unacceptable.

In doing so, it is hoped that B<Test::Script> can become a module that
you can safely make a dependency of all your modules, without risking that
your module won't on some platform because of the dependency.

Where a clash exists between wanting more functionality and maintaining
platform safety, this module will err on the side of platform safety.

=head1 FUNCTIONS

=cut

use 5.005;
use strict;
use Carp             ();
use Exporter         ();
use File::Spec       ();
use File::Spec::Unix ();
use Probe::Perl      ();
use IPC::Run3        ();
use Test::Builder    ();

use vars qw{$VERSION @ISA @EXPORT};
BEGIN {
	$VERSION = '1.07';
	@ISA     = 'Exporter';
	@EXPORT  = qw{
		script_compiles
		script_compiles_ok
		script_runs
	};
}

sub import {
	my $self = shift;
	my $pack = caller;
	my $test = Test::Builder->new;
	$test->exported_to($pack);
	$test->plan(@_);
	foreach ( @EXPORT ) {
		$self->export_to_level(1, $self, $_);
	}
}

my $perl = undef;

sub perl () {
	$perl or
	$perl = Probe::Perl->find_perl_interpreter;
}

sub path ($) {
	my $path = shift;
	unless ( defined $path ) {
		Carp::croak("Did not provide a script name");
	}
	if ( File::Spec::Unix->file_name_is_absolute($path) ) {
		Carp::croak("Script name must be relative");
	}
	File::Spec->catfile(
		File::Spec->curdir,
		split /\//, $path
	);
}





#####################################################################
# Test Functions

=pod

=head2 script_compiles

    script_compiles( 'script/foo.pl', 'Main script compiles' );

The C<script_compiles> test calls the script with "perl -c script.pl",
and checks that it returns without error.

The path it should be passed is a relative unix-format script name. This
will be localised when running C<perl -c> and if the test fails the local
name used will be shown in the diagnostic output.

Note also that the test will be run with the same L<perl> interpreter that
is running the test script (and not with the default system perl). This
will also be shown in the diagnostic output on failure.

=cut

sub script_compiles {
	my $args   = _script(shift);
	my $unix   = shift @$args;
	my $path   = path( $unix );
	my $cmd    = [ perl, '-Mblib', '-c', $path, @$args ];
	my $stdin  = '';
	my $stdout = '';
	my $stderr = '';
	my $rv     = IPC::Run3::run3( $cmd, \$stdin, \$stdout, \$stderr );
	my $exit   = $? ? ($? >> 8) : 0;
	my $ok     = !! (
		$rv and $exit == 0 and $stderr =~ /syntax OK\s+\z/si
	);

	my $test = Test::Builder->new;
	$test->ok( $ok, $_[0] || "Script $unix compiles" );
	$test->diag( "$exit - $stderr" ) unless $ok;

	return $ok;
}

=pod

=head2 script_runs

    script_runs( 'script/foo.pl', 'Main script runs' );

The C<script_runs> test executes the script with "perl script.pl" and checks
that it returns success.

The path it should be passed is a relative unix-format script name. This
will be localised when running C<perl -c> and if the test fails the local
name used will be shown in the diagnostic output.

The test will be run with the same L<perl> interpreter that is running the
test script (and not with the default system perl). This will also be shown
in the diagnostic output on failure.

=cut

sub script_runs {
	my $args   = _script(shift);
	my $unix   = shift @$args;
	my $path   = path( $unix );
	my $cmd    = [ perl, '-Mblib', $path, @$args ];
	my $stdin  = '';
	my $stdout = '';
	my $stderr = '';
	my $rv     = IPC::Run3::run3( $cmd, \$stdin, \$stdout, \$stderr );
	my $exit   = $? ? ($? >> 8) : 0;
	my $ok     = !! ( $rv and $exit == 0 );

	my $test = Test::Builder->new;
	$test->ok( $ok, $_[0] || "Script $unix runs" );
	$test->diag( "$exit - $stderr" ) unless $ok;

	return $ok;
}





######################################################################
# Support Functions

# Script params must be either a simple non-null string with the script
# name, or an array reference with one or more non-null strings.
sub _script {
	my $in = shift;
	if ( defined _STRING($in) ) {
		return [ $in ];
	}
	if ( _ARRAY($in) ) {
		unless ( scalar grep { not defined _STRING($_) } @$in ) {
			return $in;			
		}
	}
	Carp::croak("Invalid command parameter");
}

# Inline some basic Params::Util functions

sub _ARRAY ($) {
	(ref $_[0] eq 'ARRAY' and @{$_[0]}) ? $_[0] : undef;
}

sub _STRING ($) {
	(defined $_[0] and ! ref $_[0] and length($_[0])) ? $_[0] : undef;
}

BEGIN {
	# Alias to old name
	*script_compiles_ok = *script_compiles;
}

1;

=pod

=head1 SUPPORT

All bugs should be filed via the bug tracker at

L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-Script>

For other issues, or commercial enhancement and support, contact the author.

=head1 AUTHOR

Adam Kennedy E<lt>adamk@cpan.orgE<gt>

=head1 SEE ALSO

L<prove>, L<http://ali.as/>

=head1 COPYRIGHT

Copyright 2006 - 2009 Adam Kennedy.

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

The full text of the license can be found in the
LICENSE file included with this module.

=cut