Error when running metric_fu -r

160 views
Skip to first unread message

Greg Allen

unread,
Nov 19, 2013, 12:45:26 PM11/19/13
to metr...@googlegroups.com
I am trying to run metric_fu over the sources for homebrew (https://github.com/mxcl/homebrew).  The relevant versions for metric_fu and ruby are:

[root@dhcp-187-152 homebrew]# metric_fu --version
4.5.2
[root@dhcp-187-152 homebrew]# ruby --version
ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-linux]
[root@dhcp-187-152 homebrew]#

However, I get an error from metric_fu:

[root@dhcp-187-152 homebrew]# metric_fu -r
******* STARTING METRIC cane
******* ENDING METRIC cane
******* STARTING METRIC churn
******* ENDING METRIC churn
******* STARTING METRIC flay
******* ENDING METRIC flay
******* STARTING METRIC flog
******* ENDING METRIC flog
******* STARTING METRIC saikuro
******* ENDING METRIC saikuro
******* STARTING METRIC reek
*****Skipping Reek, no files found to analyze
******* ENDING METRIC reek
******* STARTING METRIC roodi
******* ENDING METRIC roodi
******* STARTING METRIC stats
/usr/local/share/gems/gems/metric_fu-4.5.2/lib/metric_fu/metrics/stats/stats.rb:45:in `set_global_stats': undefined method `[]' for nil:NilClass (NoMethodError)
    from /usr/local/share/gems/gems/metric_fu-4.5.2/lib/metric_fu/metrics/stats/stats.rb:21:in `analyze'
    from /usr/local/share/gems/gems/metric_fu-4.5.2/lib/metric_fu/metrics/generator.rb:115:in `generate_result'
    from /usr/local/share/gems/gems/metric_fu-4.5.2/lib/metric_fu/reporting/result.rb:50:in `add'
    from /usr/local/share/gems/gems/metric_fu-4.5.2/lib/metric_fu/run.rb:20:in `block in measure'
    from /usr/local/share/gems/gems/metric_fu-4.5.2/lib/metric_fu/run.rb:18:in `each'
    from /usr/local/share/gems/gems/metric_fu-4.5.2/lib/metric_fu/run.rb:18:in `measure'
    from /usr/local/share/gems/gems/metric_fu-4.5.2/lib/metric_fu/run.rb:9:in `run'
    from /usr/local/share/gems/gems/metric_fu-4.5.2/lib/metric_fu/cli/helper.rb:17:in `run'
    from /usr/local/share/gems/gems/metric_fu-4.5.2/lib/metric_fu/cli/client.rb:18:in `run'
    from /usr/local/share/gems/gems/metric_fu-4.5.2/bin/metric_fu:9:in `<top (required)>'
    from /usr/local/bin/metric_fu:23:in `load'
    from /usr/local/bin/metric_fu:23:in `<main>'
[root@dhcp-187-152 homebrew]#

Can anyone help? Am I doing something wrong?

Thanks,

-- Greg

Benjamin Fleischer

unread,
Nov 20, 2013, 12:50:10 PM11/20/13
to metr...@googlegroups.com
Hey Greg, sounds like an interesting project.

I don't you're doing anything wrong.  It looks like, for some reason, the output is empty, or is a case that results in lines breaking its contract of being an Array-like object, but is nil, instead

I'll push a fix for that issue momentarily.  I'm sorry metric_fu doesn't (yet) tell you what the metric was doing when it failed

Would you mind posting the output of metric_fu --debug-info as well?

-Benjamin


--
You received this message because you are subscribed to the Google Groups "metric_fu" group.
To unsubscribe from this group and stop receiving emails from it, send an email to metric_fu+...@googlegroups.com.
To post to this group, send email to metr...@googlegroups.com.
Visit this group at http://groups.google.com/group/metric_fu.
For more options, visit https://groups.google.com/groups/opt_out.

Benjamin Fleischer

unread,
Nov 20, 2013, 1:22:23 PM11/20/13
to metr...@googlegroups.com
What output do you get if you run 

ruby -rmetric_fu -e "metric = MetricFu::Metric.get_metric(:stats); p metric.enable; p metric.activate; p g = MetricFu::StatsGenerator.new(p metric.run_options).emit; puts g.instance_variable_get(:@output).inspect"

ruby -rmetric_fu -e "metric = MetricFu::Metric.get_metric(:stats); p metric.enable; p metric.activate; p g = MetricFu::StatsGenerator.new(metric.run_options); puts CodeMetrics::Statistics.new(*g.send(:dirs)).to_s"

Greg Allen

unread,
Nov 20, 2013, 1:34:20 PM11/20/13
to metr...@googlegroups.com, benj...@benjaminfleischer.com
Hi Benjamin,

Well, it's not my project really. I'm just using it to check out metric_fu.

The output of each of the commands follows.  It appears to me that metric_fu isn't finding any source files.  For example, if I just run reek in the project directory I get reek output. But you can see from my initial posting that when run as part of metric_fu it doesn't find any input files.  I've tried to track it in the metric_fu sources but haven't made much progress yet.

-- Greg

[root@dhcp-187-152 homebrew]# metric_fu --debug-info
{"Ruby"=>
  {"Engine"=>"ruby",
   "Version"=>"1.9.3",
   "Patchlevel"=>429,
   "Ripper Support"=>true,
   "Rubygems Version"=>"1.8.25",
   "Long Description"=>
    "ruby 1.9.3p429 (2013-05-15 revision 40747) [x86_64-linux]"},
 "Environment"=>
  {"VERBOSE"=>"false",
   "External Encoding"=>"UTF-8",
   "Internal Encoding"=>"",
   "Host Architecture"=>"x86_64-redhat-linux-gnu",
   "Ruby Prefix"=>"/usr",
   "Ruby Options"=>""},
 "MetricFu"=>
  {"Version"=>"4.5.2",
   "Verbose Mode"=>false,
   "Enabled Metrics"=>
    [:cane, :churn, :flay, :flog, :saikuro, :reek, :roodi, :stats, :hotspots],
   "Dependencies"=>
    [{"name"=>"flay", "version"=>[">= 2.0.1", "~> 2.1"]},
     {"name"=>"churn", "version"=>["~> 0.0.28"]},
     {"name"=>"flog", "version"=>[">= 4.1.1", "~> 4.1"]},
     {"name"=>"reek", "version"=>[">= 1.3.4", "~> 1.3"]},
     {"name"=>"cane", "version"=>[">= 2.5.2", "~> 2.5"]},
     {"name"=>"rails_best_practices", "version"=>[">= 1.14.3", "~> 1.14"]},
     {"name"=>"saikuro", "version"=>[">= 1.1.1.0"]},
     {"name"=>"roodi", "version"=>["~> 3.1"]},
     {"name"=>"code_metrics", "version"=>["~> 0.1"]},
     {"name"=>"redcard", "version"=>[">= 0"]},
     {"name"=>"coderay", "version"=>[">= 0"]},
     {"name"=>"multi_json", "version"=>[">= 0"]},
     {"name"=>"rcov", "version"=>["~> 0.8"]}]}}
[root@dhcp-187-152 homebrew]# ruby -rmetric_fu -e "metric = MetricFu::Metric.get_metric(:stats); p metric.enable; p metric.activate; p g = MetricFu::StatsGenerator.new(p metric.run_options).emit; puts g.instance_variable_get(:@output).inspect"
true
true
{:additional_test_directories=>[{:glob_pattern=>"./spec/**/*_spec.rb", :file_pattern=>"spec"}], :additional_app_directories=>[{:glob_pattern=>"./engines/**/*.rb", :file_pattern=>""}]}
"+----------------------+-------+-------+---------+---------+-----+-------+\n| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |\n+----------------------+-------+-------+---------+---------+-----+-------+\n+----------------------+-------+-------+---------+---------+-----+-------+\n  Code LOC: 0     Test LOC: 0     Code to Test Ratio: 1:NaN\n\n"
nil
[root@dhcp-187-152 homebrew]# ruby -rmetric_fu -e "metric = MetricFu::Metric.get_metric(:stats); p metric.enable; p metric.activate; p g = MetricFu::StatsGenerator.new(metric.run_options); puts CodeMetrics::Statistics.new(*g.send(:dirs)).to_s"
true
true
#<MetricFu::StatsGenerator:0x00000001cce150 @options={:additional_test_directories=>[{:glob_pattern=>"./spec/**/*_spec.rb", :file_pattern=>"spec"}], :additional_app_directories=>[{:glob_pattern=>"./engines/**/*.rb", :file_pattern=>""}]}>
+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 0     Test LOC: 0     Code to Test Ratio: 1:NaN


[root@dhcp-187-152 homebrew]#

Greg Allen

unread,
Nov 20, 2013, 1:37:07 PM11/20/13
to metr...@googlegroups.com, benj...@benjaminfleischer.com
And in case it makes any difference I am not running metric_fu via rake.  I am simply running metric_fu in my project directory as the README suggests.

Benjamin Fleischer

unread,
Nov 20, 2013, 2:22:06 PM11/20/13
to metr...@googlegroups.com
Thanks for all the great debugging information.  At some point I should have asked you to create a bug report when you showed the output

+----------------------+-------+-------+---------+---------+-----+-------+
| Name                 | Lines |   LOC | Classes | Methods | M/C | LOC/M |
+----------------------+-------+-------+---------+---------+-----+-------+
+----------------------+-------+-------+---------+---------+-----+-------+
  Code LOC: 0     Test LOC: 0     Code to Test Ratio: 1:NaN

That stats was reporting a code to test ratio of NaN

I'm pushing out a new release 4.6.0 that includes a test and fix.  It should now output the directories it searched in when it gets a NaN result like this.  

Basically, in your case, it's not searching the directories you want it to, so, if you want code stats, you'll need to configure the run options in a .metrics file (until we make it easier to do otherwise).

-Benjamin

Greg Allen

unread,
Nov 21, 2013, 1:14:20 PM11/21/13
to metr...@googlegroups.com, benj...@benjaminfleischer.com
Hi Benjamin,

I found another problem. This project has files with filenames that begin with "--". This causes problems with the results are generated. At that point it tries to split the line to get the file name using "--".  As you can guess, this doesn't work quite right.

However, the fix is easy:

[root@dhcp-187-152 metric_fu]# diff metrics/reek/reek.rb metrics/reek/reek.rb.orig
26c26
<         file_path = match.shift.split(' -- ').first
---
>         file_path = match.shift.split('--').first
[root@dhcp-187-152 metric_fu]#

I just added spaces on either side of the "--" and it works.  I believe this is OK as there are other places in reek.rb that check for " -- " instead of "--", and it worked for me.

Do you want to add this into the code base?

-- Greg

Benjamin Fleischer

unread,
Nov 21, 2013, 1:23:15 PM11/21/13
to metr...@googlegroups.com
Yes, please either create an issue or PR with a test.  (Or even switch to using the Reek library directly)
Reply all
Reply to author
Forward
0 new messages