Skip to content

Commit

Permalink
Added logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwynne committed Jun 16, 2009
1 parent dc758e3 commit 461d4b2
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.coverage
*.data
*.log
*.gem
rerun
coverage
7 changes: 7 additions & 0 deletions lib/cucover.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
require 'rcov'
require 'spec'

require 'logging'

$:.unshift(File.dirname(__FILE__))
require 'cucover/commands/coverage_of'
require 'cucover/commands/cucumber'
require 'cucover/cli'
require 'cucover/logging_config'
require 'cucover/monkey'
require 'cucover/rails'
require 'cucover/recording'
Expand Down Expand Up @@ -218,6 +221,10 @@ def stop_recording
@current_recording = nil
end

def logger
Logging::Logger['Cucover']
end

private

def recording?
Expand Down
2 changes: 1 addition & 1 deletion lib/cucover/commands/coverage_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def execute
end

def coverage(line_number)
@recordings.select{ |r| r.covers_line?(line_number) }.map{ |r| r.feature_filename }
@recordings.select{ |r| r.covers_line?(@filespec, line_number) }.map{ |r| r.feature_filename }
end

def recordings
Expand Down
16 changes: 16 additions & 0 deletions lib/cucover/logging_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
Logging.configure do
logger('Cucover') do
level :debug
appenders 'logfile'
end

appender('logfile') do
type 'File'
level :debug
filename File.dirname(__FILE__) + '/../../tmp/cucover.log'
layout do
type 'Pattern'
pattern '[%d] %l %c : %m\n'
end
end
end
17 changes: 15 additions & 2 deletions lib/cucover/recording.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
module Cucover
class Recording
class Data < Struct.new(:file_colon_line, :covered_files)
class Data < Struct.new(:file_colon_line, :covered_files, :analyzer)
def feature_filename
file_colon_line.split(':').first
end
def covers_file?(source_file)
Cucover.logger.info("looking for source file #{source_file} amongst #{covered_files.join(',')}")
covered_files.include?(source_file)
end
def covers_line?(source_file, line_number)
true
end
end

def initialize(scenario_or_table_row)
Expand All @@ -24,10 +34,13 @@ def start
def stop
@analyzer.remove_hook
@covered_files.concat @analyzer.analyzed_files
Cucover.logger.info("Finished recording #{file_colon_line}.")
Cucover.logger.debug("Covered files: #{@covered_files.join(',')}")
# Cucover.logger.debug("Analyzer: #{@analyzer.inspect}")
end

def to_data
Data.new(file_colon_line, @covered_files)
Data.new(file_colon_line, @covered_files, @analyzer)
end
end
end
15 changes: 3 additions & 12 deletions lib/cucover/store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@ module Cucover
class Store
def initialize
if File.exists?(data_file)
puts "reading #{data_file}"
File.open(data_file) do |f|
@recordings = Marshal.load(f)
end
else
puts "no data - starting with a blank slate"
@recordings = {}
end
at_exit do
Expand All @@ -22,7 +20,9 @@ def keep(recording)
end

def fetch_recordings_covering(source_file)
[ FakeRecording.new ]
@recordings.values.select do |recording|
recording.covers_file?(source_file)
end
end

private
Expand All @@ -31,15 +31,6 @@ def data_file
Dir.pwd + '/cucover.data'
end

class FakeRecording
def feature_filename
"features/call_foo.feature"
end
def covers_line?(line_number)
true unless [5,6,7,8].include?(line_number)
end
end

end
end

Expand Down
Empty file added tmp/.gitignore
Empty file.

0 comments on commit 461d4b2

Please sign in to comment.