tap 0.7.9
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +21 -0
- data/README +71 -0
- data/Rakefile +117 -0
- data/bin/tap +63 -0
- data/lib/tap.rb +15 -0
- data/lib/tap/app.rb +739 -0
- data/lib/tap/file_task.rb +354 -0
- data/lib/tap/generator.rb +29 -0
- data/lib/tap/generator/generators/config/USAGE +0 -0
- data/lib/tap/generator/generators/config/config_generator.rb +23 -0
- data/lib/tap/generator/generators/config/templates/config.erb +2 -0
- data/lib/tap/generator/generators/file_task/USAGE +0 -0
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +21 -0
- data/lib/tap/generator/generators/file_task/templates/task.erb +27 -0
- data/lib/tap/generator/generators/file_task/templates/test.erb +12 -0
- data/lib/tap/generator/generators/root/USAGE +0 -0
- data/lib/tap/generator/generators/root/root_generator.rb +36 -0
- data/lib/tap/generator/generators/root/templates/Rakefile +48 -0
- data/lib/tap/generator/generators/root/templates/app.yml +19 -0
- data/lib/tap/generator/generators/root/templates/config/process_tap_request.yml +4 -0
- data/lib/tap/generator/generators/root/templates/lib/process_tap_request.rb +26 -0
- data/lib/tap/generator/generators/root/templates/public/images/nav.jpg +0 -0
- data/lib/tap/generator/generators/root/templates/public/stylesheets/color.css +57 -0
- data/lib/tap/generator/generators/root/templates/public/stylesheets/layout.css +108 -0
- data/lib/tap/generator/generators/root/templates/public/stylesheets/normalize.css +40 -0
- data/lib/tap/generator/generators/root/templates/public/stylesheets/typography.css +21 -0
- data/lib/tap/generator/generators/root/templates/server/config/environment.rb +60 -0
- data/lib/tap/generator/generators/root/templates/server/lib/tasks/clear_database_prerequisites.rake +5 -0
- data/lib/tap/generator/generators/root/templates/server/test/test_helper.rb +53 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +3 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +4 -0
- data/lib/tap/generator/generators/task/USAGE +0 -0
- data/lib/tap/generator/generators/task/task_generator.rb +21 -0
- data/lib/tap/generator/generators/task/templates/task.erb +21 -0
- data/lib/tap/generator/generators/task/templates/test.erb +29 -0
- data/lib/tap/generator/generators/workflow/USAGE +0 -0
- data/lib/tap/generator/generators/workflow/templates/task.erb +16 -0
- data/lib/tap/generator/generators/workflow/templates/test.erb +7 -0
- data/lib/tap/generator/generators/workflow/workflow_generator.rb +21 -0
- data/lib/tap/generator/options.rb +26 -0
- data/lib/tap/generator/usage.rb +26 -0
- data/lib/tap/root.rb +275 -0
- data/lib/tap/script/console.rb +7 -0
- data/lib/tap/script/destroy.rb +8 -0
- data/lib/tap/script/generate.rb +8 -0
- data/lib/tap/script/run.rb +111 -0
- data/lib/tap/script/server.rb +12 -0
- data/lib/tap/support/audit.rb +415 -0
- data/lib/tap/support/batch_queue.rb +165 -0
- data/lib/tap/support/combinator.rb +114 -0
- data/lib/tap/support/logger.rb +91 -0
- data/lib/tap/support/rap.rb +38 -0
- data/lib/tap/support/run_error.rb +20 -0
- data/lib/tap/support/template.rb +81 -0
- data/lib/tap/support/templater.rb +155 -0
- data/lib/tap/support/versions.rb +63 -0
- data/lib/tap/task.rb +448 -0
- data/lib/tap/test.rb +320 -0
- data/lib/tap/test/env_vars.rb +16 -0
- data/lib/tap/test/inference_methods.rb +298 -0
- data/lib/tap/test/subset_methods.rb +260 -0
- data/lib/tap/version.rb +3 -0
- data/lib/tap/workflow.rb +73 -0
- data/test/app/config/addition_template.yml +6 -0
- data/test/app/config/batch.yml +2 -0
- data/test/app/config/empty.yml +0 -0
- data/test/app/config/erb.yml +1 -0
- data/test/app/config/template.yml +6 -0
- data/test/app/config/version-0.1.yml +1 -0
- data/test/app/config/version.yml +1 -0
- data/test/app/lib/app_test_task.rb +2 -0
- data/test/app_class_test.rb +33 -0
- data/test/app_test.rb +1372 -0
- data/test/file_task/config/batch.yml +2 -0
- data/test/file_task/config/configured.yml +1 -0
- data/test/file_task/old_file_one.txt +0 -0
- data/test/file_task/old_file_two.txt +0 -0
- data/test/file_task_test.rb +1041 -0
- data/test/root/alt_lib/alt_module.rb +4 -0
- data/test/root/lib/absolute_alt_filepath.rb +2 -0
- data/test/root/lib/alternative_filepath.rb +2 -0
- data/test/root/lib/another_module.rb +2 -0
- data/test/root/lib/nested/some_module.rb +4 -0
- data/test/root/lib/no_module_included.rb +0 -0
- data/test/root/lib/some/module.rb +4 -0
- data/test/root/lib/some_class.rb +2 -0
- data/test/root/lib/some_module.rb +3 -0
- data/test/root/load_path/load_path_module.rb +2 -0
- data/test/root/load_path/skip_module.rb +2 -0
- data/test/root/mtime/older.txt +0 -0
- data/test/root/unload/full_path.rb +2 -0
- data/test/root/unload/loaded_by_nested.rb +2 -0
- data/test/root/unload/nested/nested_load.rb +6 -0
- data/test/root/unload/nested/nested_with_ext.rb +4 -0
- data/test/root/unload/nested/relative_path.rb +4 -0
- data/test/root/unload/older.rb +2 -0
- data/test/root/unload/unload_base.rb +9 -0
- data/test/root/versions/another.yml +0 -0
- data/test/root/versions/file-0.1.2.yml +0 -0
- data/test/root/versions/file-0.1.yml +0 -0
- data/test/root/versions/file.yml +0 -0
- data/test/root_test.rb +483 -0
- data/test/support/audit_test.rb +449 -0
- data/test/support/batch_queue_test.rb +320 -0
- data/test/support/combinator_test.rb +249 -0
- data/test/support/logger_test.rb +31 -0
- data/test/support/template_test.rb +122 -0
- data/test/support/templater/erb.txt +2 -0
- data/test/support/templater/erb.yml +2 -0
- data/test/support/templater/somefile.txt +2 -0
- data/test/support/templater_test.rb +192 -0
- data/test/support/versions_test.rb +71 -0
- data/test/tap_test_helper.rb +4 -0
- data/test/tap_test_suite.rb +4 -0
- data/test/task/config/batch.yml +2 -0
- data/test/task/config/batched.yml +2 -0
- data/test/task/config/configured.yml +1 -0
- data/test/task/config/example.yml +1 -0
- data/test/task/config/overriding.yml +2 -0
- data/test/task/config/task_with_config.yml +1 -0
- data/test/task/config/template.yml +4 -0
- data/test/task_class_test.rb +118 -0
- data/test/task_execute_test.rb +233 -0
- data/test/task_test.rb +424 -0
- data/test/test/inference_methods/test_assert_expected/expected/file.txt +1 -0
- data/test/test/inference_methods/test_assert_expected/expected/folder/file.txt +1 -0
- data/test/test/inference_methods/test_assert_expected/input/file.txt +1 -0
- data/test/test/inference_methods/test_assert_expected/input/folder/file.txt +1 -0
- data/test/test/inference_methods/test_assert_files_exist/input/input_1.txt +0 -0
- data/test/test/inference_methods/test_assert_files_exist/input/input_2.txt +0 -0
- data/test/test/inference_methods/test_file_compare/expected/output_1.txt +3 -0
- data/test/test/inference_methods/test_file_compare/expected/output_2.txt +1 -0
- data/test/test/inference_methods/test_file_compare/input/input_1.txt +3 -0
- data/test/test/inference_methods/test_file_compare/input/input_2.txt +3 -0
- data/test/test/inference_methods/test_infer_glob/expected/file.yml +0 -0
- data/test/test/inference_methods/test_infer_glob/expected/file_1.txt +0 -0
- data/test/test/inference_methods/test_infer_glob/expected/file_2.txt +0 -0
- data/test/test/inference_methods/test_yml_compare/expected/output_1.yml +6 -0
- data/test/test/inference_methods/test_yml_compare/expected/output_2.yml +6 -0
- data/test/test/inference_methods/test_yml_compare/input/input_1.yml +4 -0
- data/test/test/inference_methods/test_yml_compare/input/input_2.yml +4 -0
- data/test/test/inference_methods_test.rb +311 -0
- data/test/test/subset_methods_test.rb +115 -0
- data/test/test_test.rb +233 -0
- data/test/workflow_test.rb +108 -0
- metadata +274 -0
@@ -0,0 +1,449 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../tap_test_helper'
|
2
|
+
require 'tap/support/audit'
|
3
|
+
|
4
|
+
class AuditTest < Test::Unit::TestCase
|
5
|
+
include Tap::Support
|
6
|
+
|
7
|
+
attr_reader :audit, :a, :b
|
8
|
+
|
9
|
+
def setup
|
10
|
+
@audit = Audit.new('original')
|
11
|
+
@a = setup_audit(:a, :b, :c)
|
12
|
+
@b = setup_audit(:x, :y, :z)
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
# class methods tests
|
17
|
+
#
|
18
|
+
|
19
|
+
def test_register_creates_an_audit_for_each_input_as_needed
|
20
|
+
registered = Audit.register(1, a, 2)
|
21
|
+
|
22
|
+
registered.each {|r| assert_equal Audit, r.class}
|
23
|
+
assert_equal a.object_id, registered[1].object_id
|
24
|
+
assert_equal [1, 'c', 2], registered.collect {|r| r._current}
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_merge_with_multiple_inputs_merges_inputs
|
28
|
+
m = Audit.merge(1, a, 2)
|
29
|
+
|
30
|
+
assert_equal [[1, 'c', 2]], m._values
|
31
|
+
assert_equal [[nil, a, nil]], m._sources
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_merge_with_a_single_non_audit_input_returns_new_audit
|
35
|
+
m = Audit.merge(1)
|
36
|
+
|
37
|
+
assert_equal [1], m._values
|
38
|
+
assert_equal [nil], m._sources
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_merge_with_a_single_audit_input_returns_fork
|
42
|
+
m = Audit.merge(a)
|
43
|
+
|
44
|
+
assert_not_equal a.object_id, m.object_id
|
45
|
+
assert_equal a._values, m._values
|
46
|
+
assert_equal a._sources, m._sources
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_merge_with_no_inputs_returns_audit_initialized_to_nil
|
50
|
+
m = Audit.merge
|
51
|
+
|
52
|
+
assert_equal [nil], m._values
|
53
|
+
assert_equal [nil], m._sources
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_merge_documentation
|
57
|
+
a = Audit.new(1)
|
58
|
+
b = Audit.merge(a, 2)
|
59
|
+
assert_equal [[1,2]], b._values
|
60
|
+
assert_equal [[a, nil]], b._sources
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# methods to setup audits for testing, and tests of the setup
|
65
|
+
#
|
66
|
+
|
67
|
+
def setup_audit(*sources)
|
68
|
+
audit = Audit.new
|
69
|
+
sources.each do |source|
|
70
|
+
value = case source
|
71
|
+
when Array
|
72
|
+
source.collect {|s| s.to_s }
|
73
|
+
else
|
74
|
+
source.to_s
|
75
|
+
end
|
76
|
+
|
77
|
+
audit._record(source, value)
|
78
|
+
end
|
79
|
+
audit
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_setup
|
83
|
+
assert_equal [nil], audit._sources
|
84
|
+
assert_equal ['original'], audit._values
|
85
|
+
assert_equal 'original', audit._original
|
86
|
+
assert_equal 'original', audit._current
|
87
|
+
|
88
|
+
assert_equal [nil, :a, :b, :c], a._sources
|
89
|
+
assert_equal [nil, 'a', 'b', 'c'], a._values
|
90
|
+
assert_equal 'c', a._current
|
91
|
+
assert_equal nil, a._original
|
92
|
+
|
93
|
+
assert_equal [nil, :x, :y, :z], b._sources
|
94
|
+
assert_equal [nil, 'x', 'y', 'z'], b._values
|
95
|
+
assert_equal 'z', b._current
|
96
|
+
assert_equal nil, b._original
|
97
|
+
|
98
|
+
c = setup_audit([a, b, :c])
|
99
|
+
assert_equal [nil, [a, b, :c]], c._sources
|
100
|
+
assert_equal [nil, [a.to_s, b.to_s, 'c']], c._values
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# record tests
|
105
|
+
#
|
106
|
+
|
107
|
+
def test_record
|
108
|
+
audit._record(:a, 'next')
|
109
|
+
audit._record(:b, 'final')
|
110
|
+
|
111
|
+
assert_equal [nil, :a, :b], audit._sources
|
112
|
+
assert_equal ['original', 'next', 'final'], audit._values
|
113
|
+
end
|
114
|
+
|
115
|
+
def test_record_with_arrays_and_audits
|
116
|
+
audit._record(:a, a)
|
117
|
+
audit._record(:array, [a, b, 'str'])
|
118
|
+
|
119
|
+
assert_equal [nil, :a, :array], audit._sources
|
120
|
+
assert_equal ['original', a, [a, b, 'str']], audit._values
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_record_returns_self
|
124
|
+
assert audit._eql( audit._record(:a, 'next') )
|
125
|
+
end
|
126
|
+
|
127
|
+
#
|
128
|
+
# original tests
|
129
|
+
#
|
130
|
+
|
131
|
+
def test_original_is_first_recorded_value
|
132
|
+
a = Audit.new('a', :a)
|
133
|
+
assert_equal 'a', a._original
|
134
|
+
|
135
|
+
audit._record(:b, 'next')
|
136
|
+
assert_equal 'a', a._original
|
137
|
+
end
|
138
|
+
|
139
|
+
def test_original_source_is_original_recorded_source
|
140
|
+
a = Audit.new('a', :a)
|
141
|
+
assert_equal :a, a._original_source
|
142
|
+
|
143
|
+
audit._record(:b, 'next')
|
144
|
+
assert_equal :a, a._original_source
|
145
|
+
end
|
146
|
+
|
147
|
+
#
|
148
|
+
# current tests
|
149
|
+
#
|
150
|
+
|
151
|
+
def test_current_is_last_recorded_value
|
152
|
+
audit._record(:a, 'next')
|
153
|
+
assert_equal 'next', audit._current
|
154
|
+
|
155
|
+
audit._record(:a, 'final')
|
156
|
+
assert_equal 'final', audit._current
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_current_source_is_last_recorded_source
|
160
|
+
audit._record(:a, 'next')
|
161
|
+
assert_equal :a, audit._current_source
|
162
|
+
|
163
|
+
audit._record(:b, 'final')
|
164
|
+
assert_equal :b, audit._current_source
|
165
|
+
end
|
166
|
+
|
167
|
+
#
|
168
|
+
# last tests
|
169
|
+
#
|
170
|
+
|
171
|
+
def test_last_is_value_of_last_source_equalling_input
|
172
|
+
assert_equal 'a', a._last(:a)
|
173
|
+
|
174
|
+
a._record(:a, 'next')
|
175
|
+
assert_equal 'next', a._last(:a)
|
176
|
+
|
177
|
+
a._record(:b, 'does not affect last :a')
|
178
|
+
assert_equal 'next', a._last(:a)
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_index_last_is_index_of_last_source_equalling_input
|
182
|
+
assert_equal 1, a._index_last(:a)
|
183
|
+
|
184
|
+
a._record(:a, 'next')
|
185
|
+
assert_equal 4, a._index_last(:a)
|
186
|
+
|
187
|
+
a._record(:b, 'does not affect last :a')
|
188
|
+
assert_equal 4, a._index_last(:a)
|
189
|
+
end
|
190
|
+
|
191
|
+
#
|
192
|
+
# input accessor tests
|
193
|
+
#
|
194
|
+
|
195
|
+
def test_input_returns_value_at_index
|
196
|
+
assert_equal 'c', a._input(3)
|
197
|
+
assert_equal 'c', a._input(-1)
|
198
|
+
end
|
199
|
+
|
200
|
+
def test_input_last_is_value_previous_to_matching_source
|
201
|
+
assert_equal nil, a._input_last(:a)
|
202
|
+
|
203
|
+
a._record(:a, 'next')
|
204
|
+
assert_equal 'c', a._input_last(:a)
|
205
|
+
|
206
|
+
a._record(:b, 'does not affect input last :a')
|
207
|
+
assert_equal 'c', a._input_last(:a)
|
208
|
+
end
|
209
|
+
|
210
|
+
#
|
211
|
+
# output accessor tests
|
212
|
+
#
|
213
|
+
|
214
|
+
def test_output_is_value_of_next_index
|
215
|
+
assert_equal 'c', a._output(2)
|
216
|
+
assert_equal 'c', a._output(-2)
|
217
|
+
|
218
|
+
assert_nil a._output(3)
|
219
|
+
assert_nil a._output(-1)
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_output_last_is_value_of_matching_source
|
223
|
+
assert_equal 'a', a._output_last(:a)
|
224
|
+
|
225
|
+
a._record(:a, 'next')
|
226
|
+
assert_equal 'next', a._output_last(:a)
|
227
|
+
|
228
|
+
a._record(:b, 'does not affect output last :a')
|
229
|
+
assert_equal 'next', a._output_last(:a)
|
230
|
+
end
|
231
|
+
|
232
|
+
#
|
233
|
+
# source trail tests
|
234
|
+
#
|
235
|
+
|
236
|
+
def test_source_trail_helper_method_is_hidden
|
237
|
+
assert !a.respond_to?(:source_trail)
|
238
|
+
assert_raise(NoMethodError) { a.source_trail }
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_source_trail_returns_all_sources
|
242
|
+
a = setup_audit(:a, :b, :c)
|
243
|
+
|
244
|
+
assert_equal [nil, :a, :b, :c], a._source_trail
|
245
|
+
end
|
246
|
+
|
247
|
+
def test_source_trail_returns_source_trail_when_source_is_an_audit
|
248
|
+
c = setup_audit(:p, a, :q)
|
249
|
+
|
250
|
+
assert_equal [nil, :p, a, :q], c._sources
|
251
|
+
assert_equal [nil, :p, [nil, :a, :b, :c], :q], c._source_trail
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_source_trail_resolves_each_member_in_an_arrays_of_sources
|
255
|
+
c = setup_audit(:p, [a, b, :q], [:r, :s], :t)
|
256
|
+
|
257
|
+
assert_equal [nil, :p, [[nil, :a, :b, :c], [nil, :x, :y, :z], :q],[:r, :s], :t], c._source_trail
|
258
|
+
end
|
259
|
+
|
260
|
+
#
|
261
|
+
# value trail tests
|
262
|
+
#
|
263
|
+
|
264
|
+
def test_value_trail_helper_method_is_hidden
|
265
|
+
assert !a.respond_to?(:value_trail)
|
266
|
+
assert_raise(NoMethodError) { a.value_trail }
|
267
|
+
end
|
268
|
+
|
269
|
+
def test_value_trail_returns_all_values
|
270
|
+
a = setup_audit(:a, :b, :c)
|
271
|
+
|
272
|
+
assert_equal [nil, 'a', 'b', 'c'], a._value_trail
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_value_trail_returns_value_trail_when_source_is_an_audit
|
276
|
+
c = setup_audit(:p, a, :q)
|
277
|
+
|
278
|
+
assert_equal [nil, :p, a, :q], c._sources
|
279
|
+
assert_equal [nil, 'p', [nil, 'a', 'b', 'c'], 'q'], c._value_trail
|
280
|
+
end
|
281
|
+
|
282
|
+
def test_value_trail_resolves_each_member_in_an_arrays_of_sources
|
283
|
+
c = setup_audit(:p, [a, b, :q], [:r, :s], :t)
|
284
|
+
|
285
|
+
assert_equal [nil, 'p', [[nil, 'a', 'b', 'c'], [nil, 'x', 'y', 'z'], 'q'],['r', 's'], 't'], c._value_trail
|
286
|
+
end
|
287
|
+
|
288
|
+
#
|
289
|
+
# merge tests
|
290
|
+
#
|
291
|
+
|
292
|
+
def test_merge_returns_new_audit_with_self_added_to_sources_and_value_as_array_of_current_values
|
293
|
+
c = a._merge(b, 'p')
|
294
|
+
c._record(:q, 'q')
|
295
|
+
c._record(:r, 'r')
|
296
|
+
|
297
|
+
assert_equal [[a, b, nil], :q, :r], c._sources
|
298
|
+
assert_equal [['c', 'z', 'p'], 'q', 'r'], c._values
|
299
|
+
assert_equal [[[nil, :a, :b, :c], [nil, :x, :y, :z], nil], :q, :r], c._source_trail
|
300
|
+
end
|
301
|
+
|
302
|
+
def test_merge_with_no_sources_provided_returns_fork
|
303
|
+
c = a._merge
|
304
|
+
|
305
|
+
assert_not_equal a.object_id, c.object_id
|
306
|
+
assert_equal a._sources, c._sources
|
307
|
+
assert_equal a._values, c._values
|
308
|
+
end
|
309
|
+
|
310
|
+
#
|
311
|
+
# test fork
|
312
|
+
#
|
313
|
+
|
314
|
+
def test_fork_returns_audit_with_duplicates_of_sources_and_values
|
315
|
+
a = setup_audit(:a, :b, :c)
|
316
|
+
b = a._fork
|
317
|
+
|
318
|
+
assert_equal b._sources, a._sources
|
319
|
+
assert_not_equal b._sources.object_id, a._sources.object_id
|
320
|
+
assert_equal b._values, a._values
|
321
|
+
assert_not_equal b._values.object_id, a._values.object_id
|
322
|
+
end
|
323
|
+
|
324
|
+
def test_forks_can_be_developed_independently
|
325
|
+
a = setup_audit(:a, :b)
|
326
|
+
b = a._fork
|
327
|
+
|
328
|
+
a._record(:c, 'c')
|
329
|
+
b._record(:d, 'd')
|
330
|
+
|
331
|
+
assert_equal([nil, :a, :b, :c], a._sources)
|
332
|
+
assert_equal([nil, :a, :b, :d], b._sources)
|
333
|
+
end
|
334
|
+
|
335
|
+
#
|
336
|
+
# split tests
|
337
|
+
#
|
338
|
+
|
339
|
+
def test_split_records_block_as_source_and_return_as_value
|
340
|
+
block = lambda { |current| current += 'ar' }
|
341
|
+
c = a._split(&block)
|
342
|
+
|
343
|
+
assert_equal [a, block], c._sources
|
344
|
+
assert_equal [nil, 'car'], c._values
|
345
|
+
assert_equal [[nil, :a, :b, :c], block], c._source_trail
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_split_raises_error_if_no_block_given
|
349
|
+
assert_raise(LocalJumpError) { a._split }
|
350
|
+
end
|
351
|
+
|
352
|
+
#
|
353
|
+
# comparator and method missing test
|
354
|
+
#
|
355
|
+
|
356
|
+
def test_comparators_sent_to_current
|
357
|
+
a = Audit.new(1)
|
358
|
+
assert a < 2
|
359
|
+
assert a > 0
|
360
|
+
assert a == 1
|
361
|
+
end
|
362
|
+
|
363
|
+
def test_regexp_match_sent_to_current
|
364
|
+
a = Audit.new("abcd")
|
365
|
+
assert a =~ /ab(\w)/
|
366
|
+
# note: this is not ideal behavior... should be
|
367
|
+
#assert_equal 'c', $1
|
368
|
+
assert_nil $1
|
369
|
+
|
370
|
+
assert !(a=~ /q/)
|
371
|
+
end
|
372
|
+
|
373
|
+
def test_regexp_not_match_sent_to_current
|
374
|
+
a = Audit.new("abcd")
|
375
|
+
assert !(a !~ /ab(\w)/)
|
376
|
+
# note: this is not ideal behavior... should be
|
377
|
+
#assert_equal 'c', $1
|
378
|
+
assert_nil $1
|
379
|
+
|
380
|
+
assert a !~ /q/
|
381
|
+
end
|
382
|
+
|
383
|
+
def test_missing_methods_sent_to_current
|
384
|
+
a = Audit.new("abcd")
|
385
|
+
assert "ABCD", a.upcase
|
386
|
+
|
387
|
+
a = Audit.new(3)
|
388
|
+
assert a > 2
|
389
|
+
assert a <= 3
|
390
|
+
end
|
391
|
+
|
392
|
+
#
|
393
|
+
# documentation tests
|
394
|
+
#
|
395
|
+
|
396
|
+
def test_documentation
|
397
|
+
# part 1
|
398
|
+
audit = Audit.new(3)
|
399
|
+
audit._record(:a, 4)
|
400
|
+
audit._record(:b, 5)
|
401
|
+
audit._record(:c, 7)
|
402
|
+
assert_equal([nil, :a, :b, :c], audit._source_trail)
|
403
|
+
|
404
|
+
# part 2
|
405
|
+
audit = Audit.new(3)
|
406
|
+
audit._record(:a, 4)
|
407
|
+
fork_b = audit._fork
|
408
|
+
fork_c = audit._fork
|
409
|
+
|
410
|
+
fork_b._record(:b, 5)
|
411
|
+
fork_c._record(:c, 6)
|
412
|
+
assert_equal([nil, :a, :b], fork_b._source_trail)
|
413
|
+
assert_equal([nil, :a, :c], fork_c._source_trail)
|
414
|
+
|
415
|
+
merged_audit = Audit.merge(fork_b, fork_c)
|
416
|
+
merged_audit._record(:d, 11)
|
417
|
+
assert_equal([[[nil,:a,:b], [nil,:a,:c]], :d], merged_audit._source_trail)
|
418
|
+
|
419
|
+
# part 3
|
420
|
+
t = Tap::Task.new
|
421
|
+
t.on_complete do |results|
|
422
|
+
results.each do |result|
|
423
|
+
|
424
|
+
assert_equal Audit, result.class
|
425
|
+
assert_equal "str", result._current
|
426
|
+
assert result == "str"
|
427
|
+
assert_equal "STR", result.upcase
|
428
|
+
|
429
|
+
assert !result.kind_of?(String)
|
430
|
+
assert result =~ /s(\w+)/
|
431
|
+
assert_nil $1
|
432
|
+
|
433
|
+
end
|
434
|
+
end
|
435
|
+
t.execute "str"
|
436
|
+
|
437
|
+
# part 4
|
438
|
+
t = Tap::Task.new do |task, input|
|
439
|
+
assert_equal Fixnum, input.class
|
440
|
+
input += 1
|
441
|
+
end
|
442
|
+
|
443
|
+
results = t.execute(3)
|
444
|
+
assert_equal Array, results.class
|
445
|
+
assert_equal 1, results.length
|
446
|
+
assert_equal Audit, results.first.class
|
447
|
+
assert_equal 4, results.first._current
|
448
|
+
end
|
449
|
+
end
|
@@ -0,0 +1,320 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../tap_test_helper')
|
2
|
+
require 'tap/support/batch_queue'
|
3
|
+
|
4
|
+
class BatchQueueTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
# creates readers to facilitate testing
|
7
|
+
module BatchQueueAccessors
|
8
|
+
attr_reader :tasks, :inputs
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_accessor :t, :not_executable, :queue
|
12
|
+
|
13
|
+
def setup
|
14
|
+
@t = Tap::Task.new
|
15
|
+
@not_executable = Tap::Task.new
|
16
|
+
@not_executable.condition {|task, inputs| false}
|
17
|
+
|
18
|
+
@queue = Tap::Support::BatchQueue.new
|
19
|
+
@queue.extend BatchQueueAccessors
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_not_executable_is_not_executable_with_and_without_inputs
|
23
|
+
assert !not_executable.executable?([])
|
24
|
+
assert !not_executable.executable?([:a,:b,:c])
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_documentation
|
28
|
+
t1 = Tap::Task.new
|
29
|
+
t2 = Tap::Task.new
|
30
|
+
|
31
|
+
q = Tap::Support::BatchQueue.new
|
32
|
+
q.enq t1, 1
|
33
|
+
q.enq t2, :a,:b,:c
|
34
|
+
q.enq t1, 2,3
|
35
|
+
|
36
|
+
assert_equal [t1, [1,2,3]], q.deq
|
37
|
+
assert_equal [t2, [:a,:b,:c]], q.deq
|
38
|
+
assert_nil q.deq
|
39
|
+
end
|
40
|
+
|
41
|
+
#
|
42
|
+
# initialization tests
|
43
|
+
#
|
44
|
+
|
45
|
+
def test_queue_is_empty_and_inputs_and_tasks_cannot_be_accessed
|
46
|
+
q = Tap::Support::BatchQueue.new
|
47
|
+
assert q.empty?
|
48
|
+
assert_raise(NoMethodError) { q.inputs }
|
49
|
+
assert_raise(NoMethodError) { q.tasks }
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# size, length, clear, empty? tests
|
54
|
+
#
|
55
|
+
|
56
|
+
def test_size_and_length_return_number_of_tasks
|
57
|
+
assert_equal 0, queue.size
|
58
|
+
assert_equal 0, queue.length
|
59
|
+
|
60
|
+
queue.inputs[t] = [1,2,3]
|
61
|
+
|
62
|
+
assert_equal 0, queue.size
|
63
|
+
assert_equal 0, queue.length
|
64
|
+
|
65
|
+
queue.tasks << t
|
66
|
+
|
67
|
+
assert_equal 1, queue.size
|
68
|
+
assert_equal 1, queue.length
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_empty_is_true_if_tasks_is_empty
|
72
|
+
assert queue.empty?
|
73
|
+
queue.inputs[t] = [1,2,3]
|
74
|
+
assert queue.empty?
|
75
|
+
queue.tasks << t
|
76
|
+
assert !queue.empty?
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_clear_resets_tasks_and_inputs
|
80
|
+
assert_equal({}, queue.inputs)
|
81
|
+
assert_equal [], queue.tasks
|
82
|
+
|
83
|
+
queue.inputs[t] = [1,2,3]
|
84
|
+
queue.tasks << t
|
85
|
+
queue.clear
|
86
|
+
|
87
|
+
assert_equal({}, queue.inputs)
|
88
|
+
assert_equal [], queue.tasks
|
89
|
+
end
|
90
|
+
|
91
|
+
#
|
92
|
+
# queue test
|
93
|
+
#
|
94
|
+
|
95
|
+
def test_enq_pushes_task_onto_tasks
|
96
|
+
t1 = Tap::Task.new
|
97
|
+
t2 = Tap::Task.new
|
98
|
+
assert_equal [], queue.tasks
|
99
|
+
|
100
|
+
queue.enq(t1)
|
101
|
+
assert_equal [t1], queue.tasks
|
102
|
+
|
103
|
+
queue.enq(t2)
|
104
|
+
assert_equal [t1, t2], queue.tasks
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_enq_concats_inputs_to_inputs
|
108
|
+
assert_equal nil, queue.inputs[t]
|
109
|
+
|
110
|
+
queue.enq(t,1)
|
111
|
+
assert_equal [1], queue.inputs[t]
|
112
|
+
|
113
|
+
queue.enq(t,2,3)
|
114
|
+
assert_equal [1,2,3], queue.inputs[t]
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_enq_does_not_push_task_onto_tasks_if_it_is_already_in_the_queue
|
118
|
+
t1 = Tap::Task.new
|
119
|
+
t2 = Tap::Task.new
|
120
|
+
queue.tasks << t1
|
121
|
+
queue.tasks << t2
|
122
|
+
assert_equal [t1,t2], queue.tasks
|
123
|
+
|
124
|
+
queue.enq(t1)
|
125
|
+
assert_equal [t1,t2], queue.tasks
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_enq_queues_batch_if_task_is_batched
|
129
|
+
t.batch << t.dup
|
130
|
+
assert_equal [], queue.tasks
|
131
|
+
|
132
|
+
queue.enq(t)
|
133
|
+
assert_equal t.batch, queue.tasks
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_enq_forks_inputs_if_necessary_for_batch
|
137
|
+
t.batch << t.dup
|
138
|
+
|
139
|
+
a = Tap::Support::Audit.new(2)
|
140
|
+
queue.enq(t, 1, a)
|
141
|
+
|
142
|
+
audits = []
|
143
|
+
t.batch.each do |task|
|
144
|
+
assert_equal [1, a], queue.inputs[task]
|
145
|
+
audits << queue.inputs[task].last
|
146
|
+
end
|
147
|
+
|
148
|
+
# if the object ids of these audits are not equal, but they
|
149
|
+
# evaluate to equal, we can safely assume they're forked.
|
150
|
+
assert_equal 2, audits.length
|
151
|
+
assert_equal audits.first, audits.last
|
152
|
+
assert_not_equal audits.first.object_id, audits.last.object_id
|
153
|
+
end
|
154
|
+
|
155
|
+
#
|
156
|
+
# priority_enq test
|
157
|
+
#
|
158
|
+
|
159
|
+
def test_priority_enq_shifts_task_onto_tasks
|
160
|
+
t1 = Tap::Task.new
|
161
|
+
t2 = Tap::Task.new
|
162
|
+
assert_equal [], queue.tasks
|
163
|
+
|
164
|
+
queue.priority_enq(t1)
|
165
|
+
assert_equal [t1], queue.tasks
|
166
|
+
|
167
|
+
queue.priority_enq(t2)
|
168
|
+
assert_equal [t2, t1], queue.tasks
|
169
|
+
end
|
170
|
+
|
171
|
+
#
|
172
|
+
# prioritize test
|
173
|
+
#
|
174
|
+
|
175
|
+
def test_prioritize_moves_task_to_the_front_of_the_queue
|
176
|
+
t1 = Tap::Task.new
|
177
|
+
t2 = Tap::Task.new
|
178
|
+
queue.tasks << t1
|
179
|
+
queue.tasks << t2
|
180
|
+
assert_equal [t1,t2], queue.tasks
|
181
|
+
|
182
|
+
queue.prioritize(t2)
|
183
|
+
assert_equal [t2,t1], queue.tasks
|
184
|
+
end
|
185
|
+
|
186
|
+
def test_prioritize_does_not_insert_the_task_if_the_task_is_not_in_the_queue
|
187
|
+
assert_equal [], queue.tasks
|
188
|
+
|
189
|
+
queue.prioritize(t)
|
190
|
+
assert_equal [], queue.tasks
|
191
|
+
end
|
192
|
+
|
193
|
+
def test_prioritize_prioritizes_each_task_in_a_batch_in_order
|
194
|
+
t1 = Tap::Task.new
|
195
|
+
t2 = Tap::Task.new
|
196
|
+
t2.batch << t2.dup
|
197
|
+
|
198
|
+
queue.tasks << t1
|
199
|
+
queue.tasks.concat t2.batch
|
200
|
+
|
201
|
+
assert_equal [t1] + t2.batch, queue.tasks
|
202
|
+
|
203
|
+
queue.prioritize(t2)
|
204
|
+
assert_equal t2.batch + [t1], queue.tasks
|
205
|
+
end
|
206
|
+
|
207
|
+
#
|
208
|
+
# marginalize test
|
209
|
+
#
|
210
|
+
|
211
|
+
def test_marginalize_moves_task_to_the_front_of_the_queue
|
212
|
+
t1 = Tap::Task.new
|
213
|
+
t2 = Tap::Task.new
|
214
|
+
queue.tasks << t1
|
215
|
+
queue.tasks << t2
|
216
|
+
assert_equal [t1,t2], queue.tasks
|
217
|
+
|
218
|
+
queue.marginalize(t1)
|
219
|
+
assert_equal [t2,t1], queue.tasks
|
220
|
+
end
|
221
|
+
|
222
|
+
def test_marginalizeoes_not_insert_the_task_if_the_task_is_not_in_the_queue
|
223
|
+
assert_equal [], queue.tasks
|
224
|
+
|
225
|
+
queue.marginalize(t)
|
226
|
+
assert_equal [], queue.tasks
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_marginalize_marginalizes_each_task_in_a_batch_in_order
|
230
|
+
t1 = Tap::Task.new
|
231
|
+
t2 = Tap::Task.new
|
232
|
+
t2.batch << t2.dup
|
233
|
+
|
234
|
+
queue.tasks.concat t2.batch
|
235
|
+
queue.tasks << t1
|
236
|
+
|
237
|
+
assert_equal t2.batch + [t1], queue.tasks
|
238
|
+
queue.marginalize(t2)
|
239
|
+
assert_equal [t1] + t2.batch, queue.tasks
|
240
|
+
end
|
241
|
+
|
242
|
+
#
|
243
|
+
# executable? tests
|
244
|
+
#
|
245
|
+
|
246
|
+
def test_executable_true_if_task_is_executable_with_current_inputs
|
247
|
+
t.condition {|task, inputs| inputs && inputs.length > 1 }
|
248
|
+
|
249
|
+
assert !queue.executable?(t)
|
250
|
+
queue.enq t,1
|
251
|
+
assert !queue.executable?(t)
|
252
|
+
queue.enq t,2
|
253
|
+
assert queue.executable?(t)
|
254
|
+
end
|
255
|
+
|
256
|
+
#
|
257
|
+
# deq test
|
258
|
+
#
|
259
|
+
|
260
|
+
def test_deq_returns_the_next_executable_task_and_inputs
|
261
|
+
queue.enq not_executable, :a,:b,:c
|
262
|
+
queue.enq t,1,2,3
|
263
|
+
|
264
|
+
assert_equal [t, [1,2,3]], queue.deq
|
265
|
+
assert !queue.empty?
|
266
|
+
end
|
267
|
+
|
268
|
+
def test_deq_returns_the_specified_task_even_if_not_executable
|
269
|
+
queue.enq t,1,2,3
|
270
|
+
queue.enq not_executable, :a,:b,:c
|
271
|
+
|
272
|
+
assert_equal [not_executable, [:a,:b,:c]], queue.deq(not_executable)
|
273
|
+
assert !queue.empty?
|
274
|
+
end
|
275
|
+
|
276
|
+
def test_deq_with_no_inputs_returns_empty_array_as_inputs
|
277
|
+
queue.enq t
|
278
|
+
assert_equal [t, []], queue.deq
|
279
|
+
end
|
280
|
+
|
281
|
+
#
|
282
|
+
# peek test
|
283
|
+
#
|
284
|
+
|
285
|
+
def test_peek_returns_the_next_executable_task_and_does_not_dequeue_the_task
|
286
|
+
queue.enq not_executable
|
287
|
+
queue.enq t
|
288
|
+
|
289
|
+
assert_equal t, queue.peek
|
290
|
+
assert_equal 2, queue.size
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_peek_returns_nil_if_no_tasks_are_executable
|
294
|
+
assert_equal nil, queue.peek
|
295
|
+
|
296
|
+
queue.enq not_executable
|
297
|
+
|
298
|
+
assert_equal nil, queue.peek
|
299
|
+
end
|
300
|
+
|
301
|
+
#
|
302
|
+
# num_executable test
|
303
|
+
#
|
304
|
+
|
305
|
+
def test_num_executable_returns_number_of_queued_executable_tasks
|
306
|
+
assert_equal 0, queue.num_executable
|
307
|
+
queue.enq not_executable
|
308
|
+
assert_equal 0, queue.num_executable
|
309
|
+
queue.enq t
|
310
|
+
assert_equal 1, queue.num_executable
|
311
|
+
end
|
312
|
+
|
313
|
+
def test_num_not_executable_returns_number_of_queued_non_executable_tasks
|
314
|
+
assert_equal 0, queue.num_not_executable
|
315
|
+
queue.enq t
|
316
|
+
assert_equal 0, queue.num_not_executable
|
317
|
+
queue.enq not_executable
|
318
|
+
assert_equal 1, queue.num_not_executable
|
319
|
+
end
|
320
|
+
end
|