iain-metric_fu 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/HISTORY +159 -0
- data/MIT-LICENSE +22 -0
- data/Manifest +103 -0
- data/README +1 -0
- data/Rakefile +29 -0
- data/TODO +9 -0
- data/home_page/back_all.jpg +0 -0
- data/home_page/churn.gif +0 -0
- data/home_page/flay.gif +0 -0
- data/home_page/flog.gif +0 -0
- data/home_page/footer.gif +0 -0
- data/home_page/header.jpg +0 -0
- data/home_page/img09.gif +0 -0
- data/home_page/index.html +270 -0
- data/home_page/rcov.gif +0 -0
- data/home_page/reek.gif +0 -0
- data/home_page/roodi.gif +0 -0
- data/home_page/saikuro.gif +0 -0
- data/home_page/stats.gif +0 -0
- data/home_page/styles.css +245 -0
- data/home_page/title.gif +0 -0
- data/home_page/title_back.gif +0 -0
- data/lib/base/base_template.rb +146 -0
- data/lib/base/configuration.rb +187 -0
- data/lib/base/generator.rb +160 -0
- data/lib/base/graph.rb +38 -0
- data/lib/base/md5_tracker.rb +52 -0
- data/lib/base/report.rb +100 -0
- data/lib/generators/churn.rb +90 -0
- data/lib/generators/flay.rb +33 -0
- data/lib/generators/flog.rb +140 -0
- data/lib/generators/rcov.rb +87 -0
- data/lib/generators/reek.rb +37 -0
- data/lib/generators/roodi.rb +31 -0
- data/lib/generators/saikuro.rb +208 -0
- data/lib/generators/stats.rb +43 -0
- data/lib/graphs/flay_grapher.rb +35 -0
- data/lib/graphs/flog_grapher.rb +51 -0
- data/lib/graphs/grapher.rb +19 -0
- data/lib/graphs/rcov_grapher.rb +34 -0
- data/lib/graphs/reek_grapher.rb +44 -0
- data/lib/graphs/roodi_grapher.rb +34 -0
- data/lib/graphs/stats_grapher.rb +37 -0
- data/lib/metric_fu.rb +30 -0
- data/lib/templates/awesome/awesome_template.rb +30 -0
- data/lib/templates/awesome/churn.html.erb +19 -0
- data/lib/templates/awesome/css/buttons.css +82 -0
- data/lib/templates/awesome/css/default.css +81 -0
- data/lib/templates/awesome/css/integrity.css +335 -0
- data/lib/templates/awesome/css/reset.css +7 -0
- data/lib/templates/awesome/flay.html.erb +27 -0
- data/lib/templates/awesome/flog.html.erb +47 -0
- data/lib/templates/awesome/index.html.erb +28 -0
- data/lib/templates/awesome/js/sorttable.js +492 -0
- data/lib/templates/awesome/layout.html.erb +34 -0
- data/lib/templates/awesome/rcov.html.erb +36 -0
- data/lib/templates/awesome/reek.html.erb +34 -0
- data/lib/templates/awesome/roodi.html.erb +21 -0
- data/lib/templates/awesome/saikuro.html.erb +71 -0
- data/lib/templates/awesome/stats.html.erb +46 -0
- data/lib/templates/standard/churn.html.erb +31 -0
- data/lib/templates/standard/default.css +64 -0
- data/lib/templates/standard/flay.html.erb +34 -0
- data/lib/templates/standard/flog.html.erb +53 -0
- data/lib/templates/standard/index.html.erb +38 -0
- data/lib/templates/standard/rcov.html.erb +43 -0
- data/lib/templates/standard/reek.html.erb +42 -0
- data/lib/templates/standard/roodi.html.erb +29 -0
- data/lib/templates/standard/saikuro.html.erb +84 -0
- data/lib/templates/standard/standard_template.rb +26 -0
- data/lib/templates/standard/stats.html.erb +55 -0
- data/metric_fu.gemspec +42 -0
- data/spec/base/base_template_spec.rb +161 -0
- data/spec/base/configuration_spec.rb +300 -0
- data/spec/base/generator_spec.rb +181 -0
- data/spec/base/graph_spec.rb +24 -0
- data/spec/base/md5_tracker_spec.rb +57 -0
- data/spec/base/report_spec.rb +139 -0
- data/spec/generators/churn_spec.rb +152 -0
- data/spec/generators/flay_spec.rb +104 -0
- data/spec/generators/flog_spec.rb +219 -0
- data/spec/generators/reek_spec.rb +60 -0
- data/spec/generators/saikuro_spec.rb +58 -0
- data/spec/generators/stats_spec.rb +74 -0
- data/spec/graphs/flay_grapher_spec.rb +44 -0
- data/spec/graphs/flog_grapher_spec.rb +61 -0
- data/spec/graphs/grapher_spec.rb +9 -0
- data/spec/graphs/rcov_grapher_spec.rb +44 -0
- data/spec/graphs/reek_grapher_spec.rb +53 -0
- data/spec/graphs/roodi_grapher_spec.rb +44 -0
- data/spec/graphs/stats_grapher_spec.rb +60 -0
- data/spec/resources/saikuro/app/controllers/sessions_controller.rb_cyclo.html +10 -0
- data/spec/resources/saikuro/app/controllers/users_controller.rb_cyclo.html +16 -0
- data/spec/resources/saikuro/index_cyclo.html +155 -0
- data/spec/resources/saikuro_sfiles/thing.rb_cyclo.html +11 -0
- data/spec/resources/yml/20090630.yml +7844 -0
- data/spec/resources/yml/20090822.yml +8342 -0
- data/spec/spec.opts +8 -0
- data/spec/spec_helper.rb +6 -0
- data/tasks/metric_fu.rake +22 -0
- data/vendor/_fonts/monaco.ttf +0 -0
- data/vendor/saikuro/SAIKURO_README +142 -0
- data/vendor/saikuro/saikuro.rb +1219 -0
- metadata +251 -0
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require 'rake'
|
2
|
+
namespace :metrics do
|
3
|
+
desc "Generate all metrics reports"
|
4
|
+
task :all do
|
5
|
+
MetricFu::Configuration.run {}
|
6
|
+
MetricFu.metrics.each {|metric| MetricFu.report.add(metric) }
|
7
|
+
MetricFu.report.save_output(MetricFu.report.to_yaml,
|
8
|
+
MetricFu.base_directory,
|
9
|
+
"report.yml")
|
10
|
+
MetricFu.report.save_output(MetricFu.report.to_yaml,
|
11
|
+
MetricFu.data_directory,
|
12
|
+
"#{Time.now.strftime("%Y%m%d")}.yml")
|
13
|
+
MetricFu.report.save_templatized_report
|
14
|
+
|
15
|
+
MetricFu.graphs.each {|graph| MetricFu.graph.add(graph) }
|
16
|
+
MetricFu.graph.generate
|
17
|
+
|
18
|
+
if MetricFu.report.open_in_browser?
|
19
|
+
MetricFu.report.show_in_browser(MetricFu.output_directory)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
Binary file
|
@@ -0,0 +1,142 @@
|
|
1
|
+
Version 0.2
|
2
|
+
|
3
|
+
Saikuro:
|
4
|
+
Saikuro is a Ruby cyclomatic complexity analyzer. When given Ruby
|
5
|
+
source code Saikuro will generate a report listing the cyclomatic
|
6
|
+
complexity of each method found. In addition, Saikuro counts the
|
7
|
+
number of lines per method and can generate a listing of the number of
|
8
|
+
tokens on each line of code.
|
9
|
+
|
10
|
+
License:
|
11
|
+
Saikuro uses the BSD license.
|
12
|
+
|
13
|
+
Installation:
|
14
|
+
Option 1: Using setup.rb
|
15
|
+
* login as root
|
16
|
+
* run "ruby setup.rb all"
|
17
|
+
|
18
|
+
Option 2: The manual way
|
19
|
+
Saikuro is a single Ruby file that is executable. You can run it where
|
20
|
+
you unpacked it or you can move it your preferred location such as
|
21
|
+
"/usr/local/bin" or "~/bin".
|
22
|
+
|
23
|
+
Note:
|
24
|
+
Ruby 1.8.5 has a bug in ri_options that will prevent Saikuro from
|
25
|
+
running. If you are using 1.8.5 please apply this patch :
|
26
|
+
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/lib/rdoc/ri/ri_options.rb.diff?r1=1.2.2.13;r2=1.2.2.14
|
27
|
+
|
28
|
+
|
29
|
+
Usage:
|
30
|
+
Saikuro is a command line program.
|
31
|
+
Running "saikuro -h" will output a usage statement describing all
|
32
|
+
the various arguments you can pass to it.
|
33
|
+
|
34
|
+
"saikuro -c -p tests/samples.rb"
|
35
|
+
|
36
|
+
The above command is a simple example that generates a cyclomatic
|
37
|
+
complexity report on the samples.rb file, using the default filter,
|
38
|
+
warning and error settings. The report is saved in the current
|
39
|
+
directory.
|
40
|
+
|
41
|
+
|
42
|
+
A more detailed example is
|
43
|
+
"saikuro -c -t -i tests -y 0 -w 11 -e 16 -o out/"
|
44
|
+
|
45
|
+
This will analyze all Ruby files found in the "tests/" directory.
|
46
|
+
Saikuro will generate a token count report and a cyclomatic complexity
|
47
|
+
report in the "out" directory . The "-y 0" command will turn off
|
48
|
+
filtering and thus show the complexity of all methods. The "-w 11"
|
49
|
+
will mark all methods with a complexity of 11 or higher with a
|
50
|
+
warning. Finally, "-e 16" will flag all methods with a complexity of
|
51
|
+
16 or higher with an error.
|
52
|
+
|
53
|
+
|
54
|
+
About Cyclomatic Complexity:
|
55
|
+
|
56
|
+
The following document provides a very good and detailed description
|
57
|
+
by the author of cyclomatic complexity.
|
58
|
+
|
59
|
+
NIST Special Publication 500-235
|
60
|
+
Structured Testing: A Testing Methodology Using the Cyclomatic
|
61
|
+
Complexity Metric
|
62
|
+
|
63
|
+
By Arthur H. Watson and Thomas J. McCabe
|
64
|
+
HTML
|
65
|
+
http://hissa.nist.gov/HHRFdata/Artifacts/ITLdoc/235/title.htm
|
66
|
+
PDF
|
67
|
+
http://www.mccabe.com/iq_research_nist.htm
|
68
|
+
|
69
|
+
|
70
|
+
How and what Saikuro counts to calculate the cyclomatic complexity:
|
71
|
+
|
72
|
+
Saikuro uses the Simplified Complexity Calculation, which is just
|
73
|
+
adding up the number of branch points in a method.
|
74
|
+
|
75
|
+
Each method starts with a complexity of 1, because there is at least
|
76
|
+
one path through the code. Then each conditional or looping operator
|
77
|
+
(if, unless, while, until, for, elsif, when) adds one point to the
|
78
|
+
complexity. Each "when" in a case statement adds one point. Also each
|
79
|
+
"rescue" statement adds one.
|
80
|
+
|
81
|
+
Saikuro also regards blocks as an addition to a method's complexity
|
82
|
+
because in many cases a block does add a path that may be traversed.
|
83
|
+
For example, invoking the "each" method of an array with a block would
|
84
|
+
only traverse the give block if the array is not empty. Thus if you
|
85
|
+
want to find the basis set to get 100% coverage of your code then a
|
86
|
+
block should add one point to the method's complexity. It is not yet
|
87
|
+
for sure however to what level the accuracy is decreased through this
|
88
|
+
measurement, as normal Ruby code uses blocks quite heavily and new
|
89
|
+
paths are not necessarily introduced by every block.
|
90
|
+
|
91
|
+
In addition, the short-circuiting "and" operators (&& and "and")
|
92
|
+
currently do not contribute to a method's complexity, although
|
93
|
+
McCabe's paper listed above suggests doing so.
|
94
|
+
|
95
|
+
|
96
|
+
#Example for "and" operator handling:
|
97
|
+
|
98
|
+
# Starting values for case 1 and 2
|
99
|
+
x = false
|
100
|
+
y = 15
|
101
|
+
r, q = nil
|
102
|
+
|
103
|
+
# case 1
|
104
|
+
puts "W" if ((r = x) && (q = y))
|
105
|
+
puts r # => false
|
106
|
+
puts q # => nil
|
107
|
+
|
108
|
+
# case 2
|
109
|
+
puts "W" if ((q = y) && (r = x))
|
110
|
+
puts r # => false
|
111
|
+
puts q # => 15
|
112
|
+
|
113
|
+
Case 1 illustrates why "and" operators should add to a method's
|
114
|
+
complexity, because the result of ( r = x ) is false the if statement
|
115
|
+
stops and returns false without evaluating the ( q = y ) branch. Thus
|
116
|
+
if a total coverage of source code is desired, one point should be
|
117
|
+
added to the method's complexity.
|
118
|
+
|
119
|
+
So why is it not added?
|
120
|
+
Mainly, because we have not gotten around to it. We are wondering if
|
121
|
+
this would increase the noise more than it should.
|
122
|
+
|
123
|
+
|
124
|
+
Tests:
|
125
|
+
In the test directory is a sample file that has examples of the
|
126
|
+
various possible cases that we examined and documented the expected
|
127
|
+
cyclomatic complexity result. If you find mistakes or missing tests
|
128
|
+
please report them.
|
129
|
+
|
130
|
+
Contact:
|
131
|
+
Saikuro is written by
|
132
|
+
Zev Blut (zb at ubit dot com)
|
133
|
+
|
134
|
+
Acknowledgments:
|
135
|
+
Thanks to Elbert Corpuz for writing the CSS for the HTML output!
|
136
|
+
|
137
|
+
Other metric tools for Ruby:
|
138
|
+
Ryan Davis has an abc metric program as an example in his ParseTree
|
139
|
+
product: http://www.zenspider.com/ZSS/Products/ParseTree/
|
140
|
+
|
141
|
+
The PMD project has a tool called CPD that can scan Ruby source code
|
142
|
+
looking for source duplication: http://pmd.sourceforge.net/
|