summaryrefslogtreecommitdiff
path: root/rake_tasks
diff options
context:
space:
mode:
Diffstat (limited to 'rake_tasks')
-rw-r--r--rake_tasks/benchmark.rake3
-rw-r--r--rake_tasks/bundler.rake6
-rw-r--r--rake_tasks/code_statistics.rb171
-rw-r--r--rake_tasks/diff.rake93
-rw-r--r--rake_tasks/documentation.rake9
-rw-r--r--rake_tasks/ruby-versions.rake10
-rw-r--r--rake_tasks/statistic.rake2
-rw-r--r--rake_tasks/test.rake6
8 files changed, 173 insertions, 127 deletions
diff --git a/rake_tasks/benchmark.rake b/rake_tasks/benchmark.rake
index 040951b..2e38b57 100644
--- a/rake_tasks/benchmark.rake
+++ b/rake_tasks/benchmark.rake
@@ -1,7 +1,6 @@
desc 'Do a benchmark'
task :benchmark do
- ruby "-v"
- ruby "-wIlib bench/bench.rb ruby div 3000 N5"
+ ruby 'bench/bench.rb ruby html 3000'
end
task :bench => :benchmark
diff --git a/rake_tasks/bundler.rake b/rake_tasks/bundler.rake
deleted file mode 100644
index 8de149d..0000000
--- a/rake_tasks/bundler.rake
+++ /dev/null
@@ -1,6 +0,0 @@
-begin
- require 'bundler'
- Bundler::GemHelper.install_tasks
-rescue LoadError
- puts 'Please gem install bundler.'
-end
diff --git a/rake_tasks/code_statistics.rb b/rake_tasks/code_statistics.rb
new file mode 100644
index 0000000..0a2016b
--- /dev/null
+++ b/rake_tasks/code_statistics.rb
@@ -0,0 +1,171 @@
+# From rails (http://rubyonrails.com)
+#
+# Improved by murphy
+class CodeStatistics
+
+ TEST_TYPES = /\btest/i
+
+ # Create a new Code Statistic.
+ #
+ # Rakefile Example:
+ #
+ # desc 'Report code statistics (LOC) from the application'
+ # task :stats => :copy_files do
+ # require 'rake_helpers/code_statistics'
+ # CodeStatistics.new(
+ # ["Main", "lib"],
+ # ["Tests", "test"],
+ # ["Demos", "demo"]
+ # ).to_s
+ # end
+ def initialize(*pairs)
+ @pairs = pairs
+ @statistics = calculate_statistics
+ @total = if pairs.empty? then nil else calculate_total end
+ end
+
+ # Print a textual table viewing the stats
+ #
+ # Intended for console output.
+ def print
+ print_header
+ @pairs.each { |name, path| print_line name, @statistics[name] }
+ print_splitter
+
+ if @total
+ print_line 'Total', @total
+ print_splitter
+ end
+
+ print_code_test_stats
+ end
+
+private
+
+ DEFAULT_FILE_PATTERN = /\.rb$/
+
+ def calculate_statistics
+ @pairs.inject({}) do |stats, (name, path, pattern, is_ruby_code)|
+ pattern ||= DEFAULT_FILE_PATTERN
+ path = File.join path, '*.rb'
+ stats[name] = calculate_directory_statistics path, pattern, is_ruby_code
+ stats
+ end
+ end
+
+ def calculate_directory_statistics directory, pattern = DEFAULT_FILE_PATTERN, is_ruby_code = true
+ is_ruby_code = true if is_ruby_code.nil?
+ stats = Hash.new 0
+
+ Dir[directory].each do |file_name|
+ p "Scanning #{file_name}..." if $VERBOSE
+ next unless file_name =~ pattern
+
+ lines = codelines = classes = modules = methods = 0
+ empty_lines = comment_lines = 0
+ in_comment_block = false
+
+ File.readlines(file_name).each do |line|
+ lines += 1
+ if line[/^\s*$/]
+ empty_lines += 1
+ elsif is_ruby_code
+ case line
+ when /^=end\b/
+ comment_lines += 1
+ 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 /^=begin\b/
+ in_comment_block = false
+ comment_lines += 1
+ when /^__END__$/
+ in_comment_block = true
+ end
+ end
+ end
+
+ codelines = lines - comment_lines - empty_lines
+
+ stats[:lines] += lines
+ stats[:comments] += comment_lines
+ stats[:codelines] += codelines
+ stats[:classes] += classes
+ stats[:modules] += modules
+ stats[:methods] += methods
+ stats[:files] += 1
+ end
+
+ stats
+ end
+
+ def calculate_total
+ total = Hash.new 0
+ @statistics.each_value { |pair| pair.each { |k, v| total[k] += v } }
+ total
+ end
+
+ def calculate_code
+ code_loc = 0
+ @statistics.each { |k, v| code_loc += v[:codelines] unless k[TEST_TYPES] }
+ code_loc
+ end
+
+ def calculate_tests
+ test_loc = 0
+ @statistics.each { |k, v| test_loc += v[:codelines] if k[TEST_TYPES] }
+ test_loc
+ end
+
+ def print_header
+ print_splitter
+ puts "| T=Test Name | Files | Lines | LOC | Comments | Classes | Modules | Methods | M/C | LOC/M |"
+ print_splitter
+ end
+
+ def print_splitter
+ puts "+---------------------------+-------+-------+-------+----------+---------+---------+---------+-----+-------+"
+ end
+
+ def print_line name, statistics
+ 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]
+ name = "T #{name}"
+ else
+ name = " #{name}"
+ end
+
+ line = "| %-25s | %5d | %5d | %5d | %8d | %7d | %7d | %7d | %3d | %5d |" % (
+ [name, *statistics.values_at(:files, :lines, :codelines, :comments, :classes, :modules, :methods)] +
+ [m_over_c, loc_over_m] )
+
+ puts line
+ end
+
+ def print_code_test_stats
+ code = calculate_code
+ tests = calculate_tests
+
+ puts " Code LOC = #{code} Test LOC = #{tests} Code:Test Ratio = [1 : #{sprintf("%.2f", tests.to_f/code)}]"
+ puts ""
+ end
+
+end
+
+# Run a test script.
+if $0 == __FILE__
+ $VERBOSE = true
+ CodeStatistics.new(
+ ['This dir', File.dirname(__FILE__)]
+ ).print
+end
diff --git a/rake_tasks/diff.rake b/rake_tasks/diff.rake
deleted file mode 100644
index f0af55a..0000000
--- a/rake_tasks/diff.rake
+++ /dev/null
@@ -1,93 +0,0 @@
-# A simple differ using svn. Handles externals.
-class Differ < Hash
-
- include Rake::DSL if defined? Rake::DSL
-
- def initialize path
- @path = path
- super 0
- end
-
- def count key, value
- self[key] += value
- value
- end
-
- FORMAT = ' %-30s %8d lines, %3d changes in %2d files'
-
- def scan(path = @path)
- Dir.chdir path do
- diff_file_name = 'diff'
- if File.directory? 'diff'
- diff_file_name = 'diff.diff'
- end
- system "svn diff > #{diff_file_name}"
- if File.size? diff_file_name
- puts FORMAT %
- [
- path,
- count(:LOC, `wc -l #{diff_file_name}`.to_i),
- count(:changes, `grep ^@@ #{diff_file_name} | wc -l`.to_i),
- count(:files, `grep ^Index #{diff_file_name} | wc -l`.to_i),
- ]
- else
- rm diff_file_name
- end
- end
- end
-
- def scan_with_externals(path = @path)
- scan path
- `svn status`.scan(/^X\s*(.*)/) do |external,|
- scan external
- end
- end
-
- def clean(path = @path)
- Dir.chdir path do
- rm 'diff' if File.file? 'diff'
- rm 'diff.diff' if File.file? 'diff.diff'
- end
- end
-
- def clean_with_externals(path = @path)
- clean path
- `svn status`.scan(/^X\s*(.*)/) do |external,|
- clean external
- end
- end
-
- def differences?
- self[:LOC] > 0
- end
-
- def inspect
- FORMAT %
- [ 'Total', self[:LOC], self[:changes], self[:files] ]
- end
-
-end
-
-namespace :diff do
-
- desc 'Make a diff and print a summary'
- task :summary do
- differ = Differ.new '.'
- differ.scan_with_externals
- if differ.empty?
- puts 'No differences found.'
- else
- p differ
- end
- end
-
- desc 'Remove all diffs'
- task :clean do
- differ = Differ.new '.'
- differ.clean_with_externals
- end
-
-end
-
-desc 'Make a diff and print a summary'
-task :diff => 'diff:summary'
diff --git a/rake_tasks/documentation.rake b/rake_tasks/documentation.rake
index d555022..4f7cef7 100644
--- a/rake_tasks/documentation.rake
+++ b/rake_tasks/documentation.rake
@@ -15,18 +15,9 @@ Rake::RDocTask.new :doc do |rd|
rd.title = 'CodeRay Documentation'
rd.options << '--line-numbers' << '--tab-width' << '2'
- # rd.options << '--fmt' << ENV.fetch('format', 'html_coderay')
- # require 'pathname'
- # template = File.join ROOT, 'rake_helpers', 'coderay_rdoc_template.rb'
- # rd.template = Pathname.new(template).expand_path.to_s
rd.main = 'README_INDEX.rdoc'
rd.rdoc_files.add 'README_INDEX.rdoc'
rd.rdoc_files.add Dir['lib']
rd.rdoc_dir = 'doc'
end if defined? Rake::RDocTask
-
-desc 'Copy the documentation over to the CodeRay website'
-task :copy_doc do
- cp_r 'doc/.', '../../rails/coderay/public/doc'
-end
diff --git a/rake_tasks/ruby-versions.rake b/rake_tasks/ruby-versions.rake
deleted file mode 100644
index af408ff..0000000
--- a/rake_tasks/ruby-versions.rake
+++ /dev/null
@@ -1,10 +0,0 @@
-task 'ruby:version' do
- puts
- if defined? RUBY_DESCRIPTION
- ruby_version = RUBY_DESCRIPTION
- else
- ruby_version = "ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE} patchlevel #{RUBY_PATCHLEVEL}) [#{RUBY_PLATFORM}]"
- end
- require './test/lib/term/ansicolor'
- puts Term::ANSIColor.bold(Term::ANSIColor.green(ruby_version))
-end \ No newline at end of file
diff --git a/rake_tasks/statistic.rake b/rake_tasks/statistic.rake
index 99de378..d30e9b1 100644
--- a/rake_tasks/statistic.rake
+++ b/rake_tasks/statistic.rake
@@ -1,6 +1,6 @@
desc 'Report code statistics (LOC) from the application'
task :stats do
- require 'rake_helpers/code_statistics'
+ require './rake_tasks/code_statistics'
CodeStatistics.new(
['Main', 'lib', /coderay.rb$/],
['CodeRay', 'lib/coderay/'],
diff --git a/rake_tasks/test.rake b/rake_tasks/test.rake
index a60699d..b15b999 100644
--- a/rake_tasks/test.rake
+++ b/rake_tasks/test.rake
@@ -1,9 +1,4 @@
namespace :test do
- desc 'run all sample tests'
- task :samples do
- ruby './sample/suite.rb'
- end
-
desc 'run functional tests'
task :functional do
ruby './test/functional/suite.rb'
@@ -85,4 +80,3 @@ Please rename or remove it and run again to use the GitHub repository:
end
task :test => %w(test:functional test:units test:exe)
-task :samples => 'test:samples' \ No newline at end of file