patir 0.8.1 → 0.8.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,2 @@
1
- #ruby syntax error
1
+ #ruby syntax error
2
2
  {
@@ -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.exists?(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.exists?(TEMP_LOG), "Log file not created")
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
@@ -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.exists?("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\n",cmd.output)
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.exists?("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
- end
121
-
122
- class TestCommandSequence<Test::Unit::TestCase
123
- include Patir
124
- def setup
125
- @echo=ShellCommand.new(:cmd=>"echo hello")
126
- @void=MockCommandObject.new
127
- @error=MockCommandError.new
128
- @warning=MockCommandWarning.new
129
- end
130
-
131
- def test_normal
132
- seq=CommandSequence.new("test")
133
- assert(seq.steps.empty?)
134
- assert_nothing_raised{seq.run}
135
- assert(!seq.state.success?)
136
- assert_equal(:warning,seq.state.status)
137
- assert_nothing_raised{seq.add_step(@echo)}
138
- assert_nothing_raised{seq.add_step(@void)}
139
- assert_nothing_raised{seq.run}
140
- assert(seq.state.success?)
141
- end
142
-
143
- def test_flunk_on_error
144
- seq=CommandSequence.new("test")
145
- assert(seq.steps.empty?)
146
- check_step=nil
147
- assert_nothing_raised{check_step=seq.add_step(@echo,:flunk_on_error)}
148
- assert_equal(:flunk_on_error,check_step.strategy)
149
- assert_nothing_raised{seq.add_step(@error,:flunk_on_error)}
150
- assert_nothing_raised{seq.add_step(@void,:flunk_on_error)}
151
- assert(:not_executed==seq.state.step_state(0)[:status])
152
- assert(:not_executed==seq.state.step_state(1)[:status])
153
- assert(:not_executed==seq.state.step_state(2)[:status])
154
- assert_nothing_raised{seq.run}
155
- assert(!seq.state.success?)
156
- #all three steps should have been run
157
- assert(:not_executed!=seq.state.step_state(0)[:status])
158
- assert(:not_executed!=seq.state.step_state(1)[:status])
159
- assert(:not_executed!=seq.state.step_state(2)[:status])
160
- end
161
-
162
- def test_fail_on_error
163
- seq=CommandSequence.new("test")
164
- assert(seq.steps.empty?)
165
- assert_nothing_raised{seq.add_step(@echo)}
166
- check_step=nil
167
- assert_nothing_raised{check_step=seq.add_step(@error,:fail_on_error)}
168
- assert_equal(:fail_on_error,check_step.strategy)
169
- assert_nothing_raised{seq.add_step(@void)}
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
- assert_nothing_raised{seq.run}
174
- assert(!seq.state.success?)
175
- #only two steps should have been run
176
- assert(:not_executed!=seq.state.step_state(0)[:status])
177
- assert(:not_executed!=seq.state.step_state(1)[:status])
178
- assert(:not_executed==seq.state.step_state(2)[:status])
179
- end
180
-
181
- def test_flunk_on_warning
182
- seq=CommandSequence.new("test")
183
- assert(seq.steps.empty?)
184
- assert_nothing_raised{seq.add_step(@echo)}
185
- check_step=nil
186
- assert_nothing_raised{check_step=seq.add_step(@error,:flunk_on_warning)}
187
- assert_equal(:flunk_on_warning,check_step.strategy)
188
- assert_nothing_raised{seq.add_step(@void)}
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
- assert_nothing_raised{seq.run}
193
- assert(!seq.state.success?)
194
- #all three steps should have been run
195
- assert(:not_executed!=seq.state.step_state(0)[:status])
196
- assert(:not_executed!=seq.state.step_state(1)[:status])
197
- assert(:not_executed!=seq.state.step_state(2)[:status])
198
- end
199
-
200
- def test_fail_on_warning
201
- seq=CommandSequence.new("test")
202
- assert(seq.steps.empty?)
203
- assert_nothing_raised{seq.add_step(@echo)}
204
- check_step=nil
205
- assert_nothing_raised{check_step=seq.add_step(@warning,:fail_on_warning)}
206
- assert_equal(:fail_on_warning,check_step.strategy)
207
- assert_nothing_raised{seq.add_step(@void)}
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
- assert_nothing_raised{seq.run}
212
- assert(!seq.state.success?)
213
- #only two steps should have been run
214
- assert(:not_executed!=seq.state.step_state(0)[:status])
215
- assert(:not_executed!=seq.state.step_state(1)[:status])
216
- assert(:not_executed==seq.state.step_state(2)[:status])
217
- end
218
- end
219
-
220
- class TestRubyCommand<Test::Unit::TestCase
221
- include Patir
222
- def test_normal_ruby
223
- cmd=RubyCommand.new("test"){sleep 1}
224
- assert_nothing_raised() { cmd.run}
225
- assert(cmd.success?, "Not successful.")
226
- assert_equal(:success, cmd.status)
227
- end
228
- def test_error_ruby
229
- cmd=RubyCommand.new("test"){raise "Error"}
230
- assert_nothing_raised() { cmd.run}
231
- assert(!cmd.success?, "Successful?!")
232
- assert_equal(:error, cmd.status)
233
- end
234
- def test_context
235
- context="complex"
236
- cmd=RubyCommand.new("test"){|c| c.output=c.context}
237
- assert_nothing_raised() { cmd.run(context)}
238
- assert(cmd.success?, "Not successful.")
239
- assert_equal(context, cmd.output)
240
- assert_nothing_raised() { cmd.run("other")}
241
- assert_equal("other", cmd.output)
242
- assert_equal(:success, cmd.status)
243
- end
244
- end
245
-
246
- class TestCommandSequenceStatus<Test::Unit::TestCase
247
- def test_new
248
- st=Patir::CommandSequenceStatus.new("sequence")
249
- assert(!st.running?)
250
- assert(!st.success?)
251
- assert_equal(:not_executed, st.status)
252
- assert_nil(st.step_state(3))
253
- end
254
-
255
- def test_step_equal
256
- st=Patir::CommandSequenceStatus.new("sequence")
257
- step1=MockCommandObject.new
258
- step2=MockCommandWarning.new
259
- step3=MockCommandError.new
260
- step1.run
261
- step1.number=1
262
- step2.run
263
- step2.number=2
264
- step3.run
265
- step3.number=3
266
- st.step=step1
267
- assert_equal(:success, st.status)
268
- assert_equal(step1.status, st.step_state(1)[:status])
269
- st.step=step2
270
- assert_equal(:warning, st.status)
271
- st.step=step3
272
- assert_equal(:error, st.status)
273
- step2.number=1
274
- st.step=step2
275
- assert_equal(step2.status, st.step_state(1)[:status])
276
- assert_equal(:error, st.status)
277
- st.step=step1
278
- assert_equal(:error, st.status)
279
- assert_nothing_raised() { puts st.summary }
280
- end
281
-
282
- def test_completed?
283
- st=Patir::CommandSequenceStatus.new("sequence")
284
- step1=MockCommandObject.new
285
- step1.number=1
286
- step2=MockCommandWarning.new
287
- step2.number=2
288
- step3=MockCommandError.new
289
- step3.number=3
290
- step4=MockCommandObject.new
291
- step4.number=4
292
- st.step=step1
293
- st.step=step2
294
- st.step=step3
295
- st.step=step4
296
- assert(!st.completed?, "should not be complete.")
297
- step1.run
298
- st.step=step1
299
- assert(!st.completed?, "should not be complete.")
300
- step2.run
301
- st.step=step2
302
- assert(!st.completed?, "should not be complete.")
303
- step2.strategy=:fail_on_warning
304
- st.step=step2
305
- assert(st.completed?, "should be complete.")
306
- step2.strategy=nil
307
- st.step=step2
308
- assert(!st.completed?, "should not be complete.")
309
- step3.run
310
- step3.strategy=:fail_on_error
311
- st.step=step3
312
- assert(st.completed?, "should be complete.")
313
- step3.strategy=nil
314
- st.step=step3
315
- assert(!st.completed?, "should not be complete.")
316
- step4.run
317
- st.step=step4
318
- assert(st.completed?, "should be complete.")
319
- assert_nothing_raised() { puts st.summary }
320
- end
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