minitest-cc 0.1.0.beta → 0.1.2

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
2
  SHA256:
3
- metadata.gz: 9b4e3b7affdd0bac184df62e862738f07e4fd11b5d688a73fa6215dd9d7ec287
4
- data.tar.gz: 99fd07e500ec5fb9ad6e3b7887c1189046ff83bbcb4785af1630d7952bc48c9c
3
+ metadata.gz: 848f6762978bb5db1d4bfb03e13ff466a9fc7111ee1525f5825a558863b026ae
4
+ data.tar.gz: fa59d3d0887831482fb6ea9ce737f841bd326d42808d3c3b89556f914657ba8d
5
5
  SHA512:
6
- metadata.gz: aec3e0e03446768f11a22f0abebf255d1e05d2a134e8e2a627d2afae726852a2eb0fa74715ab6a5457c6b9e555d9a98b08777e783bee92a1874517f1a67dd4fd
7
- data.tar.gz: 695f37256eef625dddf8a97d51aa32294c4c7352a07ef2c1855aee4a07409f024dfa380ecad493e81688bbbde2071ea76962f1edf9300e20dd325833996be1f6
6
+ metadata.gz: ff8cc42c16e7b0baad675f64f275a3435b8f990d43dff8ccca0288888625c3480b4e20584a2dcbb58f231c996ecefcd98609431a00eeaafdeba863afab8c9b96
7
+ data.tar.gz: 469ca5c033d2f4075207cd070758592b2d43248bf212eb0cd395b824b30c67b1a994a13f02d7e0078fb7e4ff12416c9ac8bcb87c1b98231fd37cbb102e844f66
@@ -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
- if tested
83
- str = "#{relative_path}: \n lines: #{lines_executed}/#{lines} #{lines_percent}%"
84
- str += "\tbranches: #{branches_executed}/#{branches} #{branches_percent}%" if branches
85
- str += "\tmethods: #{methods_executed}/#{methods} #{methods_percent}%" if methods
86
- str
87
- else
88
- "#{relative_path} : Not executed during the tests."
89
- end
117
+ return "#{relative_path} : Not executed during the tests." 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
+ "\tlines: #{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
+ "\tbranches: #{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
+ "\tmethods: #{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
@@ -1,19 +1,9 @@
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
@@ -3,6 +3,6 @@
3
3
  module Minitest
4
4
  module Cc
5
5
  # plugin version
6
- VERSION = '0.1.0.beta'
6
+ VERSION = '0.1.2'
7
7
  end
8
8
  end
data/lib/minitest/cc.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'minitest'
4
+
3
5
  require_relative 'cc/version'
4
6
  require_relative 'cc/reporter'
5
7
  require_relative 'cc/file_coverage'
@@ -42,6 +44,7 @@ module Minitest
42
44
  # @see https://runebook.dev/en/docs/ruby/coverage Coverage blog post explaining the use
43
45
  # @see https://ruby-doc.org/stdlib-2.7.6/libdoc/coverage/rdoc/Coverage.html Documentation of the module
44
46
  def start_coverage
47
+ require 'coverage'
45
48
  Coverage.start(coverage_mode.collect { |m| [m, true] }.to_h)
46
49
  end
47
50
 
@@ -54,6 +57,8 @@ module Minitest
54
57
  @files.each { |f| puts f.to_s } if cc_mode == :per_file
55
58
  puts resume if cc_mode == :resume
56
59
  puts
60
+ rescue NameError
61
+ puts "\n\n[!] cc extension is installed but was not started."
57
62
  end
58
63
 
59
64
  ##
@@ -80,8 +85,41 @@ module Minitest
80
85
  # compose the string with resume of averages
81
86
  # @return [String] String with averages
82
87
  def resume
83
- "lines: #{@files.lines_average}% branches: #{@files.branches_average}% methods: #{@files.methods_average}%"
88
+ str = ''
89
+ str += "lines: #{@files.lines_average.to_s_color}%\t" if coverage_mode.include? :lines
90
+ str += "branches: #{@files.branches_average.to_s_color}%\t" if coverage_mode.include? :branches
91
+ str += "methods: #{@files.methods_average.to_s_color}%\t" if coverage_mode.include? :methods
92
+ str
84
93
  end
85
94
  end
86
95
  end
87
96
  end
97
+
98
+ class String # :nodoc:
99
+ def red
100
+ "\e[31m#{self}\e[0m"
101
+ end
102
+
103
+ def green
104
+ "\e[32m#{self}\e[0m"
105
+ end
106
+
107
+ def yellow
108
+ "\e[33m#{self}\e[0m"
109
+ end
110
+ end
111
+
112
+ class Integer # :nodoc:
113
+ def to_s_color
114
+ case self
115
+ when 1..33
116
+ to_s.red
117
+ when 34..66
118
+ to_s.yellow
119
+ when 67..100
120
+ to_s.green
121
+ else
122
+ to_s
123
+ end
124
+ end
125
+ end
@@ -1,7 +1,5 @@
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
@@ -11,7 +9,5 @@ module Minitest
11
9
  def self.plugin_cc_init(_options)
12
10
  # insert ower reporter to minitest reporters
13
11
  reporter << Minitest::Cc::Reporter.new
14
- rescue StandardError
15
- puts 'The coverage plugin cannot be initialized.'
16
12
  end
17
13
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-cc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0.beta
4
+ version: 0.1.2
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-06-29 00:00:00.000000000 Z
11
+ date: 2022-07-01 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'Plugin for minitest, provide a minimal information of code coverage
14
14
  to your test output. '
@@ -44,9 +44,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
44
44
  version: 2.5.3
45
45
  required_rubygems_version: !ruby/object:Gem::Requirement
46
46
  requirements:
47
- - - ">"
47
+ - - ">="
48
48
  - !ruby/object:Gem::Version
49
- version: 1.3.1
49
+ version: '0'
50
50
  requirements: []
51
51
  rubygems_version: 3.2.22
52
52
  signing_key: