atoulme-Saikuro 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,39 @@
1
+ # This is a patch to RDoc so that when saikuro is installed as a
2
+ # RubyGem usage will read the proper file.
3
+
4
+ require 'rdoc/usage'
5
+
6
+ module RDoc
7
+
8
+ def RDoc.main_program_file=(file)
9
+ @@main_program_file = file
10
+ end
11
+
12
+ # Display usage
13
+ def RDoc.usage_no_exit(*args)
14
+ @@main_program_file ||= caller[-1].sub(/:\d+$/, '')
15
+ comment = File.open(@@main_program_file) do |file|
16
+ find_comment(file)
17
+ end
18
+
19
+ comment = comment.gsub(/^\s*#/, '')
20
+
21
+ markup = SM::SimpleMarkup.new
22
+ flow_convertor = SM::ToFlow.new
23
+
24
+ flow = markup.convert(comment, flow_convertor)
25
+
26
+ format = "plain"
27
+
28
+ unless args.empty?
29
+ flow = extract_sections(flow, args)
30
+ end
31
+
32
+ options = RI::Options.instance
33
+ if args = ENV["RI"]
34
+ options.parse(args.split)
35
+ end
36
+ formatter = options.formatter.new(options, "")
37
+ formatter.display_flow(flow)
38
+ end
39
+ end
@@ -0,0 +1,70 @@
1
+ # These are methods to show warning and errors
2
+ # The code is nonsense it is used to make large complexity values.
3
+
4
+ class ExtraTests
5
+
6
+ # CC 8
7
+ def warn_method_cc8(a, b, c)
8
+ q, r, s = nil
9
+ if a
10
+ q = a + c
11
+ end
12
+ if b
13
+ b = r - q
14
+ end
15
+ if !c
16
+ s = r + b
17
+ end
18
+ if b > q || c
19
+ a = c + q
20
+ end
21
+ if a
22
+ c = b
23
+ end
24
+ if c
25
+ b = a
26
+ end
27
+ if s
28
+ c = s + a
29
+ end
30
+ # large token count
31
+ a + b + c + q + r + s + a + b + c + q + r + s + a + b + c + q + r + s + a + b + c + q + r + s
32
+ end
33
+
34
+ # CC 11
35
+ def error_method_cc11(a, b, c)
36
+ q, r, s = nil
37
+ if a
38
+ q = a + c
39
+ end
40
+ if b
41
+ b = r - q
42
+ end
43
+ if !c
44
+ s = r + b
45
+ end
46
+ if b > q || c
47
+ a = c + q
48
+ end
49
+ if a
50
+ c = b
51
+ end
52
+ if c
53
+ b = a
54
+ end
55
+ if s
56
+ c = s + a
57
+ end
58
+ if q
59
+ r = s + q
60
+ end
61
+ if r
62
+ s = a + r
63
+ end
64
+ a + b + c + q + r + s + a + b + c + q + r + s
65
+ rescue => err
66
+ puts err
67
+ end
68
+
69
+
70
+ end
data/tests/samples.rb ADDED
@@ -0,0 +1,315 @@
1
+
2
+
3
+ # CC : 1
4
+ def cc1
5
+ "hello"
6
+ end
7
+
8
+ class CylcoIfTestClass
9
+
10
+ # CC 2
11
+ def cc2(arg)
12
+ # Comment inside method
13
+ if arg
14
+ "True Arg"
15
+ else
16
+ "False Arg"
17
+ end
18
+ end
19
+
20
+ # CC 3
21
+ def cc3(arg1 = true, arg2 = false)
22
+ if arg1
23
+ "ARG1"
24
+ elsif arg2
25
+ "ARG2"
26
+ else
27
+ "Neither ARG1 or ARG2"
28
+ end
29
+ end
30
+
31
+ # Also CC 3
32
+ def cc3_2(arg1 = true, arg2 = false)
33
+ if arg1
34
+ if arg2
35
+ "ARG1 and ARG2"
36
+ else
37
+ "ARG1"
38
+ end
39
+ else
40
+ "No ARG1"
41
+ end
42
+ end
43
+
44
+
45
+ def cc2_2(arg)
46
+ v = "not arg"
47
+ v = "arg" if arg
48
+ v
49
+ end
50
+
51
+ def cc2_2(arg)
52
+ if arg then
53
+ "True Arg"
54
+ else
55
+ "False Arg"
56
+ end
57
+ end
58
+
59
+ def cc2_ternary(arg)
60
+ arg ? "True" : "False"
61
+ end
62
+
63
+ def cc1?(arg)
64
+ cc2?
65
+ end
66
+
67
+ end
68
+
69
+ class CycloException < StandardError; end
70
+
71
+ class CycloUnlessTestClass
72
+
73
+ def cc2(arg = true)
74
+ v = "cc2"
75
+ unless arg
76
+ arg = false
77
+ v = "unless"
78
+ end
79
+ v
80
+ end
81
+
82
+ def cc2_2(arg)
83
+ unless arg
84
+ "not arg"
85
+ else
86
+ "arg"
87
+ end
88
+ end
89
+
90
+ def cc2_3(arg)
91
+ v = "arg"
92
+ v = "trail" unless arg
93
+ v
94
+ end
95
+
96
+ end
97
+
98
+ class CycloDefTestClass
99
+
100
+ def cc3
101
+ "p1"
102
+ rescue CycloException => ce
103
+ "ce"
104
+ rescue => err
105
+ "se"
106
+ end
107
+
108
+ def cc2
109
+ p = "p1"
110
+ rescue CycloException => ce
111
+ p = "CE"
112
+ else
113
+ p = "pelse"
114
+ ensure
115
+ p + "ensured"
116
+ end
117
+
118
+ def self.classm1_cc1
119
+ "c1"
120
+ end
121
+
122
+ def CycloDefTestClass.classm2_cc1
123
+ "c2"
124
+ end
125
+
126
+ end
127
+
128
+ module CycloTestModule
129
+
130
+ def cc4_case(arg)
131
+ v = "1"
132
+ case arg
133
+ when "1"
134
+ v += "c1"
135
+ when "2"
136
+ v << "c2"
137
+ when "3", "4"
138
+ v<< "c3/4"
139
+ else
140
+ v<< "else"
141
+ end
142
+ v
143
+ end
144
+
145
+ def while1_cc2(arg)
146
+ v = "no while"
147
+ while arg
148
+ v = "while"
149
+ arg = false
150
+ end
151
+ v
152
+ end
153
+
154
+ def while2_cc2(arg)
155
+ v = "no while"
156
+ arg = false while arg
157
+ v
158
+ end
159
+
160
+ def while3_cc2(arg)
161
+ v = "no while"
162
+ begin
163
+ v = "must while"
164
+ arg = false
165
+ end while arg
166
+ end
167
+
168
+ def while4_cc3(arg)
169
+ v = "no while"
170
+ while arg do
171
+ v = "while"
172
+ arg = false
173
+ end
174
+ v
175
+ end
176
+
177
+ def for_cc2(arg)
178
+ v = 0
179
+ for x in arg
180
+ v += x
181
+ end
182
+ v
183
+ end
184
+
185
+ # The do causes an error in the current implementation.
186
+ def for2_cc2(arg)
187
+ v = 0
188
+ for x in arg do
189
+ v += x
190
+ end
191
+ v
192
+ end
193
+
194
+ # def commented_out_method
195
+ # "Should not be seen"
196
+ # end
197
+
198
+ def block_cc2(arg)
199
+ v = 0
200
+ arg.each do |i|
201
+ v += x
202
+ end
203
+ v
204
+ end
205
+
206
+ def block2_cc2(arg)
207
+ v = 0
208
+ arg.each { |i| v += x }
209
+ v
210
+ end
211
+
212
+ def hash_cc1
213
+ { :x => 1 }
214
+ end
215
+
216
+ end
217
+
218
+ # Just to make sure classes wrapped in module show.
219
+ module CycloTestModule2
220
+
221
+ class CycloUntilTestClass
222
+
223
+ def until_cc2(arg)
224
+ v = "until"
225
+ until arg
226
+ v = "no more until"
227
+ arg = true
228
+ end
229
+ v
230
+ end
231
+
232
+
233
+ def until2_cc2(arg)
234
+ v = "no until"
235
+ arg = true until arg
236
+ v
237
+ end
238
+
239
+ def until3_cc2(arg)
240
+ v = "no until"
241
+ begin
242
+ v = "must until"
243
+ arg = true
244
+ end until arg
245
+ end
246
+
247
+ def until4_cc2(arg)
248
+ v = "until"
249
+ until arg do
250
+ v = "no more until"
251
+ arg = true
252
+ end
253
+ v
254
+ end
255
+
256
+ end
257
+
258
+ end
259
+
260
+ class SyntaxTests
261
+
262
+ def here_docs_cc1
263
+ str = <<-EOF
264
+ Hello
265
+ This is a here doc
266
+ EOF
267
+ str
268
+ end
269
+
270
+ def SyntaxTests::colon_method_cc1
271
+ "cc1"
272
+ end
273
+
274
+ def symbol_test_cc1(arg)
275
+ { :s1 => 1,
276
+ :class => "should not be a class",
277
+ }
278
+ end
279
+
280
+ def hash_with_hash1(arg)
281
+ h = {
282
+ :x => {
283
+ :q => arg
284
+ }
285
+ }
286
+ end
287
+
288
+ def hash_with_block_inside1(arg)
289
+ data = {
290
+ :x => 1,
291
+ :y => arg.map do |a|
292
+ a + 2
293
+ end,
294
+ }
295
+ end
296
+
297
+ def hash_with_block_inside2(arg)
298
+ data = {
299
+ :x => 1,
300
+ :y => arg.map do |a|
301
+ {
302
+ :q => b_meth { a }
303
+ }
304
+ end,
305
+ }
306
+ end
307
+
308
+
309
+ =begin
310
+ def begin_end_comment
311
+ "Should not be shown"
312
+ end
313
+ =end
314
+
315
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: atoulme-Saikuro
3
+ version: !ruby/object:Gem::Version
4
+ hash: 17
5
+ prerelease: false
6
+ segments:
7
+ - 1
8
+ - 1
9
+ - 1
10
+ version: 1.1.1
11
+ platform: ruby
12
+ authors:
13
+ - Zev Blut, Antoine Toulme
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-07-22 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: zb@ubit.com
24
+ executables:
25
+ - saikuro
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README
30
+ files:
31
+ - bin/saikuro
32
+ - lib/saikuro/usage.rb
33
+ - lib/saikuro.rb
34
+ - tests/large_example.rb
35
+ - tests/samples.rb
36
+ - README
37
+ has_rdoc: true
38
+ homepage: http://saikuro.rubyforge.org/
39
+ licenses: []
40
+
41
+ post_install_message:
42
+ rdoc_options: []
43
+
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ hash: 3
52
+ segments:
53
+ - 0
54
+ version: "0"
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ requirements: []
65
+
66
+ rubyforge_project: saikuro
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: Saikuro is a Ruby cyclomatic complexity analyzer. When given Ruby source code Saikuro will generate a report listing the cyclomatic complexity of each method found. In addition, Saikuro counts the number of lines per method and can generate a listing of the number of tokens on each line of code.
71
+ test_files: []
72
+