Class: Klenod::Test::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/klenod/test/runner.rb

Constant Summary collapse

WORKER_ARGUMENT =
"--worker"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(context:, execute:, watch: nil, worker_paths: Runner.worker_paths_from(ARGV), spawn_empty: false, worker_command: [RbConfig.ruby, $PROGRAM_NAME], process: Async::Process, output: $stdout, error_output: $stderr, env: ENV, format_error: nil) ⇒ Runner

Returns a new instance of Runner.



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
# File 'lib/klenod/test/runner.rb', line 24

def initialize(
  context:,
  execute:,
  watch: nil,
  worker_paths: Runner.worker_paths_from(ARGV),
  spawn_empty: false,
  worker_command: [RbConfig.ruby, $PROGRAM_NAME],
  process: Async::Process,
  output: $stdout,
  error_output: $stderr,
  env: ENV,
  format_error: nil
)
  @context_factory = context
  @execute = execute
  @watch = watch.nil? ? !env.key?("CI") : watch
  @worker_paths = worker_paths&.dup
  @spawn_empty = spawn_empty
  @worker_command = Array(worker_command)
  @process = process
  @output = output
  @error_output = error_output
  @env = env
  @format_error = format_error || ->(error, _context) { error.full_message }
  @last_status = 0
  @worker_mutex = Mutex.new
end

Class Method Details

.worker_paths_from(arguments) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
# File 'lib/klenod/test/runner.rb', line 16

def self.worker_paths_from(arguments)
  arguments = Array(arguments)
  return unless arguments.first == WORKER_ARGUMENT
  raise ArgumentError, "Expected -- after #{WORKER_ARGUMENT}" unless arguments[1] == "--"

  arguments.drop(2)
end

Instance Method Details

#call ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/klenod/test/runner.rb', line 52

def call
  return run_worker(worker_paths) if worker_paths

  context = context_factory.call
  plugin = test_plugin(context)
  suite = Klenod::Test::Suite.new(context:, plugin:)
  selection = suite.collect
  return run_in_worker(selection.test_paths) unless watch

  run_watch(context, suite, selection)
rescue ArgumentError => error
  error_output.puts error.message
  1
end