-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
277 additions
and
297 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,60 @@ | ||
$:.unshift(File.dirname(__FILE__)) | ||
require 'dependencies' | ||
require 'cucover/logging_config' | ||
require 'cucover/cli_commands/coverage_of' | ||
require 'cucover/cli_commands/cucumber' | ||
require 'cucover/cli_commands/show_recordings' | ||
require 'cucover/logging_config' | ||
require 'cucover/controller' | ||
require 'cucover/cli' | ||
require 'cucover/monkey' | ||
require 'cucover/rails' | ||
require 'cucover/recording' | ||
require 'cucover/controller' | ||
require 'cucover/cli' | ||
require 'cucover/recorder' | ||
require 'cucover/store' | ||
|
||
module Cucover | ||
class << self | ||
def logger | ||
Logging::Logger['Cucover'] | ||
end | ||
end | ||
|
||
def should_execute?(scenario_or_table_row) | ||
controller(scenario_or_table_row).should_execute? | ||
end | ||
|
||
def start_recording!(scenario_or_table_row) | ||
raise("Already recording. Please call stop first.") if recording? | ||
|
||
@current_recorder = Recorder.new(scenario_or_table_row) | ||
@current_recorder.start! | ||
record_file(scenario_or_table_row.file_colon_line.split(':').first) # TODO: clean this by extending the feature element | ||
end | ||
|
||
def stop_recording! | ||
return unless recording? | ||
|
||
@current_recorder.stop! | ||
store.keep!(@current_recorder.recording) | ||
@current_recorder = nil | ||
end | ||
|
||
def record_file(source_file) | ||
Cucover.logger.debug("Recording extra source file #{source_file}") | ||
@current_recorder.record_file!(source_file) | ||
end | ||
|
||
private | ||
|
||
def controller(scenario_or_table_row) | ||
Controller.new(scenario_or_table_row.file_colon_line, store) | ||
end | ||
|
||
def recording? | ||
!!@current_recorder | ||
end | ||
|
||
def store | ||
@store ||= Store.new | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Cucover | ||
class Recorder | ||
def initialize(scenario_or_table_row) | ||
@scenario_or_table_row = scenario_or_table_row | ||
@analyzer = Rcov::CodeCoverageAnalyzer.new | ||
@additional_covered_files = [] | ||
end | ||
|
||
def record_file!(source_file) | ||
unless @additional_covered_files.include?(source_file) | ||
@additional_covered_files << source_file | ||
end | ||
end | ||
|
||
def start! | ||
@start_time = Time.now | ||
@analyzer.install_hook | ||
end | ||
|
||
def stop! | ||
@end_time = Time.now | ||
@analyzer.remove_hook | ||
Cucover.logger.info("Finished recording #{@scenario_or_table_row.file_colon_line}.") | ||
Cucover.logger.debug("Covered files: #{@analyzer.analyzed_files.join(',')}") | ||
Cucover.logger.debug("Additional Covered files: #{@additional_covered_files.join(',')}") | ||
end | ||
|
||
def recording | ||
Recording.new( | ||
@scenario_or_table_row.file_colon_line, | ||
@scenario_or_table_row.exception, | ||
@additional_covered_files, | ||
@analyzer, | ||
@start_time, @end_time) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,64 @@ | ||
require 'cucover/recording/recorder' | ||
require 'cucover/recording/data' | ||
require 'cucover/recording/covered_file' | ||
require 'cucover/recording/store' | ||
|
||
module Cucover | ||
module Recording | ||
class << self | ||
def start(scenario_or_table_row) | ||
raise("Already recording. Please call stop first.") if recording? | ||
|
||
@current_recorder = Recording::Recorder.new(scenario_or_table_row) | ||
@current_recorder.start | ||
record_file(scenario_or_table_row.file_colon_line.split(':').first) # TODO: clean this by extending the feature element | ||
end | ||
class Recording < Struct.new( | ||
:file_colon_line, | ||
:exception, | ||
:additional_covered_files, | ||
:analyzer, | ||
:start_time, :end_time) | ||
|
||
def stop | ||
return unless recording? | ||
@current_recorder.stop | ||
store.keep(@current_recorder.to_data) | ||
@current_recorder = nil | ||
end | ||
|
||
def record_file(source_file) | ||
Cucover.logger.debug("Recording extra source file #{source_file}") | ||
@current_recorder.record_file(source_file) | ||
end | ||
def feature_filename | ||
file_colon_line.split(':').first | ||
end | ||
|
||
def covers_file?(source_file) | ||
covered_files.include?(source_file) | ||
end | ||
|
||
def covers_line?(source_file, line_number) | ||
covered_files.detect{ |f| f.file == source_file }.covers_line?(line_number) | ||
end | ||
|
||
def covered_files | ||
@covered_files ||= analyzed_covered_files + additional_covered_files | ||
end | ||
|
||
def record_exception(exception) | ||
@current_recorder.fail!(exception) | ||
def failed? | ||
!!exception | ||
end | ||
|
||
private | ||
|
||
def additional_covered_files | ||
super.map do |filename| | ||
CoveredFile.new(filename, nil, self) | ||
end | ||
|
||
private | ||
end | ||
|
||
def recording? | ||
!!@current_recorder | ||
def analyzed_covered_files | ||
filtered_analyzed_files.map do |filename| | ||
lines, marked_info, count_info = analyzer.data(filename) | ||
CoveredFile.new(filename, marked_info, self) | ||
end | ||
end | ||
|
||
def store | ||
store ||= Recording::Store.new | ||
def boring?(file) | ||
[ | ||
/gem/, | ||
/vendor/, | ||
/lib\/ruby/, | ||
/cucover/ | ||
].any? do |expression| | ||
file.match expression | ||
end | ||
end | ||
|
||
def filtered_analyzed_files | ||
analyzer.analyzed_files.reject{ |f| boring?(f) } | ||
end | ||
|
||
def normalized_files | ||
cleaned_analyzed_files + additional_covered_files | ||
end | ||
end | ||
end | ||
end | ||
require 'cucover/recording/covered_file' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,53 @@ | ||
module Cucover | ||
module Recording | ||
class CoveredFile | ||
|
||
module HasLineNumberDetail | ||
def covered_lines | ||
return @covered_lines if @covered_lines | ||
@covered_lines = [] | ||
@marked_info.each_with_index do |covered, index| | ||
line_number = index + 1 | ||
@covered_lines << line_number if covered | ||
end | ||
@covered_lines | ||
end | ||
end | ||
|
||
attr_reader :file | ||
|
||
def initialize(full_filename, marked_info, recording) | ||
@recording = recording | ||
@full_filename = full_filename | ||
@marked_info = marked_info | ||
@file = File.expand_path(full_filename).gsub(/^#{Dir.pwd}\//, '') | ||
|
||
extend HasLineNumberDetail if @marked_info | ||
end | ||
|
||
def dirty? | ||
Cucover.logger.debug("#{file} last modified at #{File.mtime(@full_filename)}") | ||
Cucover.logger.debug("#{file} recording started at #{@recording.start_time}") | ||
result = File.mtime(@full_filename).to_i >= @recording.start_time.to_i | ||
Cucover.logger.debug(result ? "dirty" : "not dirty") | ||
result | ||
end | ||
|
||
def covers_line?(line_number) | ||
covered_lines.include?(line_number) | ||
end | ||
|
||
def ==(other) | ||
other == file | ||
end | ||
|
||
def to_s | ||
"#{file}:#{covered_lines.join(':')}" | ||
end | ||
|
||
private | ||
|
||
class Recording::CoveredFile | ||
attr_reader :file | ||
|
||
def initialize(full_filename, rcov_marked_info, recording) | ||
@full_filename = full_filename | ||
@rcov_marked_info = rcov_marked_info | ||
@recording = recording | ||
@file = File.expand_path(full_filename).gsub(/^#{Dir.pwd}\//, '') | ||
|
||
extend HasLineNumberDetail if @rcov_marked_info | ||
end | ||
|
||
def dirty? | ||
Cucover.logger.debug("#{file} last modified at #{File.mtime(@full_filename)}") | ||
Cucover.logger.debug("#{file} recording started at #{@recording.start_time}") | ||
result = File.mtime(@full_filename).to_i >= @recording.start_time.to_i | ||
Cucover.logger.debug("verdict: #{(result ? "dirty" : "not dirty")}") | ||
result | ||
end | ||
|
||
def covers_line?(line_number) | ||
covered_lines.include?(line_number) | ||
end | ||
|
||
def ==(other) | ||
other == file | ||
end | ||
|
||
def to_s | ||
"#{file}:#{covered_lines.join(':')}" | ||
end | ||
|
||
private | ||
|
||
def covered_lines | ||
['<unknown lines>'] | ||
end | ||
|
||
module HasLineNumberDetail | ||
def covered_lines | ||
['<unknown lines>'] | ||
return @covered_lines if @covered_lines | ||
|
||
@covered_lines = [] | ||
@rcov_marked_info.each_with_index do |covered, index| | ||
line_number = index + 1 | ||
@covered_lines << line_number if covered | ||
end | ||
@covered_lines | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.