ruby_branch_coverage 1.0.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 +7 -0
- data/.circleci/config.yml +58 -0
- data/.github/workflows/lint.yml +41 -0
- data/.github/workflows/publish_gem.yml +30 -0
- data/.gitignore +68 -0
- data/.rspec +2 -0
- data/.rubocop.yml +20 -0
- data/.ruby-version +1 -0
- data/Gemfile +21 -0
- data/README.md +39 -0
- data/Rakefile +17 -0
- data/bin/rails +14 -0
- data/lib/ruby_branch_coverage/engine.rb +10 -0
- data/lib/ruby_branch_coverage/version.rb +5 -0
- data/lib/ruby_branch_coverage.rb +162 -0
- data/lib/tasks/simplecov.rake +35 -0
- data/ruby_branch_coverage.gemspec +18 -0
- metadata +97 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3b0478d4bc19f46bbd4f43cc6657ba9cdcbf5f8ac53fb370bf949956c4601377
|
|
4
|
+
data.tar.gz: 4cb88e0c0c437f7794d578b451b9132c5dd736614d2fd1d75b51c4cba91b792e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 166bfbba86784a2b6b400e229d8bd612eb7e60c948af715829043da15d2c7e28003560b09ebd5c024ac8df9bdb493cb421a0f9513047299a29cc54fd6a25a2ec
|
|
7
|
+
data.tar.gz: bf3484f97dcf07e39dae7fa1b0e92c78bfead69c1137ad0025ea41e252a96eb3261f4653faa9f455fe3da6f73604208909af6e043d62b475209a29a3e103b9ad
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
version: 2.1
|
|
2
|
+
|
|
3
|
+
common: &common
|
|
4
|
+
working_directory: ~/workspace
|
|
5
|
+
parallelism: 1
|
|
6
|
+
resource_class: small
|
|
7
|
+
steps:
|
|
8
|
+
- checkout
|
|
9
|
+
- restore_cache:
|
|
10
|
+
keys:
|
|
11
|
+
- bundle-v1-{{ checksum "ruby_branch_coverage.gemspec" }}
|
|
12
|
+
|
|
13
|
+
- run:
|
|
14
|
+
name: Build gem dependencies
|
|
15
|
+
command: |
|
|
16
|
+
gem install bundler
|
|
17
|
+
bundle lock
|
|
18
|
+
bundle config --local path '.bundle'
|
|
19
|
+
bundle check || bundle install --jobs 4
|
|
20
|
+
bundle clean
|
|
21
|
+
|
|
22
|
+
- save_cache:
|
|
23
|
+
key: bundle-v1-{{ checksum "ruby_branch_coverage.gemspec" }}
|
|
24
|
+
paths:
|
|
25
|
+
- .bundle
|
|
26
|
+
|
|
27
|
+
- run:
|
|
28
|
+
name: Run tests
|
|
29
|
+
command: |
|
|
30
|
+
mkdir coverage
|
|
31
|
+
bundle exec rspec
|
|
32
|
+
|
|
33
|
+
jobs:
|
|
34
|
+
test_3_2:
|
|
35
|
+
docker:
|
|
36
|
+
- image: cimg/ruby:3.2
|
|
37
|
+
<<: *common
|
|
38
|
+
|
|
39
|
+
upload_coveralls:
|
|
40
|
+
working_directory: ~/workspace
|
|
41
|
+
docker:
|
|
42
|
+
- image: cimg/ruby:3.2
|
|
43
|
+
steps:
|
|
44
|
+
- attach_workspace:
|
|
45
|
+
at: ~/workspace
|
|
46
|
+
- run:
|
|
47
|
+
name: Run upload coveralls
|
|
48
|
+
command: |
|
|
49
|
+
curl -k https://coveralls.io/webhook?repo_token=$COVERALLS_REPO_TOKEN -d "payload[build_num]=$CIRCLE_BUILD_NUM&payload[status]=done"
|
|
50
|
+
|
|
51
|
+
workflows:
|
|
52
|
+
version: 2
|
|
53
|
+
build-and-test:
|
|
54
|
+
jobs:
|
|
55
|
+
- test_3_2
|
|
56
|
+
- upload_coveralls:
|
|
57
|
+
requires:
|
|
58
|
+
- test_3_2
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
name: Lint
|
|
2
|
+
|
|
3
|
+
on: [pull_request]
|
|
4
|
+
|
|
5
|
+
permissions:
|
|
6
|
+
contents: read
|
|
7
|
+
pull-requests: write
|
|
8
|
+
|
|
9
|
+
jobs:
|
|
10
|
+
rubocop:
|
|
11
|
+
name: runner / rubocop
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
steps:
|
|
14
|
+
- name: Check out code
|
|
15
|
+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
|
|
16
|
+
- uses: ruby/setup-ruby@c4e5b1316158f92e3d49443a9d58b31d25ac0f8f # v1.306.0
|
|
17
|
+
- name: rubocop
|
|
18
|
+
uses: reviewdog/action-rubocop@b6d5e953a5fc0bf3ab65254e77730ea2174d6d6d # v2.22.0
|
|
19
|
+
with:
|
|
20
|
+
rubocop_version: gemfile
|
|
21
|
+
rubocop_extensions: rubocop-rspec:gemfile rubocop-checkstyle_formatter:gemfile rubocop-thread_safety:gemfile
|
|
22
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
23
|
+
fail_on_error: true
|
|
24
|
+
reporter: github-pr-review
|
|
25
|
+
|
|
26
|
+
brakeman:
|
|
27
|
+
name: runner / brakeman
|
|
28
|
+
runs-on: ubuntu-latest
|
|
29
|
+
steps:
|
|
30
|
+
- name: Check out code
|
|
31
|
+
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0
|
|
32
|
+
- name: Set up Ruby
|
|
33
|
+
uses: ruby/setup-ruby@c4e5b1316158f92e3d49443a9d58b31d25ac0f8f # v1.306.0
|
|
34
|
+
- name: brakeman
|
|
35
|
+
uses: reviewdog/action-brakeman@5083efd49634e26645a0736681b618ccc3fb7f14 # v2.19.2
|
|
36
|
+
with:
|
|
37
|
+
brakeman_version: gemfile
|
|
38
|
+
github_token: ${{ secrets.GITHUB_TOKEN }}
|
|
39
|
+
fail_on_error: true
|
|
40
|
+
reporter: github-pr-review
|
|
41
|
+
brakeman_flags: '--force'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
name: Publish gem to github private registry
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
paths:
|
|
8
|
+
- lib/ruby_branch_coverage/version.rb
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
build:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
timeout-minutes: 2
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@ee0669bd1cc54295c223e0bb666b733df41de1c5 # v2.7.0
|
|
16
|
+
- name: Tag with the gem version
|
|
17
|
+
run: |
|
|
18
|
+
GEM_VERSION=$(ruby -e "require 'rubygems'; gemspec = Dir.glob(\"./**/*.gemspec\").first; puts Gem::Specification::load(gemspec).version")
|
|
19
|
+
TAG="v$GEM_VERSION"
|
|
20
|
+
git tag $TAG && git push origin $TAG
|
|
21
|
+
- name: Set up github private registry key
|
|
22
|
+
run: |
|
|
23
|
+
mkdir -p ~/.gem
|
|
24
|
+
touch ~/.gem/credentials
|
|
25
|
+
chmod 600 ~/.gem/credentials
|
|
26
|
+
echo ":github: Bearer ${{ secrets.GITHUB_TOKEN }}" >> ~/.gem/credentials
|
|
27
|
+
- name: build and push gem
|
|
28
|
+
run: |
|
|
29
|
+
gem build *.gemspec
|
|
30
|
+
gem push --key github --host https://rubygems.pkg.github.com/moneyforward ./*.gem
|
data/.gitignore
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
*.gem
|
|
2
|
+
*.rbc
|
|
3
|
+
/.config
|
|
4
|
+
/coverage/
|
|
5
|
+
/InstalledFiles
|
|
6
|
+
/pkg/
|
|
7
|
+
/spec/reports/
|
|
8
|
+
/spec/examples.txt
|
|
9
|
+
/spec/dummy/coverage/
|
|
10
|
+
/spec/dummy/coverage_results/
|
|
11
|
+
/spec/dummy/db/*.sqlite3
|
|
12
|
+
/spec/dummy/public/packs-test/
|
|
13
|
+
/spec/dummy/tmp/
|
|
14
|
+
/spec/dummy/log/
|
|
15
|
+
/spec/dummy/lib/
|
|
16
|
+
/spec/dummy/node_modules/
|
|
17
|
+
/spec/dummy/storage/
|
|
18
|
+
/spec/dummy/vendor/
|
|
19
|
+
/spec/dummy/.rspec
|
|
20
|
+
/test/tmp/
|
|
21
|
+
/test/version_tmp/
|
|
22
|
+
/tmp/
|
|
23
|
+
/.idea/
|
|
24
|
+
Gemfile.lock
|
|
25
|
+
# Used by dotenv library to load environment variables.
|
|
26
|
+
# .env
|
|
27
|
+
|
|
28
|
+
# Ignore Byebug command history file.
|
|
29
|
+
.byebug_history
|
|
30
|
+
|
|
31
|
+
## Specific to RubyMotion:
|
|
32
|
+
.dat*
|
|
33
|
+
.repl_history
|
|
34
|
+
build/
|
|
35
|
+
*.bridgesupport
|
|
36
|
+
build-iPhoneOS/
|
|
37
|
+
build-iPhoneSimulator/
|
|
38
|
+
|
|
39
|
+
## Specific to RubyMotion (use of CocoaPods):
|
|
40
|
+
#
|
|
41
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
|
42
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
|
43
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
|
44
|
+
#
|
|
45
|
+
# vendor/Pods/
|
|
46
|
+
|
|
47
|
+
## Documentation cache and generated files:
|
|
48
|
+
/.yardoc/
|
|
49
|
+
/_yardoc/
|
|
50
|
+
/doc/
|
|
51
|
+
/rdoc/
|
|
52
|
+
|
|
53
|
+
## Environment normalization:
|
|
54
|
+
/.bundle/
|
|
55
|
+
/vendor/bundle
|
|
56
|
+
/lib/bundler/man/
|
|
57
|
+
|
|
58
|
+
# for a library or gem, you might want to ignore these files since the code is
|
|
59
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
60
|
+
# Gemfile.lock
|
|
61
|
+
# .ruby-version
|
|
62
|
+
# .ruby-gemset
|
|
63
|
+
|
|
64
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
|
65
|
+
.rvmrc
|
|
66
|
+
|
|
67
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
|
68
|
+
# .rubocop-https?--*
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require:
|
|
2
|
+
- rubocop-rspec
|
|
3
|
+
- rubocop-thread_safety
|
|
4
|
+
|
|
5
|
+
AllCops:
|
|
6
|
+
NewCops: enable
|
|
7
|
+
SuggestExtensions: false
|
|
8
|
+
Exclude:
|
|
9
|
+
- 'bin/*'
|
|
10
|
+
- 'script/**/*'
|
|
11
|
+
- 'vendor/**/*'
|
|
12
|
+
- 'spec/**/*'
|
|
13
|
+
- 'tmp/**/*'
|
|
14
|
+
- '**/Rakefile'
|
|
15
|
+
- '**/Gemfile'
|
|
16
|
+
- '*.gemspec'
|
|
17
|
+
- 'node_modules/**/*'
|
|
18
|
+
CacheRootDirectory: tmp/cache/rubocop
|
|
19
|
+
EnforcedStyle/compact:
|
|
20
|
+
Enabled: false
|
data/.ruby-version
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
4.0.4
|
data/Gemfile
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
source "https://rubygems.org"
|
|
2
|
+
|
|
3
|
+
gemspec
|
|
4
|
+
|
|
5
|
+
group :development, :test do
|
|
6
|
+
gem 'rspec' # testing framework
|
|
7
|
+
gem 'simplecov', require: false
|
|
8
|
+
gem 'json'
|
|
9
|
+
gem 'simplecov_json_formatter'
|
|
10
|
+
gem 'builder'
|
|
11
|
+
gem 'rubocop', require: false
|
|
12
|
+
gem 'rubocop-checkstyle_formatter', require: false
|
|
13
|
+
gem 'rubocop-rspec', require: false
|
|
14
|
+
gem 'rubocop-thread_safety'
|
|
15
|
+
gem 'brakeman'
|
|
16
|
+
gem 'coveralls_reborn', '~> 0.27.0', require: false
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
group :development do
|
|
20
|
+
gem 'sqlite3'
|
|
21
|
+
end
|
data/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# branchcov-xmlruby-sonar
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
[](https://coveralls.io/github/moneyforwardvietnam/branchcov-xmlruby-sonar?branch=main)
|
|
5
|
+
|
|
6
|
+
下記をアプリ側の`spec_helper`に追加して使用してください
|
|
7
|
+
|
|
8
|
+
```ruby
|
|
9
|
+
SimpleCov.start 'rails' do
|
|
10
|
+
enable_coverage :branch
|
|
11
|
+
|
|
12
|
+
add_filter '/spec/'
|
|
13
|
+
add_filter '/config/'
|
|
14
|
+
add_filter '/db/'
|
|
15
|
+
add_filter '/vendor/'
|
|
16
|
+
|
|
17
|
+
add_group 'Decorators', 'app/decorators'
|
|
18
|
+
add_group 'Forms', 'app/forms'
|
|
19
|
+
add_group 'Services', 'app/services'
|
|
20
|
+
add_group 'ViewObjects', 'app/view_objects'
|
|
21
|
+
add_group 'Batches', 'app/batches'
|
|
22
|
+
|
|
23
|
+
merge_timeout 3600
|
|
24
|
+
end
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`simplecov.rake`を動かす際には、下記のようにディレクトリを作成してコピーする必要があります
|
|
28
|
+
```ruby
|
|
29
|
+
# example of circleci/.config
|
|
30
|
+
|
|
31
|
+
- run:
|
|
32
|
+
name: Stash coverage results
|
|
33
|
+
command: |
|
|
34
|
+
mkdir coverage_results
|
|
35
|
+
cp -R coverage/.resultset.json coverage_results/.resultset-${CIRCLE_NODE_INDEX}.json || exit 0
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Kibela page
|
|
39
|
+
Check [this](https://moneyforward.kibe.la/notes/265405#circleci-using-gem) document for more configuration
|
data/Rakefile
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# require "bundler/setup"
|
|
2
|
+
|
|
3
|
+
# APP_RAKEFILE = File.expand_path("spec/dummy/Rakefile", __dir__)
|
|
4
|
+
# load "rails/tasks/engine.rake"
|
|
5
|
+
|
|
6
|
+
# load "rails/tasks/statistics.rake"
|
|
7
|
+
|
|
8
|
+
require "bundler/gem_tasks"
|
|
9
|
+
|
|
10
|
+
# require "rake/testtask"
|
|
11
|
+
|
|
12
|
+
# Rake.add_rakelib 'lib/tasks'
|
|
13
|
+
|
|
14
|
+
# # add rspec rake task
|
|
15
|
+
# require 'rspec/core/rake_task'
|
|
16
|
+
# RSpec::Core::RakeTask.new(:spec)
|
|
17
|
+
# task default: :spec
|
data/bin/rails
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
|
3
|
+
# installed from the root of your application.
|
|
4
|
+
|
|
5
|
+
ENGINE_ROOT = File.expand_path('..', __dir__)
|
|
6
|
+
ENGINE_PATH = File.expand_path('../lib/branchcov/xmlruby/sonar/engine', __dir__)
|
|
7
|
+
APP_PATH = File.expand_path('../spec/dummy/config/application', __dir__)
|
|
8
|
+
|
|
9
|
+
# Set up gems listed in the Gemfile.
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
|
|
11
|
+
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
|
|
12
|
+
|
|
13
|
+
require "rails/all"
|
|
14
|
+
require "rails/engine/commands"
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'json'
|
|
4
|
+
require 'builder'
|
|
5
|
+
require_relative 'ruby_branch_coverage/version'
|
|
6
|
+
require_relative 'ruby_branch_coverage/engine'
|
|
7
|
+
# Convert JSON to XML for branch coverage
|
|
8
|
+
class RubyBranchCoverage
|
|
9
|
+
def read_json_and_getxml(filepath, parallelism_count = 0, parallelism_processors = 0)
|
|
10
|
+
file = File.read(filepath)
|
|
11
|
+
data_hash = JSON.parse(file)
|
|
12
|
+
|
|
13
|
+
file_elements = if parallelism_count != 0 || parallelism_processors != 0
|
|
14
|
+
extract_file_elements_using_parallelism_args(data_hash, parallelism_count, parallelism_processors)
|
|
15
|
+
else
|
|
16
|
+
extract_file_elements(data_hash)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
create_xml(file_elements)
|
|
20
|
+
file_elements.size.positive?
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def extract_file_elements_using_parallelism_args(data_hash, parallelism_count, parallelism_processors)
|
|
26
|
+
warn 'parallelism_count and parallelism_processors as argument will deprecate.'
|
|
27
|
+
rspec_key = find_rspec_key(parallelism_count, parallelism_processors)
|
|
28
|
+
|
|
29
|
+
return [] if data_hash.empty? || data_hash[rspec_key].nil? || data_hash[rspec_key]['coverage'].nil?
|
|
30
|
+
|
|
31
|
+
create_file_elements(data_hash[rspec_key]['coverage'])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def extract_file_elements(data_hash)
|
|
35
|
+
raise 'No coverage data found in the JSON file' if valid_coverage_hash?(data_hash)
|
|
36
|
+
|
|
37
|
+
file_elements = []
|
|
38
|
+
data_hash.each do |_key, value|
|
|
39
|
+
file_elements.concat(create_file_elements(value['coverage'])) if value.key?('coverage')
|
|
40
|
+
end
|
|
41
|
+
file_elements
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def find_rspec_key(parallelism, parallelism_processors)
|
|
45
|
+
if parallelism_processors.positive?
|
|
46
|
+
# when parallelism is 4 and parallelism processor is 4
|
|
47
|
+
# (1/4), (1/4), (1/4), (1/4), (2/4), (2/4), (2/4), (2/4), (3/4), (3/4), (3/4), (3/4), (4/4), (4/4), (4/4), (4/4)
|
|
48
|
+
parallelism.times.map do |i|
|
|
49
|
+
parallelism_processors.times.map do |_j|
|
|
50
|
+
"(#{i + 1}/#{parallelism})"
|
|
51
|
+
end.join(', ') # (x/4), (x/4), (x/4), (x/4)
|
|
52
|
+
end.join(', ')
|
|
53
|
+
else
|
|
54
|
+
# when parallelism is 4 and parallelism processor is 0
|
|
55
|
+
# Rspec, RSpec, RSpec, RSpec
|
|
56
|
+
parallelism.times.map { |_i| 'RSpec' }.join(', ')
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def valid_coverage_hash?(data_hash)
|
|
61
|
+
data_hash.empty? || data_hash.values.none? { |v| v.is_a?(Hash) && v.key?('coverage') }
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def create_file_elements(coverage_block_by_key)
|
|
65
|
+
file_elements = []
|
|
66
|
+
coverage_block_by_key.each do |filename, value|
|
|
67
|
+
branches = value['branches']
|
|
68
|
+
|
|
69
|
+
next if branches.nil? || branches.keys.empty?
|
|
70
|
+
|
|
71
|
+
file_element = { path: filename, lineElements: line_to_cover_array(branches) }
|
|
72
|
+
file_elements.push(file_element)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
file_elements
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def line_to_cover_array(branches)
|
|
79
|
+
line_to_cover_array = []
|
|
80
|
+
branches.each do |branch, conditions_map|
|
|
81
|
+
line_number = branch.split(',')[2].strip
|
|
82
|
+
not_covered = find_notcovered_branches conditions_map
|
|
83
|
+
covered = (conditions_map.keys.size - not_covered)
|
|
84
|
+
|
|
85
|
+
line_tocover_element = line_tocover_element_by_branch(covered, line_number, conditions_map.keys.size)
|
|
86
|
+
index = check_for_duplicate_line line_number, line_to_cover_array
|
|
87
|
+
update_line_to_cover_array_by_index(line_to_cover_array, index, line_tocover_element)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
line_to_cover_array
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def find_notcovered_branches(conditions_map)
|
|
94
|
+
conditions_map.count { |_condition, hit_count| hit_count.zero? }
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def line_tocover_element_by_branch(covered, line_number, branches_to_cover)
|
|
98
|
+
{
|
|
99
|
+
lineNumber: line_number,
|
|
100
|
+
covered: covered.positive?,
|
|
101
|
+
branchesToCover: branches_to_cover,
|
|
102
|
+
coveredBranches: covered
|
|
103
|
+
}
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# To check line already present in list of lineToCover element
|
|
107
|
+
def check_for_duplicate_line(line_number, line_tocover_elements)
|
|
108
|
+
line_tocover_elements.each_with_index do |element, idx|
|
|
109
|
+
return idx if element[:lineNumber] == line_number
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
-1
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def update_line_to_cover_array_by_index(line_to_cover_array, index, line_tocover_element)
|
|
116
|
+
return line_to_cover_array.push(line_tocover_element) if index == -1
|
|
117
|
+
|
|
118
|
+
# if index == -1
|
|
119
|
+
# line_to_cover_array.push(line_tocover_element)
|
|
120
|
+
# else
|
|
121
|
+
old_line_tocover_element = line_to_cover_array[index]
|
|
122
|
+
old_line_tocover_element[:branchesToCover] =
|
|
123
|
+
old_line_tocover_element[:branchesToCover] + line_tocover_element[:branchesToCover]
|
|
124
|
+
old_line_tocover_element[:coveredBranches] =
|
|
125
|
+
old_line_tocover_element[:coveredBranches] + line_tocover_element[:coveredBranches]
|
|
126
|
+
old_line_tocover_element[:covered] = old_line_tocover_element[:covered] && line_tocover_element[:covered]
|
|
127
|
+
line_to_cover_array[index] = old_line_tocover_element
|
|
128
|
+
# end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# def update_line_to_cover_array()
|
|
132
|
+
#
|
|
133
|
+
# end
|
|
134
|
+
|
|
135
|
+
def create_xml(file_elements)
|
|
136
|
+
xml = Builder::XmlMarkup.new(indent: 2)
|
|
137
|
+
puts "Total Files: #{file_elements.size}"
|
|
138
|
+
prepare_xml_builder xml, file_elements
|
|
139
|
+
File.write('coverage/branch-coverage.xml', xml.target!)
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
def prepare_xml_builder(xml, file_elements)
|
|
143
|
+
xml.coverage('version' => '1') do
|
|
144
|
+
file_elements.each do |file_element|
|
|
145
|
+
xml.file('path' => file_element[:path]) do
|
|
146
|
+
file_element[:lineElements].each do |element|
|
|
147
|
+
xml.lineToCover(line_to_cover_hash(element))
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
def line_to_cover_hash(element)
|
|
155
|
+
{
|
|
156
|
+
'lineNumber' => element[:lineNumber],
|
|
157
|
+
'covered' => element[:covered],
|
|
158
|
+
'branchesToCover' => element[:branchesToCover],
|
|
159
|
+
'coveredBranches' => element[:coveredBranches]
|
|
160
|
+
}
|
|
161
|
+
end
|
|
162
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'simplecov'
|
|
4
|
+
require 'simplecov_json_formatter'
|
|
5
|
+
|
|
6
|
+
namespace :simplecov do
|
|
7
|
+
desc 'Merge coverage results'
|
|
8
|
+
task :report_coverage, %i[parallelism processors] => [:environment] do |_t, args|
|
|
9
|
+
SimpleCov.start 'rails' do
|
|
10
|
+
enable_coverage :branch
|
|
11
|
+
|
|
12
|
+
add_filter '/spec/'
|
|
13
|
+
add_filter '/config/'
|
|
14
|
+
add_filter '/db/'
|
|
15
|
+
add_filter '/vendor/'
|
|
16
|
+
|
|
17
|
+
add_group 'Decorators', 'app/decorators'
|
|
18
|
+
add_group 'Forms', 'app/forms'
|
|
19
|
+
add_group 'Services', 'app/services'
|
|
20
|
+
add_group 'ViewObjects', 'app/view_objects'
|
|
21
|
+
add_group 'Batches', 'app/batches'
|
|
22
|
+
|
|
23
|
+
merge_timeout 3600
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
SimpleCov.collate Dir['./coverage_results/.resultset*.json'], 'rails' do
|
|
27
|
+
formatter SimpleCov::Formatter::MultiFormatter.new([
|
|
28
|
+
SimpleCov::Formatter::HTMLFormatter,
|
|
29
|
+
SimpleCov::Formatter::JSONFormatter
|
|
30
|
+
])
|
|
31
|
+
end
|
|
32
|
+
ruby_branch = RubyBranchCoverage.new
|
|
33
|
+
ruby_branch.read_json_and_getxml('coverage/.resultset.json', args[:parallelism].to_i, args[:processors].to_i)
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require_relative 'lib/ruby_branch_coverage/version'
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |s|
|
|
4
|
+
s.name = 'ruby_branch_coverage'
|
|
5
|
+
s.version = RubyBranchCoverage::VERSION
|
|
6
|
+
s.summary = 'Branch Coverage Ruby!'
|
|
7
|
+
s.description = 'A program to convert json to xml test coverage format gem'
|
|
8
|
+
s.authors = ['Suganya']
|
|
9
|
+
s.email = ['kuppusamy.suganya@moneyforward.co.jp']
|
|
10
|
+
s.files = `git ls-files -z`.split("\x0").
|
|
11
|
+
reject { |f| f.match(%r{^(test|spec|features)/}) }
|
|
12
|
+
s.homepage =
|
|
13
|
+
'https://github.com/moneyforward/ruby_branch_coverage'
|
|
14
|
+
|
|
15
|
+
s.add_development_dependency "rspec-rails"
|
|
16
|
+
s.add_dependency "rails"
|
|
17
|
+
s.add_dependency 'simplecov'
|
|
18
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby_branch_coverage
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 1.0.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Suganya
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rspec-rails
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '0'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: rails
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
type: :runtime
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - ">="
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '0'
|
|
40
|
+
- !ruby/object:Gem::Dependency
|
|
41
|
+
name: simplecov
|
|
42
|
+
requirement: !ruby/object:Gem::Requirement
|
|
43
|
+
requirements:
|
|
44
|
+
- - ">="
|
|
45
|
+
- !ruby/object:Gem::Version
|
|
46
|
+
version: '0'
|
|
47
|
+
type: :runtime
|
|
48
|
+
prerelease: false
|
|
49
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
50
|
+
requirements:
|
|
51
|
+
- - ">="
|
|
52
|
+
- !ruby/object:Gem::Version
|
|
53
|
+
version: '0'
|
|
54
|
+
description: A program to convert json to xml test coverage format gem
|
|
55
|
+
email:
|
|
56
|
+
- kuppusamy.suganya@moneyforward.co.jp
|
|
57
|
+
executables: []
|
|
58
|
+
extensions: []
|
|
59
|
+
extra_rdoc_files: []
|
|
60
|
+
files:
|
|
61
|
+
- ".circleci/config.yml"
|
|
62
|
+
- ".github/workflows/lint.yml"
|
|
63
|
+
- ".github/workflows/publish_gem.yml"
|
|
64
|
+
- ".gitignore"
|
|
65
|
+
- ".rspec"
|
|
66
|
+
- ".rubocop.yml"
|
|
67
|
+
- ".ruby-version"
|
|
68
|
+
- Gemfile
|
|
69
|
+
- README.md
|
|
70
|
+
- Rakefile
|
|
71
|
+
- bin/rails
|
|
72
|
+
- lib/ruby_branch_coverage.rb
|
|
73
|
+
- lib/ruby_branch_coverage/engine.rb
|
|
74
|
+
- lib/ruby_branch_coverage/version.rb
|
|
75
|
+
- lib/tasks/simplecov.rake
|
|
76
|
+
- ruby_branch_coverage.gemspec
|
|
77
|
+
homepage: https://github.com/moneyforward/ruby_branch_coverage
|
|
78
|
+
licenses: []
|
|
79
|
+
metadata: {}
|
|
80
|
+
rdoc_options: []
|
|
81
|
+
require_paths:
|
|
82
|
+
- lib
|
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
84
|
+
requirements:
|
|
85
|
+
- - ">="
|
|
86
|
+
- !ruby/object:Gem::Version
|
|
87
|
+
version: '0'
|
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
|
+
requirements:
|
|
90
|
+
- - ">="
|
|
91
|
+
- !ruby/object:Gem::Version
|
|
92
|
+
version: '0'
|
|
93
|
+
requirements: []
|
|
94
|
+
rubygems_version: 4.0.10
|
|
95
|
+
specification_version: 4
|
|
96
|
+
summary: Branch Coverage Ruby!
|
|
97
|
+
test_files: []
|