Class: TestRunner::Cli::Command

Inherits:
OsCtl::Lib::Cli::Command
  • Object
show all
Defined in:
lib/test-runner/cli/command.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.run(method) ⇒ Object



5
6
7
8
9
10
# File 'lib/test-runner/cli/command.rb', line 5

def self.run(method)
  proc do |global_opts, opts, args|
    cmd = new(global_opts, opts, args)
    cmd.method(method).call
  end
end

Instance Method Details

#debugObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/test-runner/cli/command.rb', line 42

def debug
  require_args!('test')

  tl = TestRunner::TestList.new
  test = tl.by_path(args[0])

  ev = TestRunner::TestEvaluator.new(
    test,
    state_dir: File.join(state_dir, "os-test-#{test.name}"),
    sock_dir: File.join(state_dir, 'socks'),
    default_timeout: opts['timeout'],
    destructive: false
  )
  ev.interactive
end

#listObject



12
13
14
15
16
17
18
# File 'lib/test-runner/cli/command.rb', line 12

def list
  tests = select_tests(args[0])

  tests.each do |test|
    puts test.path
  end
end

#select_tests(pattern) ⇒ Array<Test> (protected)

Returns:



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/test-runner/cli/command.rb', line 61

def select_tests(pattern)
  tl = TestRunner::TestList.new

  attr_filters = Cli::LabelFilters.new(opts['label'])
  tag_filters = Cli::TagFilters.new(opts['tag'])

  tl.filter do |test|
    (pattern.nil? || test.path_matches?(pattern)) \
    && attr_filters.pass?(test) \
    && tag_filters.pass?(test)
  end
end

#state_dirObject (protected)



74
75
76
# File 'lib/test-runner/cli/command.rb', line 74

def state_dir
  File.join(opts['state-dir'] || File.join(ENV['TMPDIR'] || '/tmp', 'os-test-runner'))
end

#testObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/test-runner/cli/command.rb', line 20

def test
  tests = select_tests(args[0])

  puts 'The following tests will be run:'
  tests.each { |t| puts "  #{t.path}" }
  puts

  exec = TestRunner::Executor.new(
    tests,
    state_dir:,
    jobs: opts['jobs'],
    default_timeout: opts['timeout'],
    stop_on_failure: opts['stop-on-failure'],
    destructive: opts['destructive']
  )
  results = exec.run

  return unless results.detect(&:unexpected_result?)

  raise 'one or more tests did not have expected results'
end