File: Test.pm

package info (click to toggle)
libppi-perl 1.236-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,056 kB
  • ctags: 922
  • sloc: perl: 15,002; makefile: 8
file content (50 lines) | stat: -rwxr-xr-x 1,025 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
package PPI::Test;

use warnings;
use strict;

use File::Spec::Functions ();

use vars qw{$VERSION @ISA @EXPORT_OK %EXPORT_TAGS};
BEGIN {
	$VERSION = '1.236';
	@ISA = 'Exporter';
	@EXPORT_OK = qw( find_files quotable pause );
}


# Find file names in named t/data dirs
sub find_files {
	my ( $testdir ) = @_;

	# Does the test directory exist?
	die "Failed to find test directory $testdir" if !-e $testdir or !-d $testdir or !-r $testdir;

	# Find the .code test files
	opendir my $TESTDIR, $testdir or die "opendir: $!";
	my @perl = map { File::Spec::Functions::catfile( $testdir, $_ ) } sort grep { /\.(?:code|pm|t)$/ } readdir $TESTDIR;
	closedir $TESTDIR or die "closedir: $!";

	return @perl;
}


sub quotable {
	my ( $quotable ) = @_;
	$quotable =~ s|\\|\\\\|g;
	$quotable =~ s|\t|\\t|g;
	$quotable =~ s|\n|\\n|g;
	$quotable =~ s|\$|\\\$|g;
	$quotable =~ s|\@|\\\@|g;
	$quotable =~ s|\"|\\\"|g;
	return $quotable;
}


sub pause {
	local $@;
	sleep 1 if !eval { require Time::HiRes; Time::HiRes::sleep(0.1); 1 };
}


1;