deep-cover 0.6.4 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ddf8729ec371781a34f8b9f333e12f5a8b447ad6768f12b1106ad07bfe7f69aa
4
- data.tar.gz: 9de4ab46c4c64b1c174511c8359c2268cf5775bdc85640224deb9fcd90b52031
3
+ metadata.gz: 8b1f81b23d211ad08949890b4bc4267613e18b566b5e8129aa2ec575cc1cf28e
4
+ data.tar.gz: 3f80f743ba78813f2218aeed63bc9a8ba889447f446367f1df34a9054b59bb8b
5
5
  SHA512:
6
- metadata.gz: 0153a2468094f09c14b9339dc7e5b5eb0132bc692b73255e5e1f28a1025f390d801bf5522f3ffee89ed2d801a6056a0b86a019d73adaee090d0f2aab07be88c7
7
- data.tar.gz: 547dd15651dc7c896ed190d91ae2b5703239c883cda8037d8a3cf8d38711213abf1481197be5df0822e44cb9873b6232a4f7f72838936195a9629c7eefced66b
6
+ metadata.gz: e0763b964b08399a871dc36b4da0bd0b227a58eabf15c98b0144abae98222d0fb44a67ed4ea11cf91c64350bef1072d539c5f45f6075043f2b6a559a4cc6a24d
7
+ data.tar.gz: 342d74b8ffbc0c56c062635c66b799ae9926fecf060d3d62188adcb6aea09a957ae3a3d97b4662c1538ef407bbdc60888675930f3db4f2fc20b75c35eca3da82
@@ -5,4 +5,9 @@
5
5
  DeepCover.configure do
6
6
  tracker_global '$_dcg'
7
7
  ignore_uncovered :warn, :raise, :default_argument
8
+ # Statement analyser is only used for Istanbul output and is undertested.
9
+ # Ignore for now. TODO: test this, or get rid of StatementAnalyser
10
+ ignore_uncovered :is_statement_methods do
11
+ parent.is_a?(DeepCover::Node::Def) && parent.method_name == :is_statement
12
+ end
8
13
  end
data/.gitignore CHANGED
@@ -1,6 +1,6 @@
1
1
  .bundle/
2
2
  .yardoc
3
- /Gemfile.lock
3
+ Gemfile.lock
4
4
  /core_gem/Gemfile.lock
5
5
  /_yardoc/
6
6
  /coverage/
@@ -15,6 +15,9 @@
15
15
  # rspec failure tracking
16
16
  .rspec_status
17
17
  /Gemfile.local
18
- /spec/code_fixtures/covered_trivial_gem/deep_cover/
19
- /deep_cover
20
- /exe/deep_cover/
18
+ *.dc
19
+ *.dct
20
+ .nyc_output/
21
+
22
+ # Used in tests
23
+ *.else
@@ -109,6 +109,9 @@ Style/FrozenStringLiteralComment:
109
109
  Style/NegatedIf:
110
110
  Enabled: false
111
111
 
112
+ Style/Next:
113
+ Enabled: false
114
+
112
115
  Style/NumericPredicate:
113
116
  Enabled: false
114
117
 
@@ -119,6 +122,9 @@ Style/PercentLiteralDelimiters:
119
122
  Style/RedundantSelf:
120
123
  Enabled: false
121
124
 
125
+ Style/SpecialGlobalVars:
126
+ Enabled: false
127
+
122
128
  Style/StringLiterals:
123
129
  EnforcedStyle: single_quotes
124
130
 
@@ -188,6 +194,7 @@ Lint/Void:
188
194
  Enabled: true
189
195
  Exclude:
190
196
  - core_gem/spec/**/*
197
+ - spec/**/*
191
198
 
192
199
  Style/ClassVars:
193
200
  Enabled: false
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0
4
+
5
+ * Switched CLI to rely on Thor instead of Slop
6
+ * Added lower-level CLI commands: gather, merge, report, clear
7
+ * Added `deep-cover clone`, it does what `deep-cover` without commands did.
8
+ * Changed the default when using `deep-cover` without commands, it now shows a short help.
9
+ Use `deep-cover clone` to reproduce the previous default.
10
+ * `deep-cover exec` now uses the same default command as `deep-cover clone`
11
+ * Added global option -C (--change-directory) which basically executes a `cd` before executing deep-cover.
12
+ This replaces the default path parameter of `deep-cover clone`
13
+ * `deep-cover clone` now receives an optional command as positional argument, just like `deep-cover exec`.
14
+ It's previous positional argument (path to run) is now the -C option.
15
+ * `deep-cover` now display coverage information for files that were not loaded. This may lower your the coverage results.
16
+ * The configuration for the paths to cover can now receive globs.
17
+ * `deep-cover clone` no longer needs bundler. It still uses a Gemfile, if it finds one, to decide between
18
+ copying the current directory or the parent one.
19
+ * `deep-cover clone` is more efficient and has less edge cases that would make some files not be covered.
20
+
21
+ ## 0.6.3
22
+
23
+ * Split the gem into two: `deep-cover` and `deep-cover-core`.
24
+ `deep-cover` is the cli, and depends on `deep-cover-core`, so nothing special is needed.
25
+ Those that don't want to have the CLI (either for dependencies or because they don't use it)
26
+ may now avoid it.
27
+
28
+ ## 0.6.2
29
+
3
30
  * `#require` is much faster in MRI Ruby 2.1 and 2.2, resulting in much faster boot time for most applications when deep-cover is enabled.
4
31
 
5
32
  ## 0.6.1
data/Gemfile CHANGED
@@ -9,6 +9,10 @@ gemspec
9
9
 
10
10
  eval_gemfile File.expand_path('Gemfile.local', __dir__) if File.exist?('Gemfile.local')
11
11
 
12
- gem 'deep-cover-core', path: 'core_gem'
12
+ # This is a workaround for rubymine to stop treating the core_gem directory like an external library...
13
+ # https://youtrack.jetbrains.com/issue/RUBY-18315#comment=27-1608735
14
+ gem_name = 'deep-cover-core'
15
+ gem_path = 'core_gem'
16
+ gem gem_name, path: gem_path
13
17
 
14
18
  gem 'ruby-prof', platforms: :mri
data/README.md CHANGED
@@ -54,7 +54,7 @@ Platform support | Ruby 2.5+ | Ruby 2.1+, JRuby
54
54
 
55
55
  **Line coverage**: MRI doesn't cover some lines (e.g. `when some_value`).
56
56
 
57
- **Node coverage**: MRI provides no way to tell which parts of any line is evaluated. DeepCover covers everything.
57
+ **Node coverage**: MRI provides no way to tell which parts of any line is evaluated (e.g. `0.times { never_run }`). DeepCover covers everything.
58
58
 
59
59
  **Method coverage**: MRI considers every method defined, including methods defined on objects or via `define_method`, `class_eval`, etc. For Istanbul output, DeepCover has a different approach and covers all `def` and all blocks.
60
60
 
@@ -72,81 +72,71 @@ easy to support it if needed.
72
72
 
73
73
  ## Installation
74
74
 
75
- gem install deep-cover
76
-
77
- First we present the official way. There are also quick and dirty ways to try `deep-cover` without changing much your current setup, which we present afterwards.
78
-
79
- ### Canonical installation
80
-
81
- *1* Add the `deep-cover` gem as a dependency:
82
-
83
- For a standalone project (Rails app), add `deep-cover` to your Gemfile:
75
+ Do the appropriate of the installation of the gem, then follow the steps that correspond to your situation.
84
76
 
85
- gem 'deep-cover', '~> 0.4', group: :test, require: false
77
+ # if the project is a gem, add this to your .gemspec and then run `bundle install`
78
+ spec.add_development_dependency 'deep-cover', '~> 0.7'
86
79
 
87
- Then run `bundle`
80
+ # otherwise if using a Gemfile, add this to it and then run `bundle install`
81
+ gem 'deep-cover', '~> 0.7', group: :test, require: false
88
82
 
89
- For a gem, you want to add `spec.add_development_dependency 'deep-cover', '~> 0.4'` to your `gemspec` file instead.
83
+ # otherwise just run:
84
+ gem install deep-cover
90
85
 
91
- *2* Require `deep-cover`
92
86
 
93
- You must call `require 'deep-cover'` *before* the code you want to cover is loaded.
87
+ ### Trying `deep-cover` quickly
94
88
 
95
- Typically, you want to insert that line in your `test/test_helper.rb` or `spec/spec_helper.rb` file at the right place. For example
89
+ An easy way to try `deep-cover`, without any configuration needed:
96
90
 
97
- ```
98
- ENV['RAILS_ENV'] ||= 'test'
99
- require 'deep-cover' # Must be before the environment is loaded on the next line
100
- require File.expand_path('../../config/environment', __FILE__)
101
- require 'rails/test_help'
102
- # ...
103
- ```
91
+ deep-cover clone command to run test
92
+ # ex:
93
+ deep-cover clone rake test
104
94
 
105
- *3* Create a config file (optional)
95
+ Check the produced `coverage/index.html`.
106
96
 
107
- You may want to create a config file `.deep-cover.rb` at the root of your project, where you can set the config as you wish.
97
+ Note, this is a bit slower and may cause issues in your tests if your use relative paths that lead outside of the directory (Such as a dependency that is in a parent directory).
108
98
 
109
- ```
110
- # File .deep-cover.rb
111
- DeepCover.config do
112
- ignore :default_arguments
113
- # ...
114
- end
115
- ```
99
+ ### Regular setup
116
100
 
117
- *4* Launch it
101
+ 1. Require `deep-cover`
118
102
 
119
- Even after `DeepCover` is `require`d and configured, only a very minimal amount of code is actually loaded and coverage is *not started*.
103
+ You must call `require 'deep-cover'` **before** the code you want to cover is loaded.
120
104
 
121
- The easiest way to actually start it is to use `deep-cover exec` instead of `bundle exec`.
105
+ Typically, you want to insert that line **at the very top** of `test/test_helper.rb` or `spec/spec_helper.rb` . If `deep-cover` is required after your code, then it won't be able to detect the coverage.
122
106
 
123
- For example:
107
+ 2. Create a config file (optional)
124
108
 
125
- ```
126
- $ deep-cover exec rspec
127
- # ...all the output of rspec
128
- # ...coverage report
129
- ```
109
+ You may want to create a config file `.deep-cover.rb` at the root of your project, where you can set the config as you wish.
130
110
 
131
- ### Command line interface (for a Rails app or a Gem):
111
+ ```
112
+ # File .deep-cover.rb
113
+ DeepCover.config do
114
+ ignore :default_arguments
115
+ # ...
116
+ end
117
+ ```
132
118
 
133
- An easy way to try `deep-cover`, without any configuration needed:
119
+ 3. Launch it
134
120
 
135
- deep-cover /path/to/rails/app/or/gem
121
+ Even after `DeepCover` is `require`d and configured, only a very minimal amount of code is actually loaded and coverage is *not started*.
136
122
 
137
- This assumes your project has a `Gemfile`, and that your default `rake` task is set to execute all tests (otherwise set the `--command` option)
123
+ The easiest way to actually start it is to use `deep-cover exec`
138
124
 
139
- It also uses our builtin HTML reporter. Check the produced `coverage/index.html`.
125
+ For example:
140
126
 
141
- ### Projects using builtin Coverage (including SimpleCov) users
127
+ ```
128
+ $ deep-cover exec rspec
129
+ # ...all the output of rspec
130
+ # ...coverage report
131
+ ```
142
132
 
143
- To make it easier to transition for projects already using the builtin `Coverage` library (or indirectly those using `SimpleCov`), there is a way to overwrite the `Coverage` library using `deep-cover`'s extended coverage.
133
+ ### Already using SimpleCov / builtin Coverage
144
134
 
145
- Add to your Gemfile `gem 'deep-cover', require: false`, then run `bundle`.
135
+ To make it easier to transition for projects already using the builtin `Coverage` library (such as those using `SimpleCov`), `deep-cover` can inject itself into those tools so that, while you still only have line-by-line coverage information, it becomes stricter, only marking a line as executed if *everything* on it has been executed.
146
136
 
147
- Before you require `coverage` or `simplecov`, do a `require 'deep_cover/builtin_takeover'`.
137
+ You must call `require 'deep-cover/builtin_takeover'` **before** you require the coverage tool that you normally use.
148
138
 
149
- For example, the `test/test_helper.rb` file for `simplecov` users will look like
139
+ For example, the `test/test_helper.rb` file for `SimpleCov` users will look like
150
140
 
151
141
  ```
152
142
  require 'deep_cover/builtin_takeover'
@@ -155,6 +145,12 @@ SimpleCov.start
155
145
  # rest of `test_helper.rb`
156
146
  ```
157
147
 
148
+ Once this is done, simply generate the coverage as you normally would. In order to get detailed information about why a line is not covered, you will need to the regular `deep-cover` mode.
149
+
150
+ ### Online coverage tools such as Code Climate, Coveralls, Codecov
151
+
152
+ At the moment, those tools do not support deep-cover. It is however possible to use the takeover system to, at least, make them stricter. Follow the explanation in the above section for injecting into `SimpleCov`.
153
+
158
154
  ## Usage
159
155
 
160
156
  ### Configuration
@@ -172,8 +168,6 @@ end
172
168
 
173
169
  The file `.deep-cover.rb` is loaded automatically when requiring `deep-cover` and is the best place to put the configuration.
174
170
 
175
- *Note*: The configuration block is only executed when `deep-cover` is actually started.
176
-
177
171
  #### Custom filters
178
172
 
179
173
  `deep-cover` comes with a few filters that make it possible to ignore certain uncovered codes.
data/Rakefile CHANGED
@@ -18,30 +18,34 @@ desc 'Build & release deep-cover and deep-cover-core to rubygems.org'
18
18
  task release: ['core:sass', 'core:release', 'global:release']
19
19
 
20
20
  ### Tests tasks
21
- require 'rspec/core/rake_task'
22
- require 'rubocop/rake_task'
21
+ begin
22
+ require 'rspec/core/rake_task'
23
+ require 'rubocop/rake_task'
23
24
 
24
- RuboCop::RakeTask.new(:rubocop) do |t|
25
- t.options = ['-a'] unless ENV['TRAVIS']
26
- end
25
+ RuboCop::RakeTask.new(:rubocop) do |t|
26
+ t.options = ['-a'] unless ENV['TRAVIS']
27
+ end
27
28
 
28
- spec_path = 'spec/*_spec.rb, core_gem/spec/**/*_spec.rb'
29
- RSpec::Core::RakeTask.new(:spec).tap { |task| task.pattern = spec_path }
29
+ spec_path = 'spec/*_spec.rb, core_gem/spec/**/*_spec.rb'
30
+ RSpec::Core::RakeTask.new(:spec).tap { |task| task.pattern = spec_path }
30
31
 
31
- desc 'Run all tests'
32
- RSpec::Core::RakeTask.new('spec:all') do |task|
33
- task.pattern = spec_path
34
- task.rspec_opts = '-O .rspec_all'
35
- end
32
+ desc 'Run all tests'
33
+ RSpec::Core::RakeTask.new('spec:all') do |task|
34
+ task.pattern = spec_path
35
+ task.rspec_opts = '-O .rspec_all'
36
+ end
36
37
 
37
- multitask default: RUBY_VERSION > '2.1' ? [:rubocop, :spec] : :spec
38
- multitask 'test:all' => RUBY_VERSION > '2.1' ? [:rubocop, 'spec:all'] : 'spec:all'
38
+ multitask default: RUBY_VERSION > '2.1' ? [:rubocop, :spec] : :spec
39
+ multitask 'test:all' => RUBY_VERSION > '2.1' ? [:rubocop, 'spec:all'] : 'spec:all'
40
+ rescue LoadError
41
+ puts 'Note: rspec or rubocop not installed'
42
+ end
39
43
 
40
44
  #### Utilities
41
45
  namespace :dev do
42
46
  desc 'Self cover'
43
47
  task :cov do
44
- command = "exe/deep-cover . --no-bundle --command 'rake spec:all'"
48
+ command = "exe/deep-cover clone --no-bundle --command 'rake spec:all'"
45
49
  puts command
46
50
  system command
47
51
  end
@@ -56,6 +60,7 @@ namespace :dev do
56
60
  commands << 'bundle install --gemfile=spec/code_fixtures/simple_rails42_app/Gemfile'
57
61
  commands << 'bundle install --gemfile=spec/code_fixtures/rails_like_gem/Gemfile'
58
62
  commands << 'bundle install --gemfile=core_gem/Gemfile'
63
+ commands << 'bundle install'
59
64
 
60
65
  commands.each do |command|
61
66
  puts "Running: #{command}"
@@ -14,7 +14,7 @@ Gem::Specification.new do |spec|
14
14
  spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
- f.match(%r{^(test|spec|features|\w+_gem)/})
17
+ f.match(%r{^(test|spec|features|bin|\w+_gem)/})
18
18
  end
19
19
  spec.bindir = 'exe'
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
@@ -29,8 +29,7 @@ Gem::Specification.new do |spec|
29
29
  # CLI
30
30
  spec.add_runtime_dependency 'bundler'
31
31
  spec.add_runtime_dependency 'highline'
32
- spec.add_runtime_dependency 'slop', '~> 4.0'
33
- spec.add_runtime_dependency 'term-ansicolor'
32
+ spec.add_runtime_dependency 'thor', '>= 0.20.3'
34
33
  spec.add_runtime_dependency 'with_progress'
35
34
 
36
35
  ### Dev dependencies
@@ -3,12 +3,10 @@
3
3
 
4
4
  $LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
5
5
 
6
- require_relative '../lib/deep_cover_entry'
7
-
8
6
  # HACK: tweak $LOAD_PATH when running from source
9
7
  local_gem_path = File.expand_path('../core_gem', __dir__)
10
8
  $LOAD_PATH.unshift "#{local_gem_path}/lib" if Dir.exist?(local_gem_path)
11
9
 
12
- require 'deep_cover/cli/runner'
10
+ require_relative '../lib/deep_cover/cli'
13
11
 
14
- DeepCover::CLI::Runner.go
12
+ DeepCover::CLI.start
@@ -0,0 +1,85 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'thor'
5
+
6
+ module DeepCover
7
+ # can't use `#require_relative`: This is gem deep-cover requiring from gem deep-cover-core
8
+ # We don't want the config to be loaded right now, because we may move the current_work_dir somewhere else.
9
+ require 'deep_cover/setup/deep_cover_without_config'
10
+
11
+ bootstrap
12
+
13
+ class CLI < Thor
14
+ require_relative 'cli/tools'
15
+
16
+ # Just fail when you get an unknown option
17
+ check_unknown_options!
18
+
19
+ # If the default value of a option doesn't match its type, something is wrong.
20
+ check_default_type!
21
+
22
+ # Every top-level commands are defined in a different file, which add their method to this class
23
+ DeepCover.require_relative_dir 'cli/commands'
24
+
25
+ default_command :short_help
26
+
27
+ # Adding all of the ignore-something class options
28
+ OPTIONALLY_COVERED_MAP = OPTIONALLY_COVERED.map do |optional|
29
+ [:"ignore_#{optional}", optional]
30
+ end.to_h.freeze
31
+ OPTIONALLY_COVERED_MAP.each do |cli_option, short_name|
32
+ default = DeepCover.config.ignore_uncovered.include?(short_name)
33
+ class_option cli_option, type: :boolean, default: default
34
+ end
35
+
36
+ class_option :change_directory, desc: 'Runs as if deep-cover was started in <path>', type: :string, aliases: '-C', default: '.'
37
+
38
+ # exit_code should be non-zero when the parsing fails
39
+ def self.exit_on_failure?
40
+ true
41
+ end
42
+
43
+ no_commands do
44
+ # We have some special handling for some of the options
45
+ # We do this here, methods just need to call processed_options instead of options.
46
+ def processed_options
47
+ @processed_options ||= nil
48
+ return @processed_options if @processed_options
49
+
50
+ new_options = options.dup
51
+ new_options[:output] = false if ['false', 'f', ''].include?(new_options[:output])
52
+
53
+ # Turn all the ignore-x into entries in :ignore_uncovered
54
+ ignored = new_options[:ignore_uncovered] = []
55
+ OPTIONALLY_COVERED_MAP.each do |cli_option, option|
56
+ ignored << option if new_options.delete(cli_option)
57
+ end
58
+
59
+ @processed_options = new_options.transform_keys(&:to_sym)
60
+ end
61
+
62
+ # Before we actually execute any of the commands, we want to change directory if that option was given.
63
+ # And then we want to setup the configuration
64
+ def invoke_command(*args)
65
+ if options[:change_directory] != '.'
66
+ root_path = File.expand_path(options[:change_directory])
67
+ unless File.exist?(root_path)
68
+ warn set_color(DeepCover::Tools.strip_heredoc(<<-MSG), :red)
69
+ bad value for option --change_directory: #{root_path.inspect} is not a valid directory
70
+ MSG
71
+ exit(1)
72
+ end
73
+ Dir.chdir(root_path)
74
+ # TODO: We need way to turn on DEBUG
75
+ # warn "(in #{root_path})"
76
+ end
77
+
78
+ # We need to wait until now to setup the configuration, because it will store absolute paths
79
+ # in ENV['DEEP_COVER_OPTIONS'], so we must wait until the change_directory was applied.
80
+ require 'deep_cover/setup/deep_cover_config'
81
+ super
82
+ end
83
+ end
84
+ end
85
+ end