From a2834bb05c4ab5bd32437f333a26f8286438ade4 Mon Sep 17 00:00:00 2001 From: murphy Date: Sun, 16 Apr 2006 00:42:38 +0000 Subject: =?UTF-8?q?All=20scanners=20revisited=20not=20to=20produce=20error?= =?UTF-8?q?s=20unless=20in=20DEBUG=20mode.=20[thx@Daniel]=20Fixed=20numeri?= =?UTF-8?q?zation=20for=20input=20not=20ending=20with=20\n.=20Added=20test?= =?UTF-8?q?=20cases=20in=20C=20scanner=20tests.=20Added=20WoN=C3=A1Do=20as?= =?UTF-8?q?=20contributer=20for=20last=20Ruby=20scanner=20fix.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated TODO. --- rake_helpers/code_statistics.rb | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'rake_helpers/code_statistics.rb') diff --git a/rake_helpers/code_statistics.rb b/rake_helpers/code_statistics.rb index 28571c4..4c4b65c 100644 --- a/rake_helpers/code_statistics.rb +++ b/rake_helpers/code_statistics.rb @@ -60,25 +60,28 @@ private p "Scanning #{file_name}..." if $DEBUG next unless file_name =~ pattern - lines = codelines = classes = methods = 0 + lines = codelines = classes = modules = methods = 0 empty_lines = comment_lines = 0 - comment_block = nil + in_comment_block = false File.readlines(file_name).each do |line| lines += 1 case line - when /^=end\s/ + when /^=end\b/ comment_lines += 1 - comment_block = nil - when comment_block + in_comment_block = false + when in_comment_block comment_lines += 1 when /^\s*class\b/: classes += 1 + when /^\s*module\b/: modules += 1 when /^\s*def\b/: methods += 1 when /^\s*#/: comment_lines += 1 when /^\s*$/: empty_lines += 1 - when /^=begin\s/ - comment_block = lines + when /^=begin\b/ + in_comment_block = false comment_lines += 1 + when /^__END__$/ + in_comment_block = true end end @@ -87,6 +90,7 @@ private stats[:lines] += lines stats[:codelines] += codelines stats[:classes] += classes + stats[:modules] += modules stats[:methods] += methods stats[:files] += 1 end @@ -114,16 +118,16 @@ private def print_header print_splitter - puts "| T=Test Name | Files | Lines | LOC | Classes | Methods | M/C | LOC/M |" + puts "| T=Test Name | Files | Lines | LOC | Classes | Modules | Methods | M/C | LOC/M |" print_splitter end def print_splitter - puts "+---------------------------+-------+-------+-------+---------+---------+-----+-------+" + puts "+---------------------------+-------+-------+-------+---------+---------+---------+-----+-------+" end def print_line name, statistics - m_over_c = (statistics[:methods] / statistics[:classes]) rescue m_over_c = 0 + m_over_c = (statistics[:methods] / (statistics[:classes] + statistics[:modules])) rescue m_over_c = 0 loc_over_m = (statistics[:codelines] / statistics[:methods]) - 2 rescue loc_over_m = 0 if name[TEST_TYPES] @@ -132,8 +136,8 @@ private name = " #{name}" end - line = "| %-25s | %5d | %5d | %5d | %7d | %7d | %3d | %5d |" % ( - [name, *statistics.values_at(:files, :lines, :codelines, :classes, :methods)] + + line = "| %-25s | %5d | %5d | %5d | %7d | %7d | %7d | %3d | %5d |" % ( + [name, *statistics.values_at(:files, :lines, :codelines, :classes, :modules, :methods)] + [m_over_c, loc_over_m] ) puts line -- cgit v1.2.1