-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from BaxterStockman/safe-ps4
PS4 with subshells causes erroneous extra hits to be registered
- Loading branch information
Showing
20 changed files
with
884 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ doc/ | |
lib/bundler/man | ||
pkg | ||
rdoc | ||
.rubocop-* | ||
spec/reports | ||
test/tmp | ||
test/version_tmp | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,6 @@ | ||
Metrics/AbcSize: | ||
Enabled: false | ||
|
||
Metrics/MethodLength: | ||
Enabled: false | ||
|
||
Metrics/LineLength: | ||
Max: 120 | ||
Exclude: [spec/**/*] | ||
|
||
Style/AccessModifierIndentation: | ||
EnforcedStyle: outdent | ||
|
||
Style/AndOr: | ||
EnforcedStyle: conditionals | ||
|
||
Style/SignalException: | ||
EnforcedStyle: only_raise | ||
inherit_from: | ||
- https://gist.githubusercontent.com/infertux/cdd2ccc6e0a0cd94f458/raw | ||
|
||
Style/SpecialGlobalVars: | ||
Enabled: false | ||
|
||
Style/StringLiterals: | ||
EnforcedStyle: double_quotes | ||
|
||
Style/TrailingComma: | ||
Enabled: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
module Bashcov | ||
# Module exposing information concerning the installed Bash version | ||
# @note methods do not cache results because +bash_path+ can change at | ||
# runtime | ||
# @note receiver is expected to implement +bash_path+ | ||
module BashInfo | ||
# @return [Array<String>] An array representing the components of | ||
# +BASH_VERSINFO+ | ||
def bash_versinfo | ||
`#{bash_path} -c 'echo "${BASH_VERSINFO[@]}"'`.chomp.split | ||
end | ||
|
||
# @return [Boolean] Whether Bash supports +BASH_XTRACEFD+ | ||
def bash_xtracefd? | ||
bash_versinfo[0..1].join.to_i >= 41 | ||
end | ||
|
||
# @param [Integer] length the number of bytes to test; default 128 | ||
# @return [Boolean] whether Bash supports a +PS4+ of at least a given | ||
# number of bytes | ||
# @see https://tiswww.case.edu/php/chet/bash/CHANGES | ||
# @note Item +i.+ under the +bash-4.2-release+ to +bash-4.3-alpha+ change | ||
# list notes that version 4.2 truncates +PS4+ if it is greater than 128 | ||
# bytes. | ||
def truncated_ps4?(length = 128) | ||
ps4 = SecureRandom.base64(length) | ||
!`PS4=#{ps4} #{bash_path} 2>&1 1>&- -xc 'echo hello'`.start_with?(ps4) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Bashcov | ||
# Signals an error parsing Bash's debugging output. | ||
class XtraceError < ::RuntimeError | ||
# Will contain the coverages parsed prior to the error | ||
attr_reader :files | ||
|
||
# @param [#to_s] message An error message | ||
# @param [Hash] files A hash containing coverage information | ||
def initialize(message, files) | ||
@files = files | ||
super(message) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module Bashcov | ||
# Classes for streaming token-delimited fields | ||
class FieldStream | ||
attr_accessor :read | ||
|
||
# @param [IO] read an IO object opened for reading | ||
def initialize(read = nil) | ||
@read = read | ||
end | ||
|
||
# A convenience wrapper around +each_line(sep)+ that also does | ||
# +chomp(sep)+ on the yielded line. | ||
# @param [String, nil] delim the field separator for the stream | ||
# @return [void] | ||
# @yieldparam [String] field each +chomp+ed line | ||
def each_field(delim) | ||
return enum_for(__method__, delim) unless block_given? | ||
|
||
read.each_line(delim) do |line| | ||
yield line.chomp(delim) | ||
end | ||
end | ||
|
||
# Yields fields extracted from a input stream | ||
# @param [String, nil] delim the field separator | ||
# @param [Integer] field_count the number of fields to extract | ||
# @param [Regexp] start_match a +Regexp+ that, when matched against the | ||
# input stream, signifies the beginning of the next series of fields to | ||
# yield | ||
# @yieldparam [String] field each field extracted from the stream. If | ||
# +start_match+ is matched with fewer than +field_count+ fields yielded | ||
# since the last match, yields empty strings until +field_count+ is | ||
# reached. | ||
def each(delim, field_count, start_match) | ||
return enum_for(__method__, delim, field_count, start_match) unless block_given? | ||
|
||
# Whether the current field is the start-of-fields match | ||
matched_start = nil | ||
|
||
# The number of fields processed since passing the last start-of-fields | ||
# match | ||
seen_fields = 0 | ||
|
||
fields = each_field(delim) | ||
|
||
# Close over +field_count+ and +seen_fields+ to yield empty strings to | ||
# the caller when we've already hit the next start-of-fields match | ||
yield_remaining = -> { (field_count - seen_fields).times { yield "" } } | ||
|
||
# Advance until the first start-of-fields match | ||
loop { break if fields.next =~ start_match } | ||
|
||
fields.each do |field| | ||
# If the current field is the start-of-fields match... | ||
if field =~ start_match | ||
# Fill out any remaining (unparseable) fields with empty strings | ||
yield_remaining.call | ||
|
||
matched_start = nil | ||
seen_fields = 0 | ||
elsif seen_fields < field_count | ||
yield field | ||
seen_fields += 1 | ||
end | ||
end | ||
|
||
# One last filling-out of empty fields if we're at the end of the stream | ||
yield_remaining.call | ||
|
||
read.close unless read.closed? | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.