#!/usr/bin/perl
BEGIN {
$| = 1;
$^W = 1;
}
my
@cleanup
= ();
END {
foreach
(
@cleanup
) {
unlink
$_
if
-e
$_
;
}
}
my
$testdir
= catdir(
't'
,
'data'
);
ok( (-e
$testdir
and -d
$testdir
and -r
$testdir
),
"Test directory $testdir found"
);
opendir
( TESTDIR,
$testdir
) or
die
"opendir: $!"
;
my
@files
=
map
{ catfile(
$testdir
,
$_
) }
sort
grep
{ /\.pm$/ }
readdir
(TESTDIR);
closedir
( TESTDIR ) or
die
"closedir: $!"
;
ok(
scalar
@files
,
'Found at least one .pm file'
);
foreach
my
$input
(
@files
) {
my
$output
=
"$input.squish"
;
my
$copy
=
"$input.copy"
;
my
$copy2
=
"$input.copy2"
;
push
@cleanup
,
$copy
;
ok( copy(
$input
,
$copy
),
"Copied $input to $copy"
);
my
$Original
= new_ok(
'PPI::Document'
, [
$input
] );
my
$Input
= new_ok(
'PPI::Document'
, [
$input
] );
my
$Output
= new_ok(
'PPI::Document'
, [
$output
] );
my
$rv
= Perl::Squish->document(
$Input
);
isa_ok(
$rv
,
'PPI::Document'
);
is( refaddr(
$rv
), refaddr(
$Input
),
'->document returns original document'
);
is_deeply(
$Input
,
$Output
,
'Transform works as expected'
);
ok( Perl::Squish->file(
$copy
,
$copy2
),
'->file returned true'
);
my
$Copy
= new_ok(
'PPI::Document'
, [
$copy
] );
is_deeply(
$Copy
,
$Original
,
'targeted transform leaves original unchanged'
);
my
$Copy2
= new_ok(
'PPI::Document'
, [
$copy2
] );
is_deeply(
$Copy2
,
$Output
,
'targeted transform works as expected'
);
ok( Perl::Squish->file(
$copy
),
'->file returned true'
);
$Copy
= new_ok(
'PPI::Document'
, [
$copy
] );
is_deeply(
$Copy
,
$Output
,
'In-place transform works as expected'
);
}