1package PPI::Test;
2
3use warnings;
4use strict;
5
6use File::Spec::Functions ();
7
8our @ISA = 'Exporter';
9our @EXPORT_OK = qw( find_files quotable pause );
10our %EXPORT_TAGS;
11
12# Find file names in named t/data dirs
13sub find_files {
14	my ( $testdir ) = @_;
15
16	# Does the test directory exist?
17	die "Failed to find test directory $testdir" if !-e $testdir or !-d $testdir or !-r $testdir;
18
19	# Find the .code test files
20	opendir my $TESTDIR, $testdir or die "opendir: $!";
21	my @perl = map { File::Spec::Functions::catfile( $testdir, $_ ) } sort grep { /\.(?:code|pm|t)$/ } readdir $TESTDIR;
22	closedir $TESTDIR or die "closedir: $!";
23
24	return @perl;
25}
26
27
28sub quotable {
29	my ( $quotable ) = @_;
30	$quotable =~ s|\\|\\\\|g;
31	$quotable =~ s|\t|\\t|g;
32	$quotable =~ s|\n|\\n|g;
33	$quotable =~ s|\$|\\\$|g;
34	$quotable =~ s|\@|\\\@|g;
35	$quotable =~ s|\"|\\\"|g;
36	return $quotable;
37}
38
39
40sub pause {
41	local $@;
42	sleep 1 if !eval { require Time::HiRes; Time::HiRes::sleep(0.1); 1 };
43}
44
45
461;
47