use File::Temp qw(tempdir);
use File::Path qw(remove_tree);
-BEGIN { use_ok('File::Rewrite', 'fileset'); }
+BEGIN { use_ok('File::Rewrite', 'fileset') or BAIL_OUT('No fileset()'); }
my $target = tempdir();
if ($compare ne $output) {
fail($name);
diag(sprintf(
- 'output mismatch (got %d of %d lines with return value %s)',
+ ' Output mismatch (got %d of %d lines with return value %s)',
$output =~ tr/\n//,
$compare =~ tr/\n//,
explain($result),
));
+ diag(' got: "', join('\n', split $/, $output ), '"');
+ diag(' expected: "', join('\n', split $/, $compare), '"');
return;
}
}
testfileset('add unconditionally', "$/0$/", ['0', undef], 1, "$/0$/0$/");
testfileset('add string', "foo$/", ['bar'], 1, "foo$/bar$/");
testfileset('keep string', "foo$/bar$/", ['foo'], 0, "foo$/bar$/");
-testfileset('replace string', "1$/2$/3$/", [4, 1], 2, "2$/3$/4$/");
-testfileset('replace all', $BASICBODY, ['', qr/^re/], 3, "noremove$/.$/$/");
-testfileset('keep first', "foo$/bar$/foo$/", ['foo'], 1, "foo$/bar$/");
+testfileset('keep first', "foo$/FOO$/foo$/", ['foo'], 1, "foo$/FOO$/");
+testfileset('replace string', "$/0$/1$/2$/", [3, 0], 2, "$/1$/2$/3$/");
+testfileset('keep regex', "foo$/hi$/$/", ['hi', qr/./], 1, "hi$/$/");
testfileset('add new array', ".$/", [['foo','.'], ''], 2, ".$/foo$/.$/");
testfileset('replace by array', "$/foo$/.$/", [['foo',''], ''], 3, "foo$/.$/foo$/$/");