simplecov-markdown 1.0.0 → 1.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ee812d070b98156101ee6b0186a3b6a11ae67325a3f593894fdf9036b702ac0
4
- data.tar.gz: 65aa27e39c12f6916b4a3144eeab39bad45a4903d1273b3321c79a4a0700652f
3
+ metadata.gz: f38d023d1882b61f76b7896c5afeaafe8136a61d19431cd6b30714e4908f4d04
4
+ data.tar.gz: f4f797601b506642c93f04d8ef541a2dfc7bf4b4dea5b5a890aa3d6549081638
5
5
  SHA512:
6
- metadata.gz: 1a026ad0b6128b40e366928d33961dab0a068ab9d0f2c1f15cac7c304c38263a898aa8a97d4ace3abdb8414d7d7d192dfc9f80ed446793641d04a331c72c4491
7
- data.tar.gz: 93fbdfd1da279271c15bae0bff46b45a8dbf35884640a91a55324c5be838642b0621c7502a834e6ed1071297dcd965710d5db10fcdf9155705576132bc4ab31e
6
+ metadata.gz: f1d2bbf9c36651b81b7c22e121c5e727836a0215ffff4a3831803757e456746b89ec71f016db5c15c9cc122130b670cd34efb3a3892b61e7c6f052690bb052ee
7
+ data.tar.gz: 4da7f098aae3329e934d12a21b16e30c76b16a5a145132d1d03f445b1a5273669adef416e0b3f0250644a94e0012df9cf2bb78f5362d70aa357d7e345fe9ebe6
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simplecov-markdown (1.0.0)
4
+ simplecov-markdown (1.1.0)
5
5
  simplecov
6
6
 
7
7
  GEM
@@ -64,7 +64,7 @@ CHECKSUMS
64
64
  simplecov (0.22.0) sha256=fe2622c7834ff23b98066bb0a854284b2729a569ac659f82621fc22ef36213a5
65
65
  simplecov-console (0.9.5) sha256=b1108bcfff5f210143e2b8301698c367b01586f20d25a73e95475a5df6fc6ff6
66
66
  simplecov-html (0.13.2) sha256=bd0b8e54e7c2d7685927e8d6286466359b6f16b18cb0df47b508e8d73c777246
67
- simplecov-markdown (1.0.0)
67
+ simplecov-markdown (1.1.0)
68
68
  simplecov_json_formatter (0.1.4) sha256=529418fbe8de1713ac2b2d612aa3daa56d316975d307244399fa4838c601b428
69
69
  terminal-table (4.0.0) sha256=f504793203f8251b2ea7c7068333053f0beeea26093ec9962e62ea79f94301d2
70
70
  unicode-display_width (3.2.0) sha256=0cdd96b5681a5949cdbc2c55e7b420facae74c4aaf9a9815eee1087cb1853c42
data/README.md CHANGED
@@ -1,18 +1,50 @@
1
- SimpleCov Markdown Formatter
2
- ==================================
1
+ # SimpleCov Markdown Formatter
3
2
 
4
3
  [![Gem Version](https://badge.fury.io/rb/simplecov-markdown.svg)](https://badge.fury.io/rb/simplecov-markdown)
5
4
  [![CI](https://github.com/renuo/simplecov-markdown/actions/workflows/ci.yml/badge.svg)](https://github.com/renuo/simplecov-markdown/actions/workflows/ci.yml)
6
5
 
7
- Install
8
- ----------------------------
6
+ Adds a report in markdown format. This can be useful in CI context or for LLMs.
9
7
 
10
- gem install simplecov-markdown
8
+ ## Install
11
9
 
12
- Usage
13
- ----------------------------
10
+ ```
11
+ gem install simplecov-markdown
12
+ ```
13
+
14
+ ## Usage
14
15
 
15
16
  ```ruby
16
17
  require 'simplecov-markdown'
17
18
  SimpleCov.formatter = SimpleCov::Formatter::MarkdownFormatter
18
19
  ```
20
+
21
+ if you want to configure multiple formatters:
22
+
23
+ ```ruby
24
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter.new([
25
+ SimpleCov::Formatter::HTMLFormatter,
26
+ SimpleCov::Formatter::MarkdownFormatter
27
+ ])
28
+ ```
29
+
30
+ ## Alternatives
31
+
32
+ LLMs and CI environments work well also with [simplecov-console](https://github.com/chetan/simplecov-console).
33
+
34
+ ## Changelog
35
+
36
+ ### 1.1.0
37
+
38
+ - **Support branch coverage**
39
+
40
+ ### 1.0.0
41
+
42
+ - **Sorted results by coverage** — files are now sorted ascending by coverage percentage, so the least covered files appear first
43
+ - **Missing line numbers** — the report now includes a "Missing line numbers" column listing the exact line numbers not covered, instead of just a count
44
+ - **Revised table columns** — columns reordered and renamed: `Coverage`, `File`, `Total lines`, `Total missed`, `Missing line numbers`
45
+ - **Ruby 4.0 support** — tested against Ruby 3.2, 3.3, and 4.0 via GitHub Actions CI
46
+ - **Dropped legacy dependencies** — removed `coveralls`, `rspec-temp_dir`, and loosened `bundler`/`rake` version constraints
47
+
48
+ ### 0.2.0
49
+
50
+ Initial release by [holyshared](https://github.com/holyshared/simplecov-markdown).
@@ -1,7 +1,7 @@
1
1
  module SimpleCov
2
2
  module Formatter
3
3
  class MarkdownFormatter
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
6
6
  end
7
7
  end
@@ -18,7 +18,6 @@ class SimpleCov::Formatter::MarkdownFormatter
18
18
 
19
19
  def initialize(report_path)
20
20
  @report = File.open(report_path, 'w')
21
- @table_writer = TableWriter.new(report)
22
21
  end
23
22
 
24
23
  def write_header(title)
@@ -34,33 +33,59 @@ class SimpleCov::Formatter::MarkdownFormatter
34
33
  end
35
34
 
36
35
  def write_result(result)
37
- @table_writer.write_header
36
+ branch_coverage_enabled = result.files.any? { |f| f.total_branches.any? }
37
+ table_writer = TableWriter.new(@report, branch_coverage: branch_coverage_enabled)
38
+ table_writer.write_header
38
39
  result.files.sort_by(&:covered_percent).each do |file|
39
- missing_lines = file.missed_lines.map(&:line_number).join(", ")
40
- @table_writer.write_record(
40
+ missing_lines = format_line_numbers(file.missed_lines.map(&:line_number))
41
+ args = [
41
42
  file.covered_percent.round(2).to_s + "%",
42
- file.filename,
43
+ relative_path(file.filename),
43
44
  file.lines_of_code,
44
45
  file.missed_lines.size,
45
46
  missing_lines
46
- )
47
+ ]
48
+ if branch_coverage_enabled
49
+ missing_branches = file.missed_branches.map { |b| "#{b.start_line}[#{b.type}]" }.join(", ")
50
+ args += [file.branches_coverage_percent.round(2).to_s + "%", missing_branches]
51
+ end
52
+ table_writer.write_record(*args)
47
53
  end
48
- @table_writer.destroy!
54
+ table_writer.destroy!
49
55
  end
50
56
 
51
57
  def destroy!
52
58
  @report.close
53
59
  @report = nil
54
60
  end
61
+
62
+ private
63
+
64
+ def relative_path(filename)
65
+ filename.delete_prefix(SimpleCov.root + "/")
66
+ end
67
+
68
+ def format_line_numbers(line_numbers)
69
+ return "" if line_numbers.empty?
70
+
71
+ line_numbers.chunk_while { |a, b| b == a + 1 }.map do |group|
72
+ group.size >= 2 ? "#{group.first}-#{group.last}" : group.first.to_s
73
+ end.join(", ")
74
+ end
55
75
  end
56
76
 
57
77
  class TableWriter
58
78
  attr_reader :report, :columns_headers, :columns_header_aligns
59
79
 
60
- def initialize(report)
80
+ def initialize(report, branch_coverage: false)
61
81
  @report = report
62
- @columns_headers = ["Coverage", "File", "Total lines", "Total missed", "Missing line numbers"]
63
- @columns_header_aligns = [:right, :left, :right, :right, :left]
82
+ if branch_coverage
83
+ @columns_headers = ["Coverage", "File", "Total lines", "Total missed", "Missing line numbers", "Branch coverage", "Missing branches"]
84
+ @columns_header_aligns = [:right, :left, :right, :right, :left, :right, :left]
85
+ else
86
+ @columns_headers = ["Coverage", "File", "Total lines", "Total missed", "Missing line numbers"]
87
+ @columns_header_aligns = [:right, :left, :right, :right, :left]
88
+ end
64
89
  end
65
90
 
66
91
  def write_header
@@ -4,8 +4,8 @@ Code Coverage Report
4
4
  Project name: <%= project_name %>
5
5
  Created at: <%= created_at %>
6
6
 
7
- |Coverage|File|Total lines|Total missed|Missing line numbers|
8
- |--:|:--|--:|--:|:--|
9
- |62.5%|<%= root_directory %>/fixtures/sample3.rb|8|3|8, 12, 13|
10
- |80.0%|<%= root_directory %>/fixtures/sample2.rb|5|1|8|
11
- |100.0%|<%= root_directory %>/fixtures/sample1.rb|5|0||
7
+ |Coverage|File|Total lines|Total missed|Missing line numbers|Branch coverage|Missing branches|
8
+ |--:|:--|--:|--:|:--|--:|:--|
9
+ |54.55%|<%= root_directory.delete_prefix(SimpleCov.root + "/") %>/fixtures/sample3.rb|11|5|11, 15-17, 19|25.0%|11[else], 17[then], 19[else]|
10
+ |85.71%|<%= root_directory.delete_prefix(SimpleCov.root + "/") %>/fixtures/sample2.rb|7|1|11|50.0%|11[else]|
11
+ |100.0%|<%= root_directory.delete_prefix(SimpleCov.root + "/") %>/fixtures/sample1.rb|7|0||100.0%||
@@ -1,10 +1,14 @@
1
1
  # Sample1 class
2
2
  class Sample1
3
- def initialize
4
- @foo = 'baz'
3
+ def initialize(value)
4
+ @value = value
5
5
  end
6
6
 
7
- def bar
8
- @foo
7
+ def describe
8
+ if @value > 0
9
+ "positive"
10
+ else
11
+ "non-positive"
12
+ end
9
13
  end
10
14
  end
@@ -1,10 +1,14 @@
1
1
  # Sample2 class
2
2
  class Sample2
3
- def initialize
4
- @foo = 'baz'
3
+ def initialize(value)
4
+ @value = value
5
5
  end
6
6
 
7
- def bar
8
- @foo
7
+ def describe
8
+ if @value > 0
9
+ "positive"
10
+ else
11
+ "non-positive"
12
+ end
9
13
  end
10
14
  end
@@ -1,14 +1,22 @@
1
1
  # Sample3 class
2
2
  class Sample3
3
- def initialize
4
- @foo = 'baz'
3
+ def initialize(value)
4
+ @value = value
5
5
  end
6
6
 
7
- def bar
8
- @foo
7
+ def describe
8
+ if @value > 0
9
+ "positive"
10
+ else
11
+ "non-positive"
12
+ end
9
13
  end
10
14
 
11
- def baz
12
- @foo + 'baz'
15
+ def check
16
+ if @value.zero?
17
+ "zero"
18
+ else
19
+ "non-zero"
20
+ end
13
21
  end
14
22
  end
@@ -16,15 +16,44 @@ RSpec.describe 'MarkdownFormatter' do
16
16
  erb_script = File.open(File.join(File.dirname(__FILE__), 'fixtures/expected_report.md.erb')).read
17
17
  ERB.new(erb_script).result(binding)
18
18
  end
19
+
19
20
  let(:result) do
20
21
  sample1 = File.join(File.dirname(__FILE__), 'fixtures', 'sample1.rb')
21
22
  sample2 = File.join(File.dirname(__FILE__), 'fixtures', 'sample2.rb')
22
23
  sample3 = File.join(File.dirname(__FILE__), 'fixtures', 'sample3.rb')
23
24
 
24
25
  original_result = {
25
- sample1 => { "lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil] },
26
- sample2 => { "lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil] },
27
- sample3 => { "lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, 1, 0, 0, nil] }
26
+ sample1 => {
27
+ "lines" => [nil, 1, 1, 1, nil, nil, 1, 1, 1, nil, 1, nil, nil, nil],
28
+ "branches" => {
29
+ [:if, 0, 8, 4, 12, 7] => {
30
+ [:then, 0, 9, 6, 9, 14] => 1,
31
+ [:else, 0, 11, 6, 11, 19] => 1
32
+ }
33
+ }
34
+ },
35
+ sample2 => {
36
+ "lines" => [nil, 1, 1, 1, nil, nil, 1, 1, 1, nil, 0, nil, nil, nil],
37
+ "branches" => {
38
+ [:if, 0, 8, 4, 12, 7] => {
39
+ [:then, 0, 9, 6, 9, 14] => 1,
40
+ [:else, 0, 11, 6, 11, 19] => 0
41
+ }
42
+ }
43
+ },
44
+ sample3 => {
45
+ "lines" => [nil, 1, 1, 1, nil, nil, 1, 1, 1, nil, 0, nil, nil, nil, 0, 0, 0, nil, 0, nil, nil, nil],
46
+ "branches" => {
47
+ [:if, 0, 8, 4, 12, 7] => {
48
+ [:then, 0, 9, 6, 9, 14] => 1,
49
+ [:else, 0, 11, 6, 11, 19] => 0
50
+ },
51
+ [:if, 1, 16, 4, 20, 7] => {
52
+ [:then, 0, 17, 6, 17, 10] => 0,
53
+ [:else, 0, 19, 6, 19, 14] => 0
54
+ }
55
+ }
56
+ }
28
57
  }
29
58
  SimpleCov::Result.new(original_result)
30
59
  end
data/spec/spec_helper.rb CHANGED
@@ -2,12 +2,11 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
2
  require 'simplecov'
3
3
  require 'simplecov-console'
4
4
 
5
- SimpleCov.add_filter do |source_file|
6
- source_file.filename =~ /spec/ && !(source_file.filename =~ /fixtures/)
5
+ SimpleCov.start do
6
+ enable_coverage :branch
7
+ add_filter { |f| f.filename =~ /spec/ && !(f.filename =~ /fixtures/) }
7
8
  end
8
9
 
9
- SimpleCov.start
10
-
11
10
  require 'simplecov-markdown'
12
11
 
13
12
  if ENV["COVERALLS_REPO_TOKEN"]
@@ -15,6 +14,7 @@ if ENV["COVERALLS_REPO_TOKEN"]
15
14
  Coveralls.wear!
16
15
  else
17
16
  SimpleCov.formatters = [
17
+ SimpleCov::Formatter::HTMLFormatter,
18
18
  SimpleCov::Formatter::Console,
19
19
  SimpleCov::Formatter::MarkdownFormatter
20
20
  ]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simplecov-markdown
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alessandro Rodi