flog 3.1.0 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
@@ -1 +1,3 @@
1
- ;����%D��C.�`Rm�L���F����Ž�_V�E W/2fE�h��]��l��B����ԑ|���A��7C7�Y���O��/�+��qʵ��٨5F%�$�qY�
1
+ B�_�ƀ}scň��^�RGu\Q9]0���L�0���1��X�F�k�НF?���>cF~�m33�0;Y�%�ON��
2
+ �^_��
3
+ �A���P�a-c�Hj��WLc��8:�� �]��nu�DHϙ�F.u_n~Ümt$k �8x� �'��z��u�c]r�:+�BS��ȧl�C��OQ��o�@J�xW�� ��>OL��VW���?��u'|�d�xP�|��{⪰��v���uט�R�l��;^��۸�8��
@@ -1,3 +1,16 @@
1
+ === 3.2.0 / 2012-12-18
2
+
3
+ * 4 minor enhancements:
4
+
5
+ * Ensure rake/tasklib is loaded when defining FlogTask. (ferrous26)
6
+ * Fixed reporting / recording of methods in singleton class blocks. (mihu)
7
+ * Refactored error handling code to flog_ruby. Calls flog_ruby! for actual work
8
+ * Refactored ruby processing code to flog_ruby!
9
+
10
+ * 1 bug fix:
11
+
12
+ * Fixed flogging of || iters. (JacobNinja)
13
+
1
14
  === 3.1.0 / 2012-11-16
2
15
 
3
16
  * 4 minor enhancements:
data/Rakefile CHANGED
@@ -24,4 +24,15 @@ Hoe.spec 'flog' do
24
24
  dependency 'ruby_parser', '~> 3.0.0'
25
25
  end
26
26
 
27
+ task :debug do
28
+ require "flog"
29
+
30
+ file = ENV["F"] || "-"
31
+ ruby = file == "-" ? ENV["R"] : File.read(file)
32
+
33
+ @flog = Flog.new :parser => RubyParser
34
+ @flog.flog_ruby ruby, file
35
+ @flog.report
36
+ end
37
+
27
38
  # vim: syntax=ruby
@@ -13,7 +13,7 @@ class File
13
13
  end
14
14
 
15
15
  class Flog < SexpProcessor
16
- VERSION = '3.1.0'
16
+ VERSION = '3.2.0'
17
17
 
18
18
  THRESHOLD = 0.60
19
19
  SCORES = Hash.new 1
@@ -79,7 +79,7 @@ class Flog < SexpProcessor
79
79
  @@no_method = :none
80
80
 
81
81
  attr_accessor :multiplier
82
- attr_reader :calls, :option, :class_stack, :method_stack, :mass
82
+ attr_reader :calls, :option, :class_stack, :method_stack, :mass, :sclass
83
83
  attr_reader :method_locations
84
84
 
85
85
  def self.plugins
@@ -251,42 +251,53 @@ class Flog < SexpProcessor
251
251
  files = Flog.expand_dirs_to_files(*files_or_dirs)
252
252
 
253
253
  files.each do |file|
254
- begin
255
- # TODO: replace File.open to deal with "-"
256
- ruby = file == '-' ? $stdin.read : File.binread(file)
257
- warn "** flogging #{file}" if option[:verbose]
258
-
259
- @parser = (option[:parser] || RubyParser).new
254
+ ruby = file == '-' ? $stdin.read : File.binread(file)
260
255
 
261
- begin
262
- ast = @parser.process(ruby, file)
263
- rescue Timeout::Error
264
- warn "TIMEOUT parsing #{file}. Skipping."
265
- end
256
+ flog_ruby ruby, file
257
+ end
258
+ end
266
259
 
267
- next unless ast
268
- mass[file] = ast.mass
269
- process ast
270
- rescue RubyParser::SyntaxError, Racc::ParseError => e
271
- q = option[:quiet]
272
- if e.inspect =~ /<\%|%\>/ or ruby =~ /<\%|%\>/ then
273
- return if q
274
- warn "#{e.inspect} at #{e.backtrace.first(5).join(', ')}"
275
- warn "\n...stupid lemmings and their bad erb templates... skipping"
276
- else
277
- warn "ERROR: parsing ruby file #{file}" unless q
278
- unless option[:continue] then
279
- warn "ERROR! Aborting. You may want to run with --continue."
280
- raise e
281
- end
282
- return if q
283
- warn "%s: %s at:\n %s" % [e.class, e.message.strip,
284
- e.backtrace.first(5).join("\n ")]
285
- end
260
+ ##
261
+ # Flog the given ruby source, optionally using file to provide paths
262
+ # for methods. Smart. Handles syntax errors and timeouts so you
263
+ # don't have to.
264
+
265
+ def flog_ruby ruby, file="-", timeout = 10
266
+ flog_ruby! ruby, file, timeout
267
+ rescue Timeout::Error
268
+ warn "TIMEOUT parsing #{file}. Skipping."
269
+ rescue RubyParser::SyntaxError, Racc::ParseError => e
270
+ q = option[:quiet]
271
+ if e.inspect =~ /<\%|%\>/ or ruby =~ /<\%|%\>/ then
272
+ return if q
273
+ warn "#{e.inspect} at #{e.backtrace.first(5).join(', ')}"
274
+ warn "\n...stupid lemmings and their bad erb templates... skipping"
275
+ else
276
+ warn "ERROR: parsing ruby file #{file}" unless q
277
+ unless option[:continue] then
278
+ warn "ERROR! Aborting. You may want to run with --continue."
279
+ raise e
286
280
  end
281
+ return if q
282
+ warn "%s: %s at:\n %s" % [e.class, e.message.strip,
283
+ e.backtrace.first(5).join("\n ")]
287
284
  end
288
285
  end
289
286
 
287
+ ##
288
+ # Flog the given ruby source, optionally using file to provide paths for
289
+ # methods. Does not handle timeouts or syntax errors. See #flog_ruby.
290
+
291
+ def flog_ruby! ruby, file="-", timeout = 10
292
+ @parser = (option[:parser] || RubyParser).new
293
+
294
+ warn "** flogging #{file}" if option[:verbose]
295
+
296
+ ast = @parser.process ruby, file, timeout
297
+ mass[file] = ast.mass
298
+ process ast
299
+ end
300
+
290
301
  ##
291
302
  # Adds name to the class stack, for the duration of the block
292
303
 
@@ -324,6 +335,7 @@ class Flog < SexpProcessor
324
335
  def initialize option = {}
325
336
  super()
326
337
  @option = option
338
+ @sclass = nil
327
339
  @class_stack = []
328
340
  @method_stack = []
329
341
  @method_locations = {}
@@ -621,7 +633,8 @@ class Flog < SexpProcessor
621
633
  alias :process_lasgn :process_dasgn_curr
622
634
 
623
635
  def process_defn(exp)
624
- in_method exp.shift, exp.file, exp.line do
636
+ name = @sclass ? "::#{exp.shift}" : exp.shift
637
+ in_method name, exp.file, exp.line do
625
638
  process_until_empty exp
626
639
  end
627
640
  s()
@@ -669,6 +682,8 @@ class Flog < SexpProcessor
669
682
  context = (self.context - [:class, :module, :scope])
670
683
  context = context.uniq.sort_by { |s| s.to_s }
671
684
 
685
+ exp.delete 0 # { || ... } has 0 in arg slot
686
+
672
687
  if context == [:block, :iter] or context == [:iter] then
673
688
  recv = exp.first
674
689
 
@@ -692,8 +707,6 @@ class Flog < SexpProcessor
692
707
 
693
708
  add_to_score :branch
694
709
 
695
- exp.delete 0 # { || ... } has 0 in arg slot
696
-
697
710
  process exp.shift # no penalty for LHS
698
711
 
699
712
  penalize_by 0.1 do
@@ -736,10 +749,12 @@ class Flog < SexpProcessor
736
749
  end
737
750
 
738
751
  def process_sclass(exp)
752
+ @sclass = true
739
753
  penalize_by 0.5 do
740
754
  process exp.shift # recv
741
755
  process_until_empty exp
742
756
  end
757
+ @sclass = nil
743
758
 
744
759
  add_to_score :sclass
745
760
  s()
@@ -1,3 +1,5 @@
1
+ require 'rake/tasklib'
2
+
1
3
  class FlogTask < Rake::TaskLib
2
4
  attr_accessor :name
3
5
  attr_accessor :dirs
@@ -114,6 +114,19 @@ class TestFlog < MiniTest::Unit::TestCase
114
114
  ensure
115
115
  $stdin = old_stdin
116
116
  end
117
+
118
+ def test_flog_ruby
119
+ ruby = "2 + 3"
120
+ file = "sample.rb"
121
+
122
+ @flog.flog_ruby ruby, file
123
+
124
+ exp = { "main#none" => { :+ => 1.0, :lit_fixnum => 0.6 } }
125
+ assert_equal exp, @flog.calls
126
+
127
+ assert_equal 1.6, @flog.total unless @flog.option[:methods]
128
+ assert_equal 3, @flog.mass[file]
129
+ end
117
130
 
118
131
  def test_flog_erb
119
132
  old_stdin = $stdin
@@ -399,6 +412,21 @@ class TestFlog < MiniTest::Unit::TestCase
399
412
  util_process sexp, 0.275, :lit_fixnum => 0.275
400
413
  end
401
414
 
415
+ def test_process_defn_in_self
416
+ sexp = s(:sclass, s(:self),
417
+ s(:defn, :x,
418
+ s(:args, :y),
419
+ s(:lit, 42)))
420
+
421
+ setup
422
+ @flog.process sexp
423
+
424
+ exp = {'main::x' => {:lit_fixnum => 0.375}, 'main#none' => {:sclass => 5.0}}
425
+ assert_equal exp, @flog.calls
426
+
427
+ assert_in_delta 5.375, @flog.total
428
+ end
429
+
402
430
  def test_process_defs
403
431
  @meth = "::x" # HACK, I don't like this
404
432
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flog
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
- - 1
8
+ - 2
9
9
  - 0
10
- version: 3.1.0
10
+ version: 3.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ryan Davis
@@ -36,7 +36,7 @@ cert_chain:
36
36
  FBHgymkyj/AOSqKRIpXPhjC6
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2012-11-17 00:00:00 Z
39
+ date: 2012-12-19 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: sexp_processor
@@ -77,11 +77,11 @@ dependencies:
77
77
  requirements:
78
78
  - - ~>
79
79
  - !ruby/object:Gem::Version
80
- hash: 31
80
+ hash: 29
81
81
  segments:
82
82
  - 4
83
- - 2
84
- version: "4.2"
83
+ - 3
84
+ version: "4.3"
85
85
  type: :development
86
86
  version_requirements: *id003
87
87
  - !ruby/object:Gem::Dependency
@@ -107,11 +107,11 @@ dependencies:
107
107
  requirements:
108
108
  - - ~>
109
109
  - !ruby/object:Gem::Version
110
- hash: 1
110
+ hash: 15
111
111
  segments:
112
112
  - 3
113
- - 3
114
- version: "3.3"
113
+ - 4
114
+ version: "3.4"
115
115
  type: :development
116
116
  version_requirements: *id005
117
117
  description: |-
metadata.gz.sig CHANGED
Binary file