]> git.donarmstrong.com Git - perltidy.git/blob - t/atee.t
New upstream version 20210717
[perltidy.git] / t / atee.t
1 use strict;
2 use Test;
3 use Carp;
4 use Perl::Tidy;
5
6 BEGIN {
7     plan tests => 2;
8 }
9
10 my $sname = 'atee.t';
11
12 my $source = <<'EOM';
13 # block comment
14 =pod
15 some pod
16 =cut
17
18 print "hello world\n";
19 $xx++; # side comment
20 EOM
21
22
23 my $expect = <<'EOM';
24
25 print "hello world\n";
26 $xx++;
27 EOM
28
29 my $teefile_expect = <<'EOM';
30 # block comment
31 =pod
32 some pod
33 =cut
34 $xx++; # side comment
35 EOM
36
37 # Test capturing the .LOG, .DEBUG, .TEE outputs to strings.
38 # In this test we delete all comments and pod in the test script and send them
39 # to a .TEE file also save .DEBUG and .LOG output
40 my $params = "-dac -tac -D -g";
41
42 # Verify correctness of the formatted output and the .TEE output
43 # (.DEBUG and .LOG have been verified to work but are not checked here because 
44 # they may change over time, making work for maintaining this test file)
45
46 my $output;
47 my $teefile;
48 my $debugfile;
49 my $stderr_string;
50 my $errorfile_string;
51 my $logfile_string;
52 my $debugfile_string;
53 my $err = Perl::Tidy::perltidy(
54     source      => \$source,
55     destination => \$output,
56     perltidyrc  => \$params,
57     argv        => '',                 # for safety; hide any ARGV from perltidy
58     stderr      => \$stderr_string,
59     errorfile   => \$errorfile_string, # not used when -se flag is set
60     teefile     => \$teefile,
61     debugfile   => \$debugfile_string,
62     logfile     => \$logfile_string,
63 );
64
65 if ( $err || $stderr_string || $errorfile_string ) {
66     if ($err) {
67         print STDERR "This error received calling Perl::Tidy with '$sname'\n";
68         ok( !$err );
69     }
70     if ($stderr_string) {
71         print STDERR "---------------------\n";
72         print STDERR "<<STDERR>>\n$stderr_string\n";
73         print STDERR "---------------------\n";
74         print STDERR "This error received calling Perl::Tidy with '$sname''\n";
75         ok( !$stderr_string );
76     }
77     if ($errorfile_string) {
78         print STDERR "---------------------\n";
79         print STDERR "<<.ERR file>>\n$errorfile_string\n";
80         print STDERR "---------------------\n";
81         print STDERR "This error received calling Perl::Tidy with '$sname''\n";
82         ok( !$errorfile_string );
83     }
84 }
85 else {
86     ok( $output,  $expect );
87     ok( $teefile, $teefile_expect );
88 }