Class: Bashcov::Xtrace
- Inherits:
-
Object
- Object
- Bashcov::Xtrace
- Defined in:
- lib/bashcov/xtrace.rb
Overview
This class manages xtrace
output.
Constant Summary collapse
- DEPTH_CHAR =
- String
-
Character that will be used to indicate the nesting level of
+xtrace+d instructions
"+"
- PREFIX =
- String
-
Prefix used in
PS4
to identify relevant output
"BASHCOV>"
- FIELDS =
- Array<String>
-
A collection of Bash internal variables to expand in the
{PS4}
%w[${LINENO-} ${BASH_SOURCE-} ${PWD-} ${OLDPWD-}].freeze
- PS4_START_REGEXP =
Regexp to match the beginning of the ps4. DEPTH_CHAR will be repeated in proportion to the level of Bash call nesting.
/#{Regexp.escape(DEPTH_CHAR)}+#{Regexp.escape(PREFIX)}$/m
Class Attribute Summary collapse
-
.delimiter ⇒ Object
- String
-
A randomly-generated UUID used for delimiting the fields of the
PS4
.
-
.ps4 ⇒ String
PS4
variable used for xtrace output.
Class Method Summary collapse
-
.make_ps4(*fields) ⇒ String
A Xtrace.delimiter-separated
String
suitable for use asPS4
.
Instance Method Summary collapse
-
#close ⇒ void
Closes the pipe for writing.
-
#file_descriptor ⇒ Fixnum
File descriptor of the write end of the pipe.
-
#initialize(field_stream) ⇒ Xtrace
constructor
Creates a pipe for xtrace output.
-
#read ⇒ Hash<Pathname, Array<Integer, nil>>
Read fields extracted from Bash’s debugging output.
Constructor Details
#initialize(field_stream) ⇒ Xtrace
Creates a pipe for xtrace output.
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/bashcov/xtrace.rb', line 56 def initialize(field_stream) @field_stream = field_stream @read, @write = IO.pipe # Tracks coverage for each file under test @files ||= {} # Stacks for updating working directory changes @pwd_stack ||= [] @oldpwd_stack ||= [] end |
Class Attribute Details
.delimiter ⇒ Object
- String
-
A randomly-generated UUID used for delimiting the fields of
the PS4
.
29 30 31 |
# File 'lib/bashcov/xtrace.rb', line 29 def delimiter @delimiter ||= SecureRandom.uuid end |
Class Method Details
.make_ps4(*fields) ⇒ String
Returns a delimiter-separated String
suitable for use as PS4
.
43 44 45 46 47 |
# File 'lib/bashcov/xtrace.rb', line 43 def make_ps4(*fields) fields.reduce(DEPTH_CHAR + PREFIX) do |memo, field| memo + delimiter + field end + delimiter end |
Instance Method Details
#close ⇒ void
This method returns an undefined value.
Closes the pipe for writing.
76 77 78 |
# File 'lib/bashcov/xtrace.rb', line 76 def close @write.close end |
#file_descriptor ⇒ Fixnum
Returns File descriptor of the write end of the pipe.
70 71 72 |
# File 'lib/bashcov/xtrace.rb', line 70 def file_descriptor @write.fileno end |
#read ⇒ Hash<Pathname, Array<Integer, nil>>
Read fields extracted from Bash’s debugging output
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/bashcov/xtrace.rb', line 83 def read @field_stream.read = @read field_count = FIELDS.length fields = @field_stream.each( self.class.delimiter, field_count, PS4_START_REGEXP ) # +take(field_count)+ would be more natural here, but doesn't seem to # play nicely with +Enumerator+s backed by +IO+ objects. loop do break if (hit = (1..field_count).map { fields.next }).empty? parse_hit!(*hit) end @read.close unless @read.closed? @files end |