#!/usr/bin/perl -w
my
$tempdir
= tempdir(
'doit_XXXXXXXX'
,
TMPDIR
=> 1,
CLEANUP
=> 1);
my
$fixdir
=
"$tempdir/fixtures"
;
mkdir
$fixdir
;
{
open
my
$ofh
,
'>'
,
"$fixdir/content"
or
die
$!;
print
$ofh
"bla\n"
;
}
my
$script
=
"$tempdir/script.pl"
;
{
open
my
$ofh
,
'>'
,
$script
or
die
"Can't create $tempdir/script.pl: $!"
;
print
$ofh
<<"EOF1".<<'EOF2';
#! $^X
my \$fixdir = '$fixdir';
EOF1
my
$d
= Doit->init;
$d
->change_file(
"$fixdir/content"
, {
match
=>
"bla"
,
replace
=>
"foo"
});
if
($^O eq
'MSWin32'
) {
kill
KILL
=> $$;
}
else
{
kill
INT
=> $$;
}
EOF2
close
$ofh
or
die
$!;
}
system
$^X,
$script
,
'--dry-run'
;
{
local
$TODO
=
"there should be no leftover temp files"
;
opendir
my
$dirfh
,
$fixdir
or
die
$!;
my
@found_files
=
grep
{
$_
ne
'.'
&&
$_
ne
'..'
}
readdir
$dirfh
;
is_deeply \
@found_files
, [
'content'
],
'no temporary files left'
;
}