test harness: improve catching of usage errors in script 'test-driver'
[platform/upstream/automake.git] / t / pm / Wrap.pl
1 # Copyright (C) 2003-2013 Free Software Foundation, Inc.
2 #
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2, or (at your option)
6 # any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
15
16 use Automake::Wrap qw/wrap makefile_wrap/;
17
18 my $failed = 0;
19
20 sub test_wrap
21 {
22   my ($in, $exp_out) = @_;
23
24   my $out = &wrap (@$in);
25   if ($out ne $exp_out)
26     {
27       print STDERR "For: @$in\nGot:\n$out\nInstead of:\n$exp_out\n---\n";
28       ++$failed;
29     }
30 }
31
32 sub test_makefile_wrap
33 {
34   my ($in, $exp_out) = @_;
35
36   my $out = &makefile_wrap (@$in);
37   if ($out ne $exp_out)
38     {
39       print STDERR "For: @$in\nGot:\n$out\nInstead of:\n$exp_out\n---\n";
40       ++$failed;
41     }
42 }
43
44 my @tests = (
45   [["HEAD:", "NEXT:", "CONT", 13, "v" ,"a", "l", "ue", "s", "values"],
46 "HEAD:v aCONT
47 NEXT:l ueCONT
48 NEXT:sCONT
49 NEXT:values
50 "],
51   [["rule: ", "\t", " \\", 20, "dep1" ,"dep2", "dep3", "dep4", "dep5",
52     "dep06", "dep07", "dep08"],
53 "rule: dep1 dep2 \\
54 \tdep3 dep4 \\
55 \tdep5 dep06 \\
56 \tdep07 \\
57 \tdep08
58 "],
59   [["big header:", "big continuation:", " END", 5, "diag1", "diag2", "diag3"],
60 "big header:diag1 END
61 big continuation:diag2 END
62 big continuation:diag3
63 "],
64   [["big header:", "cont: ", " END", 16, "word1", "word2"],
65 "big header: END
66 cont: word1 END
67 cont: word2
68 "],
69   [["big header:", "", " END", 16, "w1", "w2 ", "w3"],
70 "big header: END
71 w1 w2 w3
72 "]);
73
74 my @makefile_tests = (
75   [["target:"],
76 "target:
77 "],
78   [["target:", "\t"],
79 "target:
80 "],
81   [["target:", "\t", "prereq1", "prereq2"],
82 "target: prereq1 prereq2
83 "],
84   [["target: ", "\t", "this is a long list of prerequisites ending in space",
85     "so that there is no need for another space before the backslash",
86     "unlike in the second line"],
87 "target: this is a long list of prerequisites ending in space \\
88 \tso that there is no need for another space before the backslash \\
89 \tunlike in the second line
90 "]);
91
92 test_wrap (@{$_}) foreach @tests;
93 test_makefile_wrap (@{$_}) foreach @makefile_tests;
94
95 exit $failed;
96
97 ### Setup "GNU" style for perl-mode and cperl-mode.
98 ## Local Variables:
99 ## perl-indent-level: 2
100 ## perl-continued-statement-offset: 2
101 ## perl-continued-brace-offset: 0
102 ## perl-brace-offset: 0
103 ## perl-brace-imaginary-offset: 0
104 ## perl-label-offset: -2
105 ## cperl-indent-level: 2
106 ## cperl-brace-offset: 0
107 ## cperl-continued-brace-offset: 0
108 ## cperl-label-offset: -2
109 ## cperl-extra-newline-before-brace: t
110 ## cperl-merge-trailing-else: nil
111 ## cperl-continued-statement-offset: 2
112 ## End: