bashcov 3.1.3 → 3.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.
data/lib/bashcov/lexer.rb CHANGED
@@ -13,7 +13,7 @@ module Bashcov
13
13
  IGNORE_END_WITH = %w[(].freeze
14
14
 
15
15
  # Lines containing only one of these keywords are irrelevant for coverage
16
- IGNORE_IS = %w[esac if then else elif fi while do done { } ;;].freeze
16
+ IGNORE_IS = %w[esac if then else elif fi while do done { } ;; ( )].freeze
17
17
 
18
18
  # @param [String] filename File to analyze
19
19
  # @param [Hash] coverage Coverage with executed lines marked
@@ -41,7 +41,7 @@ module Bashcov
41
41
  # heredoc
42
42
  mark_multiline(
43
43
  lines, lineno,
44
- /\A[^\n]+<<-?'?(\w+)'?.*$.*\1/m
44
+ /\A[^\n]+<<-?\s*'?(\w+)'?.*$.*\1/m
45
45
  )
46
46
 
47
47
  # multiline string concatenated with backslashes
@@ -99,17 +99,15 @@ module Bashcov
99
99
  line.sub!(/\s#.*\Z/, "") # remove comments
100
100
  line.strip!
101
101
 
102
- relevant = true
102
+ return false if line.empty? ||
103
+ IGNORE_IS.include?(line) ||
104
+ line.start_with?(*IGNORE_START_WITH) ||
105
+ line.end_with?(*IGNORE_END_WITH)
103
106
 
104
- relevant &= false if line.empty? ||
105
- IGNORE_IS.include?(line) ||
106
- line.start_with?(*IGNORE_START_WITH) ||
107
- line.end_with?(*IGNORE_END_WITH)
107
+ return false if line =~ /\A[a-zA-Z_@][a-zA-Z0-9_@\-:.]*\(\)/ # function declared without the `function` keyword
108
+ return false if line =~ /\A[^)]+\)\Z/ # case statement selector, e.g. `--help)`
108
109
 
109
- relevant &= false if line =~ /\A[a-zA-Z_][a-zA-Z0-9_:]*\(\)/ # function declared without the `function` keyword
110
- relevant &= false if line =~ /\A[^)]+\)\Z/ # case statement selector, e.g. `--help)`
111
-
112
- relevant
110
+ true
113
111
  end
114
112
  end
115
113
  end
data/lib/bashcov/line.rb CHANGED
@@ -4,11 +4,11 @@ module Bashcov
4
4
  # {Line} represents a line of code.
5
5
  module Line
6
6
  # Uncovered line
7
- # @see http://ruby-doc.org/stdlib-2.3.0/libdoc/coverage/rdoc/Coverage.html
7
+ # @see http://ruby-doc.org/stdlib-3.0.0/libdoc/coverage/rdoc/Coverage.html
8
8
  UNCOVERED = 0
9
9
 
10
10
  # Ignored line
11
- # @see http://ruby-doc.org/stdlib-2.3.0/libdoc/coverage/rdoc/Coverage.html
11
+ # @see http://ruby-doc.org/stdlib-3.0.0/libdoc/coverage/rdoc/Coverage.html
12
12
  IGNORED = nil
13
13
  end
14
14
  end
@@ -23,8 +23,7 @@ module Bashcov
23
23
  # @note Binds Bashcov +stdin+ to the program being executed.
24
24
  # @return [Process::Status] Status of the executed command
25
25
  def run
26
- # Clear out previous run
27
- @result = nil
26
+ @result = nil # clear out previous run
28
27
 
29
28
  field_stream = FieldStream.new
30
29
  @xtrace = Xtrace.new(field_stream)
@@ -34,8 +33,8 @@ module Bashcov
34
33
  options[fd] = fd # bind FDs to the child process
35
34
 
36
35
  if Bashcov.options.mute
37
- options[:out] = "/dev/null"
38
- options[:err] = "/dev/null"
36
+ options[:out] = File::NULL
37
+ options[:err] = File::NULL
39
38
  end
40
39
 
41
40
  env =
@@ -3,5 +3,5 @@
3
3
  # :nodoc:
4
4
  module Bashcov
5
5
  # Current Bashcov version
6
- VERSION = "3.1.3"
6
+ VERSION = "3.3.0"
7
7
  end
@@ -114,9 +114,9 @@ module Bashcov
114
114
  # @raise [XtraceError] when +lineno+ is not composed solely of digits,
115
115
  # indicating that something has gone wrong with parsing the +PS4+ fields
116
116
  def parse_hit!(lineno, *paths)
117
- # If +LINENO+ isn't a series of digits, something has gone wrong. Add
118
- # +@files+ to the exception in order to propagate the existing coverage
119
- # data back to the {Bashcov::Runner} instance.
117
+ # if +LINENO+ isn't a series of digits, add +@files+ to the exception in
118
+ # order to propagate the existing coverage data back to the
119
+ # {Bashcov::Runner} instance
120
120
  if /\A\d+\z/.match?(lineno)
121
121
  lineno = lineno.to_i
122
122
  elsif lineno == "${LINENO-}"
@@ -128,15 +128,14 @@ module Bashcov
128
128
  )
129
129
  end
130
130
 
131
- # The next three fields will be $BASH_SOURCE, $PWD, $OLDPWD, and $LINENO
132
131
  bash_source, pwd, oldpwd = paths.map { |p| Pathname.new(p) }
133
132
 
134
133
  update_wd_stacks!(pwd, oldpwd)
135
134
 
136
135
  script = find_script(bash_source)
137
136
 
138
- # For one-liners, +LINENO+ == 0. Do this to avoid an +IndexError+;
139
- # one-liners will be culled from the coverage results later on.
137
+ # for one-liners, +LINENO+ == 0, do this to avoid an +IndexError+
138
+ # one-liners will be culled from the coverage results later on
140
139
  index = (lineno > 1 ? lineno - 1 : 0)
141
140
 
142
141
  @files[script] ||= []
@@ -172,16 +171,16 @@ module Bashcov
172
171
  @pwd_stack[0] ||= pwd
173
172
  @oldpwd_stack[0] ||= oldpwd unless oldpwd.to_s.empty?
174
173
 
175
- # We haven't changed working directories; short-circuit.
174
+ # return if we haven't changed working directories
176
175
  return if pwd == @pwd_stack[-1]
177
176
 
178
- # If the current +pwd+ is identical to the top of the +@oldpwd_stack+ and
177
+ # if the current +pwd+ is identical to the top of the +@oldpwd_stack+ and
179
178
  # the current +oldpwd+ is identical to the second-to-top entry, then a
180
- # previous cd/pushd has been undone.
179
+ # previous cd/pushd has been undone
181
180
  if pwd == @oldpwd_stack[-1] && oldpwd == @oldpwd_stack[-2]
182
181
  @pwd_stack.pop
183
182
  @oldpwd_stack.pop
184
- else # New cd/pushd
183
+ else # new cd/pushd
185
184
  @pwd_stack << pwd
186
185
  @oldpwd_stack << oldpwd
187
186
  end
data/lib/bashcov.rb CHANGED
@@ -3,7 +3,6 @@
3
3
  require "optparse"
4
4
  require "pathname"
5
5
 
6
- require "bashcov/runner"
7
6
  require "bashcov/version"
8
7
 
9
8
  # Bashcov default module
@@ -69,17 +68,22 @@ module Bashcov
69
68
  end
70
69
 
71
70
  def bash_path
72
- # First attempt to use the value from `options`, but ignore all exceptions.
73
- # This is used early for the `BASH_VERSION` definition, so first use will likely error.
71
+ # first attempt to use the value from `options`, but ignore all exceptions
72
+ # this is used early for the `BASH_VERSION` definition, so first use will likely error
74
73
  begin
75
74
  return @options.bash_path if @options.bash_path
76
- rescue NoMethodError; end # rubocop:disable Lint/SuppressedException
75
+ rescue NoMethodError
76
+ nil
77
+ end
77
78
 
78
- # Support the same `BASHCOV_BASH_PATH` environment variable used in the spec tests.
79
+ # support the same `BASHCOV_BASH_PATH` environment variable used in the spec tests
79
80
  return ENV.fetch("BASHCOV_BASH_PATH", nil) unless ENV.fetch("BASHCOV_BASH_PATH", "").empty?
80
81
 
81
- # Fall back to standard Bash location.
82
- "/bin/bash"
82
+ # fall back to standard Bash location, if available
83
+ return "/bin/bash" if File.executable?("/bin/bash")
84
+
85
+ # otherwise, try to execute a Bash from `PATH`
86
+ "bash"
83
87
  end
84
88
 
85
89
  def bash_version
@@ -98,7 +102,7 @@ module Bashcov
98
102
  # Define option accessors
99
103
  Options.new.members.each do |option|
100
104
  [option, "#{option}="].each do |method|
101
- next if instance_methods(false).include?(method)
105
+ next if method_defined?(method, false)
102
106
 
103
107
  define_method method do |*args|
104
108
  options.public_send(*[method, *args])
@@ -109,7 +113,7 @@ module Bashcov
109
113
  private
110
114
 
111
115
  def help
112
- <<-HELP.gsub(/^ +/, "").gsub("\t", " " * 4)
116
+ <<~HELP.gsub("\t", " " * 4)
113
117
  Usage: #{program_name} [options] [--] <command> [options]
114
118
  Examples:
115
119
  \t#{program_name} ./script.sh
@@ -138,8 +142,9 @@ module Bashcov
138
142
 
139
143
  options.bash_path = p
140
144
 
141
- # Redefine `BASH_VERSION` constant with upated `bash_path`.
142
- # This is hacky, but a lot of code references that constant and this should only have to be done once.
145
+ # redefine `BASH_VERSION` constant with updated `bash_path`, this is
146
+ # hacky, but a lot of code references that constant and this should
147
+ # only have to be done once
143
148
  send(:remove_const, "BASH_VERSION")
144
149
  const_set("BASH_VERSION", bash_version.freeze)
145
150
  end
data/shell.nix ADDED
@@ -0,0 +1 @@
1
+ (import ./compat.nix).shellNix
data/test.sh CHANGED
@@ -1,4 +1,4 @@
1
- #!/bin/bash
1
+ #!/usr/bin/env bash
2
2
 
3
3
  set -euo pipefail
4
4
 
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bashcov
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.3
4
+ version: 3.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cédric Félizard
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-08-29 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: simplecov
@@ -38,6 +37,20 @@ dependencies:
38
37
  - - ">="
39
38
  - !ruby/object:Gem::Version
40
39
  version: '0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: benchmark
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
41
54
  - !ruby/object:Gem::Dependency
42
55
  name: bundler-audit
43
56
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +79,34 @@ dependencies:
66
79
  - - ">="
67
80
  - !ruby/object:Gem::Version
68
81
  version: '0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: ffi
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: 1.16.0
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: 1.16.0
96
+ - !ruby/object:Gem::Dependency
97
+ name: irb
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
69
110
  - !ruby/object:Gem::Dependency
70
111
  name: rake
71
112
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +121,20 @@ dependencies:
80
121
  - - ">="
81
122
  - !ruby/object:Gem::Version
82
123
  version: '0'
124
+ - !ruby/object:Gem::Dependency
125
+ name: rdoc
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
136
+ - !ruby/object:Gem::Version
137
+ version: '0'
83
138
  - !ruby/object:Gem::Dependency
84
139
  name: rspec
85
140
  requirement: !ruby/object:Gem::Requirement
@@ -165,13 +220,21 @@ files:
165
220
  - CHANGELOG.md
166
221
  - CONTRIBUTING.md
167
222
  - Gemfile
223
+ - Gemfile.nix.lock
168
224
  - Guardfile
225
+ - HACKING.md
226
+ - INSTALL.md
169
227
  - LICENSE.txt
170
228
  - README.md
171
229
  - Rakefile
172
230
  - TESTING.md
173
231
  - USAGE.md
174
232
  - bin/bashcov
233
+ - compat.nix
234
+ - default.nix
235
+ - flake.lock
236
+ - flake.nix
237
+ - gemset.nix
175
238
  - lib/bashcov.rb
176
239
  - lib/bashcov/detective.rb
177
240
  - lib/bashcov/errors.rb
@@ -181,6 +244,7 @@ files:
181
244
  - lib/bashcov/runner.rb
182
245
  - lib/bashcov/version.rb
183
246
  - lib/bashcov/xtrace.rb
247
+ - shell.nix
184
248
  - test.sh
185
249
  homepage: https://github.com/infertux/bashcov
186
250
  licenses:
@@ -190,7 +254,6 @@ metadata:
190
254
  source_code_uri: https://github.com/infertux/bashcov
191
255
  changelog_uri: https://github.com/infertux/bashcov/blob/master/CHANGELOG.md
192
256
  rubygems_mfa_required: 'true'
193
- post_install_message:
194
257
  rdoc_options: []
195
258
  require_paths:
196
259
  - lib
@@ -198,15 +261,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
198
261
  requirements:
199
262
  - - ">="
200
263
  - !ruby/object:Gem::Version
201
- version: 3.0.0
264
+ version: 3.2.0
202
265
  required_rubygems_version: !ruby/object:Gem::Requirement
203
266
  requirements:
204
267
  - - ">="
205
268
  - !ruby/object:Gem::Version
206
269
  version: '0'
207
270
  requirements: []
208
- rubygems_version: 3.5.10
209
- signing_key:
271
+ rubygems_version: 4.0.6
210
272
  specification_version: 4
211
273
  summary: Code coverage tool for Bash
212
274
  test_files: []