kettle-soup-cover 1.0.4 → 1.0.6

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.
@@ -0,0 +1,113 @@
1
+ module Kettle
2
+ module Soup
3
+ module Cover
4
+ module Constants
5
+ FALSE = "false"
6
+ TRUE = "true"
7
+ PREFIX = ENV.fetch("K_SOUP_COV_PREFIX", "K_SOUP_COV_")
8
+ ENV_GET = ->(suffix, default) { ENV.fetch("#{PREFIX}#{suffix}", default) }
9
+ FORMATTER_PLUGINS = {
10
+ # HTML for Humans
11
+ html: {
12
+ type: :html,
13
+ klass: "HTMLFormatter",
14
+ lib: "simplecov-html",
15
+ },
16
+ # XML for Jenkins
17
+ xml: {
18
+ type: :xml,
19
+ klass: "CoberturaFormatter",
20
+ lib: "simplecov-cobertura",
21
+ },
22
+ # RCOV for Hudson
23
+ rcov: {
24
+ type: :rcov,
25
+ klass: "RcovFormatter",
26
+ lib: "simplecov-rcov",
27
+ },
28
+ # LCOV for GCOV
29
+ lcov: {
30
+ type: :lcov,
31
+ klass: "LcovFormatter",
32
+ lib: "simplecov-lcov",
33
+ },
34
+ # JSON for CodeClimate
35
+ json: {
36
+ type: :json,
37
+ klass: "JSONFormatter",
38
+ lib: "simplecov_json_formatter",
39
+ },
40
+ # TTY / Console output
41
+ tty: {
42
+ type: :tty,
43
+ klass: "Console",
44
+ lib: "simplecov-console",
45
+ },
46
+ }
47
+
48
+ CI = ENV.fetch("CI", FALSE)
49
+ IS_CI = CI.casecmp?(TRUE)
50
+ COMMAND_NAME = ENV_GET.call("COMMAND_NAME", "RSpec (COVERAGE)")
51
+ COVERAGE_DIR = ENV_GET.call("DIR", "coverage")
52
+ DEBUG = ENV_GET.call("DEBUG", FALSE).casecmp?(TRUE)
53
+ DO_COV = ENV_GET.call("DO", CI).casecmp?(TRUE)
54
+ FILTER_DIRS = ENV_GET.call(
55
+ "FILTER_DIRS",
56
+ "bin,certs,checksums,config,coverage,docs,features,gemfiles,pkg,results,sig,spec,src,test,test-results,vendor",
57
+ )
58
+ .split(",")
59
+ .map { |dir_name| %r{^/#{Regexp.escape(dir_name)}/} }
60
+ FORMATTERS = ENV_GET.call(
61
+ "FORMATTERS",
62
+ IS_CI ? "html,xml,rcov,lcov,json,tty" : "html,tty",
63
+ )
64
+ .split(",")
65
+ .map { |fmt_name| FORMATTER_PLUGINS[fmt_name.strip.to_sym] }
66
+ MIN_COVERAGE_HARD = ENV_GET.call("MIN_HARD", CI).casecmp?(TRUE)
67
+ MIN_COVERAGE_BRANCH = ENV_GET.call("MIN_BRANCH", "80").to_i
68
+ MIN_COVERAGE_LINE = ENV_GET.call("MIN_LINE", "80").to_i
69
+ MULTI_FORMATTERS_DEFAULT = if IS_CI
70
+ TRUE
71
+ else
72
+ FORMATTERS.any? ? TRUE : FALSE
73
+ end
74
+ MULTI_FORMATTERS = ENV_GET.call("MULTI_FORMATTERS", MULTI_FORMATTERS_DEFAULT).casecmp?(TRUE)
75
+ # A wild approximation, but will suffice for nearly all users
76
+ is_mac = RbConfig::CONFIG["host_os"].include?("darwin")
77
+ # Set to "" to prevent opening a browser with the coverage rake task
78
+ OPEN_BIN = ENV_GET.call("OPEN_BIN", is_mac ? "open" : "xdg-open")
79
+ USE_MERGING = ENV_GET.call("USE_MERGING", nil)&.casecmp?(TRUE)
80
+ MERGE_TIMEOUT = ENV_GET.call("MERGE_TIMEOUT", nil)&.to_i
81
+ VERBOSE = ENV_GET.call("VERBOSE", FALSE).casecmp?(TRUE)
82
+
83
+ include Kettle::Change.new(
84
+ constants: %w[
85
+ CI
86
+ COMMAND_NAME
87
+ COVERAGE_DIR
88
+ DEBUG
89
+ DO_COV
90
+ ENV_GET
91
+ FALSE
92
+ FILTER_DIRS
93
+ FORMATTER_PLUGINS
94
+ FORMATTERS
95
+ IS_CI
96
+ MERGE_TIMEOUT
97
+ MIN_COVERAGE_BRANCH
98
+ MIN_COVERAGE_LINE
99
+ MIN_COVERAGE_HARD
100
+ MULTI_FORMATTERS_DEFAULT
101
+ MULTI_FORMATTERS
102
+ OPEN_BIN
103
+ PREFIX
104
+ TRUE
105
+ USE_MERGING
106
+ VERBOSE
107
+ ],
108
+ path: "kettle/soup/cover/constants.rb",
109
+ )
110
+ end
111
+ end
112
+ end
113
+ end
File without changes
File without changes
@@ -0,0 +1,36 @@
1
+ module Kettle
2
+ module Soup
3
+ module Cover
4
+ module Loaders
5
+ extend self
6
+
7
+ def load_formatters
8
+ SimpleCov.formatters = Kettle::Soup::Cover::Constants::FORMATTERS
9
+ .each_with_object([]) do |fmt_data, formatters|
10
+ require fmt_data[:lib].to_s
11
+
12
+ klass = SimpleCov::Formatter.const_get(fmt_data[:klass])
13
+
14
+ if fmt_data[:type] == :lcov
15
+ klass.config do |c|
16
+ c.report_with_single_file = true
17
+ c.single_report_path = "#{Kettle::Soup::Cover::Constants::COVERAGE_DIR}/lcov.info"
18
+ end
19
+ end
20
+
21
+ formatters << klass
22
+ end
23
+ end
24
+
25
+ def load_filters
26
+ require "kettle/soup/cover/filters/gt_line_filter"
27
+ require "kettle/soup/cover/filters/lt_line_filter"
28
+ end
29
+
30
+ def install_tasks
31
+ load("kettle/soup/cover/tasks.rb")
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -5,9 +5,27 @@ task :coverage do
5
5
  ENV["K_SOUP_COV_PREFIX"] = "K_SOUP_COV_"
6
6
  ENV["K_SOUP_COV_DO"] = "true"
7
7
  ENV["K_SOUP_COV_MULTI_FORMATTERS"] = "true"
8
- ENV["K_SOUP_COV_FORMATTERS"] = "html"
8
+ ENV["K_SOUP_COV_FORMATTERS"] ||= "html"
9
9
  ENV["K_SOUP_COV_DIR"] ||= "coverage"
10
10
  end
11
11
  Rake::Task["test"].invoke
12
- %x(open #{Kettle::Soup::Cover::COVERAGE_DIR}/index.html)
12
+ html_report = "#{Kettle::Soup::Cover::COVERAGE_DIR}/index.html"
13
+ if Kettle::Soup::Cover::OPEN_BIN.empty?
14
+ puts "Kettle::Soup::Cover::OPEN_BIN not configured. Coverage report is at #{html_report}"
15
+ else
16
+ begin
17
+ %x(#{Kettle::Soup::Cover::OPEN_BIN} #{html_report})
18
+ rescue Errno::ENOENT => error
19
+ message = error.message || ""
20
+ # `open` command is macOS only. xdg-open is a decent alternative on many Linux systems.
21
+ if message.include?("No such file or directory - #{Kettle::Soup::Cover::OPEN_BIN}")
22
+ puts "Configured Kettle::Soup::Cover::OPEN_BIN (#{Kettle::Soup::Cover::OPEN_BIN}) not available. Coverage report is at #{html_report}"
23
+ elsif message.include?("No such file or directory")
24
+ puts "No coverage report found at #{html_report}"
25
+ puts message
26
+ else
27
+ raise error
28
+ end
29
+ end
30
+ end
13
31
  end
File without changes
@@ -4,7 +4,7 @@ module Kettle
4
4
  module Soup
5
5
  module Cover
6
6
  module Version
7
- VERSION = "1.0.4"
7
+ VERSION = "1.0.6"
8
8
  end
9
9
  end
10
10
  end
@@ -14,156 +14,40 @@
14
14
  # SimpleCov.start
15
15
  #
16
16
 
17
+ # Standard Lib
18
+ require "rbconfig"
19
+
20
+ # External gems
21
+ require "version_gem"
22
+
23
+ # This gem
24
+ require_relative "../change"
25
+ require_relative "cover/version"
26
+ require_relative "cover/constants"
27
+ require_relative "cover/loaders"
28
+
17
29
  module Kettle
18
30
  module Soup
19
31
  module Cover
20
32
  class Error < StandardError; end
21
33
 
22
- CONSTANTS = %w[
23
- CI
24
- COMMAND_NAME
25
- COVERAGE_DIR
26
- DEBUG
27
- DO_COV
28
- ENV_GET
29
- FALSE
30
- FILTER_DIRS
31
- FORMATTER_PLUGINS
32
- FORMATTERS
33
- IS_CI
34
- MERGE_TIMEOUT
35
- MIN_COVERAGE_BRANCH
36
- MIN_COVERAGE_LINE
37
- MIN_COVERAGE_HARD
38
- MULTI_FORMATTERS_DEFAULT
39
- MULTI_FORMATTERS
40
- PREFIX
41
- TRUE
42
- USE_MERGING
43
- VERBOSE
44
- ]
45
- FALSE = "false"
46
- TRUE = "true"
47
- PREFIX = ENV.fetch("K_SOUP_COV_PREFIX", "K_SOUP_COV_")
48
- ENV_GET = ->(suffix, default) { ENV.fetch("#{PREFIX}#{suffix}", default) }
49
- FORMATTER_PLUGINS = {
50
- # HTML for Humans
51
- html: {
52
- type: :html,
53
- klass: "HTMLFormatter",
54
- lib: "simplecov-html",
55
- },
56
- # XML for Jenkins
57
- xml: {
58
- type: :xml,
59
- klass: "CoberturaFormatter",
60
- lib: "simplecov-cobertura",
61
- },
62
- # RCOV for Hudson
63
- rcov: {
64
- type: :rcov,
65
- klass: "RcovFormatter",
66
- lib: "simplecov-rcov",
67
- },
68
- # LCOV for GCOV
69
- lcov: {
70
- type: :lcov,
71
- klass: "LcovFormatter",
72
- lib: "simplecov-lcov",
73
- },
74
- # JSON for CodeClimate
75
- json: {
76
- type: :json,
77
- klass: "JSONFormatter",
78
- lib: "simplecov_json_formatter",
79
- },
80
- # TTY / Console output
81
- tty: {
82
- type: :tty,
83
- klass: "Console",
84
- lib: "simplecov-console",
85
- },
86
- }
87
-
88
- CI = ENV.fetch("CI", FALSE)
89
- IS_CI = CI.casecmp?(TRUE)
90
- COMMAND_NAME = ENV_GET.call("COMMAND_NAME", "RSpec (COVERAGE)")
91
- COVERAGE_DIR = ENV_GET.call("DIR", "coverage")
92
- DEBUG = ENV_GET.call("DEBUG", FALSE).casecmp?(TRUE)
93
- DO_COV = ENV_GET.call("DO", CI).casecmp?(TRUE)
94
- FILTER_DIRS = ENV_GET.call(
95
- "FILTER_DIRS",
96
- "bin,certs,checksums,config,coverage,docs,features,gemfiles,pkg,results,sig,spec,src,test,test-results,vendor",
97
- )
98
- .split(",")
99
- .map { |dir_name| %r{^/#{Regexp.escape(dir_name)}/} }
100
- FORMATTERS = ENV_GET.call(
101
- "FORMATTERS",
102
- IS_CI ? "html,xml,rcov,lcov,json,tty" : "html,tty",
103
- )
104
- .split(",")
105
- .map { |fmt_name| FORMATTER_PLUGINS[fmt_name.to_sym] }
106
- MIN_COVERAGE_HARD = ENV_GET.call("MIN_HARD", CI).casecmp?(TRUE)
107
- MIN_COVERAGE_BRANCH = ENV_GET.call("MIN_BRANCH", "80").to_i
108
- MIN_COVERAGE_LINE = ENV_GET.call("MIN_LINE", "80").to_i
109
- MULTI_FORMATTERS_DEFAULT = if IS_CI
110
- CI
111
- else
112
- FORMATTERS.any? ? TRUE : FALSE
113
- end
114
- MULTI_FORMATTERS = ENV_GET.call("MULTI_FORMATTERS", MULTI_FORMATTERS_DEFAULT).casecmp?(TRUE)
115
- USE_MERGING = ENV_GET.call("USE_MERGING", nil)&.casecmp?(TRUE)
116
- MERGE_TIMEOUT = ENV_GET.call("MERGE_TIMEOUT", nil)&.to_i
117
- VERBOSE = ENV_GET.call("VERBOSE", FALSE).casecmp?(TRUE)
34
+ # Provide a public API for constants that is a bit less namespaced
35
+ include Constants
36
+ extend Loaders
118
37
 
119
38
  module_function
120
39
 
121
- def load_formatters
122
- SimpleCov.formatters = FORMATTERS
123
- .each_with_object([]) do |fmt_data, formatters|
124
- require fmt_data[:lib].to_s
125
-
126
- klass = SimpleCov::Formatter.const_get(fmt_data[:klass])
127
-
128
- if fmt_data[:type] == :lcov
129
- klass.config do |c|
130
- c.report_with_single_file = true
131
- c.single_report_path = "#{Kettle::Soup::Cover::COVERAGE_DIR}/lcov.info"
132
- end
133
- end
134
-
135
- formatters << klass
136
- end
40
+ def reset_const(&block)
41
+ Constants.reset_const(&block)
137
42
  end
138
43
 
139
- def load_filters
140
- require "kettle/soup/cover/filters/gt_line_filter"
141
- require "kettle/soup/cover/filters/lt_line_filter"
142
- end
143
-
144
- def install_tasks
145
- load("kettle/soup/cover/tasks.rb")
146
- end
147
-
148
- # Const manipulation is to help with testing this gem
149
- def reset_const(&_)
150
- delete_const do
151
- yield if block_given?
152
- # Loading myself... Woah.
153
- load("kettle/soup/cover.rb")
154
- end
155
- end
156
-
157
- # Const manipulation is to help with testing this gem
158
- def delete_const(&_)
159
- CONSTANTS.each do |var|
160
- remove_const(var)
161
- end
162
- remove_const(:CONSTANTS)
163
- yield if block_given?
164
-
165
- nil
44
+ def delete_const(&block)
45
+ Constants.delete_const(&block)
166
46
  end
167
47
  end
168
48
  end
169
49
  end
50
+
51
+ Kettle::Soup::Cover::Version.class_eval do
52
+ extend VersionGem::Basic
53
+ end
@@ -1,4 +1,4 @@
1
- # USAGE:
1
+ # rubocop:disable Naming/FileName# USAGE:
2
2
  # In your `spec/spec_helper.rb`,
3
3
  # just prior to loading the library under test:
4
4
  #
@@ -10,13 +10,8 @@
10
10
  # SimpleCov.start
11
11
  #
12
12
 
13
- # External gems
14
- require "version_gem"
15
-
16
- require_relative "kettle/soup/cover/version"
17
-
13
+ # For technical reasons, if we move to Zeitwerk, this cannot be require_relative.
14
+ # See: https://github.com/fxn/zeitwerk#for_gem_extension
15
+ # Hook for other libraries to load this library (e.g. via bundler)
18
16
  require "kettle/soup/cover"
19
-
20
- Kettle::Soup::Cover::Version.class_eval do
21
- extend VersionGem::Basic
22
- end
17
+ # rubocop:enable Naming/FileName
File without changes
@@ -4,7 +4,6 @@ module Kettle
4
4
  module Cover
5
5
  CI: String
6
6
  COMMAND_NAME: String
7
- CONSTANTS: Array[String]
8
7
  COVERAGE_DIR: String
9
8
  DEBUG: bool
10
9
  DO_COV: bool
@@ -22,6 +21,7 @@ module Kettle
22
21
  MULTI_FORMATTERS_DEFAULT: String
23
22
  PREFIX: String
24
23
  TRUE: String
24
+ OPEN_BIN: String
25
25
  USE_MERGING: bool?
26
26
  VERBOSE: bool
27
27
  VERSION: String
data.tar.gz.sig CHANGED
Binary file