minitest-cc 0.1.0 → 0.1.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
2
  SHA256:
3
- metadata.gz: 69641587074cb1ab7a76d64441ca7adc6d712c29a4464c26ea1479b84249b07f
4
- data.tar.gz: 87bdd0b9a441e27e1f3d027f45bd24c36e615987190aa96a76a28c27fec06214
3
+ metadata.gz: 1c5311d840ff9b9c308e93bc13eecf90f09fe2197dd93435ceb16834cbf8b71f
4
+ data.tar.gz: 72be9edd178c3a6993a2102af5fe8f81ec304db9e418e2dfbc2c0de8a7eeaca4
5
5
  SHA512:
6
- metadata.gz: f645fa0afe130223c8bc8dbfb15cd55e2b35b6f50e69c5acf59304ebcc3d6db9d2905bcf6c0173593ee906ccb5fcaa15e184c377d20cc968d644806d4a36f320
7
- data.tar.gz: 41c92382fb9de187dfbcf40dcc37d7151ca81ff97ceff1c8afa21426f4700f1d0942e5c4d82712818743d6ff4f2301742edcc17ba7366d1d0758673cf1d573e5
6
+ metadata.gz: 01236f238a8f18ae1ab175af50a5817ab56249d0e8283ef1c3cb3b06be584231bd468fdfb2dbc3d44b8eeae54dc611d98a7a8944dd2357a6e0846cf5a65df16f
7
+ data.tar.gz: 9d721a79a0e163f1467a8e1c11b0fa1abecb5e28c7261f9309553b61bf8b00198d65e16c6b7af396b98ef72b7898910c848860c470cbb9bf9a6e3f5b7d9f0f28
@@ -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
@@ -3,6 +3,6 @@
3
3
  module Minitest
4
4
  module Cc
5
5
  # plugin version
6
- VERSION = '0.1.0'
6
+ VERSION = '0.1.1'
7
7
  end
8
8
  end
data/lib/minitest/cc.rb CHANGED
@@ -80,8 +80,41 @@ module Minitest
80
80
  # compose the string with resume of averages
81
81
  # @return [String] String with averages
82
82
  def resume
83
- "lines: #{@files.lines_average}% branches: #{@files.branches_average}% methods: #{@files.methods_average}%"
83
+ str = ''
84
+ str += "lines: #{@files.lines_average.to_s_color}%\t" if coverage_mode.include? :lines
85
+ str += "branches: #{@files.branches_average.to_s_color}%\t" if coverage_mode.include? :branches
86
+ str += "methods: #{@files.methods_average.to_s_color}%\t" if coverage_mode.include? :methods
87
+ str
84
88
  end
85
89
  end
86
90
  end
87
91
  end
92
+
93
+ class String # :nodoc:
94
+ def red
95
+ "\e[31m#{self}\e[0m"
96
+ end
97
+
98
+ def green
99
+ "\e[32m#{self}\e[0m"
100
+ end
101
+
102
+ def yellow
103
+ "\e[33m#{self}\e[0m"
104
+ end
105
+ end
106
+
107
+ class Integer # :nodoc:
108
+ def to_s_color
109
+ case self
110
+ when 1..33
111
+ to_s.red
112
+ when 34..66
113
+ to_s.yellow
114
+ when 67..100
115
+ to_s.green
116
+ else
117
+ to_s
118
+ end
119
+ end
120
+ end
@@ -11,7 +11,5 @@ module Minitest
11
11
  def self.plugin_cc_init(_options)
12
12
  # insert ower reporter to minitest reporters
13
13
  reporter << Minitest::Cc::Reporter.new
14
- rescue StandardError
15
- puts 'The coverage plugin cannot be initialized.'
16
14
  end
17
15
  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
4
+ version: 0.1.1
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-06-30 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. '