razorrisk-razor-control 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/RakeFile +46 -0
  3. data/lib/razor_risk/razor/control/cucumber_helpers/consolidate_reports.rb +80 -0
  4. data/lib/razor_risk/razor/control/cucumber_helpers/executor.rb +108 -0
  5. data/lib/razor_risk/razor/control/cucumber_helpers.rb +3 -0
  6. data/lib/razor_risk/razor/control/diagnostics/util_functions.rb +203 -0
  7. data/lib/razor_risk/razor/control/diagnostics/zeroth_include.rb +27 -0
  8. data/lib/razor_risk/razor/control/exceptions.rb +121 -0
  9. data/lib/razor_risk/razor/control/gem/gem_helpers.rb +397 -0
  10. data/lib/razor_risk/razor/control/rake_helpers/aborter.rb +90 -0
  11. data/lib/razor_risk/razor/control/rake_helpers/diagnostic_tasks.rb +74 -0
  12. data/lib/razor_risk/razor/control/rake_helpers/gem_tasks.rb +128 -0
  13. data/lib/razor_risk/razor/control/rake_helpers/razor_tasks.rb +195 -0
  14. data/lib/razor_risk/razor/control/rake_helpers/task_helpers.rb +86 -0
  15. data/lib/razor_risk/razor/control/rake_helpers.rb +3 -0
  16. data/lib/razor_risk/razor/control/razor/executor.rb +131 -0
  17. data/lib/razor_risk/razor/control/razor/razor_instance.rb +227 -0
  18. data/lib/razor_risk/razor/control/razor.rb +2 -0
  19. data/lib/razor_risk/razor/control/version.rb +41 -0
  20. data/test/unit/control/cucumber_helpers/reports/expected/groups.html +213 -0
  21. data/test/unit/control/cucumber_helpers/reports/expected/no_groups.html +170 -0
  22. data/test/unit/control/cucumber_helpers/reports/groups/LbbwConfig/LbbwConfig.json +69 -0
  23. data/test/unit/control/cucumber_helpers/reports/groups/StandardConfig/StandardConfig.json +69 -0
  24. data/test/unit/control/cucumber_helpers/reports/no_groups/LbbwConfig.json +69 -0
  25. data/test/unit/control/cucumber_helpers/reports/no_groups/StandardConfig/StandardConfig.json +69 -0
  26. data/test/unit/control/cucumber_helpers/tc_consolidate_reports.rb +73 -0
  27. data/test/unit/control/cucumber_helpers/tc_executor.rb +406 -0
  28. data/test/unit/control/gem/tc_gem_helpers.rb +405 -0
  29. data/test/unit/control/rake_helpers/tc_aborter.rb +131 -0
  30. data/test/unit/control/rake_helpers/tc_task_helpers.rb +228 -0
  31. data/test/unit/control/razor/tc_executor.rb +129 -0
  32. data/test/unit/control/razor/tc_razor_instance.rb +517 -0
  33. data/test/unit/control/razor/test_scripts/exit_failure.cmd +3 -0
  34. data/test/unit/control/razor/test_scripts/exit_strange.cmd +3 -0
  35. data/test/unit/control/razor/test_scripts/exit_success.cmd +3 -0
  36. data/test/unit/control/razor/test_scripts/pause.cmd +5 -0
  37. data/test/unit/control/razor/test_scripts/print.cmd +6 -0
  38. data/test/unit/control/tc_exceptions.rb +120 -0
  39. metadata +192 -0
@@ -0,0 +1,405 @@
1
+ # encoding: UTF-8
2
+ #! /usr/bin/env ruby
3
+
4
+ # ######################################################################## #
5
+ #
6
+ # Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
7
+ #
8
+ # ######################################################################## #
9
+
10
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
11
+
12
+ unless $DEBUG
13
+
14
+ require 'pantheios/globals'
15
+ require 'pantheios/services/null_log_service'
16
+
17
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
18
+ end
19
+
20
+ require 'razor_risk/razor/control/gem/gem_helpers'
21
+
22
+ require 'xqsr3/extensions/test/unit'
23
+
24
+ require 'fileutils'
25
+ require 'tmpdir'
26
+
27
+ require 'test/unit'
28
+
29
+ class Test_GemHelpers < Test::Unit::TestCase
30
+
31
+ include ::RazorRisk::Razor::Control::Exceptions
32
+ include ::RazorRisk::Razor::Control::Gem
33
+
34
+ def test_is_a_class
35
+
36
+ assert_kind_of ::Class, GemHelpers
37
+ end
38
+
39
+ def test_can_be_initialized
40
+
41
+ assert_nothing_raised do
42
+ GemHelpers.new
43
+ end
44
+ end
45
+
46
+ class Test_Install < Test::Unit::TestCase
47
+
48
+ include ::RazorRisk::Razor::Control::Exceptions
49
+ include ::RazorRisk::Razor::Control::Gem
50
+
51
+ def setup
52
+
53
+ MockGem.clear
54
+ end
55
+
56
+ def test_no_gemspec
57
+
58
+ Dir.mktmpdir do |dir|
59
+
60
+ name = 'abc'
61
+
62
+ MockGem::Specification.add_spec(
63
+ "#{dir}/#{name}.gemspec",
64
+ name
65
+ )
66
+
67
+ MockGem::Specification.load_block { flunk }
68
+ MockGem.install_block { flunk }
69
+
70
+ assert_raise_with_message(GemDeploymentException, /no gemspec files found/i) do
71
+ GemHelpers.new(MockGem).install_gem dir
72
+ end
73
+ end
74
+ end
75
+
76
+ def test_multiple_gemspec
77
+
78
+ Dir.mktmpdir do |dir|
79
+
80
+ name = 'abc'
81
+
82
+ FileUtils.touch(File.join(dir, "#{name}.gemspec"))
83
+ FileUtils.touch(File.join(dir, "#{name}_2.gemspec"))
84
+
85
+ MockGem::Specification.add_spec(
86
+ "#{dir}/#{name}.gemspec",
87
+ name
88
+ )
89
+
90
+ MockGem::Specification.load_block { flunk }
91
+ MockGem.install_block { flunk }
92
+
93
+ assert_raise_with_message(GemDeploymentException, /multiple gemspec files found/i) do
94
+ GemHelpers.new(MockGem).install_gem dir
95
+ end
96
+ end
97
+ end
98
+
99
+ def test_no_gem
100
+
101
+ Dir.mktmpdir do |dir|
102
+
103
+ name = 'abc'
104
+
105
+ FileUtils.touch(File.join(dir, "#{name}.gemspec"))
106
+
107
+ MockGem::Specification.add_spec(
108
+ "#{dir}/#{name}.gemspec",
109
+ name
110
+ )
111
+
112
+ MockGem::Specification.load_block do |spec|
113
+ assert_equal "#{dir}/#{name}.gemspec", spec
114
+ end
115
+ MockGem.install_block { flunk }
116
+
117
+ assert_raise_with_message(GemDeploymentException, /no project gem files found/i) do
118
+ GemHelpers.new(MockGem).install_gem dir
119
+ end
120
+ end
121
+ end
122
+
123
+ def test_multiple_gem
124
+
125
+ Dir.mktmpdir do |dir|
126
+
127
+ name = 'abc'
128
+
129
+ FileUtils.touch(File.join(dir, "#{name}.gemspec"))
130
+ FileUtils.touch(File.join(dir, "#{name}.gem"))
131
+ FileUtils.touch(File.join(dir, "#{name}_2.gem"))
132
+
133
+ MockGem::Specification.add_spec(
134
+ "#{dir}/#{name}.gemspec",
135
+ name
136
+ )
137
+
138
+ MockGem::Specification.load_block do |spec|
139
+ assert_equal "#{dir}/#{name}.gemspec", spec
140
+ end
141
+ MockGem.install_block { flunk }
142
+
143
+ assert_raise_with_message(GemDeploymentException, /multiple project gem files found/i) do
144
+ GemHelpers.new(MockGem).install_gem dir
145
+ end
146
+ end
147
+ end
148
+
149
+ def test_install
150
+
151
+ Dir.mktmpdir do |dir|
152
+
153
+ name = 'abc'
154
+
155
+ FileUtils.touch(File.join(dir, "#{name}.gem"))
156
+ FileUtils.touch(File.join(dir, "#{name}.gemspec"))
157
+
158
+ MockGem::Specification.add_spec(
159
+ "#{dir}/#{name}.gemspec",
160
+ name
161
+ )
162
+
163
+ MockGem::Specification.load_block do |spec|
164
+ assert_equal "#{dir}/#{name}.gemspec", spec
165
+ end
166
+ MockGem.install_block do |n, v, **o|
167
+ assert_equal "#{dir}/#{name}.gem", n
168
+ assert_equal nil, v
169
+ assert_equal Hash.new, o
170
+ end
171
+
172
+ GemHelpers.new(MockGem).install_gem dir
173
+ end
174
+ end
175
+ end
176
+
177
+ class Test_Build < Test::Unit::TestCase
178
+
179
+ include ::RazorRisk::Razor::Control::Exceptions
180
+ include ::RazorRisk::Razor::Control::Gem
181
+
182
+ def setup
183
+
184
+ MockGem.clear
185
+ end
186
+
187
+ def test_no_gemspec
188
+
189
+ Dir.mktmpdir do |source|
190
+
191
+ name = 'abc'
192
+
193
+ MockGem::Specification.add_spec(
194
+ "#{source}/#{name}.gemspec",
195
+ name
196
+ )
197
+
198
+ MockGem::Specification.load_block { flunk }
199
+ MockGem::Package.build_block { flunk }
200
+
201
+ assert_raise_with_message(GemDeploymentException, /no gemspec files found/i) do
202
+ GemHelpers.new(MockGem).build_gem source
203
+ end
204
+ end
205
+ end
206
+
207
+ def test_multiple_gemspec
208
+
209
+ Dir.mktmpdir do |source|
210
+
211
+ name = 'abc'
212
+
213
+ FileUtils.touch(File.join(source, "#{name}.gemspec"))
214
+ FileUtils.touch(File.join(source, "#{name}_2.gemspec"))
215
+
216
+ MockGem::Specification.add_spec(
217
+ "#{source}/#{name}.gemspec",
218
+ name
219
+ )
220
+
221
+ MockGem::Specification.load_block { flunk }
222
+ MockGem::Package.build_block { flunk }
223
+
224
+ assert_raise_with_message(GemDeploymentException, /multiple gemspec files found/i) do
225
+ GemHelpers.new(MockGem).build_gem source
226
+ end
227
+ end
228
+ end
229
+
230
+ def test_build
231
+
232
+ Dir.mktmpdir do |source|
233
+
234
+ name = 'abc'
235
+
236
+ FileUtils.touch(File.join(source, "#{name}.gemspec"))
237
+
238
+ MockGem::Specification.add_spec(
239
+ "#{source}/#{name}.gemspec",
240
+ name
241
+ )
242
+ MockGem::Package.add_gem(name)
243
+
244
+ MockGem::Specification.load_block do |spec|
245
+ assert_equal "#{source}/#{name}.gemspec", spec
246
+ end
247
+ MockGem::Package.build_block do |spec|
248
+ assert_equal name, spec.name
249
+ end
250
+
251
+ GemHelpers.new(MockGem).build_gem source
252
+ end
253
+ end
254
+
255
+ def test_build_with_moved_gem
256
+
257
+ Dir.mktmpdir do |source|
258
+ Dir.mktmpdir do |dest|
259
+
260
+ name = 'abc'
261
+
262
+ FileUtils.touch(File.join(source, "#{name}.gemspec"))
263
+
264
+ MockGem::Specification.add_spec(
265
+ "#{source}/#{name}.gemspec",
266
+ name
267
+ )
268
+ MockGem::Package.add_gem(name)
269
+
270
+ MockGem::Specification.load_block do |spec|
271
+ assert_equal "#{source}/#{name}.gemspec", spec
272
+ end
273
+ MockGem::Package.build_block do |spec|
274
+ assert_equal name, spec.name
275
+ FileUtils.touch("#{spec.name}.gem")
276
+ end
277
+
278
+ begin
279
+ GemHelpers.new(MockGem).build_gem source, dest
280
+ ensure
281
+ FileUtils.rm("#{name}.gem")
282
+ end
283
+
284
+ assert_false Dir[ "#{dest}/*.gem" ].empty?
285
+ end
286
+ end
287
+ end
288
+ end
289
+
290
+ class Test_Push < Test::Unit::TestCase
291
+
292
+ include ::RazorRisk::Razor::Control::Exceptions
293
+ include ::RazorRisk::Razor::Control::Gem
294
+
295
+ def setup
296
+
297
+ MockGem.clear
298
+ end
299
+
300
+ def test_leaves_host_as_original
301
+
302
+ Dir.mktmpdir do |dir|
303
+
304
+ name = 'abc'
305
+ original_host = 'original'
306
+ new_host = 'new'
307
+
308
+ FileUtils.touch(File.join(dir, "#{name}.gem"))
309
+ FileUtils.touch(File.join(dir, "#{name}.gemspec"))
310
+
311
+ MockGem::Specification.add_spec(
312
+ "#{dir}/#{name}.gemspec",
313
+ name
314
+ )
315
+
316
+ MockGem::Specification.load_block do |spec|
317
+ assert_equal "#{dir}/#{name}.gemspec", spec
318
+ end
319
+ MockGem::Commands::PushCommand.push_block do |g|
320
+ assert_equal new_host, MockGem.host
321
+ end
322
+ MockGem.host = original_host
323
+
324
+ assert_equal original_host, MockGem.host
325
+ GemHelpers.new(MockGem).push_gem dir, new_host
326
+ assert_equal original_host, MockGem.host
327
+ end
328
+ end
329
+
330
+ def test_push_gem
331
+
332
+ Dir.mktmpdir do |dir|
333
+
334
+ name = 'abc'
335
+ host = 'host'
336
+
337
+ FileUtils.touch(File.join(dir, "#{name}.gem"))
338
+ FileUtils.touch(File.join(dir, "#{name}.gemspec"))
339
+
340
+ MockGem::Specification.add_spec(
341
+ "#{dir}/#{name}.gemspec",
342
+ name
343
+ )
344
+
345
+ MockGem::Specification.load_block do |spec|
346
+ assert_equal "#{dir}/#{name}.gemspec", spec
347
+ end
348
+ MockGem::Commands::PushCommand.push_block do |g|
349
+ assert_equal g, "#{dir}/#{name}.gem"
350
+ end
351
+
352
+ GemHelpers.new(MockGem).push_gem dir, host
353
+ end
354
+ end
355
+ end
356
+
357
+ class Test_TempEnv < Test::Unit::TestCase
358
+
359
+ include ::RazorRisk::Razor::Control::Exceptions
360
+ include ::RazorRisk::Razor::Control::Gem
361
+
362
+ def setup
363
+
364
+ MockGem.clear
365
+ end
366
+
367
+ def test_temporary_env
368
+
369
+ gem_server = 'server'
370
+
371
+ orig = {
372
+ dir: 'dir',
373
+ path: 'path',
374
+ sources: [ 'source' ],
375
+ home: ENV['GEM_HOME'],
376
+ }
377
+
378
+ MockGem.dir = orig[:dir]
379
+ MockGem.path = orig[:path]
380
+ MockGem.sources = orig[:sources]
381
+
382
+ assert_equal orig[:dir], MockGem.dir
383
+ assert_equal orig[:path], MockGem.path
384
+ assert_equal orig[:sources], MockGem.sources
385
+ assert_equal orig[:home], ENV['GEM_HOME']
386
+
387
+ GemHelpers.new(MockGem).temporary_env do
388
+
389
+ assert_not_equal orig[:dir], MockGem.dir
390
+ assert_equal orig[:path], MockGem.path
391
+ assert_not_equal orig[:home], ENV['GEM_HOME']
392
+ MockGem.sources = [ gem_server ]
393
+ end
394
+
395
+ assert_equal orig[:dir], MockGem.dir
396
+ assert_equal orig[:path], MockGem.path
397
+ assert_equal orig[:sources], MockGem.sources
398
+ assert_equal orig[:home], ENV['GEM_HOME']
399
+ end
400
+ end
401
+ end
402
+
403
+ # ############################## end of file ############################# #
404
+
405
+
@@ -0,0 +1,131 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # ######################################################################## #
4
+ #
5
+ # Copyright (c) 2019 Razor Risk Technologies Pty Limited. All rights reserved.
6
+ #
7
+ # ######################################################################## #
8
+
9
+ $:.unshift File.join(File.dirname(__FILE__), *(['..'] * 4), 'lib')
10
+
11
+ unless $DEBUG
12
+
13
+ require 'pantheios/globals'
14
+ require 'pantheios/services/null_log_service'
15
+
16
+ ::Pantheios::Globals.INITIAL_SERVICE_CLASSES = [ ::Pantheios::Services::NullLogService ]
17
+ end
18
+
19
+ require 'razor_risk/razor/control/rake_helpers/aborter'
20
+
21
+ require 'xqsr3/extensions/test/unit'
22
+
23
+ require 'test/unit'
24
+
25
+ class Test_Aborter < Test::Unit::TestCase
26
+
27
+ include ::RazorRisk::Razor::Control::RakeHelpers
28
+ include ::RazorRisk::Razor::Control::RakeHelpers::RakeAborter
29
+
30
+ # Reset the abort hooks before each test as they are global.
31
+ def setup
32
+
33
+ RakeAborter.class_variable_set('@@abort_hook', [])
34
+ RakeAborter.class_variable_set('@@called', false)
35
+ end
36
+
37
+ def teardown
38
+
39
+ RakeAborter.class_variable_set('@@abort_hook', [])
40
+ RakeAborter.class_variable_set('@@called', false)
41
+ end
42
+
43
+ def test_is_a_module
44
+
45
+ assert_kind_of ::Module, RakeAborter
46
+ end
47
+
48
+ def test_abort_is_generated
49
+
50
+ assert_raise(::SystemExit) { abort }
51
+
52
+ previous_stderr, $stderr = $stderr, StringIO.new
53
+ begin
54
+ msg = 'some message'
55
+ assert_raise_with_message(::SystemExit, msg) do
56
+ abort msg
57
+ end
58
+ ensure
59
+ $stderr = previous_stderr
60
+ end
61
+ end
62
+
63
+ def test_hook_is_called
64
+
65
+ called = false
66
+
67
+ RakeAborter.abort_hook do
68
+ called = true
69
+ end
70
+
71
+ assert_raise(::SystemExit) { abort }
72
+ assert called
73
+ end
74
+
75
+ def test_hooks_do_not_infinte_loop
76
+
77
+ called = 0
78
+
79
+ RakeAborter.abort_hook do
80
+ called += 1
81
+ abort
82
+ end
83
+
84
+ assert_raise(::SystemExit) { abort }
85
+ assert_equal 1, called
86
+ end
87
+
88
+ def test_calls_multiple_hooks
89
+
90
+ called = 0
91
+
92
+ RakeAborter.abort_hook do
93
+ called += 1
94
+ end
95
+ RakeAborter.abort_hook do
96
+ called += 1
97
+ end
98
+
99
+ assert_raise(::SystemExit) { abort }
100
+ assert_equal 2, called
101
+ end
102
+
103
+ def test_handles_exceptions_in_hooks
104
+
105
+ msg = 'some message'
106
+ called = 0
107
+
108
+ RakeAborter.abort_hook do
109
+ called += 1
110
+ raise 'EXCEPTION'
111
+ end
112
+ RakeAborter.abort_hook do
113
+ called += 1
114
+ end
115
+
116
+ previous_stderr, $stderr = $stderr, StringIO.new
117
+ begin
118
+ assert_raise_with_message(::SystemExit, msg) do
119
+ abort msg
120
+ end
121
+ ensure
122
+ $stderr = previous_stderr
123
+ end
124
+
125
+ assert_equal 1, called
126
+ end
127
+ end
128
+
129
+ # ############################## end of file ############################# #
130
+
131
+