patir 0.8.1 → 0.8.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/History.txt +81 -77
- data/Manifest.txt +16 -16
- data/README.txt +37 -37
- data/Rakefile +18 -20
- data/lib/patir/base.rb +1 -1
- data/lib/patir/command.rb +6 -4
- 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 -320
- data/test/test_patir_configuration.rb +27 -27
- metadata +41 -49
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 'test/unit'
|
3
|
-
require 'patir/base.rb'
|
4
|
-
|
5
|
-
class TestBase<Test::Unit::TestCase
|
6
|
-
TEMP_LOG="temp.log"
|
7
|
-
def teardown
|
8
|
-
#clean up
|
9
|
-
File.delete(TEMP_LOG) if File.
|
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
|
-
assert_not_nil(logger)
|
17
|
-
logger=Patir.setup_logger(nil,:silent)
|
18
|
-
assert_not_nil(logger)
|
19
|
-
logger=Patir.setup_logger("temp.log",:silent)
|
20
|
-
assert_not_nil(logger)
|
21
|
-
assert(File.
|
22
|
-
logger.close
|
23
|
-
end
|
24
|
-
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
require 'test/unit'
|
3
|
+
require 'patir/base.rb'
|
4
|
+
|
5
|
+
class TestBase<Test::Unit::TestCase
|
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
|
+
assert_not_nil(logger)
|
17
|
+
logger=Patir.setup_logger(nil,:silent)
|
18
|
+
assert_not_nil(logger)
|
19
|
+
logger=Patir.setup_logger("temp.log",:silent)
|
20
|
+
assert_not_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,321 +1,335 @@
|
|
1
|
-
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
-
require 'test/unit'
|
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::Unit::TestCase
|
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_nothing_raised{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_nothing_raised{obj.reset}
|
39
|
-
assert_equal(:not_executed,obj.status)
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
class TestShellCommand<Test::Unit::TestCase
|
44
|
-
include Patir
|
45
|
-
def teardown
|
46
|
-
Dir.delete("missing/") if File.
|
47
|
-
end
|
48
|
-
#test the expected behaviour of a succesfull command
|
49
|
-
def test_echo
|
50
|
-
cmd=nil
|
51
|
-
assert_nothing_raised(){cmd=ShellCommand.new(:cmd=>"echo hello")}
|
52
|
-
assert_not_nil(cmd)
|
53
|
-
assert(!cmd.run?)
|
54
|
-
assert(!cmd.success?)
|
55
|
-
assert_nothing_raised(){cmd.run}
|
56
|
-
assert(cmd.run?)
|
57
|
-
assert(cmd.success?)
|
58
|
-
assert_equal("hello
|
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_nothing_raised(){cmd=ShellCommand.new(:cmd=>"cd /missing")}
|
66
|
-
assert(!cmd.run?)
|
67
|
-
assert(!cmd.success?)
|
68
|
-
assert_nothing_raised(){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_nothing_raised(){cmd=ShellCommand.new(:cmd=>"echo", :working_directory=>"missing/")}
|
77
|
-
assert_nothing_raised(){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_nothing_raised(){cmd=ShellCommand.new(:cmd=>"echo hello", :working_directory=>"missing/")}
|
85
|
-
assert_not_nil(cmd)
|
86
|
-
assert_equal(:success,cmd.run)
|
87
|
-
assert(cmd.success?)
|
88
|
-
assert(File.
|
89
|
-
end
|
90
|
-
#an exception should be thrown when :cmd is nil
|
91
|
-
def test_missing_cmd
|
92
|
-
assert_raise(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_nothing_raised(){cmd.run}
|
100
|
-
assert(cmd.run?)
|
101
|
-
if cmd.success?
|
102
|
-
assert_not_equal("", cmd.output)
|
103
|
-
else
|
104
|
-
assert_not_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_nothing_raised() { 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_nothing_raised() { 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
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
assert_nothing_raised{
|
148
|
-
|
149
|
-
|
150
|
-
assert_nothing_raised{seq.add_step(@
|
151
|
-
|
152
|
-
|
153
|
-
assert(
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
assert(
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
seq
|
164
|
-
assert(seq.
|
165
|
-
|
166
|
-
|
167
|
-
assert_nothing_raised{
|
168
|
-
|
169
|
-
|
170
|
-
assert(:not_executed
|
171
|
-
assert(:not_executed
|
172
|
-
assert(:not_executed
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
assert(
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
seq
|
183
|
-
assert(seq.
|
184
|
-
|
185
|
-
|
186
|
-
assert_nothing_raised{
|
187
|
-
|
188
|
-
|
189
|
-
assert(:not_executed
|
190
|
-
assert(:not_executed
|
191
|
-
assert(:not_executed==seq.state.step_state(2)[:status])
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
assert(
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
seq
|
202
|
-
assert(seq.
|
203
|
-
|
204
|
-
|
205
|
-
assert_nothing_raised{
|
206
|
-
|
207
|
-
|
208
|
-
assert(:not_executed
|
209
|
-
assert(:not_executed
|
210
|
-
assert(:not_executed
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
assert(
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
assert_nothing_raised
|
225
|
-
assert(
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
cmd=RubyCommand.new("test"){
|
237
|
-
assert_nothing_raised() { cmd.run
|
238
|
-
assert(cmd.success?, "Not successful.")
|
239
|
-
assert_equal(
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
st.
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
st=
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
step2.number=
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
st.
|
293
|
-
st.
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
step2.
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
st.step=step2
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__),"..","lib")
|
2
|
+
require 'test/unit'
|
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::Unit::TestCase
|
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_nothing_raised{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_nothing_raised{obj.reset}
|
39
|
+
assert_equal(:not_executed,obj.status)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
class TestShellCommand<Test::Unit::TestCase
|
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_nothing_raised(){cmd=ShellCommand.new(:cmd=>"echo hello")}
|
52
|
+
assert_not_nil(cmd)
|
53
|
+
assert(!cmd.run?)
|
54
|
+
assert(!cmd.success?)
|
55
|
+
assert_nothing_raised(){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_nothing_raised(){cmd=ShellCommand.new(:cmd=>"cd /missing")}
|
66
|
+
assert(!cmd.run?)
|
67
|
+
assert(!cmd.success?)
|
68
|
+
assert_nothing_raised(){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_nothing_raised(){cmd=ShellCommand.new(:cmd=>"echo", :working_directory=>"missing/")}
|
77
|
+
assert_nothing_raised(){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_nothing_raised(){cmd=ShellCommand.new(:cmd=>"echo hello", :working_directory=>"missing/")}
|
85
|
+
assert_not_nil(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_raise(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_nothing_raised(){cmd.run}
|
100
|
+
assert(cmd.run?)
|
101
|
+
if cmd.success?
|
102
|
+
assert_not_equal("", cmd.output)
|
103
|
+
else
|
104
|
+
assert_not_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_nothing_raised() { 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_nothing_raised() { 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_nothing_raised(){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_nothing_raised(){cmd.run}
|
131
|
+
assert(!cmd.success?, "Should fail if the executable is missing")
|
132
|
+
end
|
133
|
+
end
|
134
|
+
|
135
|
+
class TestCommandSequence<Test::Unit::TestCase
|
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
|
+
assert_nothing_raised{seq.run}
|
148
|
+
assert(!seq.state.success?)
|
149
|
+
assert_equal(:warning,seq.state.status)
|
150
|
+
assert_nothing_raised{seq.add_step(@echo)}
|
151
|
+
assert_nothing_raised{seq.add_step(@void)}
|
152
|
+
assert_nothing_raised{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_nothing_raised{check_step=seq.add_step(@echo,:flunk_on_error)}
|
161
|
+
assert_equal(:flunk_on_error,check_step.strategy)
|
162
|
+
assert_nothing_raised{seq.add_step(@error,:flunk_on_error)}
|
163
|
+
assert_nothing_raised{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
|
+
assert_nothing_raised{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_nothing_raised{seq.add_step(@echo)}
|
179
|
+
check_step=nil
|
180
|
+
assert_nothing_raised{check_step=seq.add_step(@error,:fail_on_error)}
|
181
|
+
assert_equal(:fail_on_error,check_step.strategy)
|
182
|
+
assert_nothing_raised{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
|
+
assert_nothing_raised{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_nothing_raised{seq.add_step(@echo)}
|
198
|
+
check_step=nil
|
199
|
+
assert_nothing_raised{check_step=seq.add_step(@error,:flunk_on_warning)}
|
200
|
+
assert_equal(:flunk_on_warning,check_step.strategy)
|
201
|
+
assert_nothing_raised{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
|
+
assert_nothing_raised{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_nothing_raised{seq.add_step(@echo)}
|
217
|
+
check_step=nil
|
218
|
+
assert_nothing_raised{check_step=seq.add_step(@warning,:fail_on_warning)}
|
219
|
+
assert_equal(:fail_on_warning,check_step.strategy)
|
220
|
+
assert_nothing_raised{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
|
+
assert_nothing_raised{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<Test::Unit::TestCase
|
234
|
+
include Patir
|
235
|
+
def test_normal_ruby
|
236
|
+
cmd=RubyCommand.new("test"){sleep 1}
|
237
|
+
assert_nothing_raised() { 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_nothing_raised() { 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_nothing_raised() { cmd.run(context)}
|
252
|
+
assert(cmd.success?, "Not successful.")
|
253
|
+
assert_equal(context, cmd.output)
|
254
|
+
assert_nothing_raised() { cmd.run("other")}
|
255
|
+
assert_equal("other", cmd.output)
|
256
|
+
assert_equal(:success, cmd.status)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
class TestCommandSequenceStatus<Test::Unit::TestCase
|
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
|
+
assert_nothing_raised() { puts 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
|
+
assert_nothing_raised() { puts st.summary }
|
334
|
+
end
|
321
335
|
end
|