tap 0.7.9 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History +28 -0
- data/MIT-LICENSE +1 -1
- data/README +71 -43
- data/Rakefile +81 -64
- data/Tutorial +235 -0
- data/bin/tap +80 -44
- data/lib/tap.rb +41 -12
- data/lib/tap/app.rb +243 -246
- data/lib/tap/file_task.rb +357 -118
- data/lib/tap/generator.rb +88 -29
- data/lib/tap/generator/generators/config/config_generator.rb +4 -2
- data/lib/tap/generator/generators/config/templates/config.erb +1 -2
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +3 -18
- data/lib/tap/generator/generators/file_task/templates/task.erb +22 -15
- data/lib/tap/generator/generators/file_task/templates/test.erb +13 -2
- data/{test/test/inference_methods/test_assert_files_exist/input/input_1.txt → lib/tap/generator/generators/generator/USAGE} +0 -0
- data/lib/tap/generator/generators/generator/generator_generator.rb +21 -0
- data/lib/tap/generator/generators/generator/templates/generator.erb +23 -0
- data/lib/tap/generator/generators/generator/templates/usage.erb +1 -0
- data/{test/test/inference_methods/test_assert_files_exist/input/input_2.txt → lib/tap/generator/generators/package/USAGE} +0 -0
- data/lib/tap/generator/generators/package/package_generator.rb +38 -0
- data/lib/tap/generator/generators/package/templates/package.erb +186 -0
- data/lib/tap/generator/generators/root/root_generator.rb +14 -9
- data/lib/tap/generator/generators/root/templates/Rakefile +20 -14
- data/{test/test/inference_methods/test_infer_glob/expected/file.yml → lib/tap/generator/generators/root/templates/ReadMe.txt} +0 -0
- data/lib/tap/generator/generators/root/templates/tap.yml +82 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +0 -1
- data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +2 -1
- data/{test/test/inference_methods/test_infer_glob/expected/file_1.txt → lib/tap/generator/generators/script/USAGE} +0 -0
- data/lib/tap/generator/generators/script/script_generator.rb +17 -0
- data/lib/tap/generator/generators/script/templates/script.erb +42 -0
- data/lib/tap/generator/generators/task/task_generator.rb +1 -1
- data/lib/tap/generator/generators/task/templates/task.erb +24 -16
- data/lib/tap/generator/generators/task/templates/test.erb +13 -17
- data/lib/tap/generator/generators/workflow/templates/task.erb +10 -10
- data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
- data/lib/tap/generator/generators/workflow/workflow_generator.rb +3 -18
- data/lib/tap/root.rb +108 -146
- data/lib/tap/script.rb +362 -0
- data/lib/tap/script/console.rb +28 -0
- data/lib/tap/script/destroy.rb +13 -1
- data/lib/tap/script/generate.rb +13 -1
- data/lib/tap/script/run.rb +100 -57
- data/lib/tap/support/batch_queue.rb +0 -3
- data/lib/tap/support/logger.rb +6 -3
- data/lib/tap/support/rake.rb +54 -0
- data/lib/tap/support/task_configuration.rb +169 -0
- data/lib/tap/support/tdoc.rb +198 -0
- data/lib/tap/support/tdoc/config_attr.rb +338 -0
- data/lib/tap/support/tdoc/tdoc_html_generator.rb +38 -0
- data/lib/tap/support/tdoc/tdoc_html_template.rb +42 -0
- data/lib/tap/support/versions.rb +33 -1
- data/lib/tap/task.rb +339 -227
- data/lib/tap/test.rb +86 -128
- data/lib/tap/test/env_vars.rb +16 -5
- data/lib/tap/test/file_methods.rb +373 -0
- data/lib/tap/test/subset_methods.rb +299 -180
- data/lib/tap/version.rb +2 -1
- data/lib/tap/workflow.rb +2 -0
- data/test/app/lib/app_test_task.rb +1 -0
- data/test/app_test.rb +327 -83
- data/test/check/binding_eval.rb +23 -0
- data/test/check/define_method_check.rb +22 -0
- data/test/check/dependencies_check.rb +175 -0
- data/test/check/inheritance_check.rb +22 -0
- data/test/file_task_test.rb +524 -291
- data/test/{test/inference_methods/test_infer_glob/expected/file_2.txt → root/glob/one.txt} +0 -0
- data/test/root/glob/two.txt +0 -0
- data/test/root_test.rb +330 -262
- data/test/script_test.rb +194 -0
- data/test/support/audit_test.rb +5 -2
- data/test/support/combinator_test.rb +10 -10
- data/test/support/rake_test.rb +35 -0
- data/test/support/task_configuration_test.rb +272 -0
- data/test/support/tdoc_test.rb +363 -0
- data/test/support/templater_test.rb +2 -2
- data/test/support/versions_test.rb +32 -0
- data/test/tap_test_helper.rb +39 -0
- data/test/task_base_test.rb +115 -0
- data/test/task_class_test.rb +56 -4
- data/test/task_execute_test.rb +29 -0
- data/test/task_test.rb +89 -70
- data/test/test/env_vars_test.rb +48 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/file.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/folder/file.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/input/file.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/input/folder/file.txt +0 -0
- data/test/test/file_methods/test_assert_files_exist/input/input_1.txt +0 -0
- data/test/test/file_methods/test_assert_files_exist/input/input_2.txt +0 -0
- data/test/test/file_methods/test_assert_output_files_equal/expected/one.txt +1 -0
- data/test/test/file_methods/test_assert_output_files_equal/expected/two.txt +1 -0
- data/test/test/file_methods/test_assert_output_files_equal/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_output_files_equal/input/two.txt +1 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_1.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_2.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_1.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_2.txt +0 -0
- data/test/test/file_methods/test_infer_glob/expected/file.yml +0 -0
- data/test/test/file_methods/test_infer_glob/expected/file_1.txt +0 -0
- data/test/test/file_methods/test_infer_glob/expected/file_2.txt +0 -0
- data/test/test/file_methods/test_method_glob/expected/file.yml +0 -0
- data/test/test/file_methods/test_method_glob/expected/file_1.txt +0 -0
- data/test/test/file_methods/test_method_glob/expected/file_2.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_1.yml +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_2.yml +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_1.yml +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_2.yml +0 -0
- data/test/test/file_methods_test.rb +204 -0
- data/test/test/subset_methods_test.rb +93 -33
- data/test/test/test_assert_expected_result_files/expected/task/name/a.txt +1 -0
- data/test/test/test_assert_expected_result_files/expected/task/name/b.txt +1 -0
- data/test/test/test_assert_expected_result_files/input/a.txt +1 -0
- data/test/test/test_assert_expected_result_files/input/b.txt +1 -0
- data/test/test/test_file_task_test/expected/one.txt +1 -0
- data/test/test/test_file_task_test/expected/two.txt +1 -0
- data/test/test/test_file_task_test/input/one.txt +1 -0
- data/test/test/test_file_task_test/input/two.txt +1 -0
- data/test/test_test.rb +143 -3
- data/test/workflow_test.rb +2 -0
- data/vendor/rails_generator.rb +56 -0
- data/vendor/rails_generator/base.rb +263 -0
- data/vendor/rails_generator/commands.rb +581 -0
- data/vendor/rails_generator/generated_attribute.rb +42 -0
- data/vendor/rails_generator/lookup.rb +209 -0
- data/vendor/rails_generator/manifest.rb +53 -0
- data/vendor/rails_generator/options.rb +143 -0
- data/vendor/rails_generator/scripts.rb +83 -0
- data/vendor/rails_generator/scripts/destroy.rb +7 -0
- data/vendor/rails_generator/scripts/generate.rb +7 -0
- data/vendor/rails_generator/scripts/update.rb +12 -0
- data/vendor/rails_generator/simple_logger.rb +46 -0
- data/vendor/rails_generator/spec.rb +44 -0
- metadata +180 -196
- data/lib/tap/generator/generators/root/templates/app.yml +0 -19
- data/lib/tap/generator/generators/root/templates/config/process_tap_request.yml +0 -4
- data/lib/tap/generator/generators/root/templates/lib/process_tap_request.rb +0 -26
- data/lib/tap/generator/generators/root/templates/public/images/nav.jpg +0 -0
- data/lib/tap/generator/generators/root/templates/public/stylesheets/color.css +0 -57
- data/lib/tap/generator/generators/root/templates/public/stylesheets/layout.css +0 -108
- data/lib/tap/generator/generators/root/templates/public/stylesheets/normalize.css +0 -40
- data/lib/tap/generator/generators/root/templates/public/stylesheets/typography.css +0 -21
- data/lib/tap/generator/generators/root/templates/server/config/environment.rb +0 -60
- data/lib/tap/generator/generators/root/templates/server/lib/tasks/clear_database_prerequisites.rake +0 -5
- data/lib/tap/generator/generators/root/templates/server/test/test_helper.rb +0 -53
- data/lib/tap/script/server.rb +0 -12
- data/lib/tap/support/rap.rb +0 -38
- data/lib/tap/test/inference_methods.rb +0 -298
- data/test/task/config/task_with_config.yml +0 -1
- data/test/test/inference_methods_test.rb +0 -311
data/lib/tap/version.rb
CHANGED
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
|
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
|
11
|
-
|
12
|
-
|
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
|
-
|
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
|
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
|
-
|
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
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
assert_equal
|
137
|
-
assert_equal task,
|
138
|
-
assert_equal
|
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
|
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
|
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
|
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
|
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
|
170
|
-
assert_raise(
|
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
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
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
|
-
|
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
|
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
|
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
|
-
|
770
|
-
|
771
|
-
|
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
|
-
|
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(
|
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
|
-
|
1172
|
-
|
1173
|
-
|
1174
|
-
|
1175
|
-
|
1176
|
-
|
1177
|
-
|
1178
|
-
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
|
1183
|
-
|
1184
|
-
|
1185
|
-
|
1186
|
-
|
1187
|
-
|
1188
|
-
|
1189
|
-
|
1190
|
-
|
1191
|
-
|
1192
|
-
|
1193
|
-
|
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
|
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
|
1578
|
+
sleep 1
|
1579
|
+
t.check_terminate
|
1336
1580
|
rescue
|
1337
1581
|
count_in_threaded_error_handling += 1
|
1338
1582
|
raise "term error #{n}"
|