class TestRun::Shell::Runner

Constants

CommandFailureError

Attributes

log_path[RW]
queue[RW]
working_directory[RW]

Public Class Methods

new(log_path:, working_directory:) click to toggle source
# File lib/test_run/shell/runner.rb, line 14
def initialize(log_path:, working_directory:)
  @working_directory = working_directory
  @log_path = log_path

  %x{echo "" > #{log_path}}
  Dir.chdir(%x[ git rev-parse --show-toplevel ].chomp)
end

Public Instance Methods

confirm?(question) click to toggle source
# File lib/test_run/shell/runner.rb, line 44
def confirm?(question)
  warn "#{question} [Yn]"
  answer = STDIN.gets.strip.downcase
  return answer != 'n'
end
exec(cmd) click to toggle source
# File lib/test_run/shell/runner.rb, line 29
def exec(cmd)
  notify cmd
  Kernel.exec cmd
end
notify(msg) click to toggle source
# File lib/test_run/shell/runner.rb, line 39
def notify(msg)
  log msg.to_s
  print "#{yellow(msg.to_s)}\n"
end
run(cmd, dir: working_directory, &block) click to toggle source
# File lib/test_run/shell/runner.rb, line 22
def run(cmd, dir: working_directory, &block)
  command = "cd #{Utils::Path.relative_join(dir)} && #{cmd}"
  handle_output_for(command)

  shell_out(command).split("\n")
end
warn(msg) click to toggle source
# File lib/test_run/shell/runner.rb, line 34
def warn(msg)
  log msg.to_s
  print "#{red(msg.to_s)}\n"
end

Private Instance Methods

handle_output_for(cmd) click to toggle source
# File lib/test_run/shell/runner.rb, line 56
def handle_output_for(cmd)
  log(cmd)
end
log(msg) click to toggle source
# File lib/test_run/shell/runner.rb, line 52
def log(msg)
  %x{echo "#{msg.to_s}" >> #{log_path}}
end
shell_out(command) click to toggle source
# File lib/test_run/shell/runner.rb, line 60
def shell_out(command)
  %x{ set -o pipefail && #{command} 2>> #{log_path} | tee -a #{log_path} }.chomp
end