getcov 0.3.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.
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'test_helper'
3
+ require 'tmpdir'
4
+ require 'getcov/formatter/html'
5
+
6
+ class HtmlFormatterDetailTest < Minitest::Test
7
+ def test_writes_per_file_pages_with_line_anchors
8
+ Dir.mktmpdir do |dir|
9
+ cfg = Getcov::Configuration.new
10
+ cfg.root = Dir.pwd
11
+ cfg.output_dir = dir
12
+ formatter = Getcov::Formatter::HTML.new(cfg)
13
+
14
+ src = File.expand_path('sample.rb')
15
+ File.write(src, "a = 1\n# comment\n")
16
+
17
+ raw = { src => [1, 0] }
18
+ result = Getcov::Result.new(raw, cfg)
19
+
20
+ formatter.write(result)
21
+ idx = File.join(dir, 'index.html')
22
+ per_file = File.join(dir, 'sample.rb'.gsub('/', '__') + '.html')
23
+ assert File.exist?(idx), 'index.html missing'
24
+ assert File.exist?(per_file), 'per-file page missing'
25
+ html = File.read(per_file)
26
+ assert_match(/id="L1"/, html)
27
+ assert_match(/id="L2"/, html)
28
+ ensure
29
+ File.delete(src) if File.exist?(src)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'test_helper'
3
+ require 'tmpdir'
4
+ require 'getcov/formatter/html'
5
+
6
+ class HtmlFormatterTest < Minitest::Test
7
+ def test_writes_index_html
8
+ Dir.mktmpdir do |dir|
9
+ cfg = Getcov::Configuration.new
10
+ cfg.root = Dir.pwd
11
+ cfg.output_dir = dir
12
+ formatter = Getcov::Formatter::HTML.new(cfg)
13
+
14
+ raw = { File.expand_path('a.rb') => [1, 0, nil, nil] }
15
+ result = Getcov::Result.new(raw, cfg)
16
+
17
+ formatter.write(result)
18
+ assert File.exist?(File.join(dir, 'index.html')), 'index.html missing'
19
+ content = File.read(File.join(dir, 'index.html'))
20
+ assert_match(/Getcov Coverage/, content)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'test_helper'
3
+
4
+ class IgnoreOnlyTest < Minitest::Test
5
+ def test_only_and_ignore_globs
6
+ cfg = Getcov::Configuration.new
7
+ cfg.only_files 'app/**/*.rb'
8
+ cfg.ignore_files 'app/admin/**/*'
9
+
10
+ assert cfg.filtered?('spec/models/user_spec.rb') # only doesn't match -> filtered
11
+ refute cfg.filtered?('app/models/user.rb')
12
+ assert cfg.filtered?('app/admin/dashboard.rb')
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'test_helper'
3
+
4
+ class MergeTest < Minitest::Test
5
+ def test_merge_raw_results_sums_hits
6
+ raw1 = { File.expand_path('a.rb') => [1, 0, nil] }
7
+ raw2 = { File.expand_path('a.rb') => [0, 1, nil] }
8
+ merged = Getcov.merge_raw_results([raw1, raw2])
9
+ arr = merged.values.first
10
+ assert_equal [1, 1, nil], arr
11
+ end
12
+
13
+ def test_merge_raw_results_with_branches
14
+ raw1 = { File.expand_path('a.rb') => { 'lines' => [1], 'branches' => { 'covered' => 1, 'total' => 2 } } }
15
+ raw2 = { File.expand_path('a.rb') => { 'lines' => [2], 'branches' => { 'covered' => 0, 'total' => 2 } } }
16
+ merged = Getcov.merge_raw_results([raw1, raw2])
17
+ v = merged.values.first
18
+ assert_equal({'lines' => [3], 'branches' => {'covered' => 1, 'total' => 4}}, v)
19
+ end
20
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'test_helper'
3
+
4
+ class PerFileMinimumTest < Minitest::Test
5
+ include TestSupport
6
+
7
+ def test_per_file_minimum_is_enforced_in_finalize
8
+ cfg = Getcov::Configuration.new
9
+ cfg.per_file_minimum = 80.0
10
+ # Build a fake result object by calling finalize! on a controlled raw
11
+ # We'll simulate the flow by calling Getcov.merge APIs, then Result and printing
12
+ raw = { File.expand_path('a.rb') => [1, 0] } # 50%
13
+ result = Getcov::Result.new(raw, cfg)
14
+ out, err = capture_io do
15
+ # Manually mimic finalize threshold check from core (without exiting)
16
+ failure = false
17
+ if cfg.per_file_minimum
18
+ result.files.each do |fr|
19
+ if fr.percent < cfg.per_file_minimum
20
+ failure = true
21
+ end
22
+ end
23
+ end
24
+ puts failure ? 'FAIL' : 'OK'
25
+ end
26
+ assert_match(/FAIL/, out)
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'test_helper'
3
+ require 'tmpdir'
4
+ require 'getcov/formatter/pr_comment'
5
+ require 'getcov/formatter/summary_json'
6
+
7
+ class PRCommentAndJSONTest < Minitest::Test
8
+ def test_generates_pr_comment_and_summary_json
9
+ Dir.mktmpdir do |dir|
10
+ cfg = Getcov::Configuration.new
11
+ cfg.root = Dir.pwd
12
+ cfg.output_dir = dir
13
+ raw = { File.expand_path('a.rb') => [1, 0, nil] }
14
+ result = Getcov::Result.new(raw, cfg)
15
+
16
+ Getcov::Formatter::PRComment.new(cfg).write(result)
17
+ Getcov::Formatter::SummaryJSON.new(cfg).write(result)
18
+
19
+ assert File.exist?(File.join(dir, 'pr_comment.md')), 'pr_comment.md missing'
20
+ assert File.exist?(File.join(dir, 'summary.json')), 'summary.json missing'
21
+ json = JSON.parse(File.read(File.join(dir, 'summary.json')))
22
+ assert_equal 'a.rb', json['files'][0]['path'].split('/').last
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'test_helper'
3
+
4
+ class ResultTest < Minitest::Test
5
+ include TestSupport
6
+
7
+ def build_result(files)
8
+ cfg = Getcov::Configuration.new
9
+ cfg.root = Dir.pwd
10
+ Getcov::Result.new(files, cfg)
11
+ end
12
+
13
+ def test_percentage_calculation
14
+ files = {
15
+ File.expand_path('a.rb') => [1, 0, nil, nil] # 2 relevant, 1 covered => 50%
16
+ }
17
+ r = build_result(files)
18
+ assert_in_delta 50.0, r.total_coverage, 0.001
19
+ out, _ = capture_io { r.print_summary }
20
+ assert_match(/Total Coverage: 50.00%/, out)
21
+ assert_match(/a.rb/, out)
22
+ end
23
+
24
+ def test_filters_are_applied
25
+ cfg = Getcov::Configuration.new
26
+ cfg.add_filter(/a\.rb/)
27
+ raw = { File.expand_path('a.rb') => [1], File.expand_path('b.rb') => [1] }
28
+ r = Getcov::Result.new(raw, cfg)
29
+ assert_equal 100.0, r.total_coverage
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
3
+ require 'minitest/autorun'
4
+ require 'stringio'
5
+ require 'rbconfig'
6
+ require 'getcov'
7
+ require 'getcov/configuration'
8
+ require 'getcov/result'
9
+
10
+ module TestSupport
11
+ def capture_io
12
+ old_out, old_err = $stdout, $stderr
13
+ out_io, err_io = StringIO.new, StringIO.new
14
+ $stdout, $stderr = out_io, err_io
15
+ yield
16
+ [out_io.string, err_io.string]
17
+ ensure
18
+ $stdout, $stderr = old_out, old_err
19
+ end
20
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+ require_relative 'test_helper'
3
+
4
+ class ThresholdsTest < Minitest::Test
5
+ def test_group_thresholds_evaluated
6
+ cfg = Getcov::Configuration.new
7
+ cfg.add_group 'G', /a\.rb/
8
+ cfg.add_group_minimum 'G', 80.0
9
+ raw = { File.expand_path('a.rb') => [1, 0] } # 50%
10
+ result = Getcov::Result.new(raw, cfg)
11
+ g = result.group_coverage
12
+ assert_in_delta 50.0, g['G'], 0.01
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: getcov
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - Mridul Shukla
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2025-08-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Getcov wraps Ruby's Coverage to collect and print coverage summaries
14
+ with filters, groups, HTML, exporters, and CI helpers.
15
+ email:
16
+ - mridul@example.com
17
+ executables:
18
+ - getcov
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - ".github/workflows/pages.yml"
23
+ - ".github/workflows/pr_coverage.yml"
24
+ - ".github/workflows/release.yml"
25
+ - ".github/workflows/ruby.yml"
26
+ - Gemfile
27
+ - LICENSE.txt
28
+ - README.md
29
+ - Rakefile
30
+ - exe/getcov
31
+ - lib/getcov.rb
32
+ - lib/getcov/auto.rb
33
+ - lib/getcov/configuration.rb
34
+ - lib/getcov/formatter/badge.rb
35
+ - lib/getcov/formatter/cobertura.rb
36
+ - lib/getcov/formatter/html.rb
37
+ - lib/getcov/formatter/lcov.rb
38
+ - lib/getcov/formatter/pr_comment.rb
39
+ - lib/getcov/formatter/summary_json.rb
40
+ - lib/getcov/result.rb
41
+ - lib/getcov/version.rb
42
+ - test/auto_integration_test.rb
43
+ - test/branch_summary_test.rb
44
+ - test/configuration_test.rb
45
+ - test/formatters_export_test.rb
46
+ - test/html_formatter_detail_test.rb
47
+ - test/html_formatter_test.rb
48
+ - test/ignore_only_test.rb
49
+ - test/merge_test.rb
50
+ - test/per_file_minimum_test.rb
51
+ - test/pr_comment_and_json_test.rb
52
+ - test/result_test.rb
53
+ - test/test_helper.rb
54
+ - test/thresholds_test.rb
55
+ homepage: https://example.com/getcov
56
+ licenses:
57
+ - MIT
58
+ metadata:
59
+ rubygems_mfa_required: 'true'
60
+ post_install_message:
61
+ rdoc_options: []
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - ">="
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ requirements: []
75
+ rubygems_version: 3.4.10
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: Tiny code coverage tool inspired by SimpleCov
79
+ test_files: []