]> git.donarmstrong.com Git - perltidy.git/blob - examples/testff.t
[svn-inject] Installing original source of perltidy
[perltidy.git] / examples / testff.t
1 use strict;
2 use Test;
3 use Carp;
4 BEGIN {plan tests => 1}
5 use Perl::Tidy; 
6
7 #----------------------------------------------------------------------
8 ## test file->file through arg list
9 #   Also tests:
10 #     passing parameters names through 'argv=>'
11 #     -o flag
12 #
13 #     NOTE: This will read file 'lextest' and create file 'lextest.out'
14 #     (for portability, 8.3 filenames are best)
15 #     NOTE: must use -npro flag to avoid using local perltidyrc flags
16 #----------------------------------------------------------------------
17
18 my $input_file = "lextest";
19 my $output_file = "lextest.out";
20
21 Perl::Tidy::perltidy(
22     source      => undef,
23     destination => undef,
24     perltidyrc  => undef,
25     argv        => "-nsyn -npro $input_file -o $output_file",
26 );
27
28 open FILE, "< $output_file";
29 my @output=<FILE>;
30 my @expected_output=<DATA>;
31 my $ok=1;
32 if (@expected_output == @output) {
33         while ( $_ = pop @output ) {
34             my $expect = pop @expected_output;
35             if ( $expect ne $_ ) {
36                 print STDERR "got:$_";
37                 print STDERR "---\n";
38                 print STDERR "expected_output:$expect";
39                 $ok=0;
40                 last;
41             }
42         }
43 }
44 else {
45         print STDERR "Line Counts differ\n";
46         $ok=0;
47 }
48 ok ($ok,1);
49
50 # This is the expected result of 'perltidy lextest':
51
52 __DATA__
53 # This is a simple testfile to demonstrate perltidy, from perlop(1).
54 # One way (of several) to run perltidy is as follows:
55 #
56 #   perl ./perltidy lextest
57 #
58 # The output will be "lextest.tdy"
59 $_ = <<'EOL';
60    $url = new URI::URL "http://www/";   die if $url eq "xXx";
61 EOL
62 LOOP: {
63     print(" digits"),       redo LOOP if /\G\d+\b[,.;]?\s*/gc;
64     print(" lowercase"),    redo LOOP if /\G[a-z]+\b[,.;]?\s*/gc;
65     print(" UPPERCASE"),    redo LOOP if /\G[A-Z]+\b[,.;]?\s*/gc;
66     print(" Capitalized"),  redo LOOP if /\G[A-Z][a-z]+\b[,.;]?\s*/gc;
67     print(" MiXeD"),        redo LOOP if /\G[A-Za-z]+\b[,.;]?\s*/gc;
68     print(" alphanumeric"), redo LOOP if /\G[A-Za-z0-9]+\b[,.;]?\s*/gc;
69     print(" line-noise"),   redo LOOP if /\G[^A-Za-z0-9]+/gc;
70     print ". That's all!\n";
71 }