1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
|
package TestFor::Code::TidyAll::Plugin::GenericTransformer;
use Test::Class::Most parent => 'TestFor::Code::TidyAll::Plugin';
use FindBin qw( $Bin );
use Path::Tiny qw( path );
sub test_main : Tests {
my $self = shift;
my $cmd_text = join q{ }, $self->_this_perl,
path( $Bin, qw( helper-bin generic-transformer.pl ) );
my $cmd_raw = join q{ }, $self->_this_perl, path( $Bin, qw( helper-bin raw-transformer.pl ) );
my $crlf = "a\r\nb\r\nc\r\n";
my $lf = "a\nb\nc\n";
$self->tidyall(
source => 'this text is unchanged',
expect_ok => 1,
desc => 'text not containing forbidden word is unchanged',
conf => {
cmd => $cmd_text,
},
);
$self->tidyall(
source => 'this text is forbidden',
expect_tidy => 'this text is safe',
desc => 'text containing forbidden word is transformed',
conf => {
cmd => $cmd_text,
},
);
my $crlf_file = path( $self->{root_dir}, 'crlf' );
$crlf_file->spew_raw($crlf);
$self->tidyall(
source_file => $crlf_file,
expect_tidy => sprintf( '%v02X', $crlf ),
desc => 'generic transformer preserves crlf line endings',
conf => {
cmd => $cmd_raw,
},
);
my $lf_file = path( $self->{root_dir}, 'lf' );
$lf_file->spew_raw($lf);
$self->tidyall(
source_file => $lf_file,
expect_tidy => sprintf( '%v02X', $lf ),
desc => 'generic transformer preserves linefeed line endings',
conf => {
cmd => $cmd_raw,
},
);
my $cmd_exit = join q{ }, $self->_this_perl, path( $Bin, qw( helper-bin exit.pl ) );
$self->tidyall(
source => 'this text is fine',
expect_error => qr/exited with 3/,
desc => 'exit code of 3 is an exception',
conf => {
cmd => "$cmd_exit 3",
ok_exit_codes => [ 0, 1, 2 ],
},
);
}
1;
|