tap 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Basic Overview +151 -0
- data/Command Reference +99 -0
- data/History +24 -0
- data/MIT-LICENSE +1 -1
- data/README +29 -57
- data/Rakefile +30 -37
- data/Tutorial +243 -191
- data/bin/tap +66 -35
- data/lib/tap.rb +47 -29
- data/lib/tap/app.rb +700 -342
- data/lib/tap/{script → cmd}/console.rb +0 -0
- data/lib/tap/{script → cmd}/destroy.rb +0 -0
- data/lib/tap/{script → cmd}/generate.rb +0 -0
- data/lib/tap/cmd/run.rb +156 -0
- data/lib/tap/constants.rb +4 -0
- data/lib/tap/dump.rb +57 -0
- data/lib/tap/env.rb +316 -0
- data/lib/tap/file_task.rb +106 -109
- data/lib/tap/generator.rb +4 -1
- data/lib/tap/generator/generators/command/USAGE +6 -0
- data/lib/tap/generator/generators/command/command_generator.rb +17 -0
- data/lib/tap/generator/generators/{script/templates/script.erb → command/templates/command.erb} +10 -10
- data/lib/tap/generator/generators/config/USAGE +21 -0
- data/lib/tap/generator/generators/config/config_generator.rb +17 -7
- data/lib/tap/generator/generators/file_task/USAGE +3 -0
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +16 -0
- data/lib/tap/generator/generators/file_task/templates/file.txt +2 -0
- data/lib/tap/generator/generators/file_task/templates/file.yml +3 -0
- data/lib/tap/generator/generators/file_task/templates/task.erb +26 -20
- data/lib/tap/generator/generators/file_task/templates/test.erb +20 -10
- data/lib/tap/generator/generators/generator/generator_generator.rb +1 -1
- data/lib/tap/generator/generators/generator/templates/generator.erb +21 -12
- data/lib/tap/generator/generators/root/templates/Rakefile +33 -24
- data/lib/tap/generator/generators/root/templates/tap.yml +28 -31
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +1 -0
- data/lib/tap/generator/generators/task/USAGE +3 -0
- data/lib/tap/generator/generators/task/task_generator.rb +18 -5
- data/lib/tap/generator/generators/task/templates/task.erb +7 -12
- data/lib/tap/generator/generators/task/templates/test.erb +10 -11
- data/lib/tap/generator/generators/workflow/templates/task.erb +1 -1
- data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
- data/lib/tap/patches/rake/rake_test_loader.rb +8 -0
- data/lib/tap/patches/rake/testtask.rb +55 -0
- data/lib/tap/patches/ruby19/backtrace_filter.rb +51 -0
- data/lib/tap/patches/ruby19/parsedate.rb +16 -0
- data/lib/tap/root.rb +172 -67
- data/lib/tap/script.rb +70 -336
- data/lib/tap/support/aggregator.rb +55 -0
- data/lib/tap/support/audit.rb +281 -280
- data/lib/tap/support/batchable.rb +59 -0
- data/lib/tap/support/class_configuration.rb +279 -0
- data/lib/tap/support/configurable.rb +92 -0
- data/lib/tap/support/configurable_methods.rb +296 -0
- data/lib/tap/support/executable.rb +98 -0
- data/lib/tap/support/executable_queue.rb +82 -0
- data/lib/tap/support/logger.rb +9 -15
- data/lib/tap/support/rake.rb +43 -54
- data/lib/tap/support/run_error.rb +32 -13
- data/lib/tap/support/shell_utils.rb +47 -0
- data/lib/tap/support/tdoc.rb +9 -8
- data/lib/tap/support/tdoc/config_attr.rb +40 -16
- data/lib/tap/support/validation.rb +77 -0
- data/lib/tap/support/versions.rb +36 -36
- data/lib/tap/task.rb +276 -482
- data/lib/tap/test.rb +20 -261
- data/lib/tap/test/env_vars.rb +7 -5
- data/lib/tap/test/file_methods.rb +126 -121
- data/lib/tap/test/subset_methods.rb +86 -45
- data/lib/tap/test/tap_methods.rb +271 -0
- data/lib/tap/workflow.rb +174 -46
- data/test/app/config/another/task.yml +1 -0
- data/test/app/config/erb.yml +2 -1
- data/test/app/config/some/task.yml +1 -0
- data/test/app/config/template.yml +2 -6
- data/test/app_test.rb +1241 -1008
- data/test/env/test_configure/recurse_a.yml +2 -0
- data/test/env/test_configure/recurse_b.yml +2 -0
- data/test/env/test_configure/tap.yml +23 -0
- data/test/env/test_load_env_config/dir/tap.yml +3 -0
- data/test/env/test_load_env_config/recurse_a.yml +2 -0
- data/test/env/test_load_env_config/recurse_b.yml +2 -0
- data/test/env/test_load_env_config/tap.yml +3 -0
- data/test/env_test.rb +198 -0
- data/test/file_task_test.rb +70 -53
- data/{lib/tap/generator/generators/package/USAGE → test/root/file.txt} +0 -0
- data/test/root_test.rb +621 -454
- data/test/script_test.rb +38 -174
- data/test/support/aggregator_test.rb +99 -0
- data/test/support/audit_test.rb +409 -416
- data/test/support/batchable_test.rb +74 -0
- data/test/support/{task_configuration_test.rb → class_configuration_test.rb} +106 -47
- data/test/{task/config/overriding.yml → support/configurable/config/configured.yml} +0 -0
- data/test/support/configurable_test.rb +295 -0
- data/test/support/executable_queue_test.rb +103 -0
- data/test/support/executable_test.rb +38 -0
- data/test/support/logger_test.rb +17 -17
- data/test/support/rake_test.rb +4 -2
- data/test/support/shell_utils_test.rb +24 -0
- data/test/support/tdoc_test.rb +265 -258
- data/test/support/validation_test.rb +54 -0
- data/test/support/versions_test.rb +38 -38
- data/test/tap_test_helper.rb +19 -5
- data/test/tap_test_suite.rb +5 -2
- data/test/task_base_test.rb +13 -104
- data/test/task_syntax_test.rb +300 -0
- data/test/task_test.rb +258 -381
- data/test/test/env_vars_test.rb +40 -40
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/one.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/two.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/one.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/two.txt +0 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/one.txt +0 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/two.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/one.txt +1 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_different_content}/expected/two.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/input/two.txt +1 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_missing_expected_file}/expected/one.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/two.txt +1 -0
- data/test/test/file_methods_doc/test_sub/expected/one.txt +1 -0
- data/test/test/file_methods_doc/test_sub/expected/two.txt +1 -0
- data/test/test/file_methods_doc/test_sub/input/one.txt +1 -0
- data/test/test/file_methods_doc/test_sub/input/two.txt +1 -0
- data/test/test/file_methods_doc_test.rb +29 -0
- data/test/test/file_methods_test.rb +214 -143
- data/test/test/subset_methods_test.rb +111 -115
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/a.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/b.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/a.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/b.txt +0 -0
- data/test/test/tap_methods_test.rb +399 -0
- data/test/workflow_test.rb +101 -91
- metadata +86 -70
- data/lib/tap/generator/generators/package/package_generator.rb +0 -38
- data/lib/tap/generator/generators/package/templates/package.erb +0 -186
- data/lib/tap/generator/generators/script/USAGE +0 -0
- data/lib/tap/generator/generators/script/script_generator.rb +0 -17
- data/lib/tap/script/run.rb +0 -154
- data/lib/tap/support/batch_queue.rb +0 -162
- data/lib/tap/support/combinator.rb +0 -114
- data/lib/tap/support/task_configuration.rb +0 -169
- data/lib/tap/support/template.rb +0 -81
- data/lib/tap/support/templater.rb +0 -155
- data/lib/tap/version.rb +0 -4
- data/test/app/config/addition_template.yml +0 -6
- data/test/app_class_test.rb +0 -33
- data/test/check/binding_eval.rb +0 -23
- data/test/check/define_method_check.rb +0 -22
- data/test/check/dependencies_check.rb +0 -175
- data/test/check/inheritance_check.rb +0 -22
- data/test/support/batch_queue_test.rb +0 -320
- data/test/support/combinator_test.rb +0 -249
- data/test/support/template_test.rb +0 -122
- data/test/support/templater/erb.txt +0 -2
- data/test/support/templater/erb.yml +0 -2
- data/test/support/templater/somefile.txt +0 -2
- data/test/support/templater_test.rb +0 -192
- data/test/task/config/template.yml +0 -4
- data/test/task_class_test.rb +0 -170
- data/test/task_execute_test.rb +0 -262
- data/test/test/file_methods/test_assert_expected/expected/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/expected/folder/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/input/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/input/folder/file.txt +0 -1
- 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_file_compare/expected/output_1.txt +0 -3
- data/test/test/file_methods/test_file_compare/expected/output_2.txt +0 -1
- data/test/test/file_methods/test_file_compare/input/input_1.txt +0 -3
- data/test/test/file_methods/test_file_compare/input/input_2.txt +0 -3
- 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_yml_compare/expected/output_1.yml +0 -6
- data/test/test/file_methods/test_yml_compare/expected/output_2.yml +0 -6
- data/test/test/file_methods/test_yml_compare/input/input_1.yml +0 -4
- data/test/test/file_methods/test_yml_compare/input/input_2.yml +0 -4
- data/test/test_test.rb +0 -373
data/test/task_test.rb
CHANGED
@@ -6,25 +6,42 @@ class ConfiguredTask < Tap::Task
|
|
6
6
|
config :one, 'one'
|
7
7
|
config :two, 'two'
|
8
8
|
end
|
9
|
+
class ValidatingTask < Tap::Task
|
10
|
+
config :string, 'str', &c.check(String)
|
11
|
+
config :integer, 1, &c.yaml(Integer)
|
12
|
+
end
|
13
|
+
|
14
|
+
class SubclassTask < Tap::Task
|
15
|
+
attr_accessor :shared_variable, :instance_specific_variable
|
16
|
+
def initialize(*args)
|
17
|
+
@shared_variable = Object.new
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize_batch_obj(*args)
|
22
|
+
task = super
|
23
|
+
task.instance_specific_variable = Object.new
|
24
|
+
task
|
25
|
+
end
|
26
|
+
end
|
9
27
|
|
10
28
|
class TaskTest < Test::Unit::TestCase
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
29
|
+
include Tap
|
30
|
+
include TapTestMethods
|
31
|
+
|
32
|
+
acts_as_tap_test
|
33
|
+
attr_accessor :t
|
34
|
+
|
35
|
+
def setup
|
36
|
+
super
|
37
|
+
@t = Task.new
|
38
|
+
app.root = trs.root
|
39
|
+
end
|
40
|
+
|
23
41
|
def test_documentation
|
24
42
|
t = ConfiguredTask.new
|
25
|
-
assert_equal({:one => 'one', :two => 'two'}, t.config)
|
26
43
|
assert_equal("configured_task", t.name)
|
27
|
-
assert_equal(
|
44
|
+
assert_equal({:one => 'one', :two => 'two'}, t.config)
|
28
45
|
|
29
46
|
###
|
30
47
|
# [/path/to/app/config/example.yml]
|
@@ -35,34 +52,13 @@ class TaskTest < Test::Unit::TestCase
|
|
35
52
|
assert_equal(File.join(app[:config], "example.yml"), t.config_file)
|
36
53
|
assert_equal({:one => 'ONE', :two => 'two', :three => 'three'}, t.config)
|
37
54
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
runlist = []
|
47
|
-
t1.iterate = false
|
48
|
-
t1.enq 1
|
49
|
-
t1.enq 2,3
|
50
|
-
t1.app.run
|
51
|
-
assert_equal([[1,2,3]], runlist)
|
52
|
-
|
53
|
-
###
|
54
|
-
runlist = []
|
55
|
-
t1 = Task.new {|task, input| runlist << input}
|
56
|
-
assert_equal([t1], t1.batch)
|
57
|
-
t2 = t1.create_batch_task
|
58
|
-
assert_equal([t1, t2], t1.batch)
|
59
|
-
|
60
|
-
t1.enq 1
|
61
|
-
t2.enq 2,3
|
62
|
-
t1.app.run
|
63
|
-
|
64
|
-
assert_equal([1,2,3, 1,2,3], runlist)
|
65
|
-
|
55
|
+
t = ValidatingTask.new
|
56
|
+
assert_raise(Support::Validation::ValidationError) { t.string = 1 }
|
57
|
+
assert_raise(Support::Validation::ValidationError) { t.integer = 1.1 }
|
58
|
+
|
59
|
+
t.integer = "1"
|
60
|
+
assert_equal 1, t.integer
|
61
|
+
|
66
62
|
####
|
67
63
|
# [/path/to/app/config/batch.yml]
|
68
64
|
# - one: ONE
|
@@ -73,371 +69,252 @@ class TaskTest < Test::Unit::TestCase
|
|
73
69
|
t1, t2 = t.batch
|
74
70
|
|
75
71
|
assert_equal("batch", t1.name)
|
76
|
-
assert_equal({:one => 'ONE'}, t1.config_template)
|
77
72
|
assert_equal({:one => 'ONE', :two => 'two'}, t1.config)
|
78
73
|
|
79
74
|
assert_equal("batch", t2.name)
|
80
|
-
assert_equal({:one => 'ANOTHER ONE'}, t2.
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
75
|
+
assert_equal({:one => 'ANOTHER ONE', :two => 'two'}, t2.config)
|
76
|
+
|
77
|
+
###
|
78
|
+
runlist = []
|
79
|
+
t1 = Task.new {|task, input| runlist << input}
|
80
|
+
assert_equal [t1], t1.batch
|
81
|
+
|
82
|
+
t2 = t1.initialize_batch_obj
|
83
|
+
assert_equal [t1, t2], t1.batch
|
84
|
+
assert_equal [t1, t2], t2.batch
|
85
|
+
|
86
|
+
t1.enq 1
|
87
|
+
t2.enq 2
|
88
|
+
t1.app.run
|
89
|
+
|
90
|
+
assert_equal [1,1,2,2], runlist
|
91
|
+
end
|
92
|
+
|
93
|
+
#
|
94
|
+
# initialization tests
|
95
|
+
#
|
90
96
|
|
91
|
-
t = ConfiguredTask.new "template"
|
92
|
-
assert_equal(2, t.batch.size)
|
93
|
-
t1, t2 = t.batch
|
94
97
|
|
95
|
-
|
96
|
-
|
98
|
+
def test_initialize_documenation
|
99
|
+
t1 = SubclassTask.new
|
100
|
+
t2 = t1.initialize_batch_obj
|
101
|
+
|
102
|
+
assert t1.shared_variable == t2.shared_variable
|
103
|
+
assert t1.instance_specific_variable != t2.instance_specific_variable
|
97
104
|
end
|
98
105
|
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
106
|
+
def test_default_initialization
|
107
|
+
assert_equal App.instance, t.app
|
108
|
+
assert_equal({}, t.config)
|
109
|
+
assert_equal [t], t.batch
|
110
|
+
assert_nil t.task_block
|
111
|
+
assert_equal "tap/task", t.name
|
112
|
+
end
|
113
|
+
|
114
|
+
def test_initialization_inputs
|
115
|
+
a = App.new
|
116
|
+
b = lambda {}
|
117
|
+
|
118
|
+
t = Task.new("name", {:key => 'value'}, a, &b)
|
119
|
+
assert_equal "name", t.name
|
120
|
+
assert_equal({:key => 'value'}, t.config)
|
121
|
+
assert_equal a, t.app
|
122
|
+
assert_equal b, t.task_block
|
123
|
+
end
|
116
124
|
|
117
125
|
def test_task_init_speed
|
118
|
-
benchmark_test do |x|
|
119
|
-
|
126
|
+
benchmark_test(20) do |x|
|
127
|
+
x.report("10k") { 10000.times { Task.new } }
|
128
|
+
x.report("10k {}") { 10000.times { Task.new {} } }
|
129
|
+
x.report("10k name {}") { 10000.times { Task.new('name') {} } }
|
120
130
|
end
|
121
131
|
end
|
122
132
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
end
|
130
|
-
|
131
|
-
class NamedTask < Task
|
133
|
+
def test_by_default_tasks_share_application_instance
|
134
|
+
t1 = Task.new
|
135
|
+
t2 = Task.new
|
136
|
+
|
137
|
+
assert_equal t1.app, t2.app
|
138
|
+
assert_equal App.instance, t1.app
|
132
139
|
end
|
133
140
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
t1, t2 = t.batch
|
165
|
-
assert_equal({:key => 'first'}, t1.config_template)
|
166
|
-
assert_equal({:key => 'second'}, t2.config_template)
|
167
|
-
end
|
168
|
-
|
169
|
-
def test_configs_are_merged_to_each_batched_task
|
170
|
-
t = Task.new "batched", :another => 'value'
|
171
|
-
t1, t2 = t.batch
|
172
|
-
assert_equal({:key => 'first', :another => 'value'}, t1.config)
|
173
|
-
assert_equal({:key => 'second', :another => 'value'}, t2.config)
|
174
|
-
end
|
175
|
-
|
176
|
-
#
|
177
|
-
# create_batch_task test
|
178
|
-
#
|
179
|
-
|
180
|
-
def test_created_batch_tasks_are_added_to_and_share_the_same_batch
|
181
|
-
assert_equal [t], t.batch
|
182
|
-
|
183
|
-
t1 = t.create_batch_task
|
184
|
-
t2 = t1.create_batch_task
|
185
|
-
|
186
|
-
assert_equal [t, t1, t2], t.batch
|
187
|
-
assert_equal t.batch.object_id, t1.batch.object_id
|
188
|
-
assert_equal t.batch.object_id, t2.batch.object_id
|
189
|
-
end
|
190
|
-
|
191
|
-
def test_create_batch_task_uses_input_template_and_overrides
|
192
|
-
t = TaskWithDefaultConfig.new "overriding", :three => 3
|
193
|
-
assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t.class.configurations.default)
|
194
|
-
assert_equal({:two => 'TWO', :three => 'THREE'}, t.config_template)
|
195
|
-
assert_equal({:one => 'one', :two => 'TWO', :three => 3}, t.config)
|
196
|
-
|
197
|
-
t1 = t.create_batch_task
|
198
|
-
assert_equal({}, t1.config_template)
|
199
|
-
assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t1.config)
|
141
|
+
#
|
142
|
+
# config tests
|
143
|
+
#
|
144
|
+
|
145
|
+
def test_config_is_loaded_from_config_file
|
146
|
+
t = Task.new "configured"
|
147
|
+
assert File.exists?(t.config_file)
|
148
|
+
assert_equal "key: value", File.read(t.config_file)
|
149
|
+
assert_equal({:key => 'value'}, t.config)
|
150
|
+
end
|
151
|
+
|
152
|
+
def test_batched_tasks_are_defined_with_corresponding_configs_for_batched_config_files
|
153
|
+
t = Task.new "batched"
|
154
|
+
assert File.exists?(t.config_file)
|
155
|
+
assert_equal "- key: first\n- key: second", File.read(t.config_file)
|
156
|
+
|
157
|
+
assert_equal 2, t.batch.size
|
158
|
+
|
159
|
+
t1, t2 = t.batch
|
160
|
+
assert_equal({:key => 'first'}, t1.config)
|
161
|
+
assert_equal({:key => 'second'}, t2.config)
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_configs_are_merged_to_each_batched_task
|
165
|
+
t = Task.new "batched", :another => 'value'
|
166
|
+
t1, t2 = t.batch
|
167
|
+
assert_equal({:key => 'first', :another => 'value'}, t1.config)
|
168
|
+
assert_equal({:key => 'second', :another => 'value'}, t2.config)
|
169
|
+
end
|
200
170
|
|
201
|
-
t2 = t.create_batch_task({:two => "TWO", :three => "THREE"}, {:three => 3})
|
202
|
-
assert_equal({:two => "TWO", :three => "THREE"}, t2.config_template)
|
203
|
-
assert_equal({:one => 'one', :two => 'TWO', :three => 3}, t2.config)
|
204
|
-
end
|
205
|
-
|
206
|
-
#
|
207
|
-
# batched? test
|
208
|
-
#
|
209
|
-
|
210
|
-
def test_batched_returns_true_if_batch_size_is_greater_than_one
|
211
|
-
assert !t.batched?
|
212
|
-
assert_equal 1, t.batch.size
|
213
|
-
|
214
|
-
t1 = t.create_batch_task
|
215
|
-
|
216
|
-
assert t.batched?
|
217
|
-
assert t1.batched?
|
218
|
-
end
|
219
|
-
|
220
|
-
#
|
221
|
-
# batch_index test
|
222
|
-
#
|
223
|
-
|
224
|
-
def test_batch_index_returns_the_index_of_the_task_in_batch
|
225
|
-
t1 = t.create_batch_task
|
226
|
-
|
227
|
-
assert_equal [t, t1], t.batch
|
228
|
-
assert_equal 0, t.batch_index
|
229
|
-
assert_equal 1, t1.batch_index
|
230
|
-
end
|
231
|
-
|
232
|
-
#
|
233
|
-
# config_file test
|
234
|
-
#
|
235
|
-
|
236
|
-
def test_config_file_returns_yml_filepath_for_name_relative_to_app_config_dir
|
237
|
-
assert_equal File.join(t.app['config'], t.name + ".yml"), t.config_file
|
238
|
-
end
|
239
|
-
|
240
171
|
#
|
241
|
-
#
|
172
|
+
# enq test
|
242
173
|
#
|
174
|
+
|
175
|
+
def test_enq_enqueues_task_to_app_queue_with_inputs
|
176
|
+
assert t.app.queue.empty?
|
177
|
+
|
178
|
+
t.enq 1
|
179
|
+
|
180
|
+
assert_equal 1, t.app.queue.size
|
181
|
+
assert_equal [[t, [1]]], t.app.queue.to_a
|
182
|
+
|
183
|
+
t.enq 1
|
184
|
+
t.enq 2
|
185
|
+
|
186
|
+
assert_equal [[t, [1]], [t, [1]], [t, [2]]], t.app.queue.to_a
|
187
|
+
end
|
243
188
|
|
244
|
-
def
|
245
|
-
|
246
|
-
|
189
|
+
def test_enq_enqueues_task_batch
|
190
|
+
t2 = t.initialize_batch_obj
|
191
|
+
|
192
|
+
assert t.app.queue.empty?
|
193
|
+
assert_equal 2, t.batch.size
|
194
|
+
|
195
|
+
t.enq 1
|
196
|
+
|
197
|
+
assert_equal 2, t.app.queue.size
|
198
|
+
assert_equal [[t, [1]], [t2, [1]]], t.app.queue.to_a
|
247
199
|
end
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
#
|
252
|
-
|
253
|
-
class ConfigDocSampleTask < Tap::Task
|
254
|
-
config :key, 'value'
|
200
|
+
|
201
|
+
def test_unbatched_enq_only_enqueues_task
|
202
|
+
t2 = t.initialize_batch_obj
|
255
203
|
|
256
|
-
|
257
|
-
|
204
|
+
assert_equal 2, t.batch.size
|
205
|
+
assert t.app.queue.empty?
|
206
|
+
t.unbatched_enq 1
|
207
|
+
|
208
|
+
assert_equal 1, t.app.queue.size
|
209
|
+
assert_equal [[t, [1]]], t.app.queue.to_a
|
258
210
|
end
|
211
|
+
|
212
|
+
#
|
213
|
+
# on_complete test
|
214
|
+
#
|
215
|
+
|
216
|
+
def test_on_complete_completes_task_batch
|
217
|
+
t2 = t.initialize_batch_obj
|
218
|
+
|
219
|
+
assert_nil t.on_complete_block
|
220
|
+
assert_nil t2.on_complete_block
|
221
|
+
|
222
|
+
b = lambda {}
|
223
|
+
t.on_complete(&b)
|
224
|
+
|
225
|
+
assert_equal b, t.on_complete_block
|
226
|
+
assert_equal b, t2.on_complete_block
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_unbatched_on_complete_only_completes_task
|
230
|
+
t2 = t.initialize_batch_obj
|
231
|
+
|
232
|
+
assert_nil t.on_complete_block
|
233
|
+
assert_nil t2.on_complete_block
|
259
234
|
|
260
|
-
|
261
|
-
t
|
262
|
-
|
263
|
-
|
235
|
+
b = lambda {}
|
236
|
+
t.unbatched_on_complete(&b)
|
237
|
+
|
238
|
+
assert_equal b, t.on_complete_block
|
239
|
+
assert_nil t2.on_complete_block
|
240
|
+
end
|
241
|
+
|
242
|
+
#
|
243
|
+
# multithread= test
|
244
|
+
#
|
264
245
|
|
265
|
-
|
266
|
-
|
267
|
-
t.key = 'another'
|
268
|
-
assert_equal({:key => 'another', :reader_only => nil}, t.config)
|
269
|
-
end
|
270
|
-
|
271
|
-
class TaskWithDefaultConfig < Task
|
272
|
-
config :one, 'one'
|
273
|
-
config :two, 'two'
|
274
|
-
config :three, 'three'
|
275
|
-
end
|
276
|
-
|
277
|
-
def test_config_sets_config
|
278
|
-
assert_equal({}, t.config)
|
279
|
-
t.config = {:key => 'value'}
|
280
|
-
assert_equal({:key => 'value'}, t.config)
|
281
|
-
end
|
282
|
-
|
283
|
-
def test_config_merges_class_defaults_and_config_template_and_inputs_in_order
|
284
|
-
t = TaskWithDefaultConfig.new "overriding"
|
285
|
-
assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t.class.configurations.default)
|
286
|
-
assert_equal({:two => 'TWO', :three => 'THREE'}, t.config_template)
|
287
|
-
|
288
|
-
t.config = {:three => 3}
|
289
|
-
assert_equal({:one => 'one', :two => 'TWO', :three => 3}, t.config)
|
290
|
-
end
|
291
|
-
|
292
|
-
def test_nil_is_treated_as_empty_hash
|
293
|
-
t = TaskWithDefaultConfig.new "overriding"
|
294
|
-
assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t.class.configurations.default)
|
295
|
-
assert_equal({:two => 'TWO', :three => 'THREE'}, t.config_template)
|
296
|
-
|
297
|
-
t.config[:three] = 3
|
298
|
-
assert_equal({:one => 'one', :two => 'TWO', :three => 3}, t.config)
|
299
|
-
|
300
|
-
t.config = nil
|
301
|
-
assert_equal({:one => 'one', :two => 'TWO', :three => 'THREE'}, t.config)
|
302
|
-
end
|
303
|
-
|
304
|
-
class TaskWithManyConfigs < Task
|
305
|
-
config :one, 'one'
|
306
|
-
|
307
|
-
declare_config
|
308
|
-
config :two, 'two'
|
246
|
+
def test_set_multithread_sets_multithread_for_task_batch
|
247
|
+
t2 = t.initialize_batch_obj
|
309
248
|
|
310
|
-
|
311
|
-
|
249
|
+
assert !t.multithread
|
250
|
+
assert !t2.multithread
|
251
|
+
|
252
|
+
t.multithread = true
|
312
253
|
|
313
|
-
|
314
|
-
|
254
|
+
assert t.multithread
|
255
|
+
assert t2.multithread
|
256
|
+
end
|
257
|
+
|
258
|
+
def test_unbatched_set_multithread_sets_multithread_for_task_only
|
259
|
+
t2 = t.initialize_batch_obj
|
315
260
|
|
316
|
-
|
317
|
-
|
261
|
+
assert !t.multithread
|
262
|
+
assert !t2.multithread
|
263
|
+
|
264
|
+
t.unbatched_multithread = true
|
318
265
|
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
266
|
+
assert t.multithread
|
267
|
+
assert !t2.multithread
|
268
|
+
end
|
269
|
+
|
270
|
+
#
|
271
|
+
# to_s test
|
272
|
+
#
|
273
|
+
|
274
|
+
def test_to_s_returns_name
|
275
|
+
assert_equal t.name, t.to_s
|
276
|
+
t = Task.new("alt_name")
|
277
|
+
assert_equal "alt_name", t.to_s
|
278
|
+
end
|
279
|
+
|
280
|
+
#
|
281
|
+
# process test
|
282
|
+
#
|
283
|
+
|
284
|
+
class TaskWithTwoInputsForProcessDoc < Tap::Task
|
285
|
+
def process(a, b)
|
286
|
+
[b,a]
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
def test_process_documentation
|
291
|
+
t = TaskWithTwoInputsForProcessDoc.new
|
292
|
+
t.enq(1,2).enq(3,4)
|
293
|
+
t.app.run
|
294
|
+
assert_equal [[2,1], [4,3]], t.app.results(t)
|
295
|
+
|
296
|
+
t = Task.new {|task, a, b| [b,a] }
|
297
|
+
t.enq(1,2).enq(3,4)
|
298
|
+
t.app.run
|
299
|
+
assert_equal [[2,1], [4,3]], t.app.results(t)
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_process_calls_task_block_with_input
|
303
|
+
b = lambda do |task, input|
|
304
|
+
runlist << input
|
305
|
+
input += 1
|
306
|
+
end
|
307
|
+
t = Task.new(&b)
|
308
|
+
|
309
|
+
assert_equal b, t.task_block
|
310
|
+
assert_equal 2, t.process(1)
|
311
|
+
assert_equal [1], runlist
|
312
|
+
end
|
313
|
+
|
314
|
+
def test_process_returns_inputs_if_task_block_is_not_set
|
315
|
+
t = Task.new
|
316
|
+
assert_nil t.task_block
|
317
|
+
assert_equal [1,2,3], t.process(1,2,3)
|
318
|
+
end
|
347
319
|
|
348
|
-
# both
|
349
|
-
[:one, :five, :nine].each do |config|
|
350
|
-
assert t.respond_to?(config)
|
351
|
-
assert t.respond_to?("#{config}=")
|
352
|
-
end
|
353
|
-
|
354
|
-
# neither
|
355
|
-
[:two, :six].each do |config|
|
356
|
-
assert !t.respond_to?(config)
|
357
|
-
assert !t.respond_to?("#{config}=")
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
#
|
362
|
-
# queue test
|
363
|
-
#
|
364
|
-
|
365
|
-
def test_queue_enqueues_task_to_app_queue_with_inputs
|
366
|
-
assert t.app.queue.empty?
|
367
|
-
|
368
|
-
t.enq 1
|
369
|
-
|
370
|
-
assert_equal 1, t.app.queue.size
|
371
|
-
assert_equal [t, [1]], t.app.queue.deq
|
372
|
-
|
373
|
-
t.enq 1
|
374
|
-
t.enq 2
|
375
|
-
|
376
|
-
assert_equal [t, [1,2]], t.app.queue.deq
|
377
|
-
end
|
378
|
-
|
379
|
-
#
|
380
|
-
# process test
|
381
|
-
#
|
382
|
-
|
383
|
-
def test_process_calls_task_block_with_input
|
384
|
-
b = lambda do |task, input|
|
385
|
-
runlist << input
|
386
|
-
input += 1
|
387
|
-
end
|
388
|
-
t = Task.new(&b)
|
389
|
-
|
390
|
-
assert_equal b, t.task_block
|
391
|
-
assert_equal 2, t.process(1)
|
392
|
-
assert_equal [1], runlist
|
393
|
-
end
|
394
|
-
|
395
|
-
def test_process_returns_input_if_task_block_is_not_set
|
396
|
-
t = Task.new
|
397
|
-
|
398
|
-
assert_nil t.task_block
|
399
|
-
assert_equal 1, t.process(1)
|
400
|
-
end
|
401
|
-
|
402
|
-
#
|
403
|
-
# synchronize tests
|
404
|
-
#
|
405
|
-
|
406
|
-
def test_tasks_publically_respond_to_synchronize
|
407
|
-
assert t.respond_to?(:synchronize)
|
408
|
-
was_in_block = false
|
409
|
-
t.synchronize { was_in_block = true }
|
410
|
-
assert was_in_block
|
411
|
-
end
|
412
|
-
|
413
|
-
# JRuby inconsistent test?
|
414
|
-
def test_duplicate_tasks_are_monitored_separately
|
415
|
-
extended_test do
|
416
|
-
count = 0
|
417
|
-
max_count = 0
|
418
|
-
|
419
|
-
t1 = Task.new do |task, inputs|
|
420
|
-
task.synchronize do
|
421
|
-
count += 1
|
422
|
-
|
423
|
-
# max count will be 2 if both tasks execute
|
424
|
-
# simultaneously (ie they are monitored
|
425
|
-
# separately)
|
426
|
-
max_count = count if count > max_count
|
427
|
-
sleep 0.1
|
428
|
-
count -= 1
|
429
|
-
end
|
430
|
-
end
|
431
|
-
t2 = t1.dup
|
432
|
-
|
433
|
-
th_1 = Thread.new { t1.execute nil }
|
434
|
-
th_2 = Thread.new { t2.execute nil }
|
435
|
-
|
436
|
-
th_1.join
|
437
|
-
th_2.join
|
438
|
-
|
439
|
-
assert_equal 0, count
|
440
|
-
assert_equal 2, max_count
|
441
|
-
end
|
442
|
-
end
|
443
320
|
end
|