Class: CTT::Cli::Command::TestSuite
- Inherits:
-
Base
show all
- Includes:
- CTT::Cli, Interactive
- Defined in:
- lib/cli/commands/test_suite_management.rb
Constant Summary
collapse
- SUPPORT_OPTIONS =
USER_INPUT = “USER_INPUT” TEST_SUITE_CONFIG_FILE = “tac.yml”
{"--force" => "bypass git dirty state check"}
Constants included
from CTT::Cli
RESULTS_SERVER_URL, STATIC_COMMANDS, TEST_RESULT_FILE, TEST_SUITE_CONFIG_FILE, VERSION
Instance Method Summary
collapse
Constructor Details
#initialize(command, args, runner) ⇒ TestSuite
Returns a new instance of TestSuite.
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/cli/commands/test_suite_management.rb', line 12
def initialize(command, args, runner)
super(args, runner)
pieces = command.split(" ")
pieces.insert(0, "") if pieces.size == 1
action, suite = pieces
@action = action
@suite = suite
@configs = runner.configs
@suites = runner.suites
end
|
Instance Method Details
#check_configuration ⇒ Object
117
118
119
120
121
122
|
# File 'lib/cli/commands/test_suite_management.rb', line 117
def check_configuration
unless @suites.suites["suites"].has_key?(@suite)
say("suite configure file: #{@suites.file} did not has key: #{@suite}")
exit(1)
end
end
|
#check_if_dirty_state ⇒ Object
124
125
126
127
128
129
130
131
132
|
# File 'lib/cli/commands/test_suite_management.rb', line 124
def check_if_dirty_state
if dirty_state?
say("\n%s\n" % [`git status`])
say("Your current directory has some local modifications, " +
"please discard or commit them first.\n" +
"Or use #{yellow("--force")} to bypass git dirty check.")
exit(1)
end
end
|
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/cli/commands/test_suite_management.rb', line 48
def configure
puts "configure #{@suite}"
location = @configs.configs["suites"][@suite]["location"]
location = "" if location == USER_INPUT
invalid_input = true
3.times do
user_input = ask("suite: #{@suite} source directory:", :default => location).strip
if user_input =~ /^~/
user_input = File.expand_path(user_input)
else
user_input = File.absolute_path(user_input)
end
if Dir.exist?(user_input)
if File.exist?(File.join(user_input, TEST_SUITE_CONFIG_FILE))
invalid_input = false
location = user_input
break
else
say("the configure file: #{yellow(TEST_SUITE_CONFIG_FILE)} " +
"cannot be found under #{user_input}.")
end
else
say("the directory: #{user_input} is invalid.")
end
end
if invalid_input
say("invalid inputs for 3 times. abort!", :red)
exit(1)
else
@configs.configs["suites"][@suite]["location"] = location
@configs.save
say("configure suite: #{@suite} successfully.", :green)
end
end
|
#dirty_state? ⇒ Boolean
134
135
136
137
138
139
140
141
|
# File 'lib/cli/commands/test_suite_management.rb', line 134
def dirty_state?
`which git`
return false unless $? == 0
Dir.chdir(@suites.suites["suites"][@suite])
(File.directory?(".git") || File.directory?(File.join("..", ".git"))) \
&& `git status --porcelain | wc -l`.to_i > 0
end
|
#get_suite_configs ⇒ Object
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/cli/commands/test_suite_management.rb', line 177
def get_suite_configs
suite_configs_path = File.join(@suites.suites["suites"][@suite],
CTT::Cli::TEST_SUITE_CONFIG_FILE)
@suite_configs ||= YAML.load_file(suite_configs_path)
unless @suite_configs.is_a?(Hash)
say("invalid yaml format for file: #{suite_configs_path}", :red)
exit(1)
end
@suite_configs
end
|
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/cli/commands/test_suite_management.rb', line 31
def list
check_configuration
get_suite_configs
say("all subcommands for test suite: #{@suite}", :yellow)
say("Options:", :yellow)
SUPPORT_OPTIONS.each do |opt, helper|
say("\t[#{opt}] \t#{helper}")
end
nl
@suite_configs["commands"].each do |command, details|
say("#{@suite} #{command}", :green)
say("\t#{details["desc"]}\n")
end
end
|
#parse_command ⇒ Object
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# File 'lib/cli/commands/test_suite_management.rb', line 154
def parse_command
subcmd = ""
dependencies = []
if @args.empty?
subcmd = @suite_configs["commands"]["default"]["exec"]
dependencies = @suite_configs["commands"]["default"]["dependencies"]
elsif @suite_configs["commands"].has_key?(@args[0])
subcmd = @suite_configs["commands"][@args[0]]["exec"]
dependencies = @suite_configs["commands"][@args[0]]["dependencies"]
@args.delete(@args[0])
else
say("#{@args[0]} is not invalid sub-command, run as default command")
subcmd = @suite_configs["commands"]["default"]["exec"]
dependencies = @suite_configs["commands"]["default"]["dependencies"]
end
unless @args.empty?
subcmd = subcmd + " " + @args.join(" ")
end
[dependencies, subcmd]
end
|
#parse_options ⇒ Object
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/cli/commands/test_suite_management.rb', line 143
def parse_options
@options = {}
opts = SUPPORT_OPTIONS.keys
@args.each do |arg|
if opts.index(arg)
@options[arg] = true
@args.delete(arg)
end
end
end
|
25
26
27
28
|
# File 'lib/cli/commands/test_suite_management.rb', line 25
def run
@action = "test" if @action == ""
eval(@action)
end
|
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# File 'lib/cli/commands/test_suite_management.rb', line 84
def test
check_configuration
parse_options
check_if_dirty_state unless @options["--force"]
get_suite_configs
dependencies, command = parse_command
threads = []
pwd = Dir.pwd
Dir.chdir(@suites.suites["suites"][@suite])
threads << Thread.new do
say("preparing test suite: #{@suite}...")
dependencies.each do |d|
output = `#{d}`
unless $? == 0
say(output)
say("fail to execute dependency command: #{d}. abort!", :red)
exit(1)
end
end
say("\nrun command: #{yellow(command)}")
system(command)
end
threads.each { |t| t.join }
Dir.chdir(pwd)
collector = ClientCollector.new(@runner.command, @suite, @runner)
collector.post
end
|