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.new do |global_opts, opts, args|
    cmd = new(global_opts, opts, args)
    cmd.method(method).call
  end
end

Instance Method Details

#ask_confirmationObject (protected)



70
71
72
73
74
75
76
77
# File 'lib/test-runner/cli/command.rb', line 70

def ask_confirmation
  return true if opts[:yes]

  yield
  STDOUT.write("\nContinue? [y/N]: ")
  STDOUT.flush
  STDIN.readline.strip.downcase == 'y'
end

#ask_confirmation!(&block) ⇒ Object (protected)



79
80
81
# File 'lib/test-runner/cli/command.rb', line 79

def ask_confirmation!(&block)
  fail 'Aborted' unless ask_confirmation(&block)
end

#debugObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/test-runner/cli/command.rb', line 53

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
19
20
21
22
23
24
# File 'lib/test-runner/cli/command.rb', line 12

def list
  tl = TestRunner::TestList.new
  tests =
    if args[0]
      tl.filter { |t| t.path_matches?(args[0]) }
    else
      tl.all
    end

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

#state_dirObject (protected)



83
84
85
# File 'lib/test-runner/cli/command.rb', line 83

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

#testObject



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
# File 'lib/test-runner/cli/command.rb', line 26

def test
  tl = TestRunner::TestList.new
  tests =
    if args[0]
      tl.filter { |t| t.path_matches?(args[0]) }
    else
      tl.all
    end

  ask_confirmation! do
    puts "The following tests will be run:"
    tests.each { |t| puts "  #{t.path}" }
  end

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

  fail 'one or more tests failed' if results.detect(&:failed?)
end