tap 0.7.9 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (149) hide show
  1. data/History +28 -0
  2. data/MIT-LICENSE +1 -1
  3. data/README +71 -43
  4. data/Rakefile +81 -64
  5. data/Tutorial +235 -0
  6. data/bin/tap +80 -44
  7. data/lib/tap.rb +41 -12
  8. data/lib/tap/app.rb +243 -246
  9. data/lib/tap/file_task.rb +357 -118
  10. data/lib/tap/generator.rb +88 -29
  11. data/lib/tap/generator/generators/config/config_generator.rb +4 -2
  12. data/lib/tap/generator/generators/config/templates/config.erb +1 -2
  13. data/lib/tap/generator/generators/file_task/file_task_generator.rb +3 -18
  14. data/lib/tap/generator/generators/file_task/templates/task.erb +22 -15
  15. data/lib/tap/generator/generators/file_task/templates/test.erb +13 -2
  16. data/{test/test/inference_methods/test_assert_files_exist/input/input_1.txt → lib/tap/generator/generators/generator/USAGE} +0 -0
  17. data/lib/tap/generator/generators/generator/generator_generator.rb +21 -0
  18. data/lib/tap/generator/generators/generator/templates/generator.erb +23 -0
  19. data/lib/tap/generator/generators/generator/templates/usage.erb +1 -0
  20. data/{test/test/inference_methods/test_assert_files_exist/input/input_2.txt → lib/tap/generator/generators/package/USAGE} +0 -0
  21. data/lib/tap/generator/generators/package/package_generator.rb +38 -0
  22. data/lib/tap/generator/generators/package/templates/package.erb +186 -0
  23. data/lib/tap/generator/generators/root/root_generator.rb +14 -9
  24. data/lib/tap/generator/generators/root/templates/Rakefile +20 -14
  25. data/{test/test/inference_methods/test_infer_glob/expected/file.yml → lib/tap/generator/generators/root/templates/ReadMe.txt} +0 -0
  26. data/lib/tap/generator/generators/root/templates/tap.yml +82 -0
  27. data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +0 -1
  28. data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +2 -1
  29. data/{test/test/inference_methods/test_infer_glob/expected/file_1.txt → lib/tap/generator/generators/script/USAGE} +0 -0
  30. data/lib/tap/generator/generators/script/script_generator.rb +17 -0
  31. data/lib/tap/generator/generators/script/templates/script.erb +42 -0
  32. data/lib/tap/generator/generators/task/task_generator.rb +1 -1
  33. data/lib/tap/generator/generators/task/templates/task.erb +24 -16
  34. data/lib/tap/generator/generators/task/templates/test.erb +13 -17
  35. data/lib/tap/generator/generators/workflow/templates/task.erb +10 -10
  36. data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
  37. data/lib/tap/generator/generators/workflow/workflow_generator.rb +3 -18
  38. data/lib/tap/root.rb +108 -146
  39. data/lib/tap/script.rb +362 -0
  40. data/lib/tap/script/console.rb +28 -0
  41. data/lib/tap/script/destroy.rb +13 -1
  42. data/lib/tap/script/generate.rb +13 -1
  43. data/lib/tap/script/run.rb +100 -57
  44. data/lib/tap/support/batch_queue.rb +0 -3
  45. data/lib/tap/support/logger.rb +6 -3
  46. data/lib/tap/support/rake.rb +54 -0
  47. data/lib/tap/support/task_configuration.rb +169 -0
  48. data/lib/tap/support/tdoc.rb +198 -0
  49. data/lib/tap/support/tdoc/config_attr.rb +338 -0
  50. data/lib/tap/support/tdoc/tdoc_html_generator.rb +38 -0
  51. data/lib/tap/support/tdoc/tdoc_html_template.rb +42 -0
  52. data/lib/tap/support/versions.rb +33 -1
  53. data/lib/tap/task.rb +339 -227
  54. data/lib/tap/test.rb +86 -128
  55. data/lib/tap/test/env_vars.rb +16 -5
  56. data/lib/tap/test/file_methods.rb +373 -0
  57. data/lib/tap/test/subset_methods.rb +299 -180
  58. data/lib/tap/version.rb +2 -1
  59. data/lib/tap/workflow.rb +2 -0
  60. data/test/app/lib/app_test_task.rb +1 -0
  61. data/test/app_test.rb +327 -83
  62. data/test/check/binding_eval.rb +23 -0
  63. data/test/check/define_method_check.rb +22 -0
  64. data/test/check/dependencies_check.rb +175 -0
  65. data/test/check/inheritance_check.rb +22 -0
  66. data/test/file_task_test.rb +524 -291
  67. data/test/{test/inference_methods/test_infer_glob/expected/file_2.txt → root/glob/one.txt} +0 -0
  68. data/test/root/glob/two.txt +0 -0
  69. data/test/root_test.rb +330 -262
  70. data/test/script_test.rb +194 -0
  71. data/test/support/audit_test.rb +5 -2
  72. data/test/support/combinator_test.rb +10 -10
  73. data/test/support/rake_test.rb +35 -0
  74. data/test/support/task_configuration_test.rb +272 -0
  75. data/test/support/tdoc_test.rb +363 -0
  76. data/test/support/templater_test.rb +2 -2
  77. data/test/support/versions_test.rb +32 -0
  78. data/test/tap_test_helper.rb +39 -0
  79. data/test/task_base_test.rb +115 -0
  80. data/test/task_class_test.rb +56 -4
  81. data/test/task_execute_test.rb +29 -0
  82. data/test/task_test.rb +89 -70
  83. data/test/test/env_vars_test.rb +48 -0
  84. data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/file.txt +0 -0
  85. data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/folder/file.txt +0 -0
  86. data/test/test/{inference_methods → file_methods}/test_assert_expected/input/file.txt +0 -0
  87. data/test/test/{inference_methods → file_methods}/test_assert_expected/input/folder/file.txt +0 -0
  88. data/test/test/file_methods/test_assert_files_exist/input/input_1.txt +0 -0
  89. data/test/test/file_methods/test_assert_files_exist/input/input_2.txt +0 -0
  90. data/test/test/file_methods/test_assert_output_files_equal/expected/one.txt +1 -0
  91. data/test/test/file_methods/test_assert_output_files_equal/expected/two.txt +1 -0
  92. data/test/test/file_methods/test_assert_output_files_equal/input/one.txt +1 -0
  93. data/test/test/file_methods/test_assert_output_files_equal/input/two.txt +1 -0
  94. data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_1.txt +0 -0
  95. data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_2.txt +0 -0
  96. data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_1.txt +0 -0
  97. data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_2.txt +0 -0
  98. data/test/test/file_methods/test_infer_glob/expected/file.yml +0 -0
  99. data/test/test/file_methods/test_infer_glob/expected/file_1.txt +0 -0
  100. data/test/test/file_methods/test_infer_glob/expected/file_2.txt +0 -0
  101. data/test/test/file_methods/test_method_glob/expected/file.yml +0 -0
  102. data/test/test/file_methods/test_method_glob/expected/file_1.txt +0 -0
  103. data/test/test/file_methods/test_method_glob/expected/file_2.txt +0 -0
  104. data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_1.yml +0 -0
  105. data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_2.yml +0 -0
  106. data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_1.yml +0 -0
  107. data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_2.yml +0 -0
  108. data/test/test/file_methods_test.rb +204 -0
  109. data/test/test/subset_methods_test.rb +93 -33
  110. data/test/test/test_assert_expected_result_files/expected/task/name/a.txt +1 -0
  111. data/test/test/test_assert_expected_result_files/expected/task/name/b.txt +1 -0
  112. data/test/test/test_assert_expected_result_files/input/a.txt +1 -0
  113. data/test/test/test_assert_expected_result_files/input/b.txt +1 -0
  114. data/test/test/test_file_task_test/expected/one.txt +1 -0
  115. data/test/test/test_file_task_test/expected/two.txt +1 -0
  116. data/test/test/test_file_task_test/input/one.txt +1 -0
  117. data/test/test/test_file_task_test/input/two.txt +1 -0
  118. data/test/test_test.rb +143 -3
  119. data/test/workflow_test.rb +2 -0
  120. data/vendor/rails_generator.rb +56 -0
  121. data/vendor/rails_generator/base.rb +263 -0
  122. data/vendor/rails_generator/commands.rb +581 -0
  123. data/vendor/rails_generator/generated_attribute.rb +42 -0
  124. data/vendor/rails_generator/lookup.rb +209 -0
  125. data/vendor/rails_generator/manifest.rb +53 -0
  126. data/vendor/rails_generator/options.rb +143 -0
  127. data/vendor/rails_generator/scripts.rb +83 -0
  128. data/vendor/rails_generator/scripts/destroy.rb +7 -0
  129. data/vendor/rails_generator/scripts/generate.rb +7 -0
  130. data/vendor/rails_generator/scripts/update.rb +12 -0
  131. data/vendor/rails_generator/simple_logger.rb +46 -0
  132. data/vendor/rails_generator/spec.rb +44 -0
  133. metadata +180 -196
  134. data/lib/tap/generator/generators/root/templates/app.yml +0 -19
  135. data/lib/tap/generator/generators/root/templates/config/process_tap_request.yml +0 -4
  136. data/lib/tap/generator/generators/root/templates/lib/process_tap_request.rb +0 -26
  137. data/lib/tap/generator/generators/root/templates/public/images/nav.jpg +0 -0
  138. data/lib/tap/generator/generators/root/templates/public/stylesheets/color.css +0 -57
  139. data/lib/tap/generator/generators/root/templates/public/stylesheets/layout.css +0 -108
  140. data/lib/tap/generator/generators/root/templates/public/stylesheets/normalize.css +0 -40
  141. data/lib/tap/generator/generators/root/templates/public/stylesheets/typography.css +0 -21
  142. data/lib/tap/generator/generators/root/templates/server/config/environment.rb +0 -60
  143. data/lib/tap/generator/generators/root/templates/server/lib/tasks/clear_database_prerequisites.rake +0 -5
  144. data/lib/tap/generator/generators/root/templates/server/test/test_helper.rb +0 -53
  145. data/lib/tap/script/server.rb +0 -12
  146. data/lib/tap/support/rap.rb +0 -38
  147. data/lib/tap/test/inference_methods.rb +0 -298
  148. data/test/task/config/task_with_config.yml +0 -1
  149. data/test/test/inference_methods_test.rb +0 -311
data/lib/tap/version.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  module Tap
2
- VERSION="0.7.9"
2
+ VERSION="0.8.0"
3
+ HOMEPAGE="http://tap.rubyforge.org"
3
4
  end
data/lib/tap/workflow.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Tap
2
2
 
3
+ # == UNDER CONSTRUCTION
4
+ #
3
5
  # App can build workflows directly, using methods like sequence, merge, and
4
6
  # multithread, but these workflows are hard to abstract and resuse. Workflow
5
7
  # is a specialized type of Task allows the encapsulation and reuse of workflow
@@ -1,2 +1,3 @@
1
+ require 'tap'
1
2
  class AppTestTask < Tap::Task
2
3
  end
data/test/app_test.rb CHANGED
@@ -5,11 +5,85 @@ require 'logger'
5
5
 
6
6
  class AppTest < Test::Unit::TestCase
7
7
  include Tap
8
+ include TapTestMethods
9
+
8
10
  acts_as_tap_test
9
11
 
10
- def setup
11
- super
12
- app.queue.clear
12
+ def stub_gemspec(name, version)
13
+ spec = Gem::Specification.new
14
+ spec.name = name
15
+ spec.version = version
16
+ spec.loaded_from = "/path/to/gems"
17
+ spec
18
+ end
19
+
20
+ def test_app_documentation
21
+ task = Tap::Task.new {|task, input| input += 1 }
22
+ assert_equal Tap::App.instance, task.app
23
+ task.enq 1,2,3
24
+
25
+ task.app.run
26
+
27
+ assert_equal [2,3,4], task.results.collect {|audit| audit._current}
28
+ end
29
+
30
+ #
31
+ # App instance test
32
+ #
33
+
34
+ def test_instance_returns_current_instance
35
+ a = Tap::App.new
36
+ Tap::App.instance = a
37
+ assert_equal a, Tap::App.instance
38
+ end
39
+
40
+ def test_instance_initializes_new_App_if_not_set
41
+ Tap::App.instance = nil
42
+ assert Tap::App.instance.kind_of?(Tap::App)
43
+ end
44
+
45
+ #
46
+ # App parse_yaml test
47
+ #
48
+
49
+ def test_parse_yaml_documentation
50
+ str = {'key' => 'value'}.to_yaml
51
+ assert_equal "--- \nkey: value\n", str
52
+ assert_equal({'key' => 'value'}, Tap::App.parse_yaml(str))
53
+ assert_equal "str", Tap::App.parse_yaml("str")
54
+ end
55
+
56
+ def test_parse_yaml_parses_correctly_formatted_strings
57
+ assert_equal({'key' => 'value'}, Tap::App.parse_yaml("---\nkey: value"))
58
+ end
59
+
60
+ def test_parse_yaml_returns_strings_not_matching_yaml_format
61
+ assert_equal("str", Tap::App.parse_yaml("str"))
62
+ end
63
+
64
+ #
65
+ # App read_erb_yml test
66
+ #
67
+
68
+ def test_read_erb_yaml_templates_file_using_erb_then_loads_as_yaml
69
+ file = tempfile
70
+ File.open(file, "w") do |f|
71
+ f << %Q{
72
+ <% value = "value" %>
73
+ <%= "k" + "ey" %>: <%= value %>}
74
+ end
75
+
76
+ assert_equal({'key' => 'value'}, Tap::App.read_erb_yaml(file))
77
+ end
78
+
79
+ def test_read_erb_yaml_returns_nil_if_filepath_does_not_exist_or_is_a_dir
80
+ file = File.dirname(__FILE__) + "/app/no_existant_file.txt"
81
+ dir = File.dirname(__FILE__) + "/app"
82
+
83
+ assert !File.exists?(file)
84
+ assert File.directory?(dir)
85
+ assert_nil Tap::App.read_erb_yaml(file)
86
+ assert_nil Tap::App.read_erb_yaml(dir)
13
87
  end
14
88
 
15
89
  #
@@ -40,8 +114,7 @@ class AppTest < Test::Unit::TestCase
40
114
  :logger => {
41
115
  :device => STDOUT,
42
116
  :level => 1, # corresponds to 'INFO'
43
- :datetime_format => '%H:%M:%S'},
44
- :load_paths => []
117
+ :datetime_format => '%H:%M:%S'}
45
118
  }
46
119
  assert_equal expected, app.config
47
120
 
@@ -51,18 +124,16 @@ class AppTest < Test::Unit::TestCase
51
124
  app[:abs, true] = '/absolute/path'
52
125
  strio = StringIO.new('')
53
126
  app.logger = Logger.new(strio)
54
- app.load_paths << "path"
55
-
127
+
56
128
  expected = {
57
129
  :root => Dir.pwd,
58
130
  :directories => {:lib => 'alt/lib'},
59
- :absolute_paths => {:abs => '/absolute/path'},
131
+ :absolute_paths => {:abs => File.expand_path('/absolute/path')},
60
132
  :options => {:trace => true},
61
133
  :logger => {
62
134
  :device => strio,
63
135
  :level => 0,
64
- :datetime_format => nil},
65
- :load_paths => ["path"]
136
+ :datetime_format => nil}
66
137
  }
67
138
 
68
139
  assert_equal 0, app.logger.level
@@ -73,22 +144,49 @@ class AppTest < Test::Unit::TestCase
73
144
  #
74
145
  # reconfigure test
75
146
  #
147
+
148
+ def test_reconfigure_documentation
149
+ app = Tap::App.new :root => "/root", :directories => {:dir => 'path/to/dir'}
150
+ app.reconfigure(
151
+ :root => "./new/root",
152
+ :logger => {:level => Logger::DEBUG})
153
+
154
+ assert_equal File.expand_path("./new/root"), app.root
155
+ assert_equal File.expand_path("./new/root/path/to/dir"), app[:dir]
156
+ assert_equal Logger::DEBUG, app.logger.level
157
+ end
76
158
 
77
- def test_reconfigure_may_overrride_root_directories_options_and_logging
159
+ def test_reconfigure_root_sets_app_root
78
160
  app = App.new
79
161
 
80
162
  assert_equal Dir.pwd, app.root
81
163
  app.reconfigure :root => './alt/root'
82
- assert_equal './alt/root', app.root
83
-
164
+ assert_equal File.expand_path('./alt/root'), app.root
165
+ end
166
+
167
+ def test_reconfigure_directories_sets_directories
168
+ app = App.new
84
169
  assert_equal({}, app.directories)
85
170
  app.reconfigure :directories => {:lib => 'alt/lib'}
86
171
  assert_equal({:lib => 'alt/lib'}, app.directories)
87
-
172
+ end
173
+
174
+ def test_reconfigure_absolute_paths_sets_absolute_paths
175
+ app = App.new
176
+ assert_equal({}, app.absolute_paths)
177
+ app.reconfigure :absolute_paths => {:log => '/path/to/log'}
178
+ assert_equal({:log => File.expand_path('/path/to/log')}, app.absolute_paths)
179
+ end
180
+
181
+ def test_reconfigure_options_sets_options
182
+ app = App.new
88
183
  assert_equal({}, app.options.marshal_dump)
89
184
  app.reconfigure :options => {:trace => true}
90
185
  assert_equal({:trace => true}, app.options.marshal_dump)
91
-
186
+ end
187
+
188
+ def test_reconfigure_logger_sets_logger
189
+ app = App.new
92
190
  assert_equal STDOUT, app.logger.logdev.dev
93
191
  strio = StringIO.new('')
94
192
  app.reconfigure :logger => {:device => strio, :level => Logger::WARN}
@@ -96,6 +194,64 @@ class AppTest < Test::Unit::TestCase
96
194
  assert_equal Logger::WARN, app.logger.level
97
195
  end
98
196
 
197
+ def test_reconfigure_map_sets_map
198
+ app = App.new
199
+ assert_equal({}, app.map)
200
+ app.reconfigure :map => {'some/task_name' => Tap::Task}
201
+ assert_equal({'some/task_name' => Tap::Task}, app.map)
202
+ end
203
+
204
+ def test_reconfigure_sends_unhandled_options_to_block_if_given
205
+ app = App.new
206
+ was_in_block = false
207
+ app.reconfigure(:unknown => 'value') do |key, value|
208
+ assert_equal(:unknown, key)
209
+ assert_equal('value', value)
210
+ was_in_block = true
211
+ end
212
+ assert was_in_block
213
+ end
214
+
215
+ def test_reconfigure_raises_error_for_unhandled_options
216
+ app = App.new
217
+ assert_raise(ArgumentError) { app.reconfigure(:unknown => 'value') }
218
+ end
219
+
220
+ class AppHandlesConfig < App
221
+ attr_accessor :handled_configs
222
+ def handle_configuation(key, value)
223
+ (self.handled_configs ||= []).concat [key, value]
224
+ true
225
+ end
226
+ end
227
+
228
+ def test_reconfigure_sends_unhandled_options_to_handle_configuation_if_defined
229
+ app = AppHandlesConfig.new
230
+ was_in_block = false
231
+ app.reconfigure(:unknown => 'value') do |key, value|
232
+ was_in_block = true
233
+ end
234
+ assert_equal [:unknown, 'value'], app.handled_configs
235
+ assert !was_in_block
236
+ end
237
+
238
+ class AppDoesNotHandleConfig < AppHandlesConfig
239
+ def handle_configuation(key, value)
240
+ (self.handled_configs ||= []).concat [key, value]
241
+ false
242
+ end
243
+ end
244
+
245
+ def test_reconfigure_goes_to_block_if_handle_configuration_returns_false
246
+ app = AppDoesNotHandleConfig.new
247
+ was_in_block = false
248
+ app.reconfigure(:unknown => 'value') do |key, value|
249
+ was_in_block = true
250
+ end
251
+ assert_equal [:unknown, 'value'], app.handled_configs
252
+ assert was_in_block
253
+ end
254
+
99
255
  #
100
256
  # set logger tests
101
257
  #
@@ -121,33 +277,35 @@ class AppTest < Test::Unit::TestCase
121
277
  class TaskSubClass < Task
122
278
  end
123
279
 
124
- def test_task_returns_task_if_a_task_is_provided
125
- task = Task.new
126
- assert_equal task, app.task(task)
127
-
128
- subtask = TaskSubClass.new
129
- assert_equal subtask, app.task(subtask)
280
+ class AnotherTask < Task
130
281
  end
131
282
 
132
- def test_task_reconfigures_task_with_config
133
- task = Task.new
134
- config = {"key" => "value"}
135
-
136
- assert_equal({}, task.config)
137
- assert_equal task, app.task(task, config)
138
- assert_equal(config.symbolize_keys, task.config)
283
+ def test_task_documentation
284
+ app.map = {"mapped-task" => "AppTest::AnotherTask"}
285
+
286
+ t = app.task('mapped-task-1.0', :key => 'value')
287
+ assert_equal AnotherTask, t.class
288
+ assert_equal "mapped-task-1.0", t.name
289
+ assert_equal 'value', t.config[:key]
139
290
  end
140
291
 
141
- def test_task_looks_up_and_instantiates_task_if_task_is_a_string
292
+ def test_task_looks_up_and_instantiates_task
142
293
  assert_equal TaskSubClass, app.task("AppTest::TaskSubClass").class
143
294
  end
144
295
 
145
- def test_task_translates_strings_to_class_name_using_map_if_possible
296
+ def test_task_instantiates_a_new_task_for_each_call
297
+ t1 = app.task("AppTest::TaskSubClass")
298
+ t2 = app.task("AppTest::TaskSubClass")
299
+
300
+ assert_not_equal t1.object_id, t2.object_id
301
+ end
302
+
303
+ def test_task_translates_task_name_to_class_name_using_map_if_possible
146
304
  app.map["mapped_name"] = "AppTest::TaskSubClass"
147
305
  assert_equal TaskSubClass, app.task("mapped_name").class
148
306
  end
149
307
 
150
- def test_task_translates_strings_to_class_name_using_camelize_by_default
308
+ def test_task_translates_task_name_to_class_name_using_camelize_by_default
151
309
  assert_equal TaskSubClass, app.task("app_test/task_sub_class").class
152
310
  end
153
311
 
@@ -157,7 +315,7 @@ class AppTest < Test::Unit::TestCase
157
315
  assert_equal "app_test/task_sub_class-1.1", t.name
158
316
  end
159
317
 
160
- def test_task_can_find_task_classes_along_Dependencies_load_paths
318
+ def test_task_looks_up_task_classes_along_Dependencies_load_paths
161
319
  begin
162
320
  Dependencies.load_paths << app['lib']
163
321
  assert_equal AppTestTask, app.task("AppTestTask").class
@@ -166,14 +324,60 @@ class AppTest < Test::Unit::TestCase
166
324
  end
167
325
  end
168
326
 
169
- def test_task_raises_error_if_class_cannot_be_found
170
- assert_raise(RuntimeError) { app.task("NonExistant") }
327
+ def test_task_raises_lookup_error_if_class_cannot_be_found
328
+ assert_raise(App::LookupError) { app.task("NonExistant") }
329
+ end
330
+
331
+ #
332
+ # task_class_name test
333
+ #
334
+
335
+ def test_task_class_name_documentation
336
+ t = Task.new
337
+ app.map = {"mapped-task" => "AnotherTask"}
338
+ assert_equal "Tap::Task", app.task_class_name(t)
339
+ assert_equal "AnotherTask", app.task_class_name('mapped-task-1.0')
340
+ end
341
+
342
+ def test_task_class_name_returns_task_class_name
343
+ task = Task.new
344
+ assert_equal "Tap::Task", app.task_class_name(task)
345
+
346
+ subtask = TaskSubClass.new
347
+ assert_equal "AppTest::TaskSubClass", app.task_class_name(subtask)
348
+
349
+ non_task = Object.new
350
+ non_task.extend Tap::Task::Base
351
+ assert_equal "Object", app.task_class_name(non_task)
352
+ end
353
+
354
+ def test_task_class_name_returns_deversioned_camelized_name
355
+ assert_equal "AppTest::TaskSubClass", app.task_class_name("app_test/task_sub_class-1.1")
356
+ end
357
+
358
+ def test_task_class_name_resolves_names_using_map
359
+ app.map = {"mapped-task" => "AnotherTask"}
360
+ assert_equal "AnotherTask", app.task_class_name("mapped-task-1.1")
171
361
  end
172
362
 
173
363
  #
174
364
  # config_templates tests
175
365
  #
176
366
 
367
+ def test_config_templates_documentation
368
+ simple = tempfile
369
+ File.open(simple, "w") {|f| f << "key: value"}
370
+ assert_equal([{"key" => "value"}], app.config_templates(simple))
371
+
372
+ array_with_erb = tempfile
373
+ File.open(array_with_erb, "w") do |f|
374
+ f << %Q{
375
+ - key: <%= 1 %>
376
+ - key: <%= 1 + 1 %>}
377
+ end
378
+ assert_equal([{"key" => 1}, {"key" => 2}], app.config_templates(array_with_erb))
379
+ end
380
+
177
381
  def test_config_templates_retrieves_templates_for_the_specified_task_config_file
178
382
  filepath = app.filepath('config', "version.yml")
179
383
  assert File.exists?(filepath)
@@ -212,19 +416,19 @@ class AppTest < Test::Unit::TestCase
212
416
  # execute test
213
417
  #
214
418
 
215
- def test_execute_executes_task_with_inputs
216
- t = Task.new(&add_one)
217
- t.enq(1,2,3)
218
-
219
- app.execute(t)
220
- assert_inputs(t => [1,2,3])
221
- assert_outputs(t => [2,3,4])
222
- assert_equal [1,2,3], runlist
223
- assert_audits(t.results,
224
- 0 => [[nil,1], [t,2]],
225
- 1 => [[nil,2], [t,3]],
226
- 2 => [[nil,3], [t,4]])
227
- end
419
+ # def test_execute_executes_task_with_inputs
420
+ # t = Task.new(&add_one)
421
+ # t.enq(1,2,3)
422
+ #
423
+ # app.execute(t)
424
+ # assert_inputs(t => [1,2,3])
425
+ # assert_outputs(t => [2,3,4])
426
+ # assert_equal [1,2,3], runlist
427
+ # assert_audits(t.results,
428
+ # 0 => [[nil,1], [t,2]],
429
+ # 1 => [[nil,2], [t,3]],
430
+ # 2 => [[nil,3], [t,4]])
431
+ # end
228
432
 
229
433
  #
230
434
  # run tests
@@ -409,6 +613,7 @@ class AppTest < Test::Unit::TestCase
409
613
  end
410
614
  end
411
615
 
616
+ # inconsistent test ruby, windows
412
617
  def test_multithreaded_tasks_execute_in_order
413
618
  extended_test do
414
619
  max_threads = 0
@@ -459,7 +664,11 @@ class AppTest < Test::Unit::TestCase
459
664
  threads = []
460
665
  ObjectSpace.garbage_collect
461
666
  sleep 0.2 # sleep to give garbage collect time to run
462
- ObjectSpace.each_object(Thread) {|t| threads << t.object_id}
667
+
668
+ # JRuby limits ObjectSpace to only work for Class by default
669
+ # so this line has to be made less elegant and a little slower
670
+ # ObjectSpace.each_object(Thread) {|t| threads << t.object_id}
671
+ ObjectSpace.each_object(Class) {|t| threads << t.object_id if t.kind_of?(Thread)}
463
672
  threads
464
673
  end
465
674
 
@@ -605,11 +814,13 @@ class AppTest < Test::Unit::TestCase
605
814
  # terminate test
606
815
  #
607
816
 
817
+ # TODO -- REWORD
608
818
  def test_terminate_from_main_thread_raises_run_error
609
819
  extended_test do
610
820
  was_not_terminated = false
611
821
  task = Task.new do |task, inputs|
612
822
  app.terminate
823
+ task.check_terminate
613
824
  was_not_terminated = true
614
825
  end
615
826
 
@@ -629,12 +840,14 @@ class AppTest < Test::Unit::TestCase
629
840
  end
630
841
  end
631
842
 
843
+ # TODO -- REWORD
632
844
  def test_terminate_from_main_thread_when_error_is_handled_still_raises_error
633
845
  extended_test do
634
846
  terminate_error_handled = false
635
847
  task = Task.new do |task, inputs|
636
848
  begin
637
849
  app.terminate
850
+ task.check_terminate
638
851
  rescue
639
852
  terminate_error_handled = true
640
853
  end
@@ -656,6 +869,7 @@ class AppTest < Test::Unit::TestCase
656
869
  end
657
870
  end
658
871
 
872
+ # TODO -- REWORD
659
873
  def test_terminate_raises_error_on_each_execution_thread_and_requeues_thread_queue
660
874
  extended_test do
661
875
  count = 0
@@ -664,7 +878,8 @@ class AppTest < Test::Unit::TestCase
664
878
  Task.new do |task, inputs|
665
879
  count += 1
666
880
  app.terminate if count == 2
667
- sleep 2
881
+ sleep 1
882
+ task.check_terminate
668
883
  some_thread_was_not_terminated = true
669
884
  end
670
885
  end
@@ -704,6 +919,8 @@ class AppTest < Test::Unit::TestCase
704
919
  end
705
920
  end
706
921
 
922
+ # TODO -- REWORD
923
+ # JRuby inconsistent test
707
924
  def test_terminate_on_thread_when_error_is_handled_still_raises_error
708
925
  extended_test do
709
926
  count = 0
@@ -715,7 +932,8 @@ class AppTest < Test::Unit::TestCase
715
932
  count += 1
716
933
  begin
717
934
  app.terminate if count == 2
718
- sleep 2
935
+ sleep 1
936
+ task.check_terminate
719
937
  some_thread_was_not_terminated = true
720
938
  rescue
721
939
  handled_count += 1
@@ -758,6 +976,7 @@ class AppTest < Test::Unit::TestCase
758
976
  assert_equal 'state: 0 (READY) queue: 0 waiting: 0 (0) threads: 0', app.info
759
977
  end
760
978
 
979
+ # TODO -- JRuby inconsistent test
761
980
  def test_info_can_be_called_during_a_run
762
981
  extended_test do
763
982
  count = 0
@@ -766,9 +985,11 @@ class AppTest < Test::Unit::TestCase
766
985
  tasks = Array.new(5) do
767
986
  Task.new do |task, inputs|
768
987
  count += 1
769
- info_str = app.info if count == 2
770
- app.stop if count == 2
771
- sleep 0.2
988
+ if count == 2
989
+ info_str = app.info
990
+ app.stop
991
+ end
992
+ sleep 2
772
993
  end
773
994
  end
774
995
  tasks.each do |task|
@@ -780,7 +1001,11 @@ class AppTest < Test::Unit::TestCase
780
1001
  app.run
781
1002
  end
782
1003
 
783
- assert_equal 'state: 1 (RUN) queue: 3 waiting: 3 (0) threads: 2', info_str
1004
+ # There is some ambiguity in the info string -- threads could be
1005
+ # waiting in the queue or in the thread queue, but their sum must be 3
1006
+ # Regexp patterned from 'state: 1 (RUN) queue: 3 waiting: 3 (0) threads: 2'
1007
+ assert info_str =~ /state: 1 \(RUN\) queue: 3 waiting: (\d) \((\d)\) threads: 2/, info_str
1008
+ assert_equal 3, $1.to_i + $2.to_i
784
1009
  assert_equal 'state: 0 (READY) queue: 3 waiting: 3 (0) threads: 0', app.info
785
1010
  end
786
1011
  end
@@ -942,6 +1167,7 @@ class AppTest < Test::Unit::TestCase
942
1167
  2 => [[nil,3], [t1_1,24]])
943
1168
  end
944
1169
 
1170
+ # TODO -- JRuby inconsistent test
945
1171
  def test_multithread_batched_tasks_execute_cosynchronously
946
1172
  extended_test do
947
1173
  max_threads = 0
@@ -953,8 +1179,8 @@ class AppTest < Test::Unit::TestCase
953
1179
 
954
1180
  # sleep is necessary so the other threads
955
1181
  # have an opportunity to execute
956
- sleep(0.2)
957
-
1182
+ sleep(1)
1183
+
958
1184
  n_threads -= 1
959
1185
  nil
960
1186
  end
@@ -1167,31 +1393,31 @@ class AppTest < Test::Unit::TestCase
1167
1393
  assert_equal 3, not_threaded_count
1168
1394
  end
1169
1395
 
1170
- def test_execute_is_allowed_within_non_threaded_task
1171
- # execute within a threaded task deadlocks
1172
- t2 = Task.new(&add_one)
1173
- t1 = Task.new do |task, input|
1174
- runlist << input
1175
- app.queue.enq(t2, input)
1176
- app.execute(t2)
1177
-
1178
- input += 1
1179
- end
1180
-
1181
- app.run(t1, 1,2,3)
1182
-
1183
- # remember t2, will only show the LAST input
1184
- # to have been processed
1185
- assert_inputs(t1 => [1,2,3], t2 => [3])
1186
- assert_outputs(t1 => [2,3,4], t2 => [4])
1187
- assert_equal [1,1,2,2,3,3], runlist
1188
- assert_audits(t1.results,
1189
- 0 => [[nil,1], [t1,2]],
1190
- 1 => [[nil,2], [t1,3]],
1191
- 2 => [[nil,3], [t1,4]])
1192
- assert_audits(t2.results,
1193
- 0 => [[nil,3], [t2,4]])
1194
- end
1396
+ # def test_execute_is_allowed_within_non_threaded_task
1397
+ # # execute within a threaded task deadlocks
1398
+ # t2 = Task.new(&add_one)
1399
+ # t1 = Task.new do |task, input|
1400
+ # runlist << input
1401
+ # app.queue.enq(t2, input)
1402
+ # app.execute(t2)
1403
+ #
1404
+ # input += 1
1405
+ # end
1406
+ #
1407
+ # app.run(t1, 1,2,3)
1408
+ #
1409
+ # # remember t2, will only show the LAST input
1410
+ # # to have been processed
1411
+ # assert_inputs(t1 => [1,2,3], t2 => [3])
1412
+ # assert_outputs(t1 => [2,3,4], t2 => [4])
1413
+ # assert_equal [1,1,2,2,3,3], runlist
1414
+ # assert_audits(t1.results,
1415
+ # 0 => [[nil,1], [t1,2]],
1416
+ # 1 => [[nil,2], [t1,3]],
1417
+ # 2 => [[nil,3], [t1,4]])
1418
+ # assert_audits(t2.results,
1419
+ # 0 => [[nil,3], [t2,4]])
1420
+ # end
1195
1421
 
1196
1422
  def test_run_is_allowed_within_non_threaded_task
1197
1423
  # run within a threaded task deadlocks
@@ -1263,6 +1489,9 @@ class AppTest < Test::Unit::TestCase
1263
1489
  assert string =~ /RuntimeError error/
1264
1490
  end
1265
1491
 
1492
+ # Ruby inconsistent test
1493
+ # <"error"> expected but was
1494
+ # <"Tap::App::TerminateError">.
1266
1495
  def test_unhandled_exception_raises_run_error_on_thread_when_debug
1267
1496
  t = Task.new {|t,i| raise "error"}
1268
1497
  t.multithread = true
@@ -1280,6 +1509,11 @@ class AppTest < Test::Unit::TestCase
1280
1509
  end
1281
1510
  end
1282
1511
 
1512
+ # TODO -- REWORD
1513
+
1514
+ # Ruby inconsistent test
1515
+ # <"error"> expected but was
1516
+ # <"Tap::App::TerminateError">.
1283
1517
  def test_unhandled_exception_on_thread_teminates_threads
1284
1518
  extended_test do
1285
1519
  count = 0
@@ -1291,7 +1525,8 @@ class AppTest < Test::Unit::TestCase
1291
1525
  count += 1
1292
1526
 
1293
1527
  terminated_count += 1
1294
- sleep 2
1528
+ sleep 1
1529
+ t.check_terminate
1295
1530
 
1296
1531
  # this should not happen
1297
1532
  terminated_count -= 1
@@ -1322,6 +1557,14 @@ class AppTest < Test::Unit::TestCase
1322
1557
  end
1323
1558
  end
1324
1559
 
1560
+ # Ruby inconsistent test
1561
+ # <"error"> expected but was
1562
+ # <"Tap::App::TerminateError">.
1563
+ #
1564
+ # <"term error 0"> expected but was
1565
+ # <"term error 1">.
1566
+ #
1567
+ # JRuby inconsistent test
1325
1568
  def test_exceptions_from_handling_termination_error_are_collected
1326
1569
  extended_test do
1327
1570
  count = 0
@@ -1332,7 +1575,8 @@ class AppTest < Test::Unit::TestCase
1332
1575
  n = count
1333
1576
  begin
1334
1577
  count += 1
1335
- sleep 2
1578
+ sleep 1
1579
+ t.check_terminate
1336
1580
  rescue
1337
1581
  count_in_threaded_error_handling += 1
1338
1582
  raise "term error #{n}"