Class: Bashcov::Runner
- Inherits:
-
Object
- Object
- Bashcov::Runner
- Defined in:
- lib/bashcov/runner.rb
Overview
Runs a given command with xtrace enabled then computes code coverage.
Instance Method Summary collapse
-
#initialize(command) ⇒ Runner
constructor
A new instance of Runner.
-
#result ⇒ Hash
Coverage hash of the last run.
-
#run ⇒ Process::Status
Runs the command with appropriate xtrace settings.
Constructor Details
Instance Method Details
#result ⇒ Hash
Note:
The result is memoized.
Returns Coverage hash of the last run.
66 67 68 69 70 71 72 73 74 |
# File 'lib/bashcov/runner.rb', line 66 def result @result ||= begin find_bash_files! expunge_invalid_files! mark_relevant_lines! convert_coverage end end |
#run ⇒ Process::Status
Note:
Binds Bashcov stdin
to the program being executed.
Runs the command with appropriate xtrace settings.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/bashcov/runner.rb', line 21 def run # rubocop:disable Metrics/MethodLength # Clear out previous run @result = nil field_stream = FieldStream.new @xtrace = Xtrace.new(field_stream) fd = @xtrace.file_descriptor env = { "PS4" => Xtrace.ps4 } = { in: :in } if Bashcov..mute [:out] = "/dev/null" [:err] = "/dev/null" end run_xtrace(fd, env, ) do command_pid = Process.spawn env, *@command, # spawn the command begin # start processing the xtrace output xtrace_thread = Thread.new { @xtrace.read } Process.wait command_pid @xtrace.close @coverage = xtrace_thread.value # wait for the thread to return rescue XtraceError => e write_warning <<-WARNING encountered an error parsing Bash's output (error was: #{e.}). This can occur if your script or its path contains the sequence #{Xtrace.delimiter.inspect}, or if your script unsets LINENO. Aborting early; coverage report will be incomplete. WARNING @coverage = e.files end end $? end |