File: ProhibitNegativeExpressionsInUnlessAndUntilConditions.run.PL

package info (click to toggle)
libperl-critic-perl 1.156-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 3,544 kB
  • sloc: perl: 24,092; lisp: 341; makefile: 7
file content (305 lines) | stat: -rw-r--r-- 5,996 bytes parent folder | download | duplicates (2)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
#!/usr/bin/env perl

use 5.010001;
use strict;
use warnings;

use English qw< -no_match_vars >;
use Carp qw< confess >;

use Carp qw< confess >;
use Fatal qw< open close >;

my $this_program = __FILE__;
(my $test_file_name = $this_program) =~ s/ [.] PL \z //xms;
if ($this_program eq $test_file_name) {
    confess
        'Was not able to figure out the name of the file to generate.'
        . "This program: $this_program.";
}

print "\n\nGenerating $test_file_name.\n";



open my $test_file, '>', $test_file_name    ## no critic (RequireBriefOpen)
    or confess "Could not open $test_file_name: $ERRNO";


print {$test_file} <<"END_HEADER";
# Do not edit!!!  This test suite generated by $this_program.
END_HEADER

foreach my $operator ( qw/ ! not / ) {
    emit_not_operator_code($test_file, $operator);
}
emit_not_match_code($test_file);
foreach my $operator ( qw/ ne != < > <= >= <=> lt gt le ge cmp / ) {
    emit_comparator_code($test_file, $operator);
}


print {$test_file} <<'END_FOOTER';

#-----------------------------------------------------------------------------

# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 78
#   indent-tabs-mode: nil
#   c-indentation-style: bsd
# End:
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
END_FOOTER


close $test_file;
print "Done.\n\n";

#-----------------------------------------------------------------------------

sub emit_not_operator_code {
    my ($test_file, $operator) = @_;

    print {$test_file} <<"END_NOT_OPERATOR_CODE";

## name "$operator" within positive control structures
## failures 0
## cut

if ($operator \$foo) {
    blah();
}

if (\$foo) {
    blah(\$foo);
}
elsif ($operator \$bar) {
    blah(\$bar);
}
else {
    blah(undef);
}

while ($operator \$foo) {
    blah();
}

foreach my \$bar ( grep { $operator \$_ } \@foo ) {
    blah(\$bar);
}

for (my \$bar = 0; $operator \$bar; \$bar++) {
    blah(\$bar);
}

#-----------------------------------------------------------------------------

## name "$operator" within positive postfix statement modifiers
## failures 0
## cut

blah() if $operator \$foo;

blah() while $operator \$foo;

blah(\$_) for grep { $operator \$_ } \@foo;

#-----------------------------------------------------------------------------

## name "$operator" within negative control structures
## failures 2
## cut

unless ($operator \$foo) {
    blah();
}

until ($operator \$foo) {
    blah();
}

#-----------------------------------------------------------------------------

## name "$operator" within negative postfix statement modifiers
## failures 2
## cut

blah() unless $operator \$foo;

blah() until $operator \$foo;

#-----------------------------------------------------------------------------
END_NOT_OPERATOR_CODE

    return;
}

#-----------------------------------------------------------------------------

sub emit_not_match_code {
    my ($test_file) = @_;

    print {$test_file} <<'END_NOT_MATCH_CODE';

## name "!~" within positive control structures
## failures 0
## cut

if ($foo !~ m/bar/) {
    blah();
}

if ($foo) {
    blah($foo);
}
elsif ($bar !~ m/bar/) {
    blah($bar);
}
else {
    blah(undef);
}

while ($foo !~ m/bar/) {
    blah();
}

foreach my $bar ( grep { $_ !~ m/baz/ } @foo ) {
    blah($bar);
}

for (my $bar = 0; $bar =~ m/baz/; $bar++) {
    blah($bar);
}

#-----------------------------------------------------------------------------

## name "!~" within positive postfix statement modifiers
## failures 0
## cut

blah() if $foo !~ m/bar/;

blah() while $foo !~ m/bar/;

blah($_) for grep { $_ !~ m/bar/ } @foo;

#-----------------------------------------------------------------------------

## name "!~" within negative control structures
## failures 2
## cut

unless ($foo !~ m/bar/) {
    blah();
}

until ($foo !~ m/bar/) {
    blah();
}

#-----------------------------------------------------------------------------

## name "!~" within negative postfix statement modifiers
## failures 2
## cut

blah() unless $foo !~ m/bar/;

blah() until $foo !~ m/bar/;

#-----------------------------------------------------------------------------
END_NOT_MATCH_CODE

    return;
}

#-----------------------------------------------------------------------------

sub emit_comparator_code {
    my ($test_file, $operator) = @_;

    print {$test_file} <<"END_COMPARATOR_CODE";

## name "$operator" within positive control structures
## failures 0
## cut

if (\$foo $operator \$bar) {
    blah();
}

if (\$foo $operator \$bar) {
    blah(\$foo);
}
elsif (\$bar $operator \$baz) {
    blah(\$bar);
}
else {
    blah(undef);
}

while (\$foo $operator \$bar) {
    blah();
}

foreach my \$bar ( grep { \$_ $operator \$baz } \@foo ) {
    blah(\$bar);
}

for (my \$bar = 0; \$bar $operator \$baz; \$bar++) {
    blah(\$bar);
}

#-----------------------------------------------------------------------------

## name "$operator" within positive postfix statement modifiers
## failures 0
## cut

blah() if \$foo $operator \$bar;

blah() while \$foo $operator \$bar;

blah(\$_) for grep { \$_ $operator \$bar } \@foo;

#-----------------------------------------------------------------------------

## name "$operator" within negative control structures
## failures 2
## cut

unless (\$foo $operator \$bar) {
    blah();
}

until (\$foo $operator \$bar) {
    blah();
}

#-----------------------------------------------------------------------------

## name "$operator" within negative postfix statement modifiers
## failures 2
## cut

blah() unless \$foo $operator \$bar;

blah() until \$foo $operator \$bar;

#-----------------------------------------------------------------------------
END_COMPARATOR_CODE

    return;
}

#-----------------------------------------------------------------------------
# Local Variables:
#   mode: cperl
#   cperl-indent-level: 4
#   fill-column: 78
#   indent-tabs-mode: nil
#   c-indentation-style: bsd
# End:
# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :