tap 0.9.1 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. data/History +37 -30
  2. data/MIT-LICENSE +1 -1
  3. data/README +92 -44
  4. data/bin/tap +62 -75
  5. data/cmd/console.rb +42 -0
  6. data/cmd/destroy.rb +16 -0
  7. data/cmd/generate.rb +16 -0
  8. data/cmd/run.rb +126 -0
  9. data/doc/Class Reference +362 -0
  10. data/doc/Command Reference +153 -0
  11. data/doc/Tutorial +237 -0
  12. data/lib/tap.rb +6 -45
  13. data/lib/tap/app.rb +126 -500
  14. data/lib/tap/constants.rb +2 -29
  15. data/lib/tap/env.rb +555 -250
  16. data/lib/tap/file_task.rb +60 -103
  17. data/lib/tap/generator/base.rb +109 -0
  18. data/lib/tap/generator/destroy.rb +37 -0
  19. data/lib/tap/generator/generate.rb +61 -0
  20. data/lib/tap/generator/generators/command/command_generator.rb +16 -12
  21. data/lib/tap/generator/generators/command/templates/command.erb +13 -19
  22. data/lib/tap/generator/generators/config/config_generator.rb +18 -27
  23. data/lib/tap/generator/generators/config/templates/doc.erb +12 -0
  24. data/lib/tap/generator/generators/config/templates/nodoc.erb +8 -0
  25. data/lib/tap/generator/generators/file_task/file_task_generator.rb +16 -11
  26. data/lib/tap/generator/generators/file_task/templates/file.txt +11 -2
  27. data/lib/tap/generator/generators/file_task/templates/result.yml +6 -0
  28. data/lib/tap/generator/generators/file_task/templates/task.erb +24 -31
  29. data/lib/tap/generator/generators/file_task/templates/test.erb +18 -22
  30. data/lib/tap/generator/generators/root/root_generator.rb +45 -31
  31. data/lib/tap/generator/generators/root/templates/Rakefile +64 -41
  32. data/lib/tap/generator/generators/root/templates/gemspec +27 -0
  33. data/lib/tap/generator/generators/root/templates/tapfile +8 -0
  34. data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +0 -0
  35. data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +1 -1
  36. data/lib/tap/generator/generators/root/templates/test/tapfile_test.rb +15 -0
  37. data/lib/tap/generator/generators/task/task_generator.rb +21 -28
  38. data/lib/tap/generator/generators/task/templates/task.erb +13 -23
  39. data/lib/tap/generator/generators/task/templates/test.erb +15 -18
  40. data/lib/tap/generator/manifest.rb +14 -0
  41. data/lib/tap/patches/rake/rake_test_loader.rb +0 -0
  42. data/lib/tap/patches/rake/testtask.rb +0 -0
  43. data/lib/tap/patches/ruby19/backtrace_filter.rb +0 -0
  44. data/lib/tap/patches/ruby19/parsedate.rb +0 -0
  45. data/lib/tap/root.rb +260 -21
  46. data/lib/tap/support/aggregator.rb +11 -11
  47. data/lib/tap/support/assignments.rb +172 -0
  48. data/lib/tap/support/audit.rb +20 -18
  49. data/lib/tap/support/batchable.rb +21 -10
  50. data/lib/tap/support/batchable_class.rb +107 -0
  51. data/lib/tap/support/class_configuration.rb +154 -239
  52. data/lib/tap/support/command_line.rb +97 -102
  53. data/lib/tap/support/comment.rb +270 -0
  54. data/lib/tap/support/configurable.rb +86 -65
  55. data/lib/tap/support/configurable_class.rb +296 -0
  56. data/lib/tap/support/configuration.rb +122 -0
  57. data/lib/tap/support/constant.rb +70 -0
  58. data/lib/tap/support/constant_utils.rb +127 -0
  59. data/lib/tap/support/declarations.rb +111 -0
  60. data/lib/tap/support/executable.rb +30 -17
  61. data/lib/tap/support/executable_queue.rb +0 -0
  62. data/lib/tap/support/framework.rb +71 -0
  63. data/lib/tap/support/framework_class.rb +199 -0
  64. data/lib/tap/support/instance_configuration.rb +147 -0
  65. data/lib/tap/support/lazydoc.rb +428 -0
  66. data/lib/tap/support/manifest.rb +89 -0
  67. data/lib/tap/support/run_error.rb +0 -0
  68. data/lib/tap/support/shell_utils.rb +33 -9
  69. data/lib/tap/support/summary.rb +30 -0
  70. data/lib/tap/support/tdoc.rb +339 -134
  71. data/lib/tap/support/tdoc/tdoc_html_generator.rb +0 -0
  72. data/lib/tap/support/tdoc/tdoc_html_template.rb +0 -0
  73. data/lib/tap/support/templater.rb +180 -0
  74. data/lib/tap/support/validation.rb +409 -76
  75. data/lib/tap/support/versions.rb +5 -3
  76. data/lib/tap/task.rb +78 -174
  77. data/lib/tap/tasks/dump.rb +56 -0
  78. data/lib/tap/tasks/rake.rb +93 -0
  79. data/lib/tap/test.rb +3 -3
  80. data/lib/tap/test/env_vars.rb +2 -2
  81. data/lib/tap/test/file_methods.rb +19 -20
  82. data/lib/tap/test/script_methods.rb +144 -0
  83. data/lib/tap/test/subset_methods.rb +1 -1
  84. data/lib/tap/test/tap_methods.rb +28 -62
  85. data/lib/tap/workflow.rb +22 -39
  86. metadata +48 -179
  87. data/Basic Overview +0 -151
  88. data/Command Reference +0 -99
  89. data/Rakefile +0 -127
  90. data/Tutorial +0 -287
  91. data/lib/tap/cmd/console.rb +0 -31
  92. data/lib/tap/cmd/destroy.rb +0 -20
  93. data/lib/tap/cmd/generate.rb +0 -20
  94. data/lib/tap/cmd/run.rb +0 -151
  95. data/lib/tap/dump.rb +0 -57
  96. data/lib/tap/generator.rb +0 -91
  97. data/lib/tap/generator/generators/command/USAGE +0 -6
  98. data/lib/tap/generator/generators/config/USAGE +0 -21
  99. data/lib/tap/generator/generators/config/templates/config.erb +0 -1
  100. data/lib/tap/generator/generators/file_task/USAGE +0 -3
  101. data/lib/tap/generator/generators/file_task/templates/file.yml +0 -3
  102. data/lib/tap/generator/generators/generator/USAGE +0 -0
  103. data/lib/tap/generator/generators/generator/generator_generator.rb +0 -21
  104. data/lib/tap/generator/generators/generator/templates/generator.erb +0 -32
  105. data/lib/tap/generator/generators/generator/templates/usage.erb +0 -1
  106. data/lib/tap/generator/generators/root/USAGE +0 -0
  107. data/lib/tap/generator/generators/root/templates/ReadMe.txt +0 -0
  108. data/lib/tap/generator/generators/root/templates/tap.yml +0 -80
  109. data/lib/tap/generator/generators/task/USAGE +0 -3
  110. data/lib/tap/generator/generators/workflow/USAGE +0 -0
  111. data/lib/tap/generator/generators/workflow/templates/task.erb +0 -16
  112. data/lib/tap/generator/generators/workflow/templates/test.erb +0 -7
  113. data/lib/tap/generator/generators/workflow/workflow_generator.rb +0 -6
  114. data/lib/tap/generator/options.rb +0 -26
  115. data/lib/tap/generator/usage.rb +0 -26
  116. data/lib/tap/support/batchable_methods.rb +0 -34
  117. data/lib/tap/support/command_line_methods.rb +0 -76
  118. data/lib/tap/support/configurable_methods.rb +0 -224
  119. data/lib/tap/support/logger.rb +0 -88
  120. data/lib/tap/support/rake.rb +0 -43
  121. data/lib/tap/support/tdoc/config_attr.rb +0 -362
  122. data/test/app/config/another/task.yml +0 -1
  123. data/test/app/config/batch.yml +0 -2
  124. data/test/app/config/empty.yml +0 -0
  125. data/test/app/config/erb.yml +0 -2
  126. data/test/app/config/some/task.yml +0 -1
  127. data/test/app/config/template.yml +0 -2
  128. data/test/app/config/version-0.1.yml +0 -1
  129. data/test/app/config/version.yml +0 -1
  130. data/test/app/lib/app_test_task.rb +0 -3
  131. data/test/app_test.rb +0 -1849
  132. data/test/env/test_configure/recurse_a.yml +0 -2
  133. data/test/env/test_configure/recurse_b.yml +0 -2
  134. data/test/env/test_configure/tap.yml +0 -23
  135. data/test/env/test_load_env_config/dir/tap.yml +0 -3
  136. data/test/env/test_load_env_config/recurse_a.yml +0 -2
  137. data/test/env/test_load_env_config/recurse_b.yml +0 -2
  138. data/test/env/test_load_env_config/tap.yml +0 -3
  139. data/test/env_test.rb +0 -198
  140. data/test/file_task/config/batch.yml +0 -2
  141. data/test/file_task/config/configured.yml +0 -1
  142. data/test/file_task/old_file_one.txt +0 -0
  143. data/test/file_task/old_file_two.txt +0 -0
  144. data/test/file_task_test.rb +0 -1291
  145. data/test/root/alt_lib/alt_module.rb +0 -4
  146. data/test/root/file.txt +0 -0
  147. data/test/root/glob/one.txt +0 -0
  148. data/test/root/glob/two.txt +0 -0
  149. data/test/root/lib/absolute_alt_filepath.rb +0 -2
  150. data/test/root/lib/alternative_filepath.rb +0 -2
  151. data/test/root/lib/another_module.rb +0 -2
  152. data/test/root/lib/nested/some_module.rb +0 -4
  153. data/test/root/lib/no_module_included.rb +0 -0
  154. data/test/root/lib/some/module.rb +0 -4
  155. data/test/root/lib/some_class.rb +0 -2
  156. data/test/root/lib/some_module.rb +0 -3
  157. data/test/root/load_path/load_path_module.rb +0 -2
  158. data/test/root/load_path/skip_module.rb +0 -2
  159. data/test/root/mtime/older.txt +0 -0
  160. data/test/root/unload/full_path.rb +0 -2
  161. data/test/root/unload/loaded_by_nested.rb +0 -2
  162. data/test/root/unload/nested/nested_load.rb +0 -6
  163. data/test/root/unload/nested/nested_with_ext.rb +0 -4
  164. data/test/root/unload/nested/relative_path.rb +0 -4
  165. data/test/root/unload/older.rb +0 -2
  166. data/test/root/unload/unload_base.rb +0 -9
  167. data/test/root/versions/another.yml +0 -0
  168. data/test/root/versions/file-0.1.2.yml +0 -0
  169. data/test/root/versions/file-0.1.yml +0 -0
  170. data/test/root/versions/file.yml +0 -0
  171. data/test/root_test.rb +0 -718
  172. data/test/support/aggregator_test.rb +0 -99
  173. data/test/support/audit_test.rb +0 -445
  174. data/test/support/batchable_test.rb +0 -74
  175. data/test/support/class_configuration_test.rb +0 -331
  176. data/test/support/command_line_test.rb +0 -58
  177. data/test/support/configurable/config/configured.yml +0 -2
  178. data/test/support/configurable_test.rb +0 -295
  179. data/test/support/executable_queue_test.rb +0 -103
  180. data/test/support/executable_test.rb +0 -38
  181. data/test/support/logger_test.rb +0 -31
  182. data/test/support/rake_test.rb +0 -37
  183. data/test/support/shell_utils_test.rb +0 -24
  184. data/test/support/tdoc_test.rb +0 -370
  185. data/test/support/validation_test.rb +0 -54
  186. data/test/support/versions_test.rb +0 -103
  187. data/test/tap_test_helper.rb +0 -57
  188. data/test/tap_test_suite.rb +0 -7
  189. data/test/task/config/batch.yml +0 -2
  190. data/test/task/config/batched.yml +0 -2
  191. data/test/task/config/configured.yml +0 -1
  192. data/test/task/config/example.yml +0 -1
  193. data/test/task_base_test.rb +0 -24
  194. data/test/task_syntax_test.rb +0 -300
  195. data/test/task_test.rb +0 -320
  196. data/test/test/env_vars_test.rb +0 -48
  197. data/test/test/file_methods/test_assert_files/expected/one.txt +0 -1
  198. data/test/test/file_methods/test_assert_files/expected/two.txt +0 -1
  199. data/test/test/file_methods/test_assert_files/input/one.txt +0 -1
  200. data/test/test/file_methods/test_assert_files/input/two.txt +0 -1
  201. data/test/test/file_methods/test_assert_files_can_have_no_expected_files_if_specified/input/one.txt +0 -1
  202. data/test/test/file_methods/test_assert_files_can_have_no_expected_files_if_specified/input/two.txt +0 -1
  203. data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/one.txt +0 -1
  204. data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/two.txt +0 -1
  205. data/test/test/file_methods/test_assert_files_fails_for_different_content/input/one.txt +0 -1
  206. data/test/test/file_methods/test_assert_files_fails_for_different_content/input/two.txt +0 -1
  207. data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/expected/one.txt +0 -1
  208. data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/one.txt +0 -1
  209. data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/two.txt +0 -1
  210. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/one.txt +0 -1
  211. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/two.txt +0 -1
  212. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/one.txt +0 -1
  213. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/two.txt +0 -1
  214. data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/one.txt +0 -1
  215. data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/two.txt +0 -1
  216. data/test/test/file_methods/test_method_glob/expected/file.yml +0 -0
  217. data/test/test/file_methods/test_method_glob/expected/file_1.txt +0 -0
  218. data/test/test/file_methods/test_method_glob/expected/file_2.txt +0 -0
  219. data/test/test/file_methods_doc/test_sub/expected/one.txt +0 -1
  220. data/test/test/file_methods_doc/test_sub/expected/two.txt +0 -1
  221. data/test/test/file_methods_doc/test_sub/input/one.txt +0 -1
  222. data/test/test/file_methods_doc/test_sub/input/two.txt +0 -1
  223. data/test/test/file_methods_doc_test.rb +0 -29
  224. data/test/test/file_methods_test.rb +0 -275
  225. data/test/test/subset_methods_test.rb +0 -171
  226. data/test/test/tap_methods/test_assert_files/expected/task/name/a.txt +0 -1
  227. data/test/test/tap_methods/test_assert_files/expected/task/name/b.txt +0 -1
  228. data/test/test/tap_methods/test_assert_files/input/a.txt +0 -1
  229. data/test/test/tap_methods/test_assert_files/input/b.txt +0 -1
  230. data/test/test/tap_methods_test.rb +0 -399
  231. data/test/workflow_test.rb +0 -120
  232. data/vendor/rails_generator.rb +0 -56
  233. data/vendor/rails_generator/base.rb +0 -263
  234. data/vendor/rails_generator/commands.rb +0 -581
  235. data/vendor/rails_generator/generated_attribute.rb +0 -42
  236. data/vendor/rails_generator/lookup.rb +0 -209
  237. data/vendor/rails_generator/manifest.rb +0 -53
  238. data/vendor/rails_generator/options.rb +0 -143
  239. data/vendor/rails_generator/scripts.rb +0 -83
  240. data/vendor/rails_generator/scripts/destroy.rb +0 -7
  241. data/vendor/rails_generator/scripts/generate.rb +0 -7
  242. data/vendor/rails_generator/scripts/update.rb +0 -12
  243. data/vendor/rails_generator/simple_logger.rb +0 -46
  244. data/vendor/rails_generator/spec.rb +0 -44
data/lib/tap/test.rb CHANGED
@@ -25,9 +25,9 @@ end
25
25
 
26
26
  module Tap
27
27
 
28
- # Modules facilitating testing. Tap::Test::TapMethods are specific to
29
- # Tap, but the other modules Tap::Test::SubsetMethods and
30
- # Tap::Test::FileMethods are more general in their utility.
28
+ # Modules facilitating testing. TapMethods are specific to
29
+ # Tap, but SubsetMethods and FileMethods are more general in
30
+ # their utility.
31
31
  module Test
32
32
  end
33
33
  end
@@ -1,7 +1,7 @@
1
1
  module Tap
2
2
  module Test
3
3
 
4
- # Provides a method for case-insensitive access to the ENV variables
4
+ # Provides for case-insensitive access to the ENV variables
5
5
  module EnvVars
6
6
 
7
7
  # Access to the case-insensitive ENV variables. Raises an error
@@ -20,7 +20,7 @@ module Tap
20
20
  end
21
21
  end
22
22
 
23
- # Returns true if the env_var(var) is set and matches /^true%/i
23
+ # Returns true if the env_var(var) is set and matches /^true$/i
24
24
  def env_true?(var)
25
25
  env(var) && env(var) =~ /^true$/i
26
26
  end
@@ -2,13 +2,15 @@ require 'tap/root'
2
2
  require 'tap/test/env_vars'
3
3
  require 'test/unit'
4
4
  require 'fileutils'
5
- require 'active_support/core_ext/class'
6
5
 
7
6
  module Test # :nodoc:
8
7
  module Unit # :nodoc:
9
8
  class TestCase
10
9
  class << self
11
10
 
11
+ # Access the test root structure (a Tap::Root)
12
+ attr_accessor :trs
13
+
12
14
  # Causes a TestCase to act as a file test, by instantiating a class Tap::Root
13
15
  # (trs), and including FileMethods. The root and directories used to
14
16
  # instantiate trs can be specified as options. By default file_test_root
@@ -25,10 +27,7 @@ module Test # :nodoc:
25
27
  }.merge(options)
26
28
 
27
29
  directories = options[:directories]
28
- trs = Tap::Root.new(options[:root], directories)
29
-
30
- write_inheritable_attribute(:trs, trs)
31
- class_inheritable_reader :trs
30
+ self.trs = Tap::Root.new(options[:root], directories)
32
31
 
33
32
  include Tap::Test::FileMethods
34
33
  end
@@ -57,8 +56,7 @@ end
57
56
  module Tap
58
57
  module Test
59
58
 
60
- # == Overview
61
- #
59
+
62
60
  # FileMethods sets up a TestCase with methods for accessing and utilizing
63
61
  # test-specific files and directories. Each class that acts_as_file_test
64
62
  # is set up with a Tap::Root structure (trs) that mediates the creation of
@@ -137,6 +135,10 @@ module Tap
137
135
  # % rake test keep_outputs=true
138
136
  # % tap run test keep_failures=true
139
137
  #
138
+ #
139
+ # === Class Methods
140
+ #
141
+ # See {Test::Unit::TestCase}[link:classes/Test/Unit/TestCase.html] for documentation of the class methods added by FileMethods.
140
142
  module FileMethods
141
143
  include Tap::Test::EnvVars
142
144
 
@@ -152,11 +154,14 @@ module Tap
152
154
  end
153
155
  end
154
156
 
157
+ attr_reader :method_tempfiles
158
+
155
159
  # Setup deletes the the output directory if it exists, and tries to remove the
156
160
  # method root directory so the directory structure is reset before running the
157
161
  # test, even if outputs were left over from previous tests.
158
162
  def setup
159
163
  super
164
+ @method_tempfiles = []
160
165
  clear_method_dir(:output)
161
166
  try_remove_dir(method_root)
162
167
  end
@@ -258,21 +263,20 @@ module Tap
258
263
  # - If the directory for the filepath does not exist, the directory will be created
259
264
  # - Like all files in the output directory, tempfiles will be deleted by the default
260
265
  # +teardown+ method
261
- def output_tempfile(filename=method_name_str)
262
- n = 0
266
+ def method_tempfile(filename=method_name_str, &block)
263
267
  ext = File.extname(filename)
264
268
  basename = filename.chomp(ext)
265
- filepath = make_tmpname(basename, n, ext)
266
- while File.exists?(filepath)
267
- n += 1
268
- filepath = make_tmpname(basename, n, ext)
269
- end
269
+ filepath = method_filepath(:output, sprintf('%s%d.%d%s', basename, $$, method_tempfiles.length, ext))
270
+ method_tempfiles << filepath
270
271
 
271
272
  dirname = File.dirname(filepath)
272
273
  FileUtils.mkdir_p(dirname) unless File.exists?(dirname)
274
+ if block_given?
275
+ File.open(filepath, "w", &block)
276
+ end
273
277
  filepath
274
278
  end
275
-
279
+
276
280
  # Yields to the input block for each pair of entries in the input
277
281
  # arrays. An error is raised if the input arrays do not have equal
278
282
  # numbers of entries.
@@ -368,11 +372,6 @@ module Tap
368
372
  flunk "File compare failed:\n" + errors.join("\n") unless errors.empty?
369
373
  end
370
374
 
371
- private
372
-
373
- def make_tmpname(basename, n, ext="") # :nodoc:
374
- method_filepath(:output, sprintf('%s%d.%d%s', basename, $$, n, ext))
375
- end
376
375
  end
377
376
  end
378
377
  end
@@ -0,0 +1,144 @@
1
+ require 'test/unit'
2
+ require 'tap/test/file_methods'
3
+ require 'tap/test/subset_methods'
4
+ #require 'tap/support/shell_utils'
5
+
6
+ module Test # :nodoc:
7
+ module Unit # :nodoc:
8
+ class TestCase
9
+ class << self
10
+
11
+ def acts_as_script_test(options={})
12
+ options = options.inject({:root => file_test_root}) do |hash, (key, value)|
13
+ hash[key.to_sym || key] = value
14
+ hash
15
+ end
16
+ acts_as_file_test(options)
17
+ include Tap::Test::SubsetMethods
18
+ include Tap::Test::ScriptMethods
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
25
+
26
+ module Tap
27
+ module Test
28
+
29
+ module ScriptMethods
30
+ class CommandTest
31
+ attr_accessor :command_path
32
+ attr_reader :commands
33
+
34
+ def initialize
35
+ @command_path = nil
36
+ @commands = []
37
+ end
38
+
39
+ def check(argstr, msg=nil, expected=nil, &block)
40
+ commands << ["#{command_path}#{argstr}", msg, expected, block]
41
+ end
42
+
43
+ def check_cmd(cmd, msg=nil, expected=nil, &block)
44
+ commands << [cmd, msg, expected, block]
45
+ end
46
+ end
47
+
48
+ include Tap::Support::ShellUtils
49
+
50
+ def assert_output_equal(a, b, cmd, msg)
51
+ a = a[1..-1] if a[0] == ?\n
52
+ if a == b
53
+ assert true
54
+ else
55
+ flunk %Q{
56
+ #{msg}
57
+ % #{cmd}
58
+ ==================== expected output ====================
59
+ #{a.gsub(/\t/, "\\t").gsub(/\r\n/, "\\r\\n\n").gsub(/\n/, "\\n\n")}
60
+ ======================== but was ========================
61
+ #{b.gsub(/\t/, "\\t").gsub(/\r\n/, "\\r\\n\n").gsub(/\n/, "\\n\n")}
62
+ =========================================================
63
+ }
64
+ end
65
+ end
66
+
67
+ def assert_alike(a, b, cmd, msg)
68
+ if b =~ a
69
+ assert true
70
+ else
71
+ flunk %Q{
72
+ #{msg}
73
+ % #{cmd}
74
+ ================= expected output like ==================
75
+ #{a}
76
+ ======================== but was ========================
77
+ #{b.gsub(/\t/, "\\t").gsub(/\r\n/, "\\r\\n\n").gsub(/\n/, "\\n\n")}
78
+ =========================================================
79
+ }
80
+ end
81
+ end
82
+
83
+ def script_test(test_dir=method_dir(:output))
84
+ subset_test("SCRIPT", "s") do
85
+ test = CommandTest.new
86
+ yield(test)
87
+
88
+ current_dir = Dir.pwd
89
+ current_argv = ARGV.dup
90
+ begin
91
+ ARGV.clear
92
+ make_test_directories
93
+ Dir.chdir(test_dir)
94
+
95
+ puts "\n# == #{method_name}"
96
+
97
+ test.commands.each do |cmd, msg, expected, block|
98
+ start = Time.now
99
+ result = capture_sh(cmd) {|ok, status, tempfile_path| }
100
+ elapsed = Time.now - start
101
+
102
+ case expected
103
+ when String
104
+ assert_output_equal(expected, result, cmd, msg)
105
+ when Regexp
106
+ assert_alike(expected, result, cmd, msg)
107
+ end
108
+
109
+ if block
110
+ block.call(result)
111
+ end
112
+
113
+ if env('stepwise') || (expected == nil && block == nil)
114
+ print %Q{
115
+ ------------------------------------
116
+ %s
117
+ > %s
118
+ %s
119
+ Time Elapsed: %.3fs} % [msg, cmd, result, elapsed]
120
+
121
+ if env('stepwise')
122
+ print "\nContinue? (y/n): "
123
+ break if gets.strip =~ /^no?$/i
124
+ end
125
+ else
126
+ puts "%.3fs : %s" % [elapsed, msg]
127
+ end
128
+ end
129
+ ensure
130
+ Dir.chdir(current_dir)
131
+ ARGV.clear
132
+ ARGV.concat(current_argv)
133
+ end
134
+
135
+ end
136
+ end
137
+
138
+ end
139
+ end
140
+ end
141
+
142
+
143
+
144
+
@@ -244,7 +244,7 @@ module Tap
244
244
  #
245
245
  # === Class Methods
246
246
  #
247
- # See Test::Unit::TestCase for documentation of the class methods added by SubsetMethods
247
+ # See {Test::Unit::TestCase}[link:classes/Test/Unit/TestCase.html] for documentation of the class methods added by SubsetMethods
248
248
  module SubsetMethods
249
249
  include Tap::Test::EnvVars
250
250
 
@@ -15,7 +15,10 @@ module Test # :nodoc:
15
15
  # based on the calling file. Be sure to specify the root directory explicitly
16
16
  # if you call acts_as_file_test from a file that is NOT meant to be test file.
17
17
  def acts_as_tap_test(options={})
18
- options = {:root => file_test_root}.merge(options.symbolize_keys)
18
+ options = options.inject({:root => file_test_root}) do |hash, (key, value)|
19
+ hash[key.to_sym || key] = value
20
+ hash
21
+ end
19
22
  acts_as_file_test(options)
20
23
 
21
24
  include Tap::Test::SubsetMethods
@@ -59,6 +62,10 @@ module Tap
59
62
  # Tap-specific testing methods to help with testing Tasks, such as the
60
63
  # checking of audits and test-specific modification of application
61
64
  # configuration.
65
+ #
66
+ # === Class Methods
67
+ #
68
+ # See {Test::Unit::TestCase}[link:classes/Test/Unit/TestCase.html] for documentation of the class methods added by TapMethods.
62
69
  module TapMethods
63
70
 
64
71
  # Returns the test-method-specific application.
@@ -71,10 +78,7 @@ module Tap
71
78
  # Also makes sure Tap::App.instance returns the test method app.
72
79
  def setup
73
80
  super
74
- @app = Tap::App.new(
75
- :root => method_root,
76
- :directories => trs.directories,
77
- :absolute_paths => trs.absolute_paths)
81
+ @app = Tap::App.new(app_config)
78
82
  Tap::App.instance = @app
79
83
  end
80
84
 
@@ -191,74 +195,36 @@ module Tap
191
195
 
192
196
  public
193
197
 
194
- #
195
- # application methods
196
- #
197
-
198
- # Applies the input options to the specified app for the duration
199
- # of the block. Unless merge_with_existing is false, the input
200
- # options will be merged with the existing options; otherwise
201
- # the app options will be reconfigured to just the inputs.
202
- #
203
- # For convenience, with_options is setup such that options
204
- # {:debug => true, :quiet => true} are implicitly specified.
205
- # Overrides are respected.
206
- #
207
- # app = Tap::App.new(:options => {:one => 1, :two => 2})
208
- #
209
- # with_options({:one => 'one', :quiet => false}, app) do
210
- # app.options.marshal_dump # => {:one => 'one', :two => 2, :debug => true, :quiet => false}
211
- # end
212
- #
213
- # app.options.marshal_dump # => {:one => 1, :two => 2}
214
- #
215
- def with_options(options={}, app=self.app, merge_with_existing=true, &block)
216
- app_config = {:options => options}
217
- with_config(app_config, app, merge_with_existing, &block)
198
+ # The configurations used to initialize self.app
199
+ def app_config
200
+ { :root => method_root,
201
+ :directories => trs.directories,
202
+ :absolute_paths => trs.absolute_paths,
203
+ :quiet => true,
204
+ :debug => true}
218
205
  end
219
206
 
220
- # Applies the input configurations to the specified app for the
221
- # duration of the block. Unless merge_with_existing is false,
222
- # the input configurations will be merged with the existing
223
- # configurations; otherwise the app will be reconfigured to
224
- # using the inputs as specified.
225
- #
226
- # For convenience, with_config is setup such that options
227
- # {:debug => true, :quiet => true} are implicitly specified.
228
- # Overrides are respected.
207
+ # Reconfigures app with the input configurations for the
208
+ # duration of the block.
229
209
  #
230
- # app = Tap::App.new(:directories => {:dir => 'dir', :alt => 'alt_dir'})
231
- # tmp_config = {
232
- # :directories => {:alt => 'another', :new => 'new_dir'},
233
- # :options => {:one => 1, :quiet => false}}
234
- #
235
- # with_config(tmp_config, app) do
236
- # app.directories # => {:dir => 'dir', :alt => 'another', :new => 'new_dir'}
237
- # app.options.marshal_dump # => {:one => 1, :debug => true, :quiet => false}
210
+ # app = Tap::App.new(:quiet => true, :debug => false)
211
+ # with_config({:quiet => false}, app) do
212
+ # app.quiet # => false
213
+ # app.debug # => false
238
214
  # end
239
215
  #
240
- # app.directories # => {:dir => 'dir', :alt => 'alt_dir'}
241
- # app.options.marshal_dump # => {}
216
+ # app.quiet # => true
217
+ # app.debug # => false
242
218
  #
243
- def with_config(app_config={}, app=self.app, merge_with_existing=true, default_options={:debug => true, :quiet => true}, &block)
219
+ def with_config(config={}, app=self.app, &block)
244
220
  begin
245
- hold = app.config
246
-
247
- app_config[:options] = default_options.merge(app_config[:options] || {})
248
- if merge_with_existing
249
- hold.each_pair do |key, value|
250
- next unless app_config.has_key?(key)
251
- next unless value.kind_of?(Hash)
252
-
253
- app_config[key] = value.merge(app_config[key])
254
- end
255
- end
221
+ hold = app.config.to_hash
256
222
 
257
- app.reconfigure(app_config)
223
+ app.reconfigure(config)
258
224
 
259
225
  yield block if block_given?
260
226
  ensure
261
- app.reconfigure(hold)
227
+ app.send(:initialize_config, hold)
262
228
  end
263
229
  end
264
230
 
data/lib/tap/workflow.rb CHANGED
@@ -1,11 +1,7 @@
1
1
  module Tap
2
2
 
3
- # == Overview
4
- #
5
- # App can build workflows directly, using methods like sequence, merge, and
6
- # multithread, but these workflows are hard to abstract and resuse. Workflow
7
- # is a specialized type of Task allows the encapsulation and reuse of workflow
8
- # logic. See Tap::Task for the shared documentation.
3
+ # Workflow is a specialized type of Task allowing the encapsulation and reuse of
4
+ # workflow logic. Workflows are still under construction.
9
5
  #
10
6
  # === Workflow Definition
11
7
  #
@@ -81,9 +77,8 @@ module Tap
81
77
  # app.results(w1.exit_points, w2.exit_points)) # => [8, -8]
82
78
  #
83
79
  class Workflow
84
- include Support::Configurable
85
- extend Support::CommandLineMethods
86
-
80
+ include Support::Framework
81
+
87
82
  # The entry point for self.
88
83
  attr_accessor :entry_point
89
84
 
@@ -94,24 +89,18 @@ module Tap
94
89
  attr_reader :task_block
95
90
 
96
91
  # Creates a new Task with the specified attributes.
97
- def initialize(name=nil, config={}, app=App.instance, &task_block)
92
+ def initialize(config={}, name=nil, app=App.instance, &task_block)
93
+ super(config, name, app)
98
94
  @task_block = (task_block == nil ? default_task_block : task_block)
99
- super(name, config, app)
95
+ initialize_workflow
100
96
  end
101
97
 
102
98
  # Initializes a new batch object, running workflow to set the
103
99
  # instance-specific entry/exit points. Raises an error if
104
100
  # no entry points are defined.
105
- def initialize_batch_obj(name=nil, config={})
106
- task = super(name, config)
107
-
108
- task.entry_point = {}
109
- task.exit_point = {}
110
- task.workflow
111
-
112
- raise WorkflowError.new("No entry points defined") if task.entry_points.empty?
113
-
114
- task
101
+ def initialize_copy(orig)
102
+ super
103
+ initialize_workflow
115
104
  end
116
105
 
117
106
  # Returns an array of entry points, determined from entry_point.
@@ -142,33 +131,24 @@ module Tap
142
131
  # if the entry points have different input requirements, they
143
132
  # have to be enqued separately.
144
133
  def enq(*inputs)
145
- batch.each {|t| t.unbatched_enq(*inputs) }
146
- self
147
- end
148
-
149
- # Enques all entry points to app with the inputs.
150
- def unbatched_enq(*inputs)
151
134
  entry_points.each do |task|
152
135
  app.enq(task, *inputs)
153
136
  end
154
- self
155
137
  end
156
138
 
139
+ batch_function :enq
140
+
157
141
  # Sets the on_complete_block for all exit points for self and
158
142
  # self.batch. Use unbatched_on_complete to set the on_complete_block
159
143
  # for just self.exit_points.
160
144
  def on_complete(override=false, &block)
161
- batch.each {|t| t.unbatched_on_complete(override, &block)}
162
- self
163
- end
164
-
165
- # Sets the on_complete_block for all exit points for self.
166
- def unbatched_on_complete(override=false, &block)
167
145
  exit_points.each do |task|
168
146
  task.on_complete(override, &block)
169
147
  end
170
148
  self
171
149
  end
150
+
151
+ batch_function(:on_complete) {}
172
152
 
173
153
  # The workflow definition method. By default workflow
174
154
  # simply calls the task_block. In subclasses, workflow
@@ -189,13 +169,16 @@ module Tap
189
169
  input == nil ? @name : File.join(@name, input)
190
170
  end
191
171
 
192
- # Returns name
193
- def to_s
194
- name
195
- end
196
-
197
172
  protected
198
173
 
174
+ def initialize_workflow
175
+ @entry_point = {}
176
+ @exit_point = {}
177
+
178
+ workflow
179
+ raise WorkflowError.new("No entry points defined") if entry_points.empty?
180
+ end
181
+
199
182
  # Hook to set a default task block. By default, nil.
200
183
  def default_task_block
201
184
  nil