forked from bladerunnerlabs/blade-test
-
Notifications
You must be signed in to change notification settings - Fork 0
/
execution_list.rb
59 lines (47 loc) · 1.22 KB
/
execution_list.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
50
51
52
53
54
55
56
57
58
59
# frozen_string_literal: true
# TestStepException - exception class for test stage execution list failures
class TestStepException < StandardError
def initialize(msg = 'Test step failed')
super
end
end
# ExecutionList - handle the list of commands that should be executed
class ExecutionList
def initialize(stage_name, command_list)
@stage_name = stage_name
@command_list = command_list
end
def run
puts 'Running ' + @stage_name.yellow
return if skip_execution
run_commands
end
private
def skip_execution
if @command_list.nil?
puts 'SKIPPING'.yellow
puts
return true
end
false
end
def run_commands
command_numbers = 1
@command_list.each do |command|
puts "#{command_numbers}: Executing: #{command.yellow}"
command_numbers += 1
result = system(command)
command_execution_error(command, result)
end
end
def command_execution_error(command, result)
if result.nil?
raise TestStepException,
"Stage #{@stage_name}, command #{command} not found"
end
return if result
raise TestStepException,
"Stage #{@stage_name}," \
"command #{command} failed: #{$CHILD_STATUS}"
end
end