patir 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/History.txt +85 -81
- data/Manifest.txt +16 -16
- data/README.txt +37 -37
- data/Rakefile +18 -18
- data/lib/patir/base.rb +2 -2
- data/lib/patir/configuration.rb +92 -92
- data/test/samples/syntax.cfg +1 -1
- data/test/test_patir_base.rb +24 -24
- data/test/test_patir_command.rb +334 -334
- data/test/test_patir_configuration.rb +27 -27
- metadata +5 -6
- data/.gemtest +0 -0
data/test/samples/syntax.cfg
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
#ruby syntax error
|
1
|
+
#ruby syntax error
|
2
2
|
{
|
data/test/test_patir_base.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
-
require
|
3
|
-
require 'patir/base.rb'
|
4
|
-
|
5
|
-
class TestBase<Test
|
6
|
-
TEMP_LOG="temp.log"
|
7
|
-
def teardown
|
8
|
-
#clean up
|
9
|
-
File.delete(TEMP_LOG) if File.exist?(TEMP_LOG)
|
10
|
-
end
|
11
|
-
|
12
|
-
#This is not actually testing anything meaningfull but can be expanded when we learn more about
|
13
|
-
#the logger
|
14
|
-
def test_setup_logger
|
15
|
-
logger=Patir.setup_logger
|
16
|
-
|
17
|
-
logger=Patir.setup_logger(nil,:silent)
|
18
|
-
|
19
|
-
logger=Patir.setup_logger("temp.log",:silent)
|
20
|
-
|
21
|
-
assert(File.exist?(TEMP_LOG), "Log file not created")
|
22
|
-
logger.close
|
23
|
-
end
|
24
|
-
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
require "minitest/autorun"
|
3
|
+
require 'patir/base.rb'
|
4
|
+
|
5
|
+
class TestBase<Minitest::Test
|
6
|
+
TEMP_LOG="temp.log"
|
7
|
+
def teardown
|
8
|
+
#clean up
|
9
|
+
File.delete(TEMP_LOG) if File.exist?(TEMP_LOG)
|
10
|
+
end
|
11
|
+
|
12
|
+
#This is not actually testing anything meaningfull but can be expanded when we learn more about
|
13
|
+
#the logger
|
14
|
+
def test_setup_logger
|
15
|
+
logger=Patir.setup_logger
|
16
|
+
refute_nil(logger)
|
17
|
+
logger=Patir.setup_logger(nil,:silent)
|
18
|
+
refute_nil(logger)
|
19
|
+
logger=Patir.setup_logger("temp.log",:silent)
|
20
|
+
refute_nil(logger)
|
21
|
+
assert(File.exist?(TEMP_LOG), "Log file not created")
|
22
|
+
logger.close
|
23
|
+
end
|
24
|
+
|
25
25
|
end
|
data/test/test_patir_command.rb
CHANGED
@@ -1,335 +1,335 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
-
require
|
3
|
-
require 'patir/command.rb'
|
4
|
-
|
5
|
-
class MockCommandObject
|
6
|
-
include Patir::Command
|
7
|
-
end
|
8
|
-
|
9
|
-
class MockCommandWarning
|
10
|
-
include Patir::Command
|
11
|
-
def run context=nil
|
12
|
-
@status=:warning
|
13
|
-
return :warning
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class MockCommandError
|
18
|
-
include Patir::Command
|
19
|
-
def run context=nil
|
20
|
-
@status=:error
|
21
|
-
return :error
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class TestCommand<Test
|
26
|
-
#tests the default values set by the module
|
27
|
-
def test_module
|
28
|
-
obj=MockCommandObject.new
|
29
|
-
assert_equal("",obj.name)
|
30
|
-
assert_equal(:not_executed,obj.status)
|
31
|
-
assert(!obj.run?)
|
32
|
-
|
33
|
-
assert(obj.run?)
|
34
|
-
assert_equal(:success,obj.status)
|
35
|
-
assert_equal("",obj.output)
|
36
|
-
assert_equal("",obj.error)
|
37
|
-
assert_equal(0,obj.exec_time)
|
38
|
-
|
39
|
-
assert_equal(:not_executed,obj.status)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class TestShellCommand<Test
|
44
|
-
include Patir
|
45
|
-
def teardown
|
46
|
-
Dir.delete("missing/") if File.exist?("missing/")
|
47
|
-
end
|
48
|
-
#test the expected behaviour of a succesfull command
|
49
|
-
def test_echo
|
50
|
-
cmd=nil
|
51
|
-
|
52
|
-
|
53
|
-
assert(!cmd.run?)
|
54
|
-
assert(!cmd.success?)
|
55
|
-
|
56
|
-
assert(cmd.run?)
|
57
|
-
assert(cmd.success?)
|
58
|
-
assert_equal("hello",cmd.output.chomp)
|
59
|
-
assert_equal("",cmd.error)
|
60
|
-
assert_equal(:success,cmd.status)
|
61
|
-
end
|
62
|
-
#test that error status is reported correctly, by testing a command that fails.
|
63
|
-
def test_error
|
64
|
-
cmd=nil
|
65
|
-
|
66
|
-
assert(!cmd.run?)
|
67
|
-
assert(!cmd.success?)
|
68
|
-
|
69
|
-
assert(cmd.run?)
|
70
|
-
assert(!cmd.success?)
|
71
|
-
assert_equal(:error,cmd.status)
|
72
|
-
end
|
73
|
-
#when passed a wroking directory, the command should change into that directory
|
74
|
-
def test_cwd
|
75
|
-
cmd=nil
|
76
|
-
|
77
|
-
|
78
|
-
assert(cmd.success?)
|
79
|
-
end
|
80
|
-
|
81
|
-
#when the working directory is missing, it should be created when the command is run
|
82
|
-
def test_missing_cwd
|
83
|
-
cmd=nil
|
84
|
-
|
85
|
-
|
86
|
-
assert_equal(:success,cmd.run)
|
87
|
-
assert(cmd.success?)
|
88
|
-
assert(File.exist?("missing/"))
|
89
|
-
end
|
90
|
-
#an exception should be thrown when :cmd is nil
|
91
|
-
def test_missing_cmd
|
92
|
-
|
93
|
-
end
|
94
|
-
#test with another program
|
95
|
-
def test_ls
|
96
|
-
cmd=ShellCommand.new(:cmd=>"ls")
|
97
|
-
assert(!cmd.run?)
|
98
|
-
assert(!cmd.success?)
|
99
|
-
|
100
|
-
assert(cmd.run?)
|
101
|
-
if cmd.success?
|
102
|
-
|
103
|
-
else
|
104
|
-
|
105
|
-
end
|
106
|
-
end
|
107
|
-
def test_timeout
|
108
|
-
cmd=ShellCommand.new(:cmd=>"ruby -e 't=0;while t<10 do p t;t+=1;sleep 1 end '",:timeout=>1)
|
109
|
-
|
110
|
-
assert(cmd.run?, "Should be marked as run")
|
111
|
-
assert(!cmd.success?,"Should not have been successful")
|
112
|
-
assert(!cmd.error.empty?, "There should be an error message")
|
113
|
-
#test also for an exit within the timeout
|
114
|
-
cmd=ShellCommand.new(:cmd=>"ruby -e 't=0;while t<1 do p t;t+=1;sleep 1 end '",:timeout=>4)
|
115
|
-
|
116
|
-
assert(cmd.run?, "Should be marked as run")
|
117
|
-
assert(cmd.success?,"Should have been successful")
|
118
|
-
assert(cmd.error.empty?, "There should be no error messages")
|
119
|
-
end
|
120
|
-
def test_missing_executable
|
121
|
-
cmd=ShellCommand.new(:cmd=>"bla")
|
122
|
-
assert(!cmd.run?)
|
123
|
-
assert(!cmd.success?)
|
124
|
-
|
125
|
-
assert(!cmd.success?, "Should fail if the executable is missing")
|
126
|
-
|
127
|
-
cmd=ShellCommand.new(:cmd=>'"With spaces" and params')
|
128
|
-
assert(!cmd.run?)
|
129
|
-
assert(!cmd.success?)
|
130
|
-
|
131
|
-
assert(!cmd.success?, "Should fail if the executable is missing")
|
132
|
-
end
|
133
|
-
end
|
134
|
-
|
135
|
-
class TestCommandSequence<Test
|
136
|
-
include Patir
|
137
|
-
def setup
|
138
|
-
@echo=ShellCommand.new(:cmd=>"echo hello")
|
139
|
-
@void=MockCommandObject.new
|
140
|
-
@error=MockCommandError.new
|
141
|
-
@warning=MockCommandWarning.new
|
142
|
-
end
|
143
|
-
|
144
|
-
def test_normal
|
145
|
-
seq=CommandSequence.new("test")
|
146
|
-
assert(seq.steps.empty?)
|
147
|
-
|
148
|
-
assert(!seq.state.success?)
|
149
|
-
assert_equal(:warning,seq.state.status)
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
assert(seq.state.success?)
|
154
|
-
end
|
155
|
-
|
156
|
-
def test_flunk_on_error
|
157
|
-
seq=CommandSequence.new("test")
|
158
|
-
assert(seq.steps.empty?)
|
159
|
-
check_step=nil
|
160
|
-
|
161
|
-
assert_equal(:flunk_on_error,check_step.strategy)
|
162
|
-
|
163
|
-
|
164
|
-
assert(:not_executed==seq.state.step_state(0)[:status])
|
165
|
-
assert(:not_executed==seq.state.step_state(1)[:status])
|
166
|
-
assert(:not_executed==seq.state.step_state(2)[:status])
|
167
|
-
|
168
|
-
assert(!seq.state.success?)
|
169
|
-
#all three steps should have been run
|
170
|
-
assert(:not_executed!=seq.state.step_state(0)[:status])
|
171
|
-
assert(:not_executed!=seq.state.step_state(1)[:status])
|
172
|
-
assert(:not_executed!=seq.state.step_state(2)[:status])
|
173
|
-
end
|
174
|
-
|
175
|
-
def test_fail_on_error
|
176
|
-
seq=CommandSequence.new("test")
|
177
|
-
assert(seq.steps.empty?)
|
178
|
-
|
179
|
-
check_step=nil
|
180
|
-
|
181
|
-
assert_equal(:fail_on_error,check_step.strategy)
|
182
|
-
|
183
|
-
assert(:not_executed==seq.state.step_state(0)[:status])
|
184
|
-
assert(:not_executed==seq.state.step_state(1)[:status])
|
185
|
-
assert(:not_executed==seq.state.step_state(2)[:status])
|
186
|
-
|
187
|
-
assert(!seq.state.success?)
|
188
|
-
#only two steps should have been run
|
189
|
-
assert(:not_executed!=seq.state.step_state(0)[:status])
|
190
|
-
assert(:not_executed!=seq.state.step_state(1)[:status])
|
191
|
-
assert(:not_executed==seq.state.step_state(2)[:status])
|
192
|
-
end
|
193
|
-
|
194
|
-
def test_flunk_on_warning
|
195
|
-
seq=CommandSequence.new("test")
|
196
|
-
assert(seq.steps.empty?)
|
197
|
-
|
198
|
-
check_step=nil
|
199
|
-
|
200
|
-
assert_equal(:flunk_on_warning,check_step.strategy)
|
201
|
-
|
202
|
-
assert(:not_executed==seq.state.step_state(0)[:status])
|
203
|
-
assert(:not_executed==seq.state.step_state(1)[:status])
|
204
|
-
assert(:not_executed==seq.state.step_state(2)[:status])
|
205
|
-
|
206
|
-
assert(!seq.state.success?)
|
207
|
-
#all three steps should have been run
|
208
|
-
assert(:not_executed!=seq.state.step_state(0)[:status])
|
209
|
-
assert(:not_executed!=seq.state.step_state(1)[:status])
|
210
|
-
assert(:not_executed!=seq.state.step_state(2)[:status])
|
211
|
-
end
|
212
|
-
|
213
|
-
def test_fail_on_warning
|
214
|
-
seq=CommandSequence.new("test")
|
215
|
-
assert(seq.steps.empty?)
|
216
|
-
|
217
|
-
check_step=nil
|
218
|
-
|
219
|
-
assert_equal(:fail_on_warning,check_step.strategy)
|
220
|
-
|
221
|
-
assert(:not_executed==seq.state.step_state(0)[:status])
|
222
|
-
assert(:not_executed==seq.state.step_state(1)[:status])
|
223
|
-
assert(:not_executed==seq.state.step_state(2)[:status])
|
224
|
-
|
225
|
-
assert(!seq.state.success?)
|
226
|
-
#only two steps should have been run
|
227
|
-
assert(:not_executed!=seq.state.step_state(0)[:status])
|
228
|
-
assert(:not_executed!=seq.state.step_state(1)[:status])
|
229
|
-
assert(:not_executed==seq.state.step_state(2)[:status])
|
230
|
-
end
|
231
|
-
end
|
232
|
-
|
233
|
-
class TestRubyCommand<Test
|
234
|
-
include Patir
|
235
|
-
def test_normal_ruby
|
236
|
-
cmd=RubyCommand.new("test"){sleep 1}
|
237
|
-
|
238
|
-
assert(cmd.success?, "Not successful.")
|
239
|
-
assert_equal(:success, cmd.status)
|
240
|
-
end
|
241
|
-
def test_error_ruby
|
242
|
-
cmd=RubyCommand.new("test"){raise "Error"}
|
243
|
-
|
244
|
-
assert(!cmd.success?, "Successful?!")
|
245
|
-
assert_equal("\nError", cmd.error)
|
246
|
-
assert_equal(:error, cmd.status)
|
247
|
-
end
|
248
|
-
def test_context
|
249
|
-
context="complex"
|
250
|
-
cmd=RubyCommand.new("test"){|c| c.output=c.context}
|
251
|
-
|
252
|
-
assert(cmd.success?, "Not successful.")
|
253
|
-
assert_equal(context, cmd.output)
|
254
|
-
|
255
|
-
assert_equal("other", cmd.output)
|
256
|
-
assert_equal(:success, cmd.status)
|
257
|
-
end
|
258
|
-
end
|
259
|
-
|
260
|
-
class TestCommandSequenceStatus<Test
|
261
|
-
def test_new
|
262
|
-
st=Patir::CommandSequenceStatus.new("sequence")
|
263
|
-
assert(!st.running?)
|
264
|
-
assert(!st.success?)
|
265
|
-
assert_equal(:not_executed, st.status)
|
266
|
-
assert_nil(st.step_state(3))
|
267
|
-
end
|
268
|
-
|
269
|
-
def test_step_equal
|
270
|
-
st=Patir::CommandSequenceStatus.new("sequence")
|
271
|
-
step1=MockCommandObject.new
|
272
|
-
step2=MockCommandWarning.new
|
273
|
-
step3=MockCommandError.new
|
274
|
-
step1.run
|
275
|
-
step1.number=1
|
276
|
-
step2.run
|
277
|
-
step2.number=2
|
278
|
-
step3.run
|
279
|
-
step3.number=3
|
280
|
-
st.step=step1
|
281
|
-
assert_equal(:success, st.status)
|
282
|
-
assert_equal(step1.status, st.step_state(1)[:status])
|
283
|
-
st.step=step2
|
284
|
-
assert_equal(:warning, st.status)
|
285
|
-
st.step=step3
|
286
|
-
assert_equal(:error, st.status)
|
287
|
-
step2.number=1
|
288
|
-
st.step=step2
|
289
|
-
assert_equal(step2.status, st.step_state(1)[:status])
|
290
|
-
assert_equal(:error, st.status)
|
291
|
-
st.step=step1
|
292
|
-
assert_equal(:error, st.status)
|
293
|
-
|
294
|
-
end
|
295
|
-
|
296
|
-
def test_completed?
|
297
|
-
st=Patir::CommandSequenceStatus.new("sequence")
|
298
|
-
step1=MockCommandObject.new
|
299
|
-
step1.number=1
|
300
|
-
step2=MockCommandWarning.new
|
301
|
-
step2.number=2
|
302
|
-
step3=MockCommandError.new
|
303
|
-
step3.number=3
|
304
|
-
step4=MockCommandObject.new
|
305
|
-
step4.number=4
|
306
|
-
st.step=step1
|
307
|
-
st.step=step2
|
308
|
-
st.step=step3
|
309
|
-
st.step=step4
|
310
|
-
assert(!st.completed?, "should not be complete.")
|
311
|
-
step1.run
|
312
|
-
st.step=step1
|
313
|
-
assert(!st.completed?, "should not be complete.")
|
314
|
-
step2.run
|
315
|
-
st.step=step2
|
316
|
-
assert(!st.completed?, "should not be complete.")
|
317
|
-
step2.strategy=:fail_on_warning
|
318
|
-
st.step=step2
|
319
|
-
assert(st.completed?, "should be complete.")
|
320
|
-
step2.strategy=nil
|
321
|
-
st.step=step2
|
322
|
-
assert(!st.completed?, "should not be complete.")
|
323
|
-
step3.run
|
324
|
-
step3.strategy=:fail_on_error
|
325
|
-
st.step=step3
|
326
|
-
assert(st.completed?, "should be complete.")
|
327
|
-
step3.strategy=nil
|
328
|
-
st.step=step3
|
329
|
-
assert(!st.completed?, "should not be complete.")
|
330
|
-
step4.run
|
331
|
-
st.step=step4
|
332
|
-
assert(st.completed?, "should be complete.")
|
333
|
-
|
334
|
-
end
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
require "minitest/autorun"
|
3
|
+
require 'patir/command.rb'
|
4
|
+
|
5
|
+
class MockCommandObject
|
6
|
+
include Patir::Command
|
7
|
+
end
|
8
|
+
|
9
|
+
class MockCommandWarning
|
10
|
+
include Patir::Command
|
11
|
+
def run context=nil
|
12
|
+
@status=:warning
|
13
|
+
return :warning
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class MockCommandError
|
18
|
+
include Patir::Command
|
19
|
+
def run context=nil
|
20
|
+
@status=:error
|
21
|
+
return :error
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class TestCommand<Minitest::Test
|
26
|
+
#tests the default values set by the module
|
27
|
+
def test_module
|
28
|
+
obj=MockCommandObject.new
|
29
|
+
assert_equal("",obj.name)
|
30
|
+
assert_equal(:not_executed,obj.status)
|
31
|
+
assert(!obj.run?)
|
32
|
+
assert(obj.run)
|
33
|
+
assert(obj.run?)
|
34
|
+
assert_equal(:success,obj.status)
|
35
|
+
assert_equal("",obj.output)
|
36
|
+
assert_equal("",obj.error)
|
37
|
+
assert_equal(0,obj.exec_time)
|
38
|
+
assert(obj.reset)
|
39
|
+
assert_equal(:not_executed,obj.status)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class TestShellCommand<Minitest::Test
|
44
|
+
include Patir
|
45
|
+
def teardown
|
46
|
+
Dir.delete("missing/") if File.exist?("missing/")
|
47
|
+
end
|
48
|
+
#test the expected behaviour of a succesfull command
|
49
|
+
def test_echo
|
50
|
+
cmd=nil
|
51
|
+
assert(cmd=ShellCommand.new(:cmd=>"echo hello"))
|
52
|
+
assert_instance_of(ShellCommand,cmd)
|
53
|
+
assert(!cmd.run?)
|
54
|
+
assert(!cmd.success?)
|
55
|
+
assert(cmd.run)
|
56
|
+
assert(cmd.run?)
|
57
|
+
assert(cmd.success?)
|
58
|
+
assert_equal("hello",cmd.output.chomp)
|
59
|
+
assert_equal("",cmd.error)
|
60
|
+
assert_equal(:success,cmd.status)
|
61
|
+
end
|
62
|
+
#test that error status is reported correctly, by testing a command that fails.
|
63
|
+
def test_error
|
64
|
+
cmd=nil
|
65
|
+
assert(cmd=ShellCommand.new(:cmd=>"cd /missing"))
|
66
|
+
assert(!cmd.run?)
|
67
|
+
assert(!cmd.success?)
|
68
|
+
assert(cmd.run)
|
69
|
+
assert(cmd.run?)
|
70
|
+
assert(!cmd.success?)
|
71
|
+
assert_equal(:error,cmd.status)
|
72
|
+
end
|
73
|
+
#when passed a wroking directory, the command should change into that directory
|
74
|
+
def test_cwd
|
75
|
+
cmd=nil
|
76
|
+
assert(cmd=ShellCommand.new(:cmd=>"echo", :working_directory=>"missing/"))
|
77
|
+
assert(cmd.run)
|
78
|
+
assert(cmd.success?)
|
79
|
+
end
|
80
|
+
|
81
|
+
#when the working directory is missing, it should be created when the command is run
|
82
|
+
def test_missing_cwd
|
83
|
+
cmd=nil
|
84
|
+
assert(cmd=ShellCommand.new(:cmd=>"echo hello", :working_directory=>"missing/"))
|
85
|
+
assert_instance_of(ShellCommand,cmd)
|
86
|
+
assert_equal(:success,cmd.run)
|
87
|
+
assert(cmd.success?)
|
88
|
+
assert(File.exist?("missing/"))
|
89
|
+
end
|
90
|
+
#an exception should be thrown when :cmd is nil
|
91
|
+
def test_missing_cmd
|
92
|
+
assert_raises(ParameterException){ShellCommand.new(:working_directory=>"missing/")}
|
93
|
+
end
|
94
|
+
#test with another program
|
95
|
+
def test_ls
|
96
|
+
cmd=ShellCommand.new(:cmd=>"ls")
|
97
|
+
assert(!cmd.run?)
|
98
|
+
assert(!cmd.success?)
|
99
|
+
assert(cmd.run)
|
100
|
+
assert(cmd.run?)
|
101
|
+
if cmd.success?
|
102
|
+
refute_equal("", cmd.output)
|
103
|
+
else
|
104
|
+
refute_equal("", cmd.error)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
def test_timeout
|
108
|
+
cmd=ShellCommand.new(:cmd=>"ruby -e 't=0;while t<10 do p t;t+=1;sleep 1 end '",:timeout=>1)
|
109
|
+
assert(cmd.run)
|
110
|
+
assert(cmd.run?, "Should be marked as run")
|
111
|
+
assert(!cmd.success?,"Should not have been successful")
|
112
|
+
assert(!cmd.error.empty?, "There should be an error message")
|
113
|
+
#test also for an exit within the timeout
|
114
|
+
cmd=ShellCommand.new(:cmd=>"ruby -e 't=0;while t<1 do p t;t+=1;sleep 1 end '",:timeout=>4)
|
115
|
+
assert(cmd.run)
|
116
|
+
assert(cmd.run?, "Should be marked as run")
|
117
|
+
assert(cmd.success?,"Should have been successful")
|
118
|
+
assert(cmd.error.empty?, "There should be no error messages")
|
119
|
+
end
|
120
|
+
def test_missing_executable
|
121
|
+
cmd=ShellCommand.new(:cmd=>"bla")
|
122
|
+
assert(!cmd.run?)
|
123
|
+
assert(!cmd.success?)
|
124
|
+
assert(cmd.run)
|
125
|
+
assert(!cmd.success?, "Should fail if the executable is missing")
|
126
|
+
|
127
|
+
cmd=ShellCommand.new(:cmd=>'"With spaces" and params')
|
128
|
+
assert(!cmd.run?)
|
129
|
+
assert(!cmd.success?)
|
130
|
+
assert(cmd.run)
|
131
|
+
assert(!cmd.success?, "Should fail if the executable is missing")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class TestCommandSequence<Minitest::Test
|
136
|
+
include Patir
|
137
|
+
def setup
|
138
|
+
@echo=ShellCommand.new(:cmd=>"echo hello")
|
139
|
+
@void=MockCommandObject.new
|
140
|
+
@error=MockCommandError.new
|
141
|
+
@warning=MockCommandWarning.new
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_normal
|
145
|
+
seq=CommandSequence.new("test")
|
146
|
+
assert(seq.steps.empty?)
|
147
|
+
refute_nil(seq.run)
|
148
|
+
assert(!seq.state.success?)
|
149
|
+
assert_equal(:warning,seq.state.status)
|
150
|
+
assert(seq.add_step(@echo))
|
151
|
+
assert(seq.add_step(@void))
|
152
|
+
refute_nil(seq.run)
|
153
|
+
assert(seq.state.success?)
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_flunk_on_error
|
157
|
+
seq=CommandSequence.new("test")
|
158
|
+
assert(seq.steps.empty?)
|
159
|
+
check_step=nil
|
160
|
+
assert(check_step=seq.add_step(@echo,:flunk_on_error))
|
161
|
+
assert_equal(:flunk_on_error,check_step.strategy)
|
162
|
+
assert(seq.add_step(@error,:flunk_on_error))
|
163
|
+
assert(seq.add_step(@void,:flunk_on_error))
|
164
|
+
assert(:not_executed==seq.state.step_state(0)[:status])
|
165
|
+
assert(:not_executed==seq.state.step_state(1)[:status])
|
166
|
+
assert(:not_executed==seq.state.step_state(2)[:status])
|
167
|
+
refute_nil(seq.run)
|
168
|
+
assert(!seq.state.success?)
|
169
|
+
#all three steps should have been run
|
170
|
+
assert(:not_executed!=seq.state.step_state(0)[:status])
|
171
|
+
assert(:not_executed!=seq.state.step_state(1)[:status])
|
172
|
+
assert(:not_executed!=seq.state.step_state(2)[:status])
|
173
|
+
end
|
174
|
+
|
175
|
+
def test_fail_on_error
|
176
|
+
seq=CommandSequence.new("test")
|
177
|
+
assert(seq.steps.empty?)
|
178
|
+
assert(seq.add_step(@echo))
|
179
|
+
check_step=nil
|
180
|
+
assert(check_step=seq.add_step(@error,:fail_on_error))
|
181
|
+
assert_equal(:fail_on_error,check_step.strategy)
|
182
|
+
assert(seq.add_step(@void))
|
183
|
+
assert(:not_executed==seq.state.step_state(0)[:status])
|
184
|
+
assert(:not_executed==seq.state.step_state(1)[:status])
|
185
|
+
assert(:not_executed==seq.state.step_state(2)[:status])
|
186
|
+
refute_nil(seq.run)
|
187
|
+
assert(!seq.state.success?)
|
188
|
+
#only two steps should have been run
|
189
|
+
assert(:not_executed!=seq.state.step_state(0)[:status])
|
190
|
+
assert(:not_executed!=seq.state.step_state(1)[:status])
|
191
|
+
assert(:not_executed==seq.state.step_state(2)[:status])
|
192
|
+
end
|
193
|
+
|
194
|
+
def test_flunk_on_warning
|
195
|
+
seq=CommandSequence.new("test")
|
196
|
+
assert(seq.steps.empty?)
|
197
|
+
assert(seq.add_step(@echo))
|
198
|
+
check_step=nil
|
199
|
+
assert(check_step=seq.add_step(@error,:flunk_on_warning))
|
200
|
+
assert_equal(:flunk_on_warning,check_step.strategy)
|
201
|
+
assert(seq.add_step(@void))
|
202
|
+
assert(:not_executed==seq.state.step_state(0)[:status])
|
203
|
+
assert(:not_executed==seq.state.step_state(1)[:status])
|
204
|
+
assert(:not_executed==seq.state.step_state(2)[:status])
|
205
|
+
refute_nil(seq.run)
|
206
|
+
assert(!seq.state.success?)
|
207
|
+
#all three steps should have been run
|
208
|
+
assert(:not_executed!=seq.state.step_state(0)[:status])
|
209
|
+
assert(:not_executed!=seq.state.step_state(1)[:status])
|
210
|
+
assert(:not_executed!=seq.state.step_state(2)[:status])
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_fail_on_warning
|
214
|
+
seq=CommandSequence.new("test")
|
215
|
+
assert(seq.steps.empty?)
|
216
|
+
assert(seq.add_step(@echo))
|
217
|
+
check_step=nil
|
218
|
+
assert(check_step=seq.add_step(@warning,:fail_on_warning))
|
219
|
+
assert_equal(:fail_on_warning,check_step.strategy)
|
220
|
+
assert(seq.add_step(@void))
|
221
|
+
assert(:not_executed==seq.state.step_state(0)[:status])
|
222
|
+
assert(:not_executed==seq.state.step_state(1)[:status])
|
223
|
+
assert(:not_executed==seq.state.step_state(2)[:status])
|
224
|
+
refute_nil(seq.run)
|
225
|
+
assert(!seq.state.success?)
|
226
|
+
#only two steps should have been run
|
227
|
+
assert(:not_executed!=seq.state.step_state(0)[:status])
|
228
|
+
assert(:not_executed!=seq.state.step_state(1)[:status])
|
229
|
+
assert(:not_executed==seq.state.step_state(2)[:status])
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
class TestRubyCommand<Minitest::Test
|
234
|
+
include Patir
|
235
|
+
def test_normal_ruby
|
236
|
+
cmd=RubyCommand.new("test"){sleep 1}
|
237
|
+
assert(cmd.run)
|
238
|
+
assert(cmd.success?, "Not successful.")
|
239
|
+
assert_equal(:success, cmd.status)
|
240
|
+
end
|
241
|
+
def test_error_ruby
|
242
|
+
cmd=RubyCommand.new("test"){raise "Error"}
|
243
|
+
assert(cmd.run)
|
244
|
+
assert(!cmd.success?, "Successful?!")
|
245
|
+
assert_equal("\nError", cmd.error)
|
246
|
+
assert_equal(:error, cmd.status)
|
247
|
+
end
|
248
|
+
def test_context
|
249
|
+
context="complex"
|
250
|
+
cmd=RubyCommand.new("test"){|c| c.output=c.context}
|
251
|
+
assert(cmd.run(context))
|
252
|
+
assert(cmd.success?, "Not successful.")
|
253
|
+
assert_equal(context, cmd.output)
|
254
|
+
assert(cmd.run("other"))
|
255
|
+
assert_equal("other", cmd.output)
|
256
|
+
assert_equal(:success, cmd.status)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
class TestCommandSequenceStatus<Minitest::Test
|
261
|
+
def test_new
|
262
|
+
st=Patir::CommandSequenceStatus.new("sequence")
|
263
|
+
assert(!st.running?)
|
264
|
+
assert(!st.success?)
|
265
|
+
assert_equal(:not_executed, st.status)
|
266
|
+
assert_nil(st.step_state(3))
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_step_equal
|
270
|
+
st=Patir::CommandSequenceStatus.new("sequence")
|
271
|
+
step1=MockCommandObject.new
|
272
|
+
step2=MockCommandWarning.new
|
273
|
+
step3=MockCommandError.new
|
274
|
+
step1.run
|
275
|
+
step1.number=1
|
276
|
+
step2.run
|
277
|
+
step2.number=2
|
278
|
+
step3.run
|
279
|
+
step3.number=3
|
280
|
+
st.step=step1
|
281
|
+
assert_equal(:success, st.status)
|
282
|
+
assert_equal(step1.status, st.step_state(1)[:status])
|
283
|
+
st.step=step2
|
284
|
+
assert_equal(:warning, st.status)
|
285
|
+
st.step=step3
|
286
|
+
assert_equal(:error, st.status)
|
287
|
+
step2.number=1
|
288
|
+
st.step=step2
|
289
|
+
assert_equal(step2.status, st.step_state(1)[:status])
|
290
|
+
assert_equal(:error, st.status)
|
291
|
+
st.step=step1
|
292
|
+
assert_equal(:error, st.status)
|
293
|
+
refute_nil(st.summary)
|
294
|
+
end
|
295
|
+
|
296
|
+
def test_completed?
|
297
|
+
st=Patir::CommandSequenceStatus.new("sequence")
|
298
|
+
step1=MockCommandObject.new
|
299
|
+
step1.number=1
|
300
|
+
step2=MockCommandWarning.new
|
301
|
+
step2.number=2
|
302
|
+
step3=MockCommandError.new
|
303
|
+
step3.number=3
|
304
|
+
step4=MockCommandObject.new
|
305
|
+
step4.number=4
|
306
|
+
st.step=step1
|
307
|
+
st.step=step2
|
308
|
+
st.step=step3
|
309
|
+
st.step=step4
|
310
|
+
assert(!st.completed?, "should not be complete.")
|
311
|
+
step1.run
|
312
|
+
st.step=step1
|
313
|
+
assert(!st.completed?, "should not be complete.")
|
314
|
+
step2.run
|
315
|
+
st.step=step2
|
316
|
+
assert(!st.completed?, "should not be complete.")
|
317
|
+
step2.strategy=:fail_on_warning
|
318
|
+
st.step=step2
|
319
|
+
assert(st.completed?, "should be complete.")
|
320
|
+
step2.strategy=nil
|
321
|
+
st.step=step2
|
322
|
+
assert(!st.completed?, "should not be complete.")
|
323
|
+
step3.run
|
324
|
+
step3.strategy=:fail_on_error
|
325
|
+
st.step=step3
|
326
|
+
assert(st.completed?, "should be complete.")
|
327
|
+
step3.strategy=nil
|
328
|
+
st.step=step3
|
329
|
+
assert(!st.completed?, "should not be complete.")
|
330
|
+
step4.run
|
331
|
+
st.step=step4
|
332
|
+
assert(st.completed?, "should be complete.")
|
333
|
+
refute_nil(st.summary)
|
334
|
+
end
|
335
335
|
end
|