tap 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/Basic Overview +151 -0
  2. data/Command Reference +99 -0
  3. data/History +24 -0
  4. data/MIT-LICENSE +1 -1
  5. data/README +29 -57
  6. data/Rakefile +30 -37
  7. data/Tutorial +243 -191
  8. data/bin/tap +66 -35
  9. data/lib/tap.rb +47 -29
  10. data/lib/tap/app.rb +700 -342
  11. data/lib/tap/{script → cmd}/console.rb +0 -0
  12. data/lib/tap/{script → cmd}/destroy.rb +0 -0
  13. data/lib/tap/{script → cmd}/generate.rb +0 -0
  14. data/lib/tap/cmd/run.rb +156 -0
  15. data/lib/tap/constants.rb +4 -0
  16. data/lib/tap/dump.rb +57 -0
  17. data/lib/tap/env.rb +316 -0
  18. data/lib/tap/file_task.rb +106 -109
  19. data/lib/tap/generator.rb +4 -1
  20. data/lib/tap/generator/generators/command/USAGE +6 -0
  21. data/lib/tap/generator/generators/command/command_generator.rb +17 -0
  22. data/lib/tap/generator/generators/{script/templates/script.erb → command/templates/command.erb} +10 -10
  23. data/lib/tap/generator/generators/config/USAGE +21 -0
  24. data/lib/tap/generator/generators/config/config_generator.rb +17 -7
  25. data/lib/tap/generator/generators/file_task/USAGE +3 -0
  26. data/lib/tap/generator/generators/file_task/file_task_generator.rb +16 -0
  27. data/lib/tap/generator/generators/file_task/templates/file.txt +2 -0
  28. data/lib/tap/generator/generators/file_task/templates/file.yml +3 -0
  29. data/lib/tap/generator/generators/file_task/templates/task.erb +26 -20
  30. data/lib/tap/generator/generators/file_task/templates/test.erb +20 -10
  31. data/lib/tap/generator/generators/generator/generator_generator.rb +1 -1
  32. data/lib/tap/generator/generators/generator/templates/generator.erb +21 -12
  33. data/lib/tap/generator/generators/root/templates/Rakefile +33 -24
  34. data/lib/tap/generator/generators/root/templates/tap.yml +28 -31
  35. data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +1 -0
  36. data/lib/tap/generator/generators/task/USAGE +3 -0
  37. data/lib/tap/generator/generators/task/task_generator.rb +18 -5
  38. data/lib/tap/generator/generators/task/templates/task.erb +7 -12
  39. data/lib/tap/generator/generators/task/templates/test.erb +10 -11
  40. data/lib/tap/generator/generators/workflow/templates/task.erb +1 -1
  41. data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
  42. data/lib/tap/patches/rake/rake_test_loader.rb +8 -0
  43. data/lib/tap/patches/rake/testtask.rb +55 -0
  44. data/lib/tap/patches/ruby19/backtrace_filter.rb +51 -0
  45. data/lib/tap/patches/ruby19/parsedate.rb +16 -0
  46. data/lib/tap/root.rb +172 -67
  47. data/lib/tap/script.rb +70 -336
  48. data/lib/tap/support/aggregator.rb +55 -0
  49. data/lib/tap/support/audit.rb +281 -280
  50. data/lib/tap/support/batchable.rb +59 -0
  51. data/lib/tap/support/class_configuration.rb +279 -0
  52. data/lib/tap/support/configurable.rb +92 -0
  53. data/lib/tap/support/configurable_methods.rb +296 -0
  54. data/lib/tap/support/executable.rb +98 -0
  55. data/lib/tap/support/executable_queue.rb +82 -0
  56. data/lib/tap/support/logger.rb +9 -15
  57. data/lib/tap/support/rake.rb +43 -54
  58. data/lib/tap/support/run_error.rb +32 -13
  59. data/lib/tap/support/shell_utils.rb +47 -0
  60. data/lib/tap/support/tdoc.rb +9 -8
  61. data/lib/tap/support/tdoc/config_attr.rb +40 -16
  62. data/lib/tap/support/validation.rb +77 -0
  63. data/lib/tap/support/versions.rb +36 -36
  64. data/lib/tap/task.rb +276 -482
  65. data/lib/tap/test.rb +20 -261
  66. data/lib/tap/test/env_vars.rb +7 -5
  67. data/lib/tap/test/file_methods.rb +126 -121
  68. data/lib/tap/test/subset_methods.rb +86 -45
  69. data/lib/tap/test/tap_methods.rb +271 -0
  70. data/lib/tap/workflow.rb +174 -46
  71. data/test/app/config/another/task.yml +1 -0
  72. data/test/app/config/erb.yml +2 -1
  73. data/test/app/config/some/task.yml +1 -0
  74. data/test/app/config/template.yml +2 -6
  75. data/test/app_test.rb +1241 -1008
  76. data/test/env/test_configure/recurse_a.yml +2 -0
  77. data/test/env/test_configure/recurse_b.yml +2 -0
  78. data/test/env/test_configure/tap.yml +23 -0
  79. data/test/env/test_load_env_config/dir/tap.yml +3 -0
  80. data/test/env/test_load_env_config/recurse_a.yml +2 -0
  81. data/test/env/test_load_env_config/recurse_b.yml +2 -0
  82. data/test/env/test_load_env_config/tap.yml +3 -0
  83. data/test/env_test.rb +198 -0
  84. data/test/file_task_test.rb +70 -53
  85. data/{lib/tap/generator/generators/package/USAGE → test/root/file.txt} +0 -0
  86. data/test/root_test.rb +621 -454
  87. data/test/script_test.rb +38 -174
  88. data/test/support/aggregator_test.rb +99 -0
  89. data/test/support/audit_test.rb +409 -416
  90. data/test/support/batchable_test.rb +74 -0
  91. data/test/support/{task_configuration_test.rb → class_configuration_test.rb} +106 -47
  92. data/test/{task/config/overriding.yml → support/configurable/config/configured.yml} +0 -0
  93. data/test/support/configurable_test.rb +295 -0
  94. data/test/support/executable_queue_test.rb +103 -0
  95. data/test/support/executable_test.rb +38 -0
  96. data/test/support/logger_test.rb +17 -17
  97. data/test/support/rake_test.rb +4 -2
  98. data/test/support/shell_utils_test.rb +24 -0
  99. data/test/support/tdoc_test.rb +265 -258
  100. data/test/support/validation_test.rb +54 -0
  101. data/test/support/versions_test.rb +38 -38
  102. data/test/tap_test_helper.rb +19 -5
  103. data/test/tap_test_suite.rb +5 -2
  104. data/test/task_base_test.rb +13 -104
  105. data/test/task_syntax_test.rb +300 -0
  106. data/test/task_test.rb +258 -381
  107. data/test/test/env_vars_test.rb +40 -40
  108. data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/one.txt +0 -0
  109. data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/two.txt +0 -0
  110. data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/one.txt +0 -0
  111. data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/two.txt +0 -0
  112. data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/one.txt +0 -0
  113. data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/two.txt +0 -0
  114. data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/one.txt +1 -0
  115. data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_different_content}/expected/two.txt +0 -0
  116. data/test/test/file_methods/test_assert_files_fails_for_different_content/input/one.txt +1 -0
  117. data/test/test/file_methods/test_assert_files_fails_for_different_content/input/two.txt +1 -0
  118. data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_missing_expected_file}/expected/one.txt +0 -0
  119. data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/one.txt +1 -0
  120. data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/two.txt +1 -0
  121. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/one.txt +1 -0
  122. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/two.txt +1 -0
  123. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/one.txt +1 -0
  124. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/two.txt +1 -0
  125. data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/one.txt +1 -0
  126. data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/two.txt +1 -0
  127. data/test/test/file_methods_doc/test_sub/expected/one.txt +1 -0
  128. data/test/test/file_methods_doc/test_sub/expected/two.txt +1 -0
  129. data/test/test/file_methods_doc/test_sub/input/one.txt +1 -0
  130. data/test/test/file_methods_doc/test_sub/input/two.txt +1 -0
  131. data/test/test/file_methods_doc_test.rb +29 -0
  132. data/test/test/file_methods_test.rb +214 -143
  133. data/test/test/subset_methods_test.rb +111 -115
  134. data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/a.txt +0 -0
  135. data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/b.txt +0 -0
  136. data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/a.txt +0 -0
  137. data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/b.txt +0 -0
  138. data/test/test/tap_methods_test.rb +399 -0
  139. data/test/workflow_test.rb +101 -91
  140. metadata +86 -70
  141. data/lib/tap/generator/generators/package/package_generator.rb +0 -38
  142. data/lib/tap/generator/generators/package/templates/package.erb +0 -186
  143. data/lib/tap/generator/generators/script/USAGE +0 -0
  144. data/lib/tap/generator/generators/script/script_generator.rb +0 -17
  145. data/lib/tap/script/run.rb +0 -154
  146. data/lib/tap/support/batch_queue.rb +0 -162
  147. data/lib/tap/support/combinator.rb +0 -114
  148. data/lib/tap/support/task_configuration.rb +0 -169
  149. data/lib/tap/support/template.rb +0 -81
  150. data/lib/tap/support/templater.rb +0 -155
  151. data/lib/tap/version.rb +0 -4
  152. data/test/app/config/addition_template.yml +0 -6
  153. data/test/app_class_test.rb +0 -33
  154. data/test/check/binding_eval.rb +0 -23
  155. data/test/check/define_method_check.rb +0 -22
  156. data/test/check/dependencies_check.rb +0 -175
  157. data/test/check/inheritance_check.rb +0 -22
  158. data/test/support/batch_queue_test.rb +0 -320
  159. data/test/support/combinator_test.rb +0 -249
  160. data/test/support/template_test.rb +0 -122
  161. data/test/support/templater/erb.txt +0 -2
  162. data/test/support/templater/erb.yml +0 -2
  163. data/test/support/templater/somefile.txt +0 -2
  164. data/test/support/templater_test.rb +0 -192
  165. data/test/task/config/template.yml +0 -4
  166. data/test/task_class_test.rb +0 -170
  167. data/test/task_execute_test.rb +0 -262
  168. data/test/test/file_methods/test_assert_expected/expected/file.txt +0 -1
  169. data/test/test/file_methods/test_assert_expected/expected/folder/file.txt +0 -1
  170. data/test/test/file_methods/test_assert_expected/input/file.txt +0 -1
  171. data/test/test/file_methods/test_assert_expected/input/folder/file.txt +0 -1
  172. data/test/test/file_methods/test_assert_files_exist/input/input_1.txt +0 -0
  173. data/test/test/file_methods/test_assert_files_exist/input/input_2.txt +0 -0
  174. data/test/test/file_methods/test_file_compare/expected/output_1.txt +0 -3
  175. data/test/test/file_methods/test_file_compare/expected/output_2.txt +0 -1
  176. data/test/test/file_methods/test_file_compare/input/input_1.txt +0 -3
  177. data/test/test/file_methods/test_file_compare/input/input_2.txt +0 -3
  178. data/test/test/file_methods/test_infer_glob/expected/file.yml +0 -0
  179. data/test/test/file_methods/test_infer_glob/expected/file_1.txt +0 -0
  180. data/test/test/file_methods/test_infer_glob/expected/file_2.txt +0 -0
  181. data/test/test/file_methods/test_yml_compare/expected/output_1.yml +0 -6
  182. data/test/test/file_methods/test_yml_compare/expected/output_2.yml +0 -6
  183. data/test/test/file_methods/test_yml_compare/input/input_1.yml +0 -4
  184. data/test/test/file_methods/test_yml_compare/input/input_2.yml +0 -4
  185. data/test/test_test.rb +0 -373
@@ -1,194 +1,58 @@
1
1
  require File.join(File.dirname(__FILE__), 'tap_test_helper')
2
2
  require 'tap/script'
3
3
 
4
- class ScriptConfigTest < Test::Unit::TestCase
5
- include Tap
6
-
7
- acts_as_tap_test
8
-
9
- #
10
- # class default tests
11
- #
12
-
13
- def test_defaults
14
- assert_equal({
15
- :gems => [],
16
- :load_once_paths => [],
17
- :load_paths => ["lib"],
18
- :script_paths => ["script"]},
19
- ScriptConfig.defaults)
20
- end
21
-
22
- #
23
- # class spec_filepath test
24
- #
25
-
26
- def test_spec_filepath
27
- assert_equal "tapspec.yml", ScriptConfig.spec_filepath
28
- assert_equal "path/to/dir/tapspec.yml", ScriptConfig.spec_filepath("path/to/dir")
29
- end
30
-
31
- #
32
- # default script config
33
- #
34
-
35
- def test_default_script_config
36
- config = ScriptConfig.new
37
- assert config.kind_of?(OpenStruct)
38
- assert_equal({
39
- :gems => [],
40
- :gemspecs => [],
41
- :load_once_paths => [],
42
- :load_paths => [app["lib"]],
43
- :script_paths => [app["script"]]},
44
- config.marshal_dump)
45
- end
46
-
47
- def test_script_config_with_inputs
48
- config = ScriptConfig.new :key => 'value', :load_paths => ['lib', 'test']
49
-
50
- assert_equal({
51
- :gems => [],
52
- :gemspecs => [],
53
- :load_once_paths => [],
54
- :load_paths => [app["lib"], app['test']],
55
- :script_paths => [app["script"]],
56
- :key => 'value'},
57
- config.marshal_dump)
58
- end
59
-
60
- def test_single_arguments_are_allowed
61
- config = ScriptConfig.new(
62
- :load_paths => "alt",
63
- :load_once_paths => "once")
64
-
65
- assert_equal({
66
- :gems => [],
67
- :gemspecs => [],
68
- :load_once_paths => [app["once"]],
69
- :load_paths => [app["alt"]],
70
- :script_paths => [app["script"]]},
71
- config.marshal_dump)
72
- end
73
-
74
- def test_gemspecs_and_paths_are_collected_for_the_specified_gem
75
- config = ScriptConfig.new :gems => 'activesupport'
76
- spec = Gem.loaded_specs["activesupport"]
77
-
78
- assert_equal 'activesupport', config.gems
79
- assert_equal [spec], config.gemspecs
80
- assert_equal [app['lib'], File.join(spec.full_gem_path, 'lib')], config.load_paths
81
- assert_equal [app['script'], File.join(spec.full_gem_path, 'script')], config.script_paths
82
- end
83
-
84
- #
85
- # TODO -- find a way to test the gem loading behavior,
86
- # especially when the tapspec contains nested gems
87
- # and when the tapspec contains unsafe filepaths
88
- #
4
+ class ScriptTest < Test::Unit::TestCase
5
+ include Tap::Script
89
6
 
90
7
  #
91
- # TODO -- test scripts
8
+ # split_argv test
92
9
  #
93
- end
94
-
95
- class ScriptTest < Test::Unit::TestCase
96
-
97
- acts_as_tap_test
98
10
 
99
- def setup
100
- super
101
- @load_path_hold = $LOAD_PATH.dup
102
- Dependencies.load_paths.clear
103
- Dependencies.load_once_paths.clear
11
+ def test_split_argv
12
+ argv = ["a", "-b", "--c", "--", "d", "-e", "--f"]
13
+ assert_equal([
14
+ [["a", "-b", "--c"], ["d", "-e", "--f"]]
15
+ ], split_argv(argv))
104
16
 
105
- script.reset
106
- end
107
-
108
- def teardown
109
- super
110
- $LOAD_PATH.clear
111
- $LOAD_PATH.concat @load_path_hold
112
- Dependencies.load_paths.clear
113
- Dependencies.load_once_paths.clear
17
+ argv.unshift("--")
18
+ argv.push("--")
19
+ assert_equal([
20
+ [["a", "-b", "--c"], ["d", "-e", "--f"]]
21
+ ], split_argv(argv))
22
+
23
+ argv.concat ["--++", "x", "-y", "--z"]
24
+ assert_equal([
25
+ [["a", "-b", "--c"], ["d", "-e", "--f"]],
26
+ [["x", "-y", "--z"]]
27
+ ], split_argv(argv))
28
+
29
+ argv.concat ["--+", "m", "-n", "--o"]
30
+ assert_equal([
31
+ [["a", "-b", "--c"], ["d", "-e", "--f"]],
32
+ [["m", "-n", "--o"]],
33
+ [["x", "-y", "--z"]]
34
+ ], split_argv(argv))
114
35
  end
115
36
 
116
- def script
117
- Tap::Script.instance
118
- end
119
-
120
- def tap_lib_dir
121
- File.expand_path(File.dirname(__FILE__) + "/../lib")
122
- end
123
-
124
37
  #
125
- # configure_app tests
38
+ # parse_yaml tests
126
39
  #
127
40
 
128
- def test_configure_returns_an_appropriate_script_config
129
- config = script.configure_app
130
-
131
- assert_equal [], config.gemspecs
132
- assert_equal [], config.load_once_paths
133
- assert_equal [tap_lib_dir, app['lib']], config.load_paths
134
- assert_equal [app['script']], config.script_paths
135
-
136
- config = script.configure_app :load_paths => ['alt'], :key => 'value'
137
-
138
- assert_equal [], config.gemspecs
139
- assert_equal [], config.load_once_paths
140
- assert_equal [tap_lib_dir, app['alt']], config.load_paths
141
- assert_equal [app['script']], config.script_paths
142
- assert_equal 'value', config.key
41
+ def test_parse_yaml_documentation
42
+ str = {'key' => 'value'}.to_yaml
43
+ assert_equal "--- \nkey: value\n", str
44
+ assert_equal({'key' => 'value'}, parse_yaml(str))
45
+ assert_equal "str", parse_yaml("str")
143
46
  end
144
47
 
145
- def test_configure_app_sets_default_load_and_script_paths
146
- assert !$LOAD_PATH.include?( app['lib'] )
147
- assert_equal [], Dependencies.load_paths
148
- assert_equal [], Dependencies.load_once_paths
149
-
150
- script.configure_app
151
-
152
- assert $LOAD_PATH.include?( app['lib'] )
153
-
154
- assert_equal [tap_lib_dir, app['lib']], Dependencies.load_paths
155
- assert_equal [], Dependencies.load_once_paths
156
- end
157
-
158
- def test_configure_app_resolves_aliases_and_sets_paths
159
- app['lib'] = "alt_lib"
160
- app['script'] = "alt_script"
161
- app['load_once'] = "load/once/lib"
162
-
163
- assert !$LOAD_PATH.include?( app['lib'] )
164
- assert_equal [], Dependencies.load_paths
165
- assert_equal [], Dependencies.load_once_paths
166
-
167
- script.configure_app(
168
- :load_paths => ["lib", "load_once"],
169
- :load_once_paths => ["load_once"],
170
- :script_paths => ['script'])
171
-
172
- assert $LOAD_PATH.include?( app['lib'] )
173
- assert $LOAD_PATH.include?( app['load_once'] )
174
-
175
- assert_equal [tap_lib_dir, app['lib'], app['load_once']], Dependencies.load_paths
176
- assert_equal [app['load_once']], Dependencies.load_once_paths
48
+ def test_parse_yaml_loads_arg_if_arg_matches_yaml_document_string
49
+ string = "---\nkey: value"
50
+ assert_equal({"key" => "value"}, parse_yaml(string))
177
51
  end
178
52
 
179
- def test_configure_app_raises_error_if_load_once_path_is_not_a_load_path
180
- assert_raise(RuntimeError) do
181
- script.configure_app(
182
- :load_paths => [],
183
- :load_once_paths => ["lib"])
184
- end
53
+ def test_parse_yaml_returns_arg_unless_matches_yaml_document_string
54
+ string = "key: value"
55
+ assert_equal("key: value", parse_yaml(string))
185
56
  end
186
57
 
187
- #
188
- # split_to_length test
189
- #
190
-
191
- # def test_split_to_length
192
- # assert_equal ["a a a a", "aaa aa ","a "], Tap::Script.split_to_length("a a a a aaa aa \na", 7)
193
- # end
194
58
  end
@@ -0,0 +1,99 @@
1
+ require File.join(File.dirname(__FILE__), '../tap_test_helper')
2
+ require 'tap/support/aggregator'
3
+ require 'tap/support/audit'
4
+
5
+ class AggregatorTest < Test::Unit::TestCase
6
+ include Tap::Support
7
+
8
+ attr_accessor :aggregator
9
+
10
+ def setup
11
+ @aggregator = Aggregator.new
12
+ end
13
+
14
+ #
15
+ # store test
16
+ #
17
+
18
+ def test_store_appends_audit_to_array_keyed_by_current_source
19
+ a = Audit.new
20
+ a._record(:a, 1)
21
+ assert_equal :a, a._current_source
22
+
23
+ aggregator.store(a)
24
+ assert_equal({:a => [a]}, aggregator.to_hash)
25
+
26
+ aggregator.store(a)
27
+ assert_equal({:a => [a, a]}, aggregator.to_hash)
28
+
29
+ a._record(:b, 2)
30
+ assert_equal :b, a._current_source
31
+
32
+ aggregator.store(a)
33
+ assert_equal({:a => [a, a], :b => [a]}, aggregator.to_hash)
34
+ end
35
+
36
+ #
37
+ # clear test
38
+ #
39
+
40
+ def test_clear
41
+ a = Audit.new
42
+ a._record(:a, 1)
43
+
44
+ aggregator.store(a)
45
+ aggregator.store(a)
46
+ assert_equal({:a => [a, a]}, aggregator.to_hash)
47
+
48
+ aggregator.clear
49
+ assert_equal({}, aggregator.to_hash)
50
+ end
51
+
52
+ #
53
+ # retrieve test
54
+ #
55
+
56
+ def test_retrieve_returns_array_for_source
57
+ a = Audit.new
58
+ a._record(:a, 1)
59
+
60
+ aggregator.store(a)
61
+ aggregator.store(a)
62
+ assert_equal({:a => [a, a]}, aggregator.to_hash)
63
+
64
+ assert_equal [a,a], aggregator.retrieve(:a)
65
+ end
66
+
67
+ def test_retrieve_returns_nil_for_unknown_source
68
+ assert_nil aggregator.retrieve(:unknown)
69
+ end
70
+
71
+ #
72
+ # retrieve_all test
73
+ #
74
+
75
+ def test_retrieve_all_returns_concatenated_arrays_for_sources
76
+ a = Audit.new
77
+ a._record(:a, 1)
78
+
79
+ aggregator.store(a)
80
+ aggregator.store(a)
81
+
82
+ b = Audit.new
83
+ b._record(:b, 1)
84
+ aggregator.store(b)
85
+
86
+ assert_equal({:a => [a, a], :b => [b]}, aggregator.to_hash)
87
+
88
+ assert_equal [a,a], aggregator.retrieve_all(:a)
89
+ assert_equal [b], aggregator.retrieve_all(:b)
90
+ assert_equal [a,a,b], aggregator.retrieve_all(:a, :b)
91
+ assert_equal [b,a,a], aggregator.retrieve_all(:b, :a)
92
+
93
+ assert_equal [a,a,b], aggregator.retrieve_all(:a, :unknown, :b)
94
+ end
95
+
96
+ def test_retrieve_all_returns_empty_array_for_all_unknown_sources
97
+ assert_equal [], aggregator.retrieve_all(:a, :unknown, :b)
98
+ end
99
+ end
@@ -2,311 +2,275 @@ require File.dirname(__FILE__) + '/../tap_test_helper'
2
2
  require 'tap/support/audit'
3
3
 
4
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
-
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
+ # methods to setup audits for testing, and tests of the setup
17
+ #
18
+
19
+ def setup_audit(*sources)
20
+ audit = Audit.new
21
+ sources.each do |source|
22
+ value = case source
23
+ when Array
24
+ source.collect {|s| s.to_s }
25
+ else
26
+ source.to_s
27
+ end
28
+
29
+ audit._record(source, value)
30
+ end
31
+ audit
32
+ end
33
+
34
+ def test_setup
35
+ assert_equal [nil], audit._sources
36
+ assert_equal ['original'], audit._values
37
+ assert_equal 'original', audit._original
38
+ assert_equal 'original', audit._current
39
+
40
+ assert_equal [:a, :b, :c], a._sources
41
+ assert_equal ['a', 'b', 'c'], a._values
42
+ assert_equal 'c', a._current
43
+ assert_equal 'a', a._original
44
+
45
+ assert_equal [:x, :y, :z], b._sources
46
+ assert_equal ['x', 'y', 'z'], b._values
47
+ assert_equal 'z', b._current
48
+ assert_equal 'x', b._original
49
+
50
+ c = setup_audit([a, b, :c])
51
+ assert_equal [[a, b, :c]], c._sources
52
+ assert_equal [[a.to_s, b.to_s, 'c']], c._values
53
+ end
54
+
55
+ #
56
+ # documentation tests
57
+ #
58
+
59
+ def test_documentation
60
+ # initialize a new audit
61
+ a = Audit.new(1, nil)
62
+
63
+ # record some values
64
+ a._record(:A, 2)
65
+ a._record(:B, 3)
66
+
67
+ assert_equal [nil, :A, :B], a._source_trail
68
+ assert_equal [1, 2, 3], a._value_trail
69
+ assert_equal 1, a._original
70
+ assert_equal nil, a._original_source
71
+ assert_equal 3, a._current
72
+ assert_equal :B, a._current_source
73
+
74
+ b = Audit.new(10, nil)
75
+ b._record(:C, 11)
76
+ b._record(:D, 12)
77
+
78
+ c = Audit.merge(a, b)
79
+ assert_equal [ [[nil, :A, :B], [nil, :C, :D]] ], c._source_trail
80
+ assert_equal [ [[1,2,3], [10, 11, 12]] ], c._value_trail
81
+ assert_equal [3, 12], c._current
82
+
83
+ c._record(:E, "a string value")
84
+ c._record(:F, {'a' => 'hash value'})
85
+ c._record(:G, ['an', 'array', 'value'])
86
+
87
+ assert_equal [ [[nil, :A, :B], [nil, :C, :D]], :E, :F, :G], c._source_trail
88
+ assert_equal [ [[1,2,3], [10, 11, 12]], "a string value", {'a' => 'hash value'}, ['an', 'array', 'value']], c._value_trail
89
+
90
+ a1 = a._fork
91
+ a._record(:X, -1)
92
+ a1._record(:Y, -2)
93
+
94
+ assert_equal [nil, :A, :B, :X], a._source_trail
95
+ assert_equal [nil, :A, :B, :Y], a1._source_trail
96
+ assert_equal [ [[nil, :A, :B], [nil, :C, :D]], :E, :F, :G], c._source_trail
97
+
98
+ expected = %Q{o-[] 1
99
+ o-[A] 2
100
+ o-[B] 3
101
+ |
102
+ | o-[] 10
103
+ | o-[C] 11
104
+ | o-[D] 12
105
+ | |
106
+ `-`-o-[E] "a string value"
107
+ o-[F] {"a"=>"hash value"}
108
+ o-[G] ["an", "array", "value"]
109
+ }
110
+
111
+ assert_equal expected, c._to_s
112
+ end
113
+
114
+ #
115
+ # Audit merge tests
116
+ #
117
+
118
+ def test_merge_documentation
119
+ a = Audit.new
120
+ a._record(:a, 'a')
121
+
122
+ b = Audit.new
123
+ b._record(:b, 'b')
124
+
125
+ c = Audit.merge(a, b, 1)
126
+ c._record(:c, 'c')
127
+
128
+ assert_equal [['a','b', 1], 'c'], c._values
129
+ assert_equal [AuditMerge[a, b, Audit.new(1)], :c], c._sources
130
+ end
131
+
132
+ def test_merge
133
+ c = Audit.merge(a, b, 'p')
134
+ c._record(:q, 'q')
135
+ c._record(:r, 'r')
136
+
137
+ assert_equal [AuditMerge[a, b, Audit.new('p')], :q, :r], c._sources
138
+ assert_equal [['c', 'z', 'p'], 'q', 'r'], c._values
139
+
140
+ assert_equal [[[:a, :b, :c], [:x, :y, :z], [nil]], :q, :r], c._source_trail
141
+ assert_equal [[['a', 'b', 'c'], ['x', 'y', 'z'], ['p']], 'q', 'r'], c._value_trail
142
+ end
143
+
144
+ def test_merge_with_one_input_returns_fork
145
+ c = Audit.merge(a)
146
+ assert_equal c, a
147
+ end
148
+
149
+ def test_merge_with_no_inputs_returns_new_audit
150
+ a = Audit.merge
151
+ assert_equal Audit.new, a
152
+ end
153
+
154
+ #
155
+ # record tests
156
+ #
157
+
158
+ def test_record
159
+ audit._record(:a, 'next')
160
+ audit._record(:b, 'final')
161
+
162
+ assert_equal [nil, :a, :b], audit._sources
163
+ assert_equal ['original', 'next', 'final'], audit._values
164
+ end
165
+
166
+ def test_record_with_arrays_and_audits
167
+ audit._record(:a, a)
168
+ audit._record(:array, [a, b, 'str'])
169
+
170
+ assert_equal [nil, :a, :array], audit._sources
171
+ assert_equal ['original', a, [a, b, 'str']], audit._values
172
+ end
173
+
174
+ def test_record_returns_self
175
+ assert audit, audit._record(:a, 'next')
176
+ end
177
+
178
+ #
179
+ # original tests
180
+ #
181
+
182
+ def test_original_is_first_recorded_value
183
+ a = Audit.new('a', :a)
184
+ assert_equal 'a', a._original
185
+
186
+ audit._record(:b, 'next')
187
+ assert_equal 'a', a._original
188
+ end
189
+
190
+ def test_original_source_is_original_recorded_source
191
+ a = Audit.new('a', :a)
192
+ assert_equal :a, a._original_source
193
+
194
+ audit._record(:b, 'next')
195
+ assert_equal :a, a._original_source
196
+ end
197
+
198
+ #
199
+ # current tests
200
+ #
201
+
202
+ def test_current_is_last_recorded_value
203
+ audit._record(:a, 'next')
204
+ assert_equal 'next', audit._current
205
+
206
+ audit._record(:a, 'final')
207
+ assert_equal 'final', audit._current
208
+ end
209
+
210
+ def test_current_source_is_last_recorded_source
211
+ audit._record(:a, 'next')
212
+ assert_equal :a, audit._current_source
213
+
214
+ audit._record(:b, 'final')
215
+ assert_equal :b, audit._current_source
216
+ end
217
+
218
+ #
219
+ # source trail tests
220
+ #
221
+
222
+ def test_source_trail_helper_method_is_hidden
223
+ assert !a.respond_to?(:source_trail)
224
+ assert_raise(NoMethodError) { a.source_trail }
225
+ end
226
+
227
+ def test_source_trail_returns_all_sources
228
+ a = setup_audit(:a, :b, :c)
229
+
230
+ assert_equal [:a, :b, :c], a._source_trail
231
+ end
232
+
233
+ def test_source_trail_returns_source_trail_when_source_is_an_audit
234
+ c = setup_audit(:p, a, :q)
235
+
236
+ assert_equal [:p, a, :q], c._sources
237
+ assert_equal [:p, [:a, :b, :c], :q], c._source_trail
238
+ end
239
+
240
+ def test_source_trail_resolves_each_member_in_an_audit_merge_source
241
+ c = setup_audit(:p, AuditMerge[a, b, :q], [:r, :s], :t)
242
+
243
+ assert_equal [:p, [[:a, :b, :c], [:x, :y, :z], :q],[:r, :s], :t], c._source_trail
244
+ end
245
+
246
+ #
247
+ # value trail tests
248
+ #
249
+
250
+ def test_value_trail_helper_method_is_hidden
251
+ assert !a.respond_to?(:value_trail)
252
+ assert_raise(NoMethodError) { a.value_trail }
253
+ end
254
+
255
+ def test_value_trail_returns_all_values
256
+ a = setup_audit(:a, :b, :c)
257
+
258
+ assert_equal ['a', 'b', 'c'], a._value_trail
259
+ end
260
+
261
+ def test_value_trail_returns_value_trail_when_source_is_an_audit
262
+ c = setup_audit(:p, a, :q)
263
+
264
+ assert_equal [:p, a, :q], c._sources
265
+ assert_equal ['p', ['a', 'b', 'c'], 'q'], c._value_trail
266
+ end
267
+
268
+ def test_value_trail_resolves_each_member_in_an_audit_merge_source
269
+ c = setup_audit(:p, AuditMerge[a, b, :q], [:r, :s], :t)
270
+
271
+ assert_equal ['p', [['a', 'b', 'c'], ['x', 'y', 'z'], 'q'],['r', 's'], 't'], c._value_trail
272
+ end
273
+
310
274
  #
311
275
  # test fork
312
276
  #
@@ -328,125 +292,154 @@ class AuditTest < Test::Unit::TestCase
328
292
  a._record(:c, 'c')
329
293
  b._record(:d, 'd')
330
294
 
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
295
+ assert_equal([:a, :b, :c], a._sources)
296
+ assert_equal([:a, :b, :d], b._sources)
297
+ end
298
+
299
+ #
300
+ # split tests
394
301
  #
395
302
 
396
- def test_documentation
397
- # reset the app, in case it is in an unexpected state
398
- Tap::App.instance = nil
399
-
400
- # part 1
401
- audit = Audit.new(3)
402
- audit._record(:a, 4)
403
- audit._record(:b, 5)
404
- audit._record(:c, 7)
405
- assert_equal([nil, :a, :b, :c], audit._source_trail)
303
+ def test_split_forks_and_records_result_yielding_to_current
304
+ block = lambda { |current| current += 'ar' }
305
+ c = a._split(&block)
406
306
 
407
- # part 2
408
- audit = Audit.new(3)
409
- audit._record(:a, 4)
410
- fork_b = audit._fork
411
- fork_c = audit._fork
307
+ assert_equal [:a, :b, :c, AuditSplit.new(block)], c._sources
308
+ assert_equal ['a', 'b', 'c', 'car'], c._values
309
+ end
310
+
311
+ def test_split_raises_error_if_no_block_given
312
+ assert_raise(LocalJumpError) { a._split }
313
+ end
314
+
315
+ #
316
+ # expand tests
317
+ #
318
+
319
+ def test_expand_forks_for_and_records_each_in_current
320
+ a = Audit.new([1,2,3])
321
+ e = a._expand
412
322
 
413
- fork_b._record(:b, 5)
414
- fork_c._record(:c, 6)
415
- assert_equal([nil, :a, :b], fork_b._source_trail)
416
- assert_equal([nil, :a, :c], fork_c._source_trail)
323
+ assert_equal 3, e.length
417
324
 
418
- merged_audit = Audit.merge(fork_b, fork_c)
419
- merged_audit._record(:d, 11)
420
- assert_equal([[[nil,:a,:b], [nil,:a,:c]], :d], merged_audit._source_trail)
325
+ assert_equal [nil, AuditExpand.new(0)], e[0]._sources
326
+ assert_equal [[1,2,3], 1], e[0]._values
421
327
 
422
- # part 3
423
- t = Tap::Task.new
424
- t.on_complete do |results|
425
- results.each do |result|
426
-
427
- assert_equal Audit, result.class
428
- assert_equal "str", result._current
429
- assert result == "str"
430
- assert_equal "STR", result.upcase
328
+ assert_equal [nil, AuditExpand.new(1)], e[1]._sources
329
+ assert_equal [[1,2,3], 2], e[1]._values
431
330
 
432
- assert !result.kind_of?(String)
433
- assert result =~ /s(\w+)/
434
- assert_nil $1
435
-
436
- end
437
- end
438
- t.execute "str"
331
+ assert_equal [nil, AuditExpand.new(2)], e[2]._sources
332
+ assert_equal [[1,2,3], 3], e[2]._values
333
+ end
334
+
335
+ def test_expand_raises_error_if_current_does_not_respond_to_each
336
+ a = Audit.new(nil)
337
+ assert_raise(NoMethodError) { a._expand }
338
+ end
339
+
340
+ #
341
+ # _to_s test
342
+ #
343
+
344
+ def new_audit(letter, n=0)
345
+ a = Tap::Support::Audit.new
346
+ 1.upto(n) {|i| a._record(letter, "#{letter}#{i}")}
347
+ a
348
+ end
349
+
350
+ def test_to_s_for_sequence
351
+ a = Audit.new
352
+ assert_equal %Q{\n}, a._to_s
353
+
354
+ a = new_audit(:a, 3)
355
+ assert_equal %Q{
356
+ o-[a] "a1"
357
+ o-[a] "a2"
358
+ o-[a] "a3"
359
+ }[1..-1], a._to_s
360
+ end
361
+
362
+ def test_to_s_for_fork_is_same_as_forked
363
+ a = new_audit(:a)
364
+ assert_equal a._to_s, a._fork._to_s
365
+
366
+ a = new_audit(:a, 3)._fork
367
+ assert_equal a._to_s, a._fork._to_s
368
+ end
369
+
370
+ def test_to_s_for_merge_without_additional_records
371
+ a = new_audit(:a, 3)
372
+ b = new_audit(:b, 3)
373
+ c = Tap::Support::Audit.merge(a,b)
374
+
375
+ assert_equal %Q{
376
+ o-[a] "a1"
377
+ o-[a] "a2"
378
+ o-[a] "a3"
379
+ |
380
+ | o-[b] "b1"
381
+ | o-[b] "b2"
382
+ | o-[b] "b3"
383
+ }[1..-1], c._to_s
384
+ end
385
+
386
+ def test_to_s_for_merge_with_additional_records
387
+ a = new_audit(:a, 3)
388
+ b = new_audit(:b, 3)
389
+ c = Tap::Support::Audit.merge(a,b)
390
+ 1.upto(3) {|i| c._record(:c, "c#{i}")}
391
+
392
+ assert_equal %Q{
393
+ o-[a] "a1"
394
+ o-[a] "a2"
395
+ o-[a] "a3"
396
+ |
397
+ | o-[b] "b1"
398
+ | o-[b] "b2"
399
+ | o-[b] "b3"
400
+ | |
401
+ `-`-o-[c] "c1"
402
+ o-[c] "c2"
403
+ o-[c] "c3"
404
+ }[1..-1], c._to_s
405
+ end
406
+
407
+ def test_to_s_for_merge_with_multiple_input_audits
408
+ a = new_audit(:a, 1)
409
+ b = new_audit(:b, 1)
410
+ c = Tap::Support::Audit.merge(a,b)
411
+ 1.upto(1) {|i| c._record(:c, "c#{i}")}
439
412
 
440
- # part 4
441
- t = Tap::Task.new do |task, input|
442
- assert_equal Fixnum, input.class
443
- input += 1
444
- end
413
+ d = new_audit(:d, 1)
414
+ e = new_audit(:e, 1)
415
+ f = Tap::Support::Audit.merge(d, e, 'x1', 'y1', 'z1')
416
+ 1.upto(1) {|i| f._record(:f, "f#{i}")}
445
417
 
446
- results = t.execute(3)
447
- assert_equal Array, results.class
448
- assert_equal 1, results.length
449
- assert_equal Audit, results.first.class
450
- assert_equal 4, results.first._current
418
+ g = Tap::Support::Audit.merge(c, f)
419
+ 1.upto(1) {|i| g._record(:g, "g#{i}")}
420
+
421
+ assert_equal %Q{
422
+ o-[a] "a1"
423
+ |
424
+ | o-[b] "b1"
425
+ | |
426
+ `-`-o-[c] "c1"
427
+ |
428
+ | o-[d] "d1"
429
+ | |
430
+ | | o-[e] "e1"
431
+ | | |
432
+ | | | o-[] "x1"
433
+ | | | |
434
+ | | | | o-[] "y1"
435
+ | | | | |
436
+ | | | | | o-[] "z1"
437
+ | | | | | |
438
+ | `-`-`-`-`-o-[f] "f1"
439
+ | |
440
+ `-----------`-o-[g] "g1"
441
+ }[1..-1], g._to_s
451
442
  end
443
+
444
+
452
445
  end