Permalink
Browse files

+ DSL reporting now handles regexp literals for 'method' names (Marty…

… Andrews)

+ Cleaned method_name to return "#method" or "::method".
+ Improved tests for process_iter's myriad complexities.
- Fixed DSL reporting excluding solo-blocks. (eg a single rake task)

[git-p4: depot-paths = "//src/flog/dev/": change = 5544]
  • Loading branch information...
zenspider committed Dec 15, 2009
1 parent d0a73d6 commit 7f9dffd9c24af9a7967fde0ffba7ea86b9c2b034
Showing with 52 additions and 9 deletions.
  1. +7 −7 lib/flog.rb
  2. +45 −2 test/test_flog.rb
View
@@ -198,8 +198,8 @@ def in_klass name
# Adds name to the method stack, for the duration of the block
def in_method(name, file, line)
- @method_stack.unshift name
- # "#{klass_name}##{name}"
+ method_name = Regexp === name ? name.inspect : name.to_s
+ @method_stack.unshift method_name
@method_locations[signature] = "#{file}:#{line}"
yield
@method_stack.shift
@@ -245,7 +245,7 @@ def klass_name
def method_name
m = @method_stack.first || @@no_method
- m = "##{m}" unless m =~ /::/ unless m == @@no_method # FIX
+ m = "##{m}" unless m =~ /::/
m
end
@@ -358,9 +358,7 @@ def score_method(tally)
end
def signature
- m = method_name
- m = "#none" if m == @@no_method
- "#{klass_name}#{m}" # FIX: ugly
+ "#{klass_name}#{method_name}"
end
def total # FIX: I hate this indirectness
@@ -525,7 +523,9 @@ def process_if(exp)
def process_iter(exp)
context = (self.context - [:class, :module, :scope])
- if context.uniq.sort_by { |s| s.to_s } == [:block, :iter] then
+ context = context.uniq.sort_by { |s| s.to_s }
+
+ if context == [:block, :iter] or context == [:iter] then
recv = exp.first
# DSL w/ names. eg task :name do ... end
View
@@ -167,14 +167,14 @@ def test_klass_name_sexp
end
def test_method_name
- assert_equal :none, @flog.method_name
+ assert_equal "#none", @flog.method_name
@flog.method_stack << "whatevs"
assert_equal "#whatevs", @flog.method_name
end
def test_method_name_cls
- assert_equal :none, @flog.method_name
+ assert_equal "#none", @flog.method_name
@flog.method_stack << "::whatevs"
assert_equal "::whatevs", @flog.method_name
@@ -403,6 +403,36 @@ def test_process_iter
util_process sexp, 2.326, :loop => 1.0, :branch => 2.1
end
+ def test_process_iter_dsl
+ # task :blah do
+ # something
+ # end
+
+ sexp = s(:iter,
+ s(:call, nil, :task, s(:arglist, s(:lit, :blah))),
+ nil,
+ s(:call, nil, :something, s(:arglist)))
+
+ @klass, @meth = "task", "#blah"
+
+ util_process sexp, 2.0, :something => 1.0, :task => 1.0
+ end
+
+ def test_process_iter_dsl_regexp
+ # task /regexp/ do
+ # something
+ # end
+
+ sexp = s(:iter,
+ s(:call, nil, :task, s(:arglist, s(:lit, /regexp/))),
+ nil,
+ s(:call, nil, :something, s(:arglist)))
+
+ @klass, @meth = "task", "#/regexp/"
+
+ util_process sexp, 2.0, :something => 1.0, :task => 1.0
+ end
+
def test_process_lit
sexp = s(:lit, :y)
util_process sexp, 0.0
@@ -513,6 +543,19 @@ def test_score_method
:branch => 4.0)
end
+ def test_signature
+ assert_equal "main#none", @flog.signature
+
+ @flog.class_stack << "X"
+ assert_equal "X#none", @flog.signature
+
+ @flog.method_stack << "y"
+ assert_equal "X#y", @flog.signature
+
+ @flog.class_stack.shift
+ assert_equal "main#y", @flog.signature
+ end
+
def test_total
@flog.add_to_score "blah", 2
assert_equal 2.0, @flog.total

0 comments on commit 7f9dffd

Please sign in to comment.