Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 125 lines (113 sloc) 3.705 kb
54ae57d @colszowka Working on JRuby support on 1.6.0.RC1:
authored
1 require 'rubygems'
2
bbb1c22 @colszowka More documentation; Removed unneccessary attr_accessor
authored
3 #
4 # Code coverage for ruby 1.9. Please check out README for a full introduction.
5 #
6a755b4 @colszowka Initial lib import
authored
6 module SimpleCov
bbb1c22 @colszowka More documentation; Removed unneccessary attr_accessor
authored
7 # Indicates invalid coverage data
e835f2c @colszowka Improved error handling for invalid coverage data
authored
8 class CoverageDataError < StandardError; end;
bbb1c22 @colszowka More documentation; Removed unneccessary attr_accessor
authored
9
6a755b4 @colszowka Initial lib import
authored
10 class << self
bbb1c22 @colszowka More documentation; Removed unneccessary attr_accessor
authored
11 attr_accessor :running#, :result # TODO: Remove result?
e1baf7a @colszowka Getting ready for 0.0.1
authored
12
15039b1 @colszowka Added documentation to configuration, unified the config API a bit
authored
13 #
14 # Sets up SimpleCov to run against your project.
bbb1c22 @colszowka More documentation; Removed unneccessary attr_accessor
authored
15 # You can optionally specify an adapter to use as well as configuration with a block:
16 # SimpleCov.start
17 # OR
18 # SimpleCov.start 'rails' # using rails adapter
19 # OR
20 # SimpleCov.start do
21 # add_filter 'test'
22 # end
23 # OR
24 # SimpleCov.start 'rails' do
25 # add_filter 'test'
26 # end
15039b1 @colszowka Added documentation to configuration, unified the config API a bit
authored
27 #
bbb1c22 @colszowka More documentation; Removed unneccessary attr_accessor
authored
28 # Please check out the RDoc for SimpleCov::Configuration to find about available config options
15039b1 @colszowka Added documentation to configuration, unified the config API a bit
authored
29 #
5b3d56f @colszowka Added adapters for easy definition and access to default configs.
authored
30 def start(adapter=nil, &block)
a7b582a @colszowka Added version checks to unit tests so they only get executed on
authored
31 return false unless SimpleCov.usable?
32
15039b1 @colszowka Added documentation to configuration, unified the config API a bit
authored
33 require 'coverage'
5b3d56f @colszowka Added adapters for easy definition and access to default configs.
authored
34 load_adapter(adapter) unless adapter.nil?
2c5abaf @colszowka Added simple formatter
authored
35 Coverage.start
e1baf7a @colszowka Getting ready for 0.0.1
authored
36 configure(&block) if block_given?
2c5abaf @colszowka Added simple formatter
authored
37 @result = nil
38 self.running = true
39 end
40
15039b1 @colszowka Added documentation to configuration, unified the config API a bit
authored
41 #
bbb1c22 @colszowka More documentation; Removed unneccessary attr_accessor
authored
42 # Returns the result for the current coverage run, merging it across test suites
43 # from cache using SimpleCov::ResultMerger if use_merging is activated (default)
15039b1 @colszowka Added documentation to configuration, unified the config API a bit
authored
44 #
2c5abaf @colszowka Added simple formatter
authored
45 def result
46 @result ||= SimpleCov::Result.new(Coverage.result) if running
4f37de8 @colszowka Resultset merging added
authored
47 # If we're using merging of results, store the current result
bbb1c22 @colszowka More documentation; Removed unneccessary attr_accessor
authored
48 # first, then merge the results and return those
4f37de8 @colszowka Resultset merging added
authored
49 if use_merging
50 SimpleCov::ResultMerger.store_result(@result) if @result
51 return SimpleCov::ResultMerger.merged_result
52 else
53 return @result
54 end
2c5abaf @colszowka Added simple formatter
authored
55 ensure
56 self.running = false
57 end
58
37f9696 @colszowka Unit test for result, moved filters to own file
authored
59 #
15039b1 @colszowka Added documentation to configuration, unified the config API a bit
authored
60 # Applies the configured filters to the given array of SimpleCov::SourceFile items
0ac92bd @colszowka Grouping added
authored
61 #
62 def filtered(files)
37f9696 @colszowka Unit test for result, moved filters to own file
authored
63 result = files.clone
64 filters.each do |filter|
65 result = result.select {|source_file| filter.passes?(source_file) }
66 end
3b050c1 @colszowka Moved file set coverage analytics from simplecov-html to SimpleCov::File...
authored
67 SimpleCov::FileList.new result
6a755b4 @colszowka Initial lib import
authored
68 end
0ac92bd @colszowka Grouping added
authored
69
15039b1 @colszowka Added documentation to configuration, unified the config API a bit
authored
70 #
71 # Applies the configured groups to the given array of SimpleCov::SourceFile items
72 #
0ac92bd @colszowka Grouping added
authored
73 def grouped(files)
74 grouped = {}
75 grouped_files = []
76 groups.each do |name, filter|
3b050c1 @colszowka Moved file set coverage analytics from simplecov-html to SimpleCov::File...
authored
77 grouped[name] = SimpleCov::FileList.new(files.select {|source_file| !filter.passes?(source_file)})
0ac92bd @colszowka Grouping added
authored
78 grouped_files += grouped[name]
79 end
b6bc302 @colszowka Filter root by default
authored
80 if groups.length > 0 and (other_files = files.reject {|source_file| grouped_files.include?(source_file)}).length > 0
3b050c1 @colszowka Moved file set coverage analytics from simplecov-html to SimpleCov::File...
authored
81 grouped["Ungrouped"] = SimpleCov::FileList.new(other_files)
e1baf7a @colszowka Getting ready for 0.0.1
authored
82 end
0ac92bd @colszowka Grouping added
authored
83 grouped
84 end
5b3d56f @colszowka Added adapters for easy definition and access to default configs.
authored
85
86 #
87 # Applies the adapter of given name on SimpleCov configuration
88 #
89 def load_adapter(name)
90 adapters.load(name)
91 end
20d6a8c @colszowka Make sure the correct exit status is propagated from tests when running
authored
92
a7b582a @colszowka Added version checks to unit tests so they only get executed on
authored
93 #
94 # Checks whether we're on a proper version of ruby (1.9+) and returns false if this is not the case,
95 # also printing an appropriate warning
96 #
97 def usable?
98 unless "1.9".respond_to?(:encoding)
99 warn "WARNING: SimpleCov is activated, but you're not running Ruby 1.9+ - no coverage analysis will happen"
100 return false
101 end
102 true
103 end
6a755b4 @colszowka Initial lib import
authored
104 end
105 end
106
e1baf7a @colszowka Getting ready for 0.0.1
authored
107 $LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
54ae57d @colszowka Working on JRuby support on 1.6.0.RC1:
authored
108 require 'simplecov/jruby_float_fix'
776d207 @colszowka Renamed from simple_cov to simplecov
authored
109 require 'simplecov/configuration'
15039b1 @colszowka Added documentation to configuration, unified the config API a bit
authored
110 SimpleCov.send :extend, SimpleCov::Configuration
776d207 @colszowka Renamed from simple_cov to simplecov
authored
111 require 'simplecov/adapters'
112 require 'simplecov/source_file'
3b050c1 @colszowka Moved file set coverage analytics from simplecov-html to SimpleCov::File...
authored
113 require 'simplecov/file_list'
776d207 @colszowka Renamed from simple_cov to simplecov
authored
114 require 'simplecov/result'
115 require 'simplecov/filter'
116 require 'simplecov/formatter'
117 require 'simplecov/merge_helpers'
118 require 'simplecov/result_merger'
e5f8df3 @colszowka Added guessing of test suite names (for command_name in merging)
authored
119 require 'simplecov/command_guesser'
7b76120 @colszowka Load VERSION file...
authored
120 require 'simplecov/version'
121
94019a8 @colszowka Switched from YAML to JSON for result storing and merging.
authored
122 autoload :JSON, 'json'
123
b07ef0e @colszowka Moved defaults to defaults.rb
authored
124 # Load default config
125 require 'simplecov/defaults'
Something went wrong with that request. Please try again.