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
@@ -1,249 +0,0 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), '../tap_test_helper')
|
2
|
-
require 'tap/support/combinator'
|
3
|
-
|
4
|
-
class CombinatorTest < Test::Unit::TestCase
|
5
|
-
include Tap::Support
|
6
|
-
include Tap::Test::SubsetMethods
|
7
|
-
include Benchmark
|
8
|
-
|
9
|
-
def test_documentation
|
10
|
-
c = Combinator.new [1,2], [3,4]
|
11
|
-
assert_equal [[1,3], [1,4], [2,3], [2,4]], c.collect
|
12
|
-
|
13
|
-
c = Combinator.new [1,2], [3,4], [5,6]
|
14
|
-
assert_equal [[1],[2]], c.a
|
15
|
-
assert_equal Combinator, c.b.class
|
16
|
-
assert_equal [[3],[4]], c.b.a
|
17
|
-
assert_equal [[5],[6]], c.b.b
|
18
|
-
end
|
19
|
-
|
20
|
-
#
|
21
|
-
# initialize tests
|
22
|
-
#
|
23
|
-
|
24
|
-
def test_initialize
|
25
|
-
c = Combinator.new
|
26
|
-
assert_equal [], c.a
|
27
|
-
assert_equal [], c.b
|
28
|
-
|
29
|
-
{
|
30
|
-
[[1], [2,3], [3, [4]]] =>[[[1]], [[2], [3]], [[3],[[4]]]], # arrays have each element arrayified
|
31
|
-
[nil, nil, nil] => [[], [], []], # nil returns an empty array
|
32
|
-
[[], [{:one => 1},nil], nil] => [[], [[{:one => 1}],[nil]], []] # mixture
|
33
|
-
}.each_pair do |sets, expected|
|
34
|
-
c = Combinator.new(*sets)
|
35
|
-
assert_equal expected[0], c.a
|
36
|
-
assert_equal Combinator, c.b.class
|
37
|
-
assert_equal expected[1], c.b.a
|
38
|
-
assert_equal expected[2], c.b.b
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
def test_initialize_raises_error_unless_sets_are_all_arrays_combinators_or_nil
|
43
|
-
[
|
44
|
-
[1],
|
45
|
-
[[], 1],
|
46
|
-
[1,[]]
|
47
|
-
].each do |sets|
|
48
|
-
assert_raise(ArgumentError) { Combinator.new(*sets) }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
#
|
53
|
-
# sets test
|
54
|
-
#
|
55
|
-
|
56
|
-
def test_sets_returns_input_sets_minus_nil_or_empty_arrays
|
57
|
-
[
|
58
|
-
[],
|
59
|
-
[[1]],
|
60
|
-
[[1], [2]],
|
61
|
-
[[1], [2,3], [4,5,6]],
|
62
|
-
[[1], [2,[3]], [4,5,6]],
|
63
|
-
[[1], nil, [], [4,5,6], nil]
|
64
|
-
].each do |sets|
|
65
|
-
expected = sets.reject {|s| s.nil? || s.empty? }
|
66
|
-
assert_equal expected, Combinator.new(*sets).sets, PP.singleline_pp(sets, "")
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
#
|
71
|
-
# length test
|
72
|
-
#
|
73
|
-
|
74
|
-
def test_length
|
75
|
-
{
|
76
|
-
[] => 0,
|
77
|
-
[[1]] => 1,
|
78
|
-
[[1], [2]] => 1,
|
79
|
-
[[1],[2],[3]] => 1,
|
80
|
-
[[1],[], nil,[3]] => 1,
|
81
|
-
|
82
|
-
[[1,2]] => 2,
|
83
|
-
[[1], [2,3]] => 2,
|
84
|
-
[[1,2], [3,4]] => 4,
|
85
|
-
[[1,2], [3,4], [5,6]] => 8,
|
86
|
-
[[1,2], nil, [3,4], [], [5,6]] => 8
|
87
|
-
}.each_pair do |sets, expected|
|
88
|
-
assert_equal expected, Combinator.new(*sets).length, PP.singleline_pp(sets, "")
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
#
|
93
|
-
# each tests
|
94
|
-
#
|
95
|
-
|
96
|
-
def test_each
|
97
|
-
{
|
98
|
-
[[1]] => [[1]],
|
99
|
-
[[1], [2]] => [[1,2]],
|
100
|
-
[[1],[2],[3]] => [[1,2,3]],
|
101
|
-
[[1],[], nil,[3]] => [[1,3]],
|
102
|
-
|
103
|
-
[[1,2]] => [[1],[2]],
|
104
|
-
[[1], [2,3]] => [[1,2], [1,3]],
|
105
|
-
[[1,2], [3,4]] => [[1,3],[1,4],[2,3],[2,4]],
|
106
|
-
[[1,2], [3,4], [5,6]] => [[1,3,5],[1,3,6],[1,4,5],[1,4,6],[2,3,5],[2,3,6],[2,4,5],[2,4,6]],
|
107
|
-
[[1,2], nil, [3,4], [], [5,6]] => [[1,3,5],[1,3,6],[1,4,5],[1,4,6],[2,3,5],[2,3,6],[2,4,5],[2,4,6]]
|
108
|
-
}.each_pair do |set, expected|
|
109
|
-
comb = Combinator.new(*set)
|
110
|
-
|
111
|
-
combinations = []
|
112
|
-
comb.each { |c| combinations << c }
|
113
|
-
assert_equal expected, combinations, PP.singleline_pp(set, "")
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
def test_each_with_deferencing
|
118
|
-
comb = Combinator.new([1], [2,3])
|
119
|
-
combinations = []
|
120
|
-
comb.each { |a,b| combinations << [a,b] }
|
121
|
-
|
122
|
-
assert_equal [[1,2], [1,3]], combinations
|
123
|
-
end
|
124
|
-
|
125
|
-
#
|
126
|
-
# collect test
|
127
|
-
#
|
128
|
-
|
129
|
-
def test_collect
|
130
|
-
comb = Combinator.new([0,1], [0,1])
|
131
|
-
expected = [[0,0],[0,1],[1,0],[1,1]].collect { |c| c << 2 }
|
132
|
-
assert_equal expected, comb.collect { |c| c << 2 }
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_collect_returns_all_if_no_block_given
|
136
|
-
comb = Combinator.new([0,1], [0,1])
|
137
|
-
assert_equal [[0,0],[0,1],[1,0],[1,1]], comb.collect
|
138
|
-
end
|
139
|
-
|
140
|
-
#
|
141
|
-
# additional tests
|
142
|
-
#
|
143
|
-
|
144
|
-
def test_combinator_3_by_3_by_3
|
145
|
-
comb = Combinator.new([0,1,2], [0,1,2], [0,1,2])
|
146
|
-
expected = [
|
147
|
-
[0, 0, 0],
|
148
|
-
[0, 0, 1],
|
149
|
-
[0, 0, 2],
|
150
|
-
[0, 1, 0],
|
151
|
-
[0, 1, 1],
|
152
|
-
[0, 1, 2],
|
153
|
-
[0, 2, 0],
|
154
|
-
[0, 2, 1],
|
155
|
-
[0, 2, 2],
|
156
|
-
[1, 0, 0],
|
157
|
-
[1, 0, 1],
|
158
|
-
[1, 0, 2],
|
159
|
-
[1, 1, 0],
|
160
|
-
[1, 1, 1],
|
161
|
-
[1, 1, 2],
|
162
|
-
[1, 2, 0],
|
163
|
-
[1, 2, 1],
|
164
|
-
[1, 2, 2],
|
165
|
-
[2, 0, 0],
|
166
|
-
[2, 0, 1],
|
167
|
-
[2, 0, 2],
|
168
|
-
[2, 1, 0],
|
169
|
-
[2, 1, 1],
|
170
|
-
[2, 1, 2],
|
171
|
-
[2, 2, 0],
|
172
|
-
[2, 2, 1],
|
173
|
-
[2, 2, 2],
|
174
|
-
]
|
175
|
-
|
176
|
-
assert_equal 3*3*3, comb.length
|
177
|
-
assert_equal expected, comb.collect
|
178
|
-
end
|
179
|
-
|
180
|
-
def test_combinator_3_by_2_by_3
|
181
|
-
comb = Combinator.new([0,1,2], [0,1], [0,1,2])
|
182
|
-
expected = [
|
183
|
-
[0, 0, 0],
|
184
|
-
[0, 0, 1],
|
185
|
-
[0, 0, 2],
|
186
|
-
[0, 1, 0],
|
187
|
-
[0, 1, 1],
|
188
|
-
[0, 1, 2],
|
189
|
-
[1, 0, 0],
|
190
|
-
[1, 0, 1],
|
191
|
-
[1, 0, 2],
|
192
|
-
[1, 1, 0],
|
193
|
-
[1, 1, 1],
|
194
|
-
[1, 1, 2],
|
195
|
-
[2, 0, 0],
|
196
|
-
[2, 0, 1],
|
197
|
-
[2, 0, 2],
|
198
|
-
[2, 1, 0],
|
199
|
-
[2, 1, 1],
|
200
|
-
[2, 1, 2],
|
201
|
-
]
|
202
|
-
|
203
|
-
assert_equal 3*2*3, comb.length
|
204
|
-
assert_equal expected, comb.collect
|
205
|
-
end
|
206
|
-
|
207
|
-
def test_combinator_3_by_2_by_1
|
208
|
-
comb = Combinator.new([0,1,2], [0,1], [0])
|
209
|
-
expected = [
|
210
|
-
[0, 0, 0],
|
211
|
-
[0, 1, 0],
|
212
|
-
[1, 0, 0],
|
213
|
-
[1, 1, 0],
|
214
|
-
[2, 0, 0],
|
215
|
-
[2, 1, 0],
|
216
|
-
]
|
217
|
-
|
218
|
-
assert_equal 3*2*1, comb.length
|
219
|
-
assert_equal expected, comb.collect
|
220
|
-
end
|
221
|
-
|
222
|
-
# From these tests, it looks like (sensibly) the Combinator is more sensitive to the
|
223
|
-
# number of sets than to the number of items in each set. ie for ten items:
|
224
|
-
# Combinator.new([1,2],[1,2],[1,2],[1,2],[1,2])
|
225
|
-
# runs slower than
|
226
|
-
# Combinator.new([1,2,3,4,5], [1,2,3,4,5])
|
227
|
-
#
|
228
|
-
# Of course they generate different output too... like [1,1,1,1,1] vs [1,1]... so you
|
229
|
-
# really do not have a choice in how you structure the combination.
|
230
|
-
def test_combination_speed
|
231
|
-
benchmark_test(15) do |x|
|
232
|
-
[[3,10],[10,3],[10,4],[10,5]].each do |trial|
|
233
|
-
items, fold = *trial
|
234
|
-
set = []
|
235
|
-
sets = []
|
236
|
-
length = items ** fold
|
237
|
-
|
238
|
-
1.upto(items) {|i| set << i}
|
239
|
-
fold.times { sets << set }
|
240
|
-
|
241
|
-
c = Combinator.new(*sets)
|
242
|
-
assert_equal length, c.length
|
243
|
-
|
244
|
-
x.report("#{items}x#{fold} - #{length}") { assert_equal length, c.collect.length }
|
245
|
-
end
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|
@@ -1,122 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../tap_test_helper'
|
2
|
-
require 'tap/support/template'
|
3
|
-
|
4
|
-
class TemplateTest < Test::Unit::TestCase
|
5
|
-
include Tap::Support
|
6
|
-
include Tap::Test::SubsetMethods
|
7
|
-
|
8
|
-
class MockTemplater
|
9
|
-
attr_reader :templates
|
10
|
-
|
11
|
-
def initialize
|
12
|
-
@templates = []
|
13
|
-
end
|
14
|
-
|
15
|
-
def <<(template)
|
16
|
-
self.templates << template
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def new_template(hash)
|
21
|
-
hash.extend Template
|
22
|
-
hash.templater = MockTemplater.new
|
23
|
-
hash
|
24
|
-
end
|
25
|
-
|
26
|
-
def test_new_template
|
27
|
-
t = new_template({})
|
28
|
-
assert_equal({}, t)
|
29
|
-
assert_equal MockTemplater, t.templater.class
|
30
|
-
assert_equal [], t.templater.templates
|
31
|
-
end
|
32
|
-
|
33
|
-
def test_documentation
|
34
|
-
# variations
|
35
|
-
t = {"default" => "default value"}.extend Template
|
36
|
-
t.templater = []
|
37
|
-
t.variations([
|
38
|
-
{"default" => "non-default value"},
|
39
|
-
{"another" => "value"}])
|
40
|
-
|
41
|
-
expected = [{"default" => "non-default value"},
|
42
|
-
{"default" => "default value", "another" => "value"}]
|
43
|
-
assert_equal expected, t.templater
|
44
|
-
|
45
|
-
|
46
|
-
# combinations
|
47
|
-
t = {"default" => "default value"}.extend Template
|
48
|
-
t.templater = []
|
49
|
-
t.combinations(
|
50
|
-
"letter" => ["a", "b"],
|
51
|
-
"number" => [1, 2])
|
52
|
-
|
53
|
-
expected = [{"default" => "default value", "letter" => "a", "number" => 1},
|
54
|
-
{"default" => "default value", "letter" => "a", "number" => 2},
|
55
|
-
{"default" => "default value", "letter" => "b", "number" => 1},
|
56
|
-
{"default" => "default value", "letter" => "b", "number" => 2}]
|
57
|
-
assert_equal expected.length, t.templater.length
|
58
|
-
expected.each do |expectation|
|
59
|
-
assert t.templater.include?(expectation)
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
#
|
64
|
-
# variations test
|
65
|
-
#
|
66
|
-
|
67
|
-
def test_variations_bang_pushes_merged_template_for_each_input_variation_to_templater_and_does_not_clear_self
|
68
|
-
t = new_template(:key => 'default')
|
69
|
-
t.variations!([{:key => 'non-default'}, {:another => 'value'}])
|
70
|
-
|
71
|
-
assert_equal({:key => 'default'}, t)
|
72
|
-
assert_equal([
|
73
|
-
{:key => 'non-default'},
|
74
|
-
{:key => 'default', :another => 'value'}],
|
75
|
-
t.templater.templates)
|
76
|
-
end
|
77
|
-
|
78
|
-
def test_variations_is_variations_bang_but_clears_self
|
79
|
-
t1 = new_template(:key => 'default')
|
80
|
-
t1.variations([{:key => 'non-default'}, {:another => 'value'}])
|
81
|
-
|
82
|
-
t2 = new_template(:key => 'default')
|
83
|
-
t2.variations!([{:key => 'non-default'}, {:another => 'value'}])
|
84
|
-
|
85
|
-
assert_equal({}, t1)
|
86
|
-
assert_equal t1.templater.templates, t2.templater.templates
|
87
|
-
end
|
88
|
-
|
89
|
-
#
|
90
|
-
# combinations tests
|
91
|
-
#
|
92
|
-
|
93
|
-
def test_combinations_bang_pushes_all_combinations_of_variables_to_templater_and_does_not_clear_self
|
94
|
-
t = new_template(:default => 'value', :key => 'default')
|
95
|
-
t.combinations!({:key => [0,1], :another => [2,3]})
|
96
|
-
|
97
|
-
assert_equal({:default => 'value', :key => 'default'}, t)
|
98
|
-
|
99
|
-
# a two-step check for the templates is necessary because the order of the
|
100
|
-
# origninal sets is hash-order dependent
|
101
|
-
expected = [
|
102
|
-
{:default => 'value', :key => 0, :another => 2},
|
103
|
-
{:default => 'value', :key => 0, :another => 3},
|
104
|
-
{:default => 'value', :key => 1, :another => 2},
|
105
|
-
{:default => 'value', :key => 1, :another => 3}]
|
106
|
-
|
107
|
-
assert_equal expected.length, t.templater.templates.length
|
108
|
-
expected.each { |expectation| assert t.templater.templates.include?(expectation) }
|
109
|
-
end
|
110
|
-
|
111
|
-
def test_combinations_is_combinations_bang_but_clears_self
|
112
|
-
t1 = new_template(:default => 'value', :key => 'default')
|
113
|
-
t1.combinations({:key => [0,1], :another => [2,3]})
|
114
|
-
|
115
|
-
t2 = new_template(:default => 'value', :key => 'default')
|
116
|
-
t2.combinations!({:key => [0,1], :another => [2,3]})
|
117
|
-
|
118
|
-
assert_equal({}, t1)
|
119
|
-
assert_equal t1.templater.templates, t2.templater.templates
|
120
|
-
end
|
121
|
-
|
122
|
-
end
|
@@ -1,192 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../tap_test_helper'
|
2
|
-
require 'tap/support/templater'
|
3
|
-
|
4
|
-
class TemplaterTest < Test::Unit::TestCase
|
5
|
-
include Tap::Support
|
6
|
-
include Tap::Test::SubsetMethods
|
7
|
-
|
8
|
-
module ProcessModule
|
9
|
-
def process(input)
|
10
|
-
self.store(:processed, "#{input} was processed")
|
11
|
-
end
|
12
|
-
|
13
|
-
def bang_process!(input)
|
14
|
-
self.store(:processed, "#{input} was bang processed")
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_new_method_call(input)
|
18
|
-
self.store(:add_new_method_call, "#{input} was processed")
|
19
|
-
self.store("process!", "entry from new method call")
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
module MethodModule
|
24
|
-
def do_something(input)
|
25
|
-
self["processed"] = "#{input} was processed"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
module DocMethods
|
30
|
-
def method_call(input)
|
31
|
-
self["result"] = "#{input} was processed"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def test_documentation
|
36
|
-
t = Templater.new(
|
37
|
-
"key"=> "value",
|
38
|
-
"method_call!" => "method input",
|
39
|
-
"replacement=" => "replacement input")
|
40
|
-
t.run_methods(DocMethods)
|
41
|
-
t.run_replace do |input|
|
42
|
-
"#{input} was replaced"
|
43
|
-
end
|
44
|
-
|
45
|
-
expected = [{"key" => "value",
|
46
|
-
"result" => "method input was processed",
|
47
|
-
"replacement" => "replacement input was replaced"}]
|
48
|
-
assert_equal expected, t.templates
|
49
|
-
|
50
|
-
# run methods
|
51
|
-
t = Templater.new('method_call!' => 'input')
|
52
|
-
t.run_methods(DocMethods)
|
53
|
-
assert_equal [{"result" => "input was processed"}], t.templates
|
54
|
-
|
55
|
-
# run_replace
|
56
|
-
t = Templater.new('replacement=' => 'some value')
|
57
|
-
t.run_replace {|value| "#{value} was replaced"}
|
58
|
-
assert_equal [{"replacement" => "some value was replaced"}], t.templates
|
59
|
-
end
|
60
|
-
|
61
|
-
#
|
62
|
-
# initialization test
|
63
|
-
#
|
64
|
-
|
65
|
-
def test_initialize
|
66
|
-
t = Templater.new({'key' => 'value'})
|
67
|
-
assert_equal([{'key' => 'value'}], t.templates)
|
68
|
-
end
|
69
|
-
|
70
|
-
#
|
71
|
-
# push tests
|
72
|
-
#
|
73
|
-
|
74
|
-
def test_push_skips_empty_templates
|
75
|
-
t = Templater.new({})
|
76
|
-
t << {}
|
77
|
-
assert_equal [], t.templates
|
78
|
-
end
|
79
|
-
|
80
|
-
#
|
81
|
-
# run templater test
|
82
|
-
#
|
83
|
-
|
84
|
-
def test_run_templater_does_not_select_non_string_values
|
85
|
-
t = Templater.new(:key => "value", 1 => "value")
|
86
|
-
t.run_templater(/.*/) do |template, key, value|
|
87
|
-
flunk "should not have run"
|
88
|
-
end
|
89
|
-
|
90
|
-
assert_equal([{:key => "value", 1 => "value"}], t.templates)
|
91
|
-
end
|
92
|
-
|
93
|
-
def test_run_templater_works_on_each_template
|
94
|
-
t = Templater.new('key' => "value")
|
95
|
-
t << {"another" => "another value"}
|
96
|
-
t.run_templater(/.*/) do |template, key, value|
|
97
|
-
template[key.to_sym] = "#{value} was templated"
|
98
|
-
end
|
99
|
-
|
100
|
-
assert_equal([
|
101
|
-
{:key => "value was templated"},
|
102
|
-
{:another => "another value was templated"}],
|
103
|
-
t.templates)
|
104
|
-
end
|
105
|
-
|
106
|
-
def test_run_templater_extends_templates_with_Template_and_sets_input_templater
|
107
|
-
t = Templater.new({'key' => 'value'})
|
108
|
-
t << {'another' => 'value'}
|
109
|
-
assert_equal [{'key' => 'value'}, {'another' => 'value'}], t.templates
|
110
|
-
|
111
|
-
t.templates.each do |template|
|
112
|
-
assert !template.respond_to?(:templater)
|
113
|
-
end
|
114
|
-
|
115
|
-
t.run_templater(/.*/) do |template, key, value|
|
116
|
-
assert template.respond_to?(:templater)
|
117
|
-
assert_equal t, template.templater
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
def test_run_templater_removes_empty_templates
|
122
|
-
t = Templater.new('key' => 'value')
|
123
|
-
t.run_templater(/.*/) do |template, key, value|
|
124
|
-
t << {}
|
125
|
-
template.templater << {}
|
126
|
-
end
|
127
|
-
|
128
|
-
assert_equal([], t.templates)
|
129
|
-
end
|
130
|
-
|
131
|
-
|
132
|
-
#
|
133
|
-
# run methods test
|
134
|
-
#
|
135
|
-
|
136
|
-
def test_run_methods_extends_templates_with_input_modules
|
137
|
-
t = Templater.new('process!' => "entry")
|
138
|
-
t.run_methods(ProcessModule)
|
139
|
-
|
140
|
-
assert_equal([{:processed => 'entry was processed'}], t.templates)
|
141
|
-
end
|
142
|
-
|
143
|
-
def test_run_methods_runs_methods_added_during_processing
|
144
|
-
t = Templater.new('add_new_method_call!' => "entry")
|
145
|
-
t.run_methods(ProcessModule)
|
146
|
-
|
147
|
-
assert_equal([{
|
148
|
-
:add_new_method_call => 'entry was processed',
|
149
|
-
:processed => 'entry from new method call was processed'}], t.templates)
|
150
|
-
end
|
151
|
-
|
152
|
-
def test_run_methods_raises_no_method_error_when_method_does_not_exist
|
153
|
-
[
|
154
|
-
'non_existant!',
|
155
|
-
'non existant!'
|
156
|
-
].each do |key|
|
157
|
-
t = Templater.new(key => 'entry')
|
158
|
-
assert !t.templates.first.respond_to?(key)
|
159
|
-
assert_raise(NoMethodError) { t.run_methods }
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
def test_run_methods_works_recursively
|
164
|
-
t = Templater.new(
|
165
|
-
'key' => 'default',
|
166
|
-
"variations!!" => [
|
167
|
-
{'key' => 'non-default'},
|
168
|
-
{'key' => 'with variations',
|
169
|
-
"variations!!" => [
|
170
|
-
{'another' => 'value'}]}]
|
171
|
-
)
|
172
|
-
t.run_methods
|
173
|
-
|
174
|
-
assert_equal([
|
175
|
-
{'key' => 'default'},
|
176
|
-
{'key' => 'non-default'},
|
177
|
-
{'key' => 'with variations'},
|
178
|
-
{'key' => 'with variations', 'another' => 'value'}],
|
179
|
-
t.templates)
|
180
|
-
end
|
181
|
-
|
182
|
-
#
|
183
|
-
# run_replace test
|
184
|
-
#
|
185
|
-
|
186
|
-
def test_run_replace_replaces_value_with_return_from_block
|
187
|
-
t = Templater.new('replaced=' => "value")
|
188
|
-
t.run_replace {|value| "#{value} was replaced" }
|
189
|
-
|
190
|
-
assert_equal([{'replaced' => 'value was replaced'}], t.templates)
|
191
|
-
end
|
192
|
-
end
|