simplecov 0.14.1 → 0.15.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: bda7293a0b718da578a1e9b6897393d21d955fbf
4
- data.tar.gz: d81ac2993a335e716a47a19dd648fe635cc4a635
2
+ SHA256:
3
+ metadata.gz: f8f001c1d4f9343c21eee5371b68f31a56caf35b752a08a662115418176a6156
4
+ data.tar.gz: 519eaaee340436685bc0c31a61d9fc1356072e1d39d573bce8049afe79332252
5
5
  SHA512:
6
- metadata.gz: 6e25b2151aec02177f9a6dd1f14366d44ad1ab2158d8502c65bbf2db4e2672a1926eaba1107580f4a642ad99d79f57d421d54759bed341099ec4a1a4cb9a3a04
7
- data.tar.gz: 34fe7bc261f7e105b230652e5b8ceed4e4b179bf7f36e5424c51cf7767e14ae91173a01b9da2e89707bd147ab212f85367e28791cfa1bbfcac3d055660e2ca43
6
+ metadata.gz: 94a6c0d8f0245befdf662d339bae1b2e0d4a077d3591764f9c215f06453f9e86a40127d3fe5f7488875c470caf8743d19307352e72eaff6f5dfc2c657a828622
7
+ data.tar.gz: eb674773b777504acba00508c7cc62f2e0f1451fb26d1a06463a822130e2cceeda4a8aba964569579becd62b7951f5968dbdd351549143cc81a69e1628923cad
data/.rubocop.yml CHANGED
@@ -3,6 +3,7 @@ AllCops:
3
3
  - 'spec/fixtures/iso-8859.rb'
4
4
  - 'tmp/**/*'
5
5
  - 'vendor/bundle/**/*'
6
+ TargetRubyVersion: 1.9
6
7
 
7
8
  Bundler/OrderedGems:
8
9
  Enabled: false
@@ -35,7 +36,7 @@ Metrics/ParameterLists:
35
36
  Max: 4
36
37
  CountKeywordArgs: true
37
38
 
38
- Style/AccessModifierIndentation:
39
+ Layout/AccessModifierIndentation:
39
40
  EnforcedStyle: outdent
40
41
 
41
42
  Style/CollectionMethods:
@@ -54,10 +55,13 @@ Style/DoubleNegation:
54
55
  Style/HashSyntax:
55
56
  EnforcedStyle: hash_rockets
56
57
 
58
+ Layout/IndentHeredoc:
59
+ Enabled: false
60
+
57
61
  Style/RegexpLiteral:
58
62
  Enabled: false
59
63
 
60
- Style/SpaceInsideHashLiteralBraces:
64
+ Layout/SpaceInsideHashLiteralBraces:
61
65
  EnforcedStyle: no_space
62
66
 
63
67
  Style/SpecialGlobalVars:
data/.travis.yml CHANGED
@@ -15,12 +15,12 @@ rvm:
15
15
  - 1.9.3
16
16
  - 2.0.0
17
17
  - 2.1.10
18
- - 2.2.6
19
- - 2.3.3
20
- - 2.4.0
18
+ - 2.2.7
19
+ - 2.3.4
20
+ - 2.4.1
21
+ - jruby-9.1.13.0
21
22
  - ruby-head
22
23
  - jruby-head
23
- - jruby-9.1.8.0
24
24
 
25
25
  matrix:
26
26
  allow_failures:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ 0.15.1 (2017-09-11) ([changes](https://github.com/colszowka/simplecov/compare/v0.15.0...v0.15.1))
2
+ =======
3
+
4
+ ## Bugfixes
5
+
6
+ * Filter directories outside SimpleCov.root that have it as a prefix. See [#617](https://github.com/colszowka/simplecov/pull/617) (thanks @jenseng)
7
+ * Fix standard rails profile rails filter (didn't work). See [#618](https://github.com/colszowka/simplecov/pull/618) (thanks @jenseng again!)
8
+
9
+ 0.15.0 (2017-08-14) ([changes](https://github.com/colszowka/simplecov/compare/v0.14.1...v0.15.0))
10
+ =======
11
+
12
+ ## Enhancements
13
+
14
+ * Ability to use regex filters for removing files from the output. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel)
15
+
16
+ ## Bugfixes
17
+
18
+ * Fix merging race condition when running tests in parallel and merging them. See [#570](https://github.com/colszowka/simplecov/pull/570) (thanks @jenseng)
19
+ * Fix relevant lines for unloaded files - comments, skipped code etc. are correctly classigied as irrelevant. See [#605](https://github.com/colszowka/simplecov/pull/605) (thanks @odlp)
20
+ * Allow using simplecov with frozen-string-literals enabled. See [#590](https://github.com/colszowka/simplecov/pull/590) (thanks @pat)
21
+ * Make sure Array Filter can use all other filter types. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel)
22
+ * Make sure file names use `Simplecov.root` as base avoiding using full absolute project paths. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel)
23
+
1
24
  0.14.1 2017-03-18 ([changes](https://github.com/colszowka/simplecov/compare/v0.14.0...v0.14.1))
2
25
  ========
3
26
 
@@ -256,7 +279,7 @@ has been added.
256
279
  * Average hits per line for groups of files is now computed correctly.
257
280
  See [#192](http://github.com/colszowka/simplecov/pull/192) and
258
281
  [#179](http://github.com/colszowka/simplecov/issues/179) (thanks to @graysonwright)
259
- * Compatability with BINARY internal encoding.
282
+ * Compatibility with BINARY internal encoding.
260
283
  See [#194](https://github.com/colszowka/simplecov/pull/194) and
261
284
  [#127](https://github.com/colszowka/simplecov/issues/127) (thanks to @justfalter)
262
285
  * Special characters in `SimpleCov.root` are now correctly escaped before being used as a RegExp.
data/Gemfile CHANGED
@@ -23,13 +23,13 @@ group :test do
23
23
  gem "rack", "~> 1.6"
24
24
  end
25
25
  platforms :jruby, :ruby_19, :ruby_20, :ruby_21, :ruby_22, :ruby_23, :ruby_24, :ruby_25 do
26
- gem "aruba", "~> 0.7.4"
26
+ gem "aruba", "~> 0.14"
27
27
  gem "capybara"
28
28
  gem "nokogiri", RUBY_VERSION < "2.1" ? "~> 1.6.0" : ">= 1.7"
29
29
  gem "cucumber"
30
30
  gem "phantomjs", "~> 2.1"
31
31
  gem "poltergeist"
32
- gem "rubocop" unless RUBY_VERSION.start_with?("1.")
32
+ gem "rubocop", "0.49.1" unless RUBY_VERSION.start_with?("1.")
33
33
  gem "test-unit"
34
34
  end
35
35
  gem "json", RUBY_VERSION.start_with?("1.") ? "~> 1.8" : "~> 2.0"
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2010-2015 Christoph Olszowka
1
+ Copyright (c) 2010-2017 Christoph Olszowka
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -40,7 +40,7 @@ automatically when you launch SimpleCov. If you're curious, you can find it [on
40
40
 
41
41
  *Questions, Problems, Suggestions, etc.*
42
42
 
43
- * [Mailing List]: https://groups.google.com/forum/#!forum/simplecov "Open mailing list for discussion and announcements on Google Groups"
43
+ * [Mailing List](https://groups.google.com/forum/#!forum/simplecov) "Open mailing list for discussion and announcements on Google Groups"
44
44
 
45
45
  Getting started
46
46
  ---------------
@@ -133,6 +133,17 @@ to use SimpleCov with them. Here's an overview of the known ones:
133
133
 
134
134
  <table>
135
135
  <tr><th>Framework</th><th>Notes</th><th>Issue</th></tr>
136
+ <tr>
137
+ <th>
138
+ bootsnap
139
+ </th>
140
+ <td>
141
+ <a href="#want-to-use-bootsnap-with-simplecov">See section below.</a>
142
+ </td>
143
+ <td>
144
+ <a href="https://github.com/Shopify/bootsnap/issues/35">Shopify/bootsnap#35</a>
145
+ </td>
146
+ </tr>
136
147
  <tr>
137
148
  <th>
138
149
  parallel_tests
@@ -262,7 +273,7 @@ report.
262
273
 
263
274
  ### Defining custom filters
264
275
 
265
- You can currently define a filter using either a String (that will then be Regexp-matched against each source file's path),
276
+ You can currently define a filter using either a String or Regexp (that will then be Regexp-matched against each source file's path),
266
277
  a block or by passing in your own Filter class.
267
278
 
268
279
  #### String filter
@@ -275,6 +286,16 @@ end
275
286
 
276
287
  This simple string filter will remove all files that match "/test/" in their path.
277
288
 
289
+ #### Regex filter
290
+
291
+ ```ruby
292
+ SimpleCov.start do
293
+ add_filter %r{^/test/}
294
+ end
295
+ ```
296
+
297
+ This simple regex filter will remove all files that start with /test/ in their path.
298
+
278
299
  #### Block filter
279
300
 
280
301
  ```ruby
@@ -305,6 +326,17 @@ Defining your own filters is pretty easy: Just inherit from SimpleCov::Filter an
305
326
  the filter, a true return value from this method will result in the removal of the given source_file. The filter_argument method
306
327
  is being set in the SimpleCov::Filter initialize method and thus is set to 5 in this example.
307
328
 
329
+ #### Array filter
330
+
331
+ ```ruby
332
+ SimpleCov.start do
333
+ proc = Proc.new { |source_file| false }
334
+ add_filter ["string", /regex/, proc, LineFilter.new(5)]
335
+ end
336
+ ```
337
+
338
+ You can pass in an array containing any of the other filter types.
339
+
308
340
  #### Ignoring/skipping code
309
341
 
310
342
  You can exclude code from the coverage report by wrapping it in `# :nocov:`.
@@ -317,8 +349,7 @@ end
317
349
  # :nocov:
318
350
  ```
319
351
 
320
- The name of the token can be changed to your liking. [Learn more about the nocov feature.][nocov]
321
- [nocov]: https://github.com/colszowka/simplecov/blob/master/features/config_nocov_token.feature
352
+ The name of the token can be changed to your liking. [Learn more about the nocov feature.]( https://github.com/colszowka/simplecov/blob/master/features/config_nocov_token.feature)
322
353
 
323
354
  **Note:** You shouldn't have to use the nocov token to skip private methods that are being included in your coverage. If you appropriately test the public interface of your classes and objects you should automatically get full coverage of your private methods.
324
355
 
@@ -570,10 +601,10 @@ being an instance of SimpleCov::Result. Do whatever your wish with that!
570
601
  As of SimpleCov 0.9, you can specify multiple result formats:
571
602
 
572
603
  ```ruby
573
- SimpleCov.formatters = [
604
+ SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
574
605
  SimpleCov::Formatter::HTMLFormatter,
575
606
  SimpleCov::Formatter::CSVFormatter,
576
- ]
607
+ ])
577
608
  ```
578
609
 
579
610
  ## Available formatters, editor integrations and hosted services
@@ -624,6 +655,20 @@ If you're using [Spring](https://github.com/rails/spring) to speed up test suite
624
655
  ```
625
656
  3. Run `spring rspec <path>` as normal. Remember to run `spring stop` after
626
657
  making important changes to your app or its specs!
658
+
659
+ ## Want to use bootsnap with SimpleCov?
660
+
661
+ As mentioned in [this issue](https://github.com/Shopify/bootsnap/issues/35) iseq
662
+ loading/dumping doesn't work with coverage. Hence you need to deactivate it when
663
+ you run coverage so for instance when you use the environment `COVERAGE=true` to
664
+ decide that you want to gather coverage you can do:
665
+
666
+ ```ruby
667
+ Bootsnap.setup(
668
+ compile_cache_iseq: !ENV["COVERAGE"], # Compile Ruby code into ISeq cache, breaks coverage reporting.
669
+ # all those other options
670
+ )
671
+ ```
627
672
 
628
673
  ## Contributing
629
674
 
@@ -635,4 +680,4 @@ Thanks to Aaron Patterson for the original idea for this!
635
680
 
636
681
  ## Copyright
637
682
 
638
- Copyright (c) 2010-2015 Christoph Olszowka. See MIT-LICENSE for details.
683
+ Copyright (c) 2010-2017 Christoph Olszowka. See MIT-LICENSE for details.
data/Rakefile CHANGED
@@ -1,5 +1,3 @@
1
- #!/usr/bin/env rake
2
-
3
1
  require "rubygems"
4
2
  require "bundler/setup"
5
3
  Bundler::GemHelper.install_tasks
@@ -33,4 +33,9 @@ JSON formatter for SimpleCov
33
33
  #### [simplecov-single_file_reporter](https://github.com/grosser/simplecov-single_file_reporter)
34
34
  *by [Michael Grosser](http://grosser.it)*
35
35
 
36
- A formatter that prints the coverage of the file under test when you run a single test file.
36
+ A formatter that prints the coverage of the file under test when you run a single test file.
37
+
38
+ #### [simplecov-t_wada](https://github.com/ysksn/simplecov-t_wada)
39
+ *by [Yosuke Kabuto](https://github.com/ysksn)*
40
+
41
+ t_wada AA formatter for SimpleCov
@@ -7,7 +7,12 @@ Some editors have a graphical integration for the simplecov gem.
7
7
 
8
8
  Adds an overview of your current test coverage to Atom.
9
9
 
10
+ #### [Sublime Editor: Simple​Cov](https://packagecontrol.io/packages/SimpleCov)
11
+ *by sentience*
12
+
13
+ Adds in editor live coverage highlighting, status bar coverage information, and summary coverage information.
14
+
10
15
  #### [cadre](https://github.com/nyarly/cadre)
11
16
  *by Judson Lester*
12
17
 
13
- Includes a formatter for Simplecov that emits a Vim script to mark up code files with coverage information.
18
+ Includes a formatter for Simplecov that emits a Vim script to mark up code files with coverage information.
@@ -16,7 +16,7 @@ Feature:
16
16
  When I open the coverage report generated with `bundle exec rake test`
17
17
  Then I should see the groups:
18
18
  | name | coverage | files |
19
- | All Files | 76.81% | 7 |
19
+ | All Files | 77.94% | 7 |
20
20
 
21
21
  And I should see the source files:
22
22
  | name | coverage |
@@ -0,0 +1,31 @@
1
+ @rspec
2
+ Feature:
3
+
4
+ Using the setting `tracked_files` should classify whether lines
5
+ are relevant or not (such as whitespace or comments).
6
+
7
+ Scenario:
8
+ Given SimpleCov for RSpec is configured with:
9
+ """
10
+ require 'simplecov'
11
+ SimpleCov.start do
12
+ track_files "lib/**/*.rb"
13
+ end
14
+ """
15
+ Given a file named "lib/not_loaded.rb" with:
16
+ """
17
+ # A comment line. Plus a whitespace line below:
18
+
19
+ # :nocov:
20
+ def ignore_me
21
+ end
22
+ # :nocov:
23
+
24
+ def this_is_relevant
25
+ puts "still relevant"
26
+ end
27
+ """
28
+
29
+ When I open the coverage report generated with `bundle exec rspec spec`
30
+ Then I follow "lib/not_loaded.rb"
31
+ Then I should see "3 relevant lines" within ".highlighted"
@@ -8,6 +8,6 @@
8
8
  #
9
9
  Transform "bundle exec rspec spec" do |_|
10
10
  files = nil # Avoid shadowing
11
- in_current_directory { files = Dir["spec/**/*_spec.rb"] }
11
+ cd(".") { files = Dir["spec/**/*_spec.rb"] }
12
12
  "bundle exec rspec #{files.sort.join(' ')}"
13
13
  end
@@ -0,0 +1,53 @@
1
+ # Freedom patch because of not working absolute directories, see: https://github.com/cucumber/aruba/issues/478
2
+ # code taken directly from aruba 0.14.2 - roughly here: https://github.com/cucumber/aruba/blob/master/lib/aruba/api/core.rb#L122-L159
3
+ # rubocop:disable all
4
+ module Aruba
5
+ module Api
6
+ module Core
7
+ def expand_path(file_name, dir_string = nil)
8
+ # only line added, don't ask why but I couldn't get alias_method to work...
9
+ return file_name if absolute?(file_name)
10
+ check_for_deprecated_variables if Aruba::VERSION < '1'
11
+
12
+ message = %(Filename "#{file_name}" needs to be a string. It cannot be nil or empty either. Please use `expand_path('.')` if you want the current directory to be expanded.)
13
+
14
+ fail ArgumentError, message unless file_name.is_a?(String) && !file_name.empty?
15
+
16
+ aruba.logger.warn %(`aruba`'s working directory does not exist. Maybe you forgot to run `setup_aruba` before using it's API. This warning will be an error from 1.0.0) unless Aruba.platform.directory? File.join(aruba.config.root_directory, aruba.config.working_directory)
17
+
18
+ if RUBY_VERSION < '1.9'
19
+ prefix = file_name.chars.to_a[0].to_s
20
+ rest = if file_name.chars.to_a[2..-1].nil?
21
+ nil
22
+ else
23
+ file_name.chars.to_a[2..-1].join
24
+ end
25
+ else
26
+ prefix = file_name[0]
27
+ rest = file_name[2..-1]
28
+ end
29
+
30
+ if aruba.config.fixtures_path_prefix == prefix
31
+ path = File.join(*[aruba.fixtures_directory, rest].compact)
32
+
33
+ fail ArgumentError, %(Fixture "#{rest}" does not exist in fixtures directory "#{aruba.fixtures_directory}". This was the one we found first on your system from all possible candidates: #{aruba.config.fixtures_directories.map { |p| format('"%s"', p) }.join(', ')}.) unless Aruba.platform.exist? path
34
+
35
+ path
36
+ elsif '~' == prefix
37
+ path = with_environment do
38
+ ArubaPath.new(File.expand_path(file_name))
39
+ end
40
+
41
+ fail ArgumentError, 'Expanding "~/" to "/" is not allowed' if path.to_s == '/'
42
+ fail ArgumentError, %(Expanding "~/" to a relative path "#{path}" is not allowed) unless path.absolute?
43
+
44
+ path.to_s
45
+ else
46
+ directory = File.join(aruba.root_directory, aruba.current_directory)
47
+ ArubaPath.new(File.join(*[directory, dir_string, file_name].compact)).expand_path.to_s
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ # rubocop:enable all
@@ -6,7 +6,8 @@ end
6
6
  require "bundler"
7
7
  Bundler.setup
8
8
  require "aruba/cucumber"
9
- require "aruba/jruby" if RUBY_ENGINE == "jruby"
9
+ require "aruba/config/jruby" if RUBY_ENGINE == "jruby"
10
+ require_relative "aruba_freedom_patch"
10
11
  require "capybara/cucumber"
11
12
  require "phantomjs/poltergeist"
12
13
 
@@ -34,7 +35,7 @@ Before do
34
35
  this_dir = File.dirname(__FILE__)
35
36
 
36
37
  # Clean up and create blank state for fake project
37
- in_current_directory do
38
+ cd(".") do
38
39
  FileUtils.rm_rf "project"
39
40
  FileUtils.cp_r File.join(this_dir, "../../spec/faked_project/"), "project"
40
41
  end
@@ -44,7 +45,6 @@ end
44
45
 
45
46
  # Workaround for https://github.com/cucumber/aruba/pull/125
46
47
  Aruba.configure do |config|
47
- config.before_cmd do
48
- set_env("JRUBY_OPTS", "--dev --debug")
49
- end
48
+ config.exit_timeout = RUBY_ENGINE == "jruby" ? 60 : 20
49
+ config.command_runtime_environment = {"JRUBY_OPTS" => "--dev --debug"}
50
50
  end
@@ -291,16 +291,12 @@ module SimpleCov
291
291
  # The actual filter processor. Not meant for direct use
292
292
  #
293
293
  def parse_filter(filter_argument = nil, &filter_proc)
294
- if filter_argument.is_a?(SimpleCov::Filter)
295
- filter_argument
296
- elsif filter_argument.is_a?(String)
297
- SimpleCov::StringFilter.new(filter_argument)
298
- elsif filter_proc
299
- SimpleCov::BlockFilter.new(filter_proc)
300
- elsif filter_argument.is_a?(Array)
301
- SimpleCov::ArrayFilter.new(filter_argument)
294
+ filter = filter_argument || filter_proc
295
+
296
+ if filter
297
+ SimpleCov::Filter.build_filter(filter)
302
298
  else
303
- raise ArgumentError, "Please specify either a string or a block to filter with"
299
+ raise ArgumentError, "Please specify either a filter or a block to filter with"
304
300
  end
305
301
  end
306
302
  end
@@ -6,8 +6,8 @@ SimpleCov.profiles.define "root_filter" do
6
6
  # Exclude all files outside of simplecov root
7
7
  root_filter = nil
8
8
  add_filter do |src|
9
- root_filter ||= /\A#{Regexp.escape(SimpleCov.root)}/io
10
- !(src.filename =~ root_filter)
9
+ root_filter ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io
10
+ src.filename !~ root_filter
11
11
  end
12
12
  end
13
13
 
@@ -25,15 +25,15 @@ end
25
25
  SimpleCov.profiles.define "rails" do
26
26
  load_profile "test_frameworks"
27
27
 
28
- add_filter "/config/"
29
- add_filter "/db/"
28
+ add_filter %r{^/config/}
29
+ add_filter %r{^/db/}
30
30
 
31
31
  add_group "Controllers", "app/controllers"
32
32
  add_group "Channels", "app/channels" if defined?(ActionCable)
33
33
  add_group "Models", "app/models"
34
34
  add_group "Mailers", "app/mailers"
35
35
  add_group "Helpers", "app/helpers"
36
- add_group "Jobs", %w(app/jobs app/workers)
36
+ add_group "Jobs", %w[app/jobs app/workers]
37
37
  add_group "Libraries", "lib"
38
38
 
39
39
  track_files "{app,lib}/**/*.rb"
@@ -5,25 +5,25 @@ module SimpleCov
5
5
  # Returns the count of lines that have coverage
6
6
  def covered_lines
7
7
  return 0.0 if empty?
8
- map { |f| f.covered_lines.count }.inject(&:+)
8
+ map { |f| f.covered_lines.count }.inject(:+)
9
9
  end
10
10
 
11
11
  # Returns the count of lines that have been missed
12
12
  def missed_lines
13
13
  return 0.0 if empty?
14
- map { |f| f.missed_lines.count }.inject(&:+)
14
+ map { |f| f.missed_lines.count }.inject(:+)
15
15
  end
16
16
 
17
17
  # Returns the count of lines that are not relevant for coverage
18
18
  def never_lines
19
19
  return 0.0 if empty?
20
- map { |f| f.never_lines.count }.inject(&:+)
20
+ map { |f| f.never_lines.count }.inject(:+)
21
21
  end
22
22
 
23
23
  # Returns the count of skipped lines
24
24
  def skipped_lines
25
25
  return 0.0 if empty?
26
- map { |f| f.skipped_lines.count }.inject(&:+)
26
+ map { |f| f.skipped_lines.count }.inject(:+)
27
27
  end
28
28
 
29
29
  # Computes the coverage based upon lines covered and lines missed for each file
@@ -53,7 +53,7 @@ module SimpleCov
53
53
  # @return [Float]
54
54
  def covered_strength
55
55
  return 0.0 if empty? || lines_of_code.zero?
56
- Float(map { |f| f.covered_strength * f.lines_of_code }.inject(&:+) / lines_of_code)
56
+ Float(map { |f| f.covered_strength * f.lines_of_code }.inject(:+) / lines_of_code)
57
57
  end
58
58
  end
59
59
  end
@@ -24,13 +24,40 @@ module SimpleCov
24
24
  warn "#{Kernel.caller.first}: [DEPRECATION] #passes? is deprecated. Use #matches? instead."
25
25
  matches?(source_file)
26
26
  end
27
+
28
+ def self.build_filter(filter_argument)
29
+ return filter_argument if filter_argument.is_a?(SimpleCov::Filter)
30
+ class_for_argument(filter_argument).new(filter_argument)
31
+ end
32
+
33
+ def self.class_for_argument(filter_argument)
34
+ if filter_argument.is_a?(String)
35
+ SimpleCov::StringFilter
36
+ elsif filter_argument.is_a?(Regexp)
37
+ SimpleCov::RegexFilter
38
+ elsif filter_argument.is_a?(Array)
39
+ SimpleCov::ArrayFilter
40
+ elsif filter_argument.is_a?(Proc)
41
+ SimpleCov::BlockFilter
42
+ else
43
+ raise ArgumentError, "You have provided an unrecognized filter type"
44
+ end
45
+ end
27
46
  end
28
47
 
29
48
  class StringFilter < SimpleCov::Filter
30
49
  # Returns true when the given source file's filename matches the
31
50
  # string configured when initializing this Filter with StringFilter.new('somestring)
32
51
  def matches?(source_file)
33
- (source_file.filename =~ /#{filter_argument}/)
52
+ (source_file.project_filename =~ /#{filter_argument}/)
53
+ end
54
+ end
55
+
56
+ class RegexFilter < SimpleCov::Filter
57
+ # Returns true when the given source file's filename matches the
58
+ # regex configured when initializing this Filter with RegexFilter.new(/someregex/)
59
+ def matches?(source_file)
60
+ (source_file.project_filename =~ filter_argument)
34
61
  end
35
62
  end
36
63
 
@@ -43,11 +70,19 @@ module SimpleCov
43
70
  end
44
71
 
45
72
  class ArrayFilter < SimpleCov::Filter
46
- # Returns true if any of the file paths passed in the given array matches the string
47
- # configured when initializing this Filter with StringFilter.new(['some/path', 'other/path'])
73
+ def initialize(filter_argument)
74
+ filter_objects = filter_argument.map do |arg|
75
+ Filter.build_filter(arg)
76
+ end
77
+
78
+ super(filter_objects)
79
+ end
80
+
81
+ # Returns true if any of the filters in the array match the given source file.
82
+ # Configure this Filter like StringFilter.new(['some/path', /^some_regex/, Proc.new {|src_file| ... }])
48
83
  def matches?(source_files_list)
49
84
  filter_argument.any? do |arg|
50
- source_files_list.filename =~ /#{arg}/
85
+ arg.matches?(source_files_list)
51
86
  end
52
87
  end
53
88
  end
@@ -6,7 +6,7 @@ module SimpleCov
6
6
  class SimpleFormatter
7
7
  # Takes a SimpleCov::Result and generates a string out of it
8
8
  def format(result)
9
- output = ""
9
+ output = "".dup
10
10
  result.groups.each do |name, files|
11
11
  output << "Group: #{name}\n"
12
12
  output << "=" * 40
@@ -0,0 +1,32 @@
1
+ module SimpleCov
2
+ # Classifies whether lines are relevant for code coverage analysis.
3
+ # Comments & whitespace lines, and :nocov: token blocks, are considered not relevant.
4
+
5
+ class LinesClassifier
6
+ RELEVANT = 0
7
+ NOT_RELEVANT = nil
8
+
9
+ WHITESPACE_LINE = /^\s*$/
10
+ COMMENT_LINE = /^\s*#/
11
+ WHITESPACE_OR_COMMENT_LINE = Regexp.union(WHITESPACE_LINE, COMMENT_LINE)
12
+
13
+ def self.no_cov_line
14
+ /^(\s*)#(\s*)(\:#{SimpleCov.nocov_token}\:)/
15
+ end
16
+
17
+ def classify(lines)
18
+ skipping = false
19
+
20
+ lines.map do |line|
21
+ if line =~ self.class.no_cov_line
22
+ skipping = !skipping
23
+ NOT_RELEVANT
24
+ elsif skipping || line =~ WHITESPACE_OR_COMMENT_LINE
25
+ NOT_RELEVANT
26
+ else
27
+ RELEVANT
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end