Login
Get generation of t/NamingConventions/Capitalization.run in place.
[gknop/Perl-Critic.git] / t / NamingConventions / Capitalization.run.PL
CommitLineData
d33d2185
ES
1#!/usr/bin/env perl
2
3use 5.006001;
4use strict;
5use warnings;
6
7use English qw< -no_match_vars >;
8use Carp qw< confess >;
9
10use Carp qw< confess >;
11use Fatal qw< open close >;
12
13our $VERSION = '1.093_01';
14
15
16
17my $this_program = __FILE__;
18(my $test_file_name = $this_program) =~ s/ [.] PL \z //xms;
19if ($this_program eq $test_file_name) {
20 confess
21 'Was not able to figure out the name of the file to generate.'
22 . "This program: $this_program.";
23}
24
25print "\n\nGenerating $test_file_name.\n";
26
27
28
29open my $test_file, '>', $test_file_name ## no critic (RequireBriefOpen)
30 or confess "Could not open $test_file_name: $ERRNO";
31
32
33print {$test_file} <<"END_HEADER";
34# Do not edit!!! This test suite generated by $this_program.
35END_HEADER
36
37emit_simple_tests($test_file);
38emit_footer($test_file);
39
40close $test_file;
41print "Done.\n\n";
42
43#-----------------------------------------------------------------------------
44
45sub emit_simple_tests {
46 my ($test_file) = @_;
47
48 print {$test_file} <<'END_SIMPLE_TESTS';
49#-----------------------------------------------------------------------------
50
1a33d0ae
ES
51## name Basic Passes
52## failures 0
53## cut
54
55my $foo;
56our $bar;
57my($foo, $bar) = ("BLEH", "BLEH");
58my @foo;
59my %bar;
60sub foo {}
61
62my $foo123;
63my $foo123bar;
64sub foo123 {}
65sub foo123bar {}
66
1a33d0ae
ES
67package This::SomeThing;
68package This;
69package This::Thing;
70package Acme::12345;
71package YYZ;
72
73#-----------------------------------------------------------------------------
74
75## name Basic Failures
76## failures 14
77## cut
78
79my $Foo;
80our $Bar;
81my @Foo;
82my %Bar;
83sub Foo {}
84
85my $foo_Bar;
86sub foo_Bar {}
87
88my $FooBar;
89sub FooBar {}
90
91my $foo123Bar;
92sub foo123Bar {}
93
94package pragma;
95package Foo::baz;
96package baz::FooBar;
97
98#-----------------------------------------------------------------------------
99
c86a4fc6
CD
100## name Special case: main
101## failures 0
102## cut
103
104package main;
105
106#-----------------------------------------------------------------------------
107
1a33d0ae
ES
108## name Combined passes and fails
109## failures 2
110## cut
111
112my($foo, $Bar);
113our($Bar, $foo);
114
115#-----------------------------------------------------------------------------
116
117## name Variables from other packages should pass
118## failures 0
119## cut
120
121local $Other::Package::Foo;
122$Other::Package::Foo;
123
124#-----------------------------------------------------------------------------
125
126## name Only cares about declarations
127## failures 0
128## cut
129Foo();
130$Foo = 42;
131
132#-----------------------------------------------------------------------------
133
134## name Constants must be all caps, passes
135## failures 0
136## cut
137
138Readonly::Scalar my $CONSTANT = 23;
139
140#-----------------------------------------------------------------------------
141
142## name Constants must be all caps, failures
143## TODO Detect whether a scalar is constant or not
144## failures 4
145## cut
146
147Readonly::Scalar my $Foo = 23;
148Readonly::Scalar my $foo = 23;
149Readonly::Scalar my $fooBAR = 23;
150my $CONSTANT = 23;
d33d2185
ES
151END_SIMPLE_TESTS
152
153 return;
154}
155
156
157sub emit_footer {
158
159 print {$test_file} <<'END_FOOTER';
160
161#-----------------------------------------------------------------------------
162# Local Variables:
163# mode: cperl
164# cperl-indent-level: 4
165# fill-column: 78
166# indent-tabs-mode: nil
167# c-indentation-style: bsd
168# End:
169# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :
170END_FOOTER
1a33d0ae 171
d33d2185
ES
172 return;
173}
1a33d0ae
ES
174
175#-----------------------------------------------------------------------------
176# Local Variables:
177# mode: cperl
178# cperl-indent-level: 4
179# fill-column: 78
180# indent-tabs-mode: nil
181# c-indentation-style: bsd
182# End:
183# ex: set ts=8 sts=4 sw=4 tw=78 ft=perl expandtab shiftround :