Skip to content

Commit c1aa3c6

Browse files
committed
Modernize Gem for Ruby 3 and fix the test suite
[References #63] [Fixes #31] [Fixes #43] [Fixes #56]
1 parent 7e6163d commit c1aa3c6

39 files changed

+279
-355
lines changed

.gitlab-ci.yml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Official language image. Look for the different tagged releases at:
2+
# https://hub.docker.com/r/library/ruby/tags/
3+
image: ruby:latest
4+
5+
before_script:
6+
- ruby -v
7+
- bundle install -j $(nproc)
8+
- ./spec/install_bash.sh
9+
- bash --version
10+
- id
11+
- env
12+
13+
# Bash versions can be found at https://git.savannah.gnu.org/cgit/bash.git
14+
rspec-bash-5.2:
15+
variables:
16+
INSTALL_BASH_VERSION: "5.2"
17+
script: rspec
18+
19+
rspec-bash-5.1:
20+
variables:
21+
INSTALL_BASH_VERSION: "5.1"
22+
script: rspec
23+
24+
rspec-bash-5.0:
25+
variables:
26+
INSTALL_BASH_VERSION: "5.0"
27+
script: rspec
28+
29+
rspec-bash-4.4:
30+
variables:
31+
INSTALL_BASH_VERSION: "4.4"
32+
script: rspec
33+
34+
rspec-bash-4.3:
35+
variables:
36+
INSTALL_BASH_VERSION: "4.3"
37+
script: rspec
38+
39+
rubocop:
40+
script: rubocop
41+
42+
yard:
43+
script: yard stats --list-undoc

.rubocop.yml

+31-15
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,44 @@
1-
AllCops:
2-
TargetRubyVersion: 2.5
3-
4-
Metrics/AbcSize:
5-
Max: 30
6-
7-
Metrics/BlockLength:
8-
Exclude: ["spec/**/*.rb"]
1+
require:
2+
- rubocop-rake
3+
- rubocop-rspec
94

10-
Metrics/ClassLength:
11-
Max: 150
5+
AllCops:
6+
TargetRubyVersion: 3.0
7+
NewCops: enable
128

13-
Metrics/LineLength:
14-
Max: 100
15-
Exclude: ["spec/**/*.rb"]
9+
Metrics:
10+
Enabled: false
1611

17-
Metrics/MethodLength:
18-
Max: 20
12+
Gemspec/DevelopmentDependencies:
13+
Enabled: false
1914

2015
Layout/AccessModifierIndentation:
2116
EnforcedStyle: outdent
2217

18+
Layout/LineLength:
19+
Enabled: 100
20+
2321
Lint/RedundantSplatExpansion:
2422
Enabled: false
2523

24+
RSpec/ExampleLength:
25+
Enabled: false
26+
27+
RSpec/InstanceVariable:
28+
Enabled: false
29+
30+
RSpec/MessageSpies:
31+
EnforcedStyle: receive
32+
33+
RSpec/MultipleExpectations:
34+
Enabled: false
35+
36+
RSpec/NamedSubject:
37+
Enabled: false
38+
39+
RSpec/NestedGroups:
40+
Enabled: false
41+
2642
Style/ParallelAssignment:
2743
Enabled: false
2844

.travis.yml

-47
This file was deleted.

CHANGELOG.md

+12-6
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
## Unreleased ([changes](https://github.com/infertux/bashcov/compare/v2.0.0...master))
1+
## Unreleased ([changes](https://github.com/infertux/bashcov/compare/v3.0.0...master))
22

33
* TBD
44

5-
## v2.0.0, 2020-07-?? ([changes](https://github.com/infertux/bashcov/compare/v1.8.2...v2.0.0))
5+
## v3.0.0, 2023-04-10 ([changes](https://github.com/infertux/bashcov/compare/v1.8.2...v3.0.0))
66

7+
* [MISC] New minimum Bash version supported is 4.3
8+
* [MISC] New minimum Ruby version supported is 3.0
9+
* [BUGFIX] Running Bashcov as root is now working (especially useful with Docker) although it is not recommended (#31, #43 and #56)
10+
* [BUGFIX] Fix comments preceded by tabs not filtered out (#68)
11+
* [BUGFIX] Fix two-line multilines not being treated as related (#67)
12+
* [BUGFIX] Redefine `BASH_VERSION` when `bash_path` is read from command options (#57)
13+
* [BUGFIX] Mute output from Bashcov and SimpleCov when requested (#54)
14+
* [BUGFIX] Correctly handle empty scripts by short-circuiting
15+
`FieldStream#each` if the reader stream is at end-of-file before
16+
the start-of-fields pattern is encountered (#41)
717
* [FEATURE] Bashcov omits from the coverage results any files that match one
818
or more of the filters in `SimpleCov.filters` (#38)
919
* [FEATURE] Ensure that files matching the `SimpleCov.tracked_files` glob
1020
pattern are included in the coverage results, regardless of
1121
whether `Bashcov.skip_uncovered` is enabled (#38)
12-
* [MISC] Add support for Ruby 2.6 and drop 2.3
13-
* [BUGFIX] Correctly handle empty scripts by short-circuiting
14-
`FieldStream#each` if the reader stream is at end-of-file before
15-
the start-of-fields pattern is encountered (#41)
1622

1723
## v1.8.2, 2018-03-27 ([changes](https://github.com/infertux/bashcov/compare/v1.8.1...v1.8.2))
1824

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Bashcov
22

33
[![Gem Version](https://img.shields.io/gem/v/bashcov.svg)](https://rubygems.org/gems/bashcov)
4-
[![Build Status](https://api.travis-ci.org/infertux/bashcov.svg?branch=master)](https://travis-ci.org/infertux/bashcov)
4+
[![Build Status](https://gitlab.com/infertux/bashcov/badges/master/pipeline.svg)](https://gitlab.com/infertux/bashcov/-/pipelines)
55
[![Coverage Status](https://coveralls.io/repos/infertux/bashcov/badge.svg?branch=master)](https://coveralls.io/r/infertux/bashcov)
66
[![Maintainability](https://api.codeclimate.com/v1/badges/083fdbba795049cd5f06/maintainability)](https://codeclimate.com/github/infertux/bashcov/maintainability)
77
[![Inline docs](http://inch-ci.org/github/infertux/bashcov.svg)](http://inch-ci.org/github/infertux/bashcov)
@@ -22,8 +22,8 @@ It uses the [SimpleCov](https://github.com/colszowka/simplecov) coverage library
2222
SimpleCov gets installed automatically when you install Bashcov.
2323

2424
Here are example coverages generated by Bashcov:
25-
[test app demo](https://infertux.github.com/bashcov/test_app/ "Coverage for the bundled test application") &
26-
[RVM demo](https://infertux.github.com/bashcov/rvm/ "Coverage for RVM").
25+
[test app demo](https://infertux.github.io/bashcov/test_app/ "Coverage for the bundled test application") &
26+
[RVM demo](https://infertux.github.io/bashcov/rvm/ "Coverage for RVM").
2727

2828
## Installation
2929

TESTING.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
`./test.sh` will run all [GitLab CI pipelines](https://gitlab.com/infertux/bashcov/-/pipelines) locally.
2+
3+
You'll need [Docker](https://www.docker.com/) and [GitLab Runner](https://gitlab.com/gitlab-org/gitlab-runner) installed on your machine.

USAGE.md

-8
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,3 @@ it may yield a path that doesn't refer to the currently-running script.
6464
However, it performs well under the various working directory changes performed
6565
in the [test app demo] and avoids the spurious extra hits caused by using
6666
subshells in the `PS4`.
67-
68-
One final note on innards: Bash 4.3 fixed a bug in which `PS4` expansion is
69-
truncated to a maximum of 128 characters. On platforms whose Bash version
70-
suffers from this bug, Bashcov uses the ASCII record separator character to
71-
delimit the `PS4` fields, whereas it uses a long random string on Bash 4.3 and
72-
above. When the field delimiter appears in the path of a script under test or
73-
in a command the script executes, Bashcov won't correctly parse the `PS4` and
74-
will abort early with incomplete coverage results.

bashcov.gemspec

+34-28
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,43 @@
11
# frozen_string_literal: true
22

3-
lib = File.expand_path("lib", __dir__)
4-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5-
require "bashcov/version"
3+
require_relative "lib/bashcov/version"
64

7-
Gem::Specification.new do |gem|
8-
gem.name = "bashcov"
9-
gem.version = Bashcov::VERSION
10-
gem.authors = ["Cédric Félizard"]
11-
gem.email = ["[email protected]"]
12-
gem.description = "Code coverage tool for Bash"
13-
gem.summary = gem.description
14-
gem.homepage = "https://github.com/infertux/bashcov"
15-
gem.license = "MIT"
5+
Gem::Specification.new do |spec|
6+
spec.name = "bashcov"
7+
spec.version = Bashcov::VERSION
8+
spec.authors = ["Cédric Félizard"]
9+
spec.email = ["[email protected]"]
1610

17-
gem.files = `git ls-files -z`.split("\x0").reject do |file|
18-
file.start_with?(".") || file.match(%r{\A(test|spec|features)/})
19-
end
11+
spec.summary = spec.description
12+
spec.description = "Code coverage tool for Bash"
13+
spec.homepage = "https://github.com/infertux/bashcov"
14+
spec.license = "MIT"
15+
spec.required_ruby_version = ">= 3.0.0"
2016

21-
gem.executables = gem.files.grep(%r{\Abin/}).map { |f| File.basename(f) }
22-
gem.require_paths = ["lib"]
17+
spec.metadata["homepage_uri"] = spec.homepage
18+
spec.metadata["source_code_uri"] = "https://github.com/infertux/bashcov"
19+
spec.metadata["changelog_uri"] = "https://github.com/infertux/bashcov/blob/master/CHANGELOG.md"
2320

24-
gem.required_ruby_version = ">= 2.5.8"
21+
# Specify which files should be added to the gem when it is released.
22+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
24+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
25+
end
26+
spec.bindir = "exe"
27+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
28+
spec.require_paths = ["lib"]
2529

26-
gem.add_dependency "simplecov", "~> 0.18.5"
30+
spec.add_dependency "simplecov", "~> 0.21.2"
2731

28-
gem.add_development_dependency "aruba"
29-
gem.add_development_dependency "bundler-audit"
30-
gem.add_development_dependency "coveralls"
31-
gem.add_development_dependency "cucumber"
32-
gem.add_development_dependency "mutant-rspec"
33-
gem.add_development_dependency "rake"
34-
gem.add_development_dependency "rspec"
35-
gem.add_development_dependency "rubocop"
36-
gem.add_development_dependency "yard"
32+
spec.add_development_dependency "aruba"
33+
spec.add_development_dependency "bundler-audit"
34+
# spec.add_development_dependency "coveralls"
35+
spec.add_development_dependency "cucumber"
36+
spec.add_development_dependency "rake"
37+
spec.add_development_dependency "rspec"
38+
spec.add_development_dependency "rubocop"
39+
spec.add_development_dependency "rubocop-rake"
40+
spec.add_development_dependency "rubocop-rspec"
41+
spec.add_development_dependency "yard"
42+
spec.metadata["rubygems_mfa_required"] = "true"
3743
end

features/step_definitions/bashcov_steps.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def aruba_working_directory_expanded
1717
end
1818

1919
def simplecov_results_json
20-
run_command_and_stop(<<-'COMMAND')
20+
run_command_and_stop(<<-COMMAND)
2121
ruby -rjson -rsimplecov -e '
2222
SimpleCov.at_exit { } # noop to prevent output other than the desired JSON
2323
print SimpleCov::ResultMerger.results.map(&:to_hash).to_json

lib/bashcov.rb

+7-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
require "optparse"
44
require "pathname"
55

6-
require "bashcov/bash_info"
76
require "bashcov/runner"
87
require "bashcov/version"
98

109
# Bashcov default module
1110
# @note Keep it short!
1211
module Bashcov
13-
extend Bashcov::BashInfo
14-
1512
# A +Struct+ to store Bashcov configuration
1613
Options = Struct.new(
1714
*%i[skip_uncovered mute bash_path root_directory command command_name]
@@ -55,8 +52,9 @@ def fullname
5552
VERSION,
5653
"with Bash #{BASH_VERSION},",
5754
"Ruby #{RUBY_VERSION},",
58-
"and SimpleCov #{SimpleCov::VERSION}.",
59-
].join(" ")
55+
"and SimpleCov #{SimpleCov::VERSION}",
56+
(Process.uid.zero? ? " as root user (NOT recommended)" : nil),
57+
].compact.join(" ")
6058
end
6159

6260
# @return [String] The value to use as +SimpleCov.command_name+. Uses the
@@ -65,7 +63,7 @@ def fullname
6563
# representation of {Bashcov#command}.
6664
def command_name
6765
return @options.command_name if @options.command_name
68-
return ENV["BASHCOV_COMMAND_NAME"] unless ENV.fetch("BASHCOV_COMMAND_NAME", "").empty?
66+
return ENV.fetch("BASHCOV_COMMAND_NAME", nil) unless ENV.fetch("BASHCOV_COMMAND_NAME", "").empty?
6967

7068
command.compact.join(" ")
7169
end
@@ -78,7 +76,7 @@ def bash_path
7876
rescue NoMethodError; end # rubocop:disable Lint/SuppressedException
7977

8078
# Support the same `BASHCOV_BASH_PATH` environment variable used in the spec tests.
81-
return ENV["BASHCOV_BASH_PATH"] unless ENV.fetch("BASHCOV_BASH_PATH", "").empty?
79+
return ENV.fetch("BASHCOV_BASH_PATH", nil) unless ENV.fetch("BASHCOV_BASH_PATH", "").empty?
8280

8381
# Fall back to standard Bash location.
8482
"/bin/bash"
@@ -121,8 +119,8 @@ def help
121119
HELP
122120
end
123121

124-
def option_parser # rubocop:disable Metrics/MethodLength
125-
OptionParser.new do |opts| # rubocop:disable Metrics/BlockLength
122+
def option_parser
123+
OptionParser.new do |opts|
126124
opts.program_name = program_name
127125
opts.version = Bashcov::VERSION
128126
opts.banner = help

lib/bashcov/bash_info.rb

-26
This file was deleted.

0 commit comments

Comments
 (0)