Debian Codegraph @

t/lib/TidierTests.pm

raw symbols SCIP
1 package TidierTests;
2
3 use strict;
4 use warnings;
5 use Perl::Tidy::Sweetened;
6 use Test::Most;
7
8 use Exporter;
9 @TidierTests::ISA = qw(Exporter);
10 @TidierTests::EXPORT = qw(run_test);
11 @TidierTests::EXPORT_OK = qw($indent_tc $indent_csc);
12
13 sub run_test {
14 my ( $raw, $expected, $msg, $todo, @args ) = @_;
15
16 my $errorbuffer = '';
17 my @tidied;
18 ## warn "# -nsyn -ce -npro -l=60 " . join( ' ', @args ), "\n";
19 Perl::Tidy::Sweetened::perltidy(
20 source => \$raw,
21 destination => \@tidied,
22 perltidyrc => undef,
23 errorfile => \$errorbuffer,
24 argv => '-nsyn -ce -npro -l=60 ' . join( ' ', @args ),
25 );
26 my $tidied = join '', @tidied;
27
28 if ($todo) {
29
30 TODO: {
31 # Works with Test::More prior to 1.301001_?
32 local $TidierTests::TODO = 'Not implmented';
33
34 # Works with Test::More after 1.301001_021
35 local $TODO = 'Not implmented';
36
37 return check_test( $tidied, $expected, $errorbuffer, $msg );
38 }
39
40 } else {
41 return check_test( $tidied, $expected, $errorbuffer, $msg );
42 }
43 }
44
45 sub check_test {
46 my ( $tidied, $expected, $errors, $msg ) = @_;
47
48 my $ok_log = is( $errors, '', "$msg: no errors" );
49 my $ok_tidy = eq_or_diff( $tidied, $expected, "$msg: matches" );
50
51 return $ok_log && $ok_tidy;
52 }
53
54 # Handle changes in spacing between versions
55 require Perl::Tidy;
56 ## Perl::Tidy changed spacing for trailing comments in v v20200907
57 our $indent_tc = ' ' x ( ( $Perl::Tidy::VERSION < 20200907 ) ? 8 : 4 );
58 ## Perl::Tidy changed spacing for closing side comments in v20200110
59 our $indent_csc = ' ' x ( ( $Perl::Tidy::VERSION < 20200110 ) ? 4 : 1 );
60
61 1;