Class: SnapCI::ParallelTests::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/snap_ci/parallel_tests/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(runner, argv) ⇒ CLI

Returns a new instance of CLI.



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/snap_ci/parallel_tests/cli.rb', line 8

def initialize(runner, argv)
  @runner = runner

  @argv = argv.dup
  @test_opts = nil

  if split_index = @argv.index('--')
    @test_opts = @argv.drop(split_index + 1).join(' ')
    @argv = @argv.take(split_index)
  end
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



6
7
8
# File 'lib/snap_ci/parallel_tests/cli.rb', line 6

def argv
  @argv
end

#runnerObject (readonly)

Returns the value of attribute runner.



6
7
8
# File 'lib/snap_ci/parallel_tests/cli.rb', line 6

def runner
  @runner
end

#test_optsObject (readonly)

Returns the value of attribute test_opts.



6
7
8
# File 'lib/snap_ci/parallel_tests/cli.rb', line 6

def test_opts
  @test_opts
end

Instance Method Details

#runObject



20
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
# File 'lib/snap_ci/parallel_tests/cli.rb', line 20

def run
  options = parse!
  test_files = find_all_tests(options[:files_or_dirs], options)

  if options[:trace]
    $stderr.puts "Found the following #{runner.test_file_name}s"
    $stderr.puts test_files.collect { |t| " - #{t}" }.join("\n")
  end

  report_number_of_tests(test_files, SnapCI::ParallelTests.total_workers)

  test_files_to_run = SnapCI::ParallelTests.partition(
    things: test_files,
    total_workers: SnapCI::ParallelTests.total_workers,
    current_worker_index: SnapCI::ParallelTests.worker_index,
    group_by: options[:group_by]
  )

  if test_files_to_run.empty?
    $stderr.puts 'No tests to run'
  else
    if options[:trace]
      $stderr.puts "Will run the following #{runner.test_file_name}s and ignore others"
      $stderr.puts test_files.collect { |t| " - #{t}" }.join("\n")
    end
    runner.execute(test_files_to_run, options)
  end


end