App-Actions
view release on metacpan or search on metacpan
t/space-path.t view on Meta::CPAN
if $root =~ / /;
# The copy is made here, not in the distribution, so the tests below exercise
# the code under test and not a stale duplicate. What goes into it is what
# MANIFEST says the distribution ships, which is the list of files the suite
# may read: a test that starts reading a new file is covered here as soon as
# that file is in the distribution, rather than failing - or, worse, skipping -
# in this copy alone. Modes are kept, because the hook is run rather than read.
my $manifest = File::Spec->catfile($root, 'MANIFEST');
open my $listing, '<', $manifest or die "cannot read '$manifest': $!\n";
my @shipped;
while (my $line = <$listing>) {
next if $line =~ /\A#/;
# make distdir rewrites MANIFEST with a description after each name, so
# only the first field is the file. A name cannot contain whitespace, so
# this is the same list whichever form the file is in.
my ($file) = split /\s+/, $line;
next unless defined $file && length $file;
push @shipped, $file;
}
close $listing;
my $temp = tempdir('app-actions space XXXX', TMPDIR => 1, CLEANUP => 1);
my $copy = File::Spec->catdir($temp, 'suite with spaces');
make_path($copy);
for my $file (@shipped) {
my $from = File::Spec->catfile($root, split m{/}, $file);
my $to = File::Spec->catfile($copy, split m{/}, $file);
die "MANIFEST lists '$file', which is not in the tree\n" unless -e $from;
make_path(dirname($to));
copy($from, $to) or die "cannot copy '$from' to '$to': $!\n";
chmod((stat $from)[2] & 07777, $to)
or die "cannot set the mode of '$to': $!\n";
}
like($copy, qr/ /, 'the copy lives under a path with spaces');
my $tests = File::Spec->catdir($copy, 't');
my $lib = File::Spec->catdir($copy, 'lib');
opendir my $directory, $tests or die "cannot read '$tests': $!\n";
my @tests = sort grep { /\.t\z/ } readdir $directory;
closedir $directory;
ok(@tests, 'the copy contains the test suite');
my @failed;
{
my $original = File::Spec->rel2abs(File::Spec->curdir);
chdir $copy or die "cannot change to '$copy': $!\n";
for my $test (@tests) {
my $file = File::Spec->catfile($tests, $test);
my ($stdout, $stderr, $status) = capture {
local $ENV{APP_ACTIONS_SPACE_PATH_CHILD} = 1;
App::Actions::Process::stream([ $^X, '-I' . $lib, $file ]);
};
my $ok = ok(
$status == 0,
"$test passes when the suite is run from a path with spaces",
);
next if $ok;
push @failed, $test;
diag "stdout:\n$stdout" if length $stdout;
diag "stderr:\n$stderr" if length $stderr;
}
chdir $original or die "cannot return to '$original': $!\n";
}
is_deeply(\@failed, [], 'every test file passes from a path with spaces');
done_testing;
( run in 0.926 second using v1.01-cache-2.11-cpan-60884a8df76 )