minitest-cc 0.1.0 → 0.2.0
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 +4 -4
- data/lib/minitest/cc/file_coverage.rb +71 -8
- data/lib/minitest/cc/reporter.rb +3 -10
- data/lib/minitest/cc/version.rb +1 -1
- data/lib/minitest/cc.rb +64 -15
- data/lib/minitest/cc_plugin.rb +1 -7
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f0eeacbc8612187f1e09acf48af6bbe01dc408ae645fc34baff37d469791f93
|
4
|
+
data.tar.gz: 0b8dc1f33f412392782265b63919b305d1d5f9154327242d627769225aff3d42
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5807504cf8912e3253123e166fd961cbdceb403d9e4cf7ddaf3a03620b2355070358ddf678b7d75fc8fba676ea5fa8d6072daf7cea3c91127ab7f1c4467477cb
|
7
|
+
data.tar.gz: 5e825e40992f750669825a5d823f5fcc68ceec3aa420c4d37b813c9b45f6b16062f80eb7e1e5c741785bfc5094cddcc7cd57a4f2e86c3ca50fb09e2331435bec
|
@@ -4,26 +4,55 @@ module Minitest
|
|
4
4
|
module Cc
|
5
5
|
# model for a file
|
6
6
|
class FileCoverage
|
7
|
+
#
|
7
8
|
# @return [String] the name of the file with extension
|
9
|
+
#
|
8
10
|
attr_accessor :name
|
11
|
+
|
12
|
+
#
|
9
13
|
# @return [String] the absolute path to the file
|
14
|
+
#
|
10
15
|
attr_accessor :path
|
16
|
+
|
17
|
+
#
|
11
18
|
# @return [String] the relative path to the file
|
19
|
+
#
|
12
20
|
attr_accessor :relative_path
|
21
|
+
|
22
|
+
#
|
13
23
|
# @return [Boolean] if this was tested or not.
|
14
24
|
# this indicate if the file was tracked by coverage or not
|
25
|
+
#
|
15
26
|
attr_accessor :tested
|
27
|
+
|
28
|
+
#
|
16
29
|
# @return [Integer] total lines of the file
|
30
|
+
#
|
17
31
|
attr_accessor :lines
|
32
|
+
|
33
|
+
#
|
18
34
|
# @return [Integer] total lines executed of the file
|
35
|
+
#
|
19
36
|
attr_accessor :lines_executed
|
37
|
+
|
38
|
+
#
|
20
39
|
# @return [Integer] total branches of the file
|
40
|
+
#
|
21
41
|
attr_accessor :branches
|
42
|
+
|
43
|
+
#
|
22
44
|
# @return [Integer] total branches executed of the file
|
45
|
+
#
|
23
46
|
attr_accessor :branches_executed
|
47
|
+
|
48
|
+
#
|
24
49
|
# @return [Integer] total methods of the file
|
50
|
+
#
|
25
51
|
attr_accessor :methods
|
52
|
+
|
53
|
+
#
|
26
54
|
# @return [Integer] total methods executed of the file
|
55
|
+
#
|
27
56
|
attr_accessor :methods_executed
|
28
57
|
|
29
58
|
##
|
@@ -31,6 +60,7 @@ module Minitest
|
|
31
60
|
# @param path [String] full path to the file
|
32
61
|
# @param relative_path [String] relative path to the file
|
33
62
|
# @param result [Hash] object with the result of the coverage for the file
|
63
|
+
#
|
34
64
|
def initialize(path, relative_path, result = nil)
|
35
65
|
@path = path
|
36
66
|
@relative_path = relative_path
|
@@ -42,6 +72,7 @@ module Minitest
|
|
42
72
|
##
|
43
73
|
# Set the results of the coverage into the object variables
|
44
74
|
# @param result [Hash] object with the result of the coverage
|
75
|
+
#
|
45
76
|
def from_result(result)
|
46
77
|
@lines, @lines_executed = count_lines(result) unless result[:lines].nil?
|
47
78
|
@branches, @branches_executed = count_branches(result) unless result[:branches].nil?
|
@@ -52,6 +83,7 @@ module Minitest
|
|
52
83
|
# count total lines and executed lines
|
53
84
|
# @param result [Hash] object with the result of the coverage
|
54
85
|
# @return [Array] Array with two values: First: the total lines. Second: the lines executed
|
86
|
+
#
|
55
87
|
def count_lines(result)
|
56
88
|
[result[:lines].count { |n| n.is_a? Integer }, result[:lines].count { |n| n.is_a?(Integer) && n != 0 }]
|
57
89
|
end
|
@@ -60,6 +92,7 @@ module Minitest
|
|
60
92
|
# count total branches and executed branches
|
61
93
|
# @param result [Hash] object with the result of the coverage
|
62
94
|
# @return [Array] Array with two values: First: the total branches. Second: the branches executed
|
95
|
+
#
|
63
96
|
def count_branches(result)
|
64
97
|
[
|
65
98
|
result[:branches].values.reduce(0) { |sum, v| sum + v.size },
|
@@ -71,6 +104,7 @@ module Minitest
|
|
71
104
|
# count total methods and executed methods
|
72
105
|
# @param result [Hash] object with the result of the coverage
|
73
106
|
# @return [Array] Array with two values: First: the total methods. Second: the methods executed
|
107
|
+
#
|
74
108
|
def count_methods(result)
|
75
109
|
[result[:methods].length, result[:methods].values.reject(&:zero?).count]
|
76
110
|
end
|
@@ -78,20 +112,47 @@ module Minitest
|
|
78
112
|
##
|
79
113
|
# Transform the object to a readable string
|
80
114
|
# @return [String] contains the information ready to print
|
115
|
+
#
|
81
116
|
def to_s
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
117
|
+
return "#{relative_path} : Not executed or tracked by cov." unless tested
|
118
|
+
|
119
|
+
"#{relative_path}:\n" + to_s_lines + to_s_branches + to_s_methods
|
120
|
+
end
|
121
|
+
|
122
|
+
##
|
123
|
+
# Transform lines information to string
|
124
|
+
# @return [String] contains information of lines with percent in color
|
125
|
+
#
|
126
|
+
def to_s_lines
|
127
|
+
return '' unless lines
|
128
|
+
|
129
|
+
" - l: #{lines_executed}/#{lines} #{lines_percent.to_s_color}%"
|
130
|
+
end
|
131
|
+
|
132
|
+
##
|
133
|
+
# Transform branches information to string
|
134
|
+
# @return [String] contains information of branches with percent in color
|
135
|
+
#
|
136
|
+
def to_s_branches
|
137
|
+
return '' unless branches
|
138
|
+
|
139
|
+
" - b: #{branches_executed}/#{branches} #{branches_percent.to_s_color}%"
|
140
|
+
end
|
141
|
+
|
142
|
+
##
|
143
|
+
# Transform methods information to string
|
144
|
+
# @return [String] contains information of methods with percent in color
|
145
|
+
#
|
146
|
+
def to_s_methods
|
147
|
+
return '' unless methods
|
148
|
+
|
149
|
+
" - m: #{methods_executed}/#{methods} #{methods_percent.to_s_color}%"
|
90
150
|
end
|
91
151
|
|
92
152
|
##
|
93
153
|
# Calculate the percent of coverage lines
|
94
154
|
# @return [Integer] percent of coverage. executed lines / total lines
|
155
|
+
#
|
95
156
|
def lines_percent
|
96
157
|
lines_executed * 100 / lines
|
97
158
|
rescue ZeroDivisionError
|
@@ -101,6 +162,7 @@ module Minitest
|
|
101
162
|
##
|
102
163
|
# Calculate the percent of coverage branches
|
103
164
|
# @return [Integer] percent of coverage. executed branches / total branches
|
165
|
+
#
|
104
166
|
def branches_percent
|
105
167
|
branches_executed * 100 / branches
|
106
168
|
rescue ZeroDivisionError
|
@@ -110,6 +172,7 @@ module Minitest
|
|
110
172
|
##
|
111
173
|
# Calculate the percent of coverage methods
|
112
174
|
# @return [Integer] percent of coverage. executed methods / total methods
|
175
|
+
#
|
113
176
|
def methods_percent
|
114
177
|
methods_executed * 100 / methods
|
115
178
|
rescue ZeroDivisionError
|
data/lib/minitest/cc/reporter.rb
CHANGED
@@ -1,23 +1,16 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'minitest'
|
4
|
-
|
5
3
|
module Minitest
|
6
4
|
module Cc
|
7
5
|
# Reporter class extend of Minitest Reporter
|
8
|
-
# this get 5 important methods from the parent
|
9
|
-
# but we use only 2
|
10
6
|
class Reporter < Minitest::AbstractReporter
|
11
|
-
##
|
12
|
-
# Executed in the beginin of the minitest run
|
13
|
-
def start
|
14
|
-
Cc.start_coverage
|
15
|
-
end
|
16
|
-
|
17
7
|
##
|
18
8
|
# Executed in the final of the minitest run
|
19
9
|
def report
|
10
|
+
Cc.peek_result
|
20
11
|
Cc.summary
|
12
|
+
rescue StandardError => e
|
13
|
+
puts "\n\n[!] cc extension has problem for generate the report: #{e}"
|
21
14
|
end
|
22
15
|
end
|
23
16
|
end
|
data/lib/minitest/cc/version.rb
CHANGED
data/lib/minitest/cc.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'coverage'
|
4
|
+
require 'minitest'
|
5
|
+
|
3
6
|
require_relative 'cc/version'
|
4
7
|
require_relative 'cc/reporter'
|
5
8
|
require_relative 'cc/file_coverage'
|
@@ -9,6 +12,8 @@ module Minitest
|
|
9
12
|
# Main module of the plugin
|
10
13
|
# @author Andres
|
11
14
|
module Cc
|
15
|
+
MODES = %i[lines branches methods].freeze
|
16
|
+
|
12
17
|
@results = []
|
13
18
|
@files = FileArray.new
|
14
19
|
|
@@ -30,35 +35,46 @@ module Minitest
|
|
30
35
|
# @return [Array] mode of the coverage, this array could contain:
|
31
36
|
# :lines, :branches, :methods
|
32
37
|
cattr_accessor :coverage_mode
|
33
|
-
self.coverage_mode =
|
34
|
-
lines
|
35
|
-
branches
|
36
|
-
methods
|
37
|
-
]
|
38
|
+
self.coverage_mode = MODES
|
38
39
|
|
39
40
|
class << self
|
40
41
|
##
|
41
42
|
# Start the coverage process
|
42
43
|
# @see https://runebook.dev/en/docs/ruby/coverage Coverage blog post explaining the use
|
43
44
|
# @see https://ruby-doc.org/stdlib-2.7.6/libdoc/coverage/rdoc/Coverage.html Documentation of the module
|
45
|
+
# @deprecated Use {#self.start(*args)} instead.
|
44
46
|
def start_coverage
|
45
|
-
Coverage.start(coverage_mode.collect { |m| [m, true] }.to_h)
|
47
|
+
Coverage.start(@coverage_mode.collect { |m| [m, true] }.to_h)
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# start coverage process
|
52
|
+
# this method recive the arguments direct and not depend on set coverage mode before start
|
53
|
+
# @see https://runebook.dev/en/docs/ruby/coverage Coverage blog post explaining the use
|
54
|
+
# @see https://ruby-doc.org/stdlib-2.7.6/libdoc/coverage/rdoc/Coverage.html Documentation of the module
|
55
|
+
#
|
56
|
+
def start(*args)
|
57
|
+
@coverage_mode = args.collect(&:to_sym).select { |a| MODES.include? a } unless args.empty?
|
58
|
+
Coverage.start(@coverage_mode.collect { |m| [m, true] }.to_h)
|
46
59
|
end
|
47
60
|
|
48
61
|
##
|
49
|
-
# Print
|
62
|
+
# Print results after the runs
|
63
|
+
#
|
50
64
|
def summary
|
51
|
-
@results = Coverage.peek_result
|
52
|
-
list_files
|
53
65
|
puts "\n\n# Coverage:\n\n"
|
54
|
-
|
55
|
-
|
56
|
-
|
66
|
+
case cc_mode
|
67
|
+
when :per_file
|
68
|
+
@files.each { |f| puts f.to_s }
|
69
|
+
else
|
70
|
+
puts resume
|
71
|
+
end
|
57
72
|
end
|
58
73
|
|
59
74
|
##
|
60
75
|
# This method populate the FileArray variable with results
|
61
|
-
def
|
76
|
+
def peek_result
|
77
|
+
@results = Coverage.result
|
62
78
|
Dir.glob(tracked_files.each { |f| File.expand_path(f) }).each do |d|
|
63
79
|
full_path = File.expand_path(d)
|
64
80
|
@files << FileCoverage.new(full_path, d, result_for_file(full_path))
|
@@ -77,11 +93,44 @@ module Minitest
|
|
77
93
|
end
|
78
94
|
|
79
95
|
##
|
80
|
-
# compose the string with resume of
|
96
|
+
# compose the string with resume of cc
|
81
97
|
# @return [String] String with averages
|
82
98
|
def resume
|
83
|
-
|
99
|
+
str = ''
|
100
|
+
str += "lines: #{@files.lines_average.to_s_color}%\t" if coverage_mode.include? :lines
|
101
|
+
str += "branches: #{@files.branches_average.to_s_color}%\t" if coverage_mode.include? :branches
|
102
|
+
str += "methods: #{@files.methods_average.to_s_color}%\t" if coverage_mode.include? :methods
|
103
|
+
str
|
84
104
|
end
|
85
105
|
end
|
86
106
|
end
|
87
107
|
end
|
108
|
+
|
109
|
+
class String # :nodoc:
|
110
|
+
def red
|
111
|
+
"\e[31m#{self}\e[0m"
|
112
|
+
end
|
113
|
+
|
114
|
+
def green
|
115
|
+
"\e[32m#{self}\e[0m"
|
116
|
+
end
|
117
|
+
|
118
|
+
def yellow
|
119
|
+
"\e[33m#{self}\e[0m"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
class Integer # :nodoc:
|
124
|
+
def to_s_color
|
125
|
+
case self
|
126
|
+
when 1..33
|
127
|
+
to_s.red
|
128
|
+
when 34..66
|
129
|
+
to_s.yellow
|
130
|
+
when 67..100
|
131
|
+
to_s.green
|
132
|
+
else
|
133
|
+
to_s
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
data/lib/minitest/cc_plugin.rb
CHANGED
@@ -1,17 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'coverage'
|
4
|
-
require 'minitest'
|
5
3
|
require 'minitest/cc'
|
6
4
|
|
7
5
|
# Minitest module
|
8
6
|
module Minitest
|
9
7
|
# Init method called from minitest
|
10
|
-
# it start the plugin
|
11
8
|
def self.plugin_cc_init(_options)
|
12
|
-
|
13
|
-
reporter << Minitest::Cc::Reporter.new
|
14
|
-
rescue StandardError
|
15
|
-
puts 'The coverage plugin cannot be initialized.'
|
9
|
+
reporter << Minitest::Cc::Reporter.new if Coverage.running?
|
16
10
|
end
|
17
11
|
end
|
metadata
CHANGED
@@ -1,17 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: minitest-cc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- a-chacon
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: 'Plugin for minitest
|
14
|
-
to your test output. '
|
13
|
+
description: 'Plugin for minitest. It provides minimal information about code coverage. '
|
15
14
|
email:
|
16
15
|
- andres.ch@protonmail.com
|
17
16
|
executables: []
|
@@ -41,14 +40,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
40
|
requirements:
|
42
41
|
- - ">="
|
43
42
|
- !ruby/object:Gem::Version
|
44
|
-
version: 2.5.
|
43
|
+
version: 2.5.0
|
45
44
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
46
45
|
requirements:
|
47
46
|
- - ">="
|
48
47
|
- !ruby/object:Gem::Version
|
49
48
|
version: '0'
|
50
49
|
requirements: []
|
51
|
-
rubygems_version: 3.2.
|
50
|
+
rubygems_version: 3.2.33
|
52
51
|
signing_key:
|
53
52
|
specification_version: 4
|
54
53
|
summary: Minitest plugin, add code coverage metrics.
|