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
@@ -0,0 +1,54 @@
1
+ require File.join(File.dirname(__FILE__), '../tap_test_helper')
2
+ require 'tap/support/validation'
3
+
4
+ class ValidationTest < Test::Unit::TestCase
5
+ include Tap::Support::Validation
6
+
7
+ #
8
+ # validate test
9
+ #
10
+
11
+ def test_validate
12
+ assert_equal 1, validate(1, Integer)
13
+ assert_raise(ValidationError) { validate(nil, Integer) }
14
+ assert_equal 1, validate(1, [Integer, nil])
15
+ assert_equal nil, validate(nil, [Integer, nil])
16
+
17
+ assert_equal "str", validate("str", /str/)
18
+ assert_raise(ValidationError) { validate("str", /non/) }
19
+ end
20
+
21
+ #
22
+ # check test
23
+ #
24
+
25
+ def test_check_returns_validation_block
26
+ m = check(Integer)
27
+ assert_equal Proc, m.class
28
+ assert_equal 1, m.call(1)
29
+ assert_raise(ValidationError) { m.call(nil) }
30
+ end
31
+
32
+ #
33
+ # yaml test
34
+ #
35
+
36
+ def test_yaml_doc
37
+ b = yaml(Integer, nil)
38
+ assert_equal Proc, b.class
39
+ assert_equal 1, b.call(1)
40
+ assert_equal 1, b.call("1")
41
+ assert_equal nil, b.call(nil)
42
+ assert_raise(ValidationError) { b.call("str") }
43
+ end
44
+
45
+ def test_yaml_block_loads_strings_as_yaml_and_checks_result
46
+ m = yaml(Integer)
47
+ assert_equal Proc, m.class
48
+ assert_equal 1, m.call(1)
49
+ assert_equal 1, m.call("1")
50
+ assert_raise(ValidationError) { m.call(nil) }
51
+ assert_raise(ValidationError) { m.call("str") }
52
+ end
53
+
54
+ end
@@ -2,7 +2,7 @@ require File.join(File.dirname(__FILE__), '../tap_test_helper')
2
2
  require 'tap/support/versions'
3
3
 
4
4
  class VersionTest < Test::Unit::TestCase
5
- include Tap::Support::Versions
5
+ include Tap::Support::Versions
6
6
  include Tap::Test::SubsetMethods
7
7
 
8
8
  def test_documentation
@@ -17,58 +17,58 @@ class VersionTest < Test::Unit::TestCase
17
17
  # version tests
18
18
  #
19
19
 
20
- def test_version_accepts_string_or_numeric_versions
21
- assert_equal "path/to/file-1.1.txt", version("path/to/file.txt", "1.1")
22
- assert_equal "path/to/file-1.1.txt", version("path/to/file.txt", 1.1)
23
-
24
- assert_equal "path/to/file-1.1", version("path/to/file", "1.1")
25
- end
20
+ def test_version_accepts_string_or_numeric_versions
21
+ assert_equal "path/to/file-1.1.txt", version("path/to/file.txt", "1.1")
22
+ assert_equal "path/to/file-1.1.txt", version("path/to/file.txt", 1.1)
23
+
24
+ assert_equal "path/to/file-1.1", version("path/to/file", "1.1")
25
+ end
26
26
 
27
27
  def test_version_defaults_to_filepath_when_no_version_is_specified
28
- assert_equal "path/to/file.txt", version("path/to/file.txt", "")
29
- assert_equal "path/to/file.txt", version("path/to/file.txt", " ")
30
- assert_equal "path/to/file.txt", version("path/to/file.txt", nil)
31
-
32
- assert_equal "path/to/file", version("path/to/file", "")
33
- end
28
+ assert_equal "path/to/file.txt", version("path/to/file.txt", "")
29
+ assert_equal "path/to/file.txt", version("path/to/file.txt", " ")
30
+ assert_equal "path/to/file.txt", version("path/to/file.txt", nil)
31
+
32
+ assert_equal "path/to/file", version("path/to/file", "")
33
+ end
34
34
 
35
35
  #
36
36
  # deversion tests
37
37
  #
38
38
 
39
- def test_deversion_returns_filepath_and_version
40
- assert_equal ["path/to/file.txt", "1.1"], deversion("path/to/file-1.1.txt")
41
- assert_equal ["path/to/file", "1.1"], deversion("path/to/file-1.1")
42
- end
39
+ def test_deversion_returns_filepath_and_version
40
+ assert_equal ["path/to/file.txt", "1.1"], deversion("path/to/file-1.1.txt")
41
+ assert_equal ["path/to/file", "1.1"], deversion("path/to/file-1.1")
42
+ end
43
43
 
44
44
  def test_deversion_returns_nil_for_version_when_no_version_is_specified
45
- assert_equal ["path/to/file.txt", nil], deversion("path/to/file.txt")
46
- assert_equal ["path/to/file", nil], deversion("path/to/file")
47
- end
48
-
49
- #
45
+ assert_equal ["path/to/file.txt", nil], deversion("path/to/file.txt")
46
+ assert_equal ["path/to/file", nil], deversion("path/to/file")
47
+ end
48
+
49
+ #
50
50
  # increment tests
51
51
  #
52
52
 
53
- def test_increment_adds_increment_to_current_version
54
- assert_equal "path/to/file-1.0.1.txt", increment("path/to/file-1.0.txt", "0.0.1")
55
- assert_equal "path/to/file-2.1.txt", increment("path/to/file-1.0.txt", 1.1)
56
- assert_equal "path/to/file-2.0.txt", increment("path/to/file-1.0.txt", 1)
57
- assert_equal "path/to/file-1.1.txt", increment("path/to/file.txt", 1.1)
58
-
59
- assert_equal "path/to/file-1.0.1", increment("path/to/file-1.0", "0.0.1")
60
- assert_equal "path/to/file-2.1", increment("path/to/file-1.0", 1.1)
61
- assert_equal "path/to/file-2.0", increment("path/to/file-1.0", 1)
62
- assert_equal "path/to/file-1.1", increment("path/to/file", 1.1)
63
- end
53
+ def test_increment_adds_increment_to_current_version
54
+ assert_equal "path/to/file-1.0.1.txt", increment("path/to/file-1.0.txt", "0.0.1")
55
+ assert_equal "path/to/file-2.1.txt", increment("path/to/file-1.0.txt", 1.1)
56
+ assert_equal "path/to/file-2.0.txt", increment("path/to/file-1.0.txt", 1)
57
+ assert_equal "path/to/file-1.1.txt", increment("path/to/file.txt", 1.1)
58
+
59
+ assert_equal "path/to/file-1.0.1", increment("path/to/file-1.0", "0.0.1")
60
+ assert_equal "path/to/file-2.1", increment("path/to/file-1.0", 1.1)
61
+ assert_equal "path/to/file-2.0", increment("path/to/file-1.0", 1)
62
+ assert_equal "path/to/file-1.1", increment("path/to/file", 1.1)
63
+ end
64
64
 
65
65
  def test_increment_adds_zero_if_increment_is_nil
66
66
  assert_equal "path/to/file-1.0.txt", increment("path/to/file-1.0.txt", nil)
67
- assert_equal "path/to/file.txt", increment("path/to/file.txt", nil)
68
-
69
- assert_equal "path/to/file-1.0", increment("path/to/file-1.0", nil)
70
- assert_equal "path/to/file", increment("path/to/file", nil)
71
- end
67
+ assert_equal "path/to/file.txt", increment("path/to/file.txt", nil)
68
+
69
+ assert_equal "path/to/file-1.0", increment("path/to/file-1.0", nil)
70
+ assert_equal "path/to/file", increment("path/to/file", nil)
71
+ end
72
72
 
73
73
  #
74
74
  # compare versions test
@@ -3,12 +3,26 @@ require 'rubygems'
3
3
  require File.dirname(__FILE__) + '/../lib/tap'
4
4
  require 'tap/test'
5
5
 
6
+ # Apply version-specific patches
7
+ case RUBY_VERSION
8
+ when /^1.9/
9
+ require 'tap/patches/ruby19/backtrace_filter'
10
+ end
11
+
12
+ unless defined?(ObjectWithExecute)
13
+ class ObjectWithExecute
14
+ def execute(input)
15
+ input
16
+ end
17
+ end
18
+ end
19
+
6
20
  unless defined?(TapTestMethods)
7
21
 
8
22
  # Some convenience methods used in testing tasks, workflows, app, etc.
9
23
  module TapTestMethods # :nodoc:
10
24
  attr_accessor :runlist
11
-
25
+
12
26
  # Setup clears the test using clear_tasks and assures that Tap::App.instance
13
27
  # is the test-specific application.
14
28
  def setup
@@ -25,12 +39,12 @@ unless defined?(TapTestMethods)
25
39
 
26
40
  # A tracing procedure. echo adds input to runlist then returns input.
27
41
  def echo
28
- lambda do |task, input|
29
- @runlist << input
30
- input
42
+ lambda do |task, *inputs|
43
+ @runlist << inputs
44
+ inputs
31
45
  end
32
46
  end
33
-
47
+
34
48
  # A tracing procedure for numeric inputs. add_one adds the input to
35
49
  # runlist then returns input + 1.
36
50
  def add_one
@@ -1,4 +1,7 @@
1
- $:.unshift File.join(File.dirname(__FILE__), '../lib')
1
+ $:.unshift File.dirname(__FILE__) + '/../lib'
2
2
 
3
3
  ENV["ALL"] = 'true'
4
- Dir.glob("./**/*_test.rb").each {|test| require test}
4
+ Dir.glob(File.dirname(__FILE__) + "/**/*_test.rb").each do |test|
5
+ next if test =~ /test\/check/
6
+ require test
7
+ end
@@ -2,114 +2,23 @@ require File.join(File.dirname(__FILE__), 'tap_test_helper')
2
2
  require 'tap/task'
3
3
 
4
4
  class TaskBaseTest < Test::Unit::TestCase
5
- include Tap
6
- include Benchmark
7
-
8
- acts_as_tap_test :root => File.dirname(__FILE__) + "/task"
9
- attr_accessor :t
10
-
11
- class ObjectWithProcess
12
- def process(input)
13
- input
14
- end
15
- end
16
-
17
- def setup
18
- super
19
- @t = ObjectWithProcess.new
20
- @t.extend Tap::Task::Base
21
- end
22
-
23
- #
24
- # extend tests
25
- #
26
-
27
- def test_initialization_of_variables_on_extend
28
- assert_equal [], t.results
29
- assert_equal [t], t.batch
30
- assert_nil t.condition_block
31
- assert_nil t.on_complete_block
32
- assert !t.multithread
33
- assert !t.iterate
34
- end
35
-
36
- #
37
- # multithread test
38
- #
5
+ include Tap
39
6
 
40
- def test_multithread_returns_value_of_multithread
41
- t.multithread = false
42
- assert !t.multithread?
43
- t.multithread = true
44
- assert t.multithread?
7
+ attr_accessor :t
8
+
9
+ def setup
10
+ super
11
+ @t = ObjectWithExecute.new
12
+ Tap::Task::Base.initialize(@t, :execute)
45
13
  end
46
14
 
47
15
  #
48
- # iterate test
16
+ # initialize tests
49
17
  #
50
-
51
- def test_iterate_can_be_set
52
- t.iterate = false
53
- assert !t.iterate?
54
- t.iterate = true
55
- assert t.iterate?
18
+
19
+ def test_initialize
20
+ assert_equal [t], t.batch
21
+ assert_equal Tap::App.instance, t.app
56
22
  end
57
23
 
58
- #
59
- # executable? test
60
- #
61
-
62
- def test_executable_evaluates_condition_block_with_inputs
63
- t.condition do |task, inputs|
64
- inputs == [1,2,3]
65
- end
66
-
67
- assert t.executable?([1,2,3])
68
- assert !t.executable?(1)
69
- end
70
-
71
- def test_executable_returns_true_if_condition_block_is_nil
72
- assert_nil t.condition_block
73
- assert t.executable?(nil)
74
- end
75
-
76
- #
77
- # on_complete block test
78
- #
79
-
80
- def test_on_complete_sets_on_complete_block
81
- block = lambda {}
82
- t.on_complete(&block)
83
- assert_equal block, t.on_complete_block
84
- end
85
-
86
- def test_on_complete_can_only_be_set_once
87
- t.on_complete {}
88
- assert_raise(RuntimeError) { t.on_complete {} }
89
- assert_raise(RuntimeError) { t.on_complete }
90
- end
91
-
92
- #
93
- # condition block test
94
- #
95
-
96
- def test_condition_sets_condition_block
97
- block = lambda {}
98
- t.condition(&block)
99
- assert_equal block, t.condition_block
100
- end
101
-
102
- def test_condition_can_only_be_set_once
103
- t.condition {}
104
- assert_raise(RuntimeError) { t.condition {} }
105
- assert_raise(RuntimeError) { t.condition }
106
- end
107
-
108
- #
109
- # process test
110
- #
111
-
112
- def test_process_returns_input
113
- assert_equal 1, t.process(1)
114
- end
115
- end
24
+ end
@@ -0,0 +1,300 @@
1
+ require File.join(File.dirname(__FILE__), 'tap_test_helper')
2
+ require 'tap/task'
3
+
4
+
5
+ class TaskSyntaxTest < Test::Unit::TestCase
6
+ include Tap
7
+ include TapTestMethods
8
+
9
+ acts_as_tap_test
10
+
11
+ #
12
+ # syntax and arity tests
13
+ #
14
+
15
+ class ProcessTestBase < Tap::Task
16
+ attr_reader :runlist
17
+
18
+ def initialize(*args)
19
+ super
20
+ @runlist = []
21
+ end
22
+ end
23
+
24
+ ##
25
+ class ProcessWithNoInput < Tap::Task
26
+ attr_reader :was_in_process
27
+
28
+ def initialize(*args)
29
+ super
30
+ @was_in_process = false
31
+ end
32
+
33
+ def process
34
+ @was_in_process = true
35
+ end
36
+ end
37
+
38
+ def test_process_with_no_input
39
+ t = ProcessWithNoInput.new
40
+ assert !t.was_in_process
41
+
42
+ with_options :debug => true do
43
+ assert_raise(Tap::Support::RunError) do
44
+ t.enq 1
45
+ app.run
46
+ end
47
+
48
+ t.enq
49
+ app.run
50
+ assert t.was_in_process
51
+ end
52
+ end
53
+
54
+ def test_block_with_no_input
55
+ was_in_block = false
56
+ t = Tap::Task.new do |task|
57
+ was_in_block = true
58
+ end
59
+
60
+ with_options :debug => true do
61
+ assert_raise(Tap::Support::RunError) do
62
+ t.enq 1
63
+ app.run
64
+ end
65
+
66
+ t.enq
67
+ app.run
68
+ assert was_in_block
69
+ end
70
+ end
71
+
72
+ ##
73
+ class ProcessWithOneInput < ProcessTestBase
74
+ def process(input)
75
+ runlist << input
76
+ end
77
+ end
78
+
79
+ def test_process_with_one_input
80
+ t = ProcessWithOneInput.new
81
+
82
+ with_options :debug => true do
83
+ assert_raise(Tap::Support::RunError) do
84
+ t.enq
85
+ app.run
86
+ end
87
+
88
+ t.enq 1
89
+ app.run
90
+ assert_equal [1], t.runlist
91
+
92
+ assert_raise(Tap::Support::RunError) do
93
+ t.enq 1, 2, 3
94
+ app.run
95
+ end
96
+ end
97
+ end
98
+
99
+ def test_block_with_one_input
100
+ runlist = []
101
+ t = Tap::Task.new do |task, input|
102
+ runlist << input
103
+ end
104
+
105
+ with_options :debug => true do
106
+ assert_raise(Tap::Support::RunError) do
107
+ t.enq
108
+ app.run
109
+ end
110
+ assert_raise(Tap::Support::RunError) do
111
+ t.enq 1, 2
112
+ app.run
113
+ end
114
+
115
+ t.enq 1
116
+ app.run
117
+ assert_equal [1], runlist
118
+ end
119
+ end
120
+
121
+ ##
122
+ class ProcessWithMultipleInputs < ProcessTestBase
123
+ def process(a, b)
124
+ runlist << [a,b]
125
+ end
126
+ end
127
+
128
+ def test_process_with_multiple_inputs
129
+ t = ProcessWithMultipleInputs.new
130
+
131
+ with_options :debug => true do
132
+ assert_raise(Tap::Support::RunError) do
133
+ t.enq
134
+ app.run
135
+ end
136
+ assert_raise(Tap::Support::RunError) do
137
+ t.enq 1
138
+ app.run
139
+ end
140
+
141
+ t.enq 1, 2
142
+ app.run
143
+ assert_equal [[1, 2]], t.runlist
144
+ end
145
+ end
146
+
147
+ def test_block_with_multiple_inputs
148
+ runlist = []
149
+ t = Tap::Task.new do |task, a, b|
150
+ runlist << [a,b]
151
+ end
152
+
153
+ with_options :debug => true do
154
+ assert_raise(Tap::Support::RunError) do
155
+ t.enq
156
+ app.run
157
+ end
158
+ assert_raise(Tap::Support::RunError) do
159
+ t.enq 1
160
+ app.run
161
+ end
162
+
163
+ t.enq 1, 2
164
+ app.run
165
+ assert_equal [[1, 2]], runlist
166
+ end
167
+ end
168
+
169
+ ##
170
+ class ProcessWithArbitraryInputs < ProcessTestBase
171
+ def process(*args)
172
+ runlist << args
173
+ end
174
+ end
175
+
176
+ def test_process_with_arbitrary_inputs
177
+ t = ProcessWithArbitraryInputs.new
178
+
179
+ with_options :debug => true do
180
+ t.enq
181
+ app.run
182
+ assert_equal [[]], t.runlist
183
+
184
+ t.enq 1
185
+ app.run
186
+ assert_equal [[], [1]], t.runlist
187
+
188
+ t.enq 1, 2, 3
189
+ app.run
190
+ assert_equal [[], [1], [1,2,3]], t.runlist
191
+ end
192
+ end
193
+
194
+ def test_block_with_arbitrary_inputs
195
+ runlist = []
196
+ t = Tap::Task.new do |task, *args|
197
+ runlist << args
198
+ end
199
+
200
+ with_options :debug => true do
201
+ t.enq
202
+ app.run
203
+ assert_equal [[]], runlist
204
+
205
+ t.enq 1
206
+ app.run
207
+ assert_equal [[], [1]], runlist
208
+
209
+ t.enq 1, 2, 3
210
+ app.run
211
+ assert_equal [[], [1], [1,2,3]], runlist
212
+ end
213
+ end
214
+
215
+ ##
216
+ class ProcessWithMixedArbitraryInputs < ProcessTestBase
217
+ def process(a, b, *args)
218
+ runlist << [a, b, args]
219
+ end
220
+ end
221
+
222
+ def test_process_with_mixed_arbitrary_inputs
223
+ t = ProcessWithMixedArbitraryInputs.new
224
+
225
+ with_options :debug => true do
226
+ assert_raise(Tap::Support::RunError) do
227
+ t.enq
228
+ app.run
229
+ end
230
+ assert_raise(Tap::Support::RunError) do
231
+ t.enq 1
232
+ app.run
233
+ end
234
+
235
+ t.enq 1, 2
236
+ app.run
237
+ assert_equal [[1, 2, []]], t.runlist
238
+
239
+ t.enq 1, 2, 3
240
+ app.run
241
+ assert_equal [[1, 2, []], [1, 2, [3]]], t.runlist
242
+ end
243
+ end
244
+
245
+ def test_block_with_mixed_arbitrary_inputs
246
+ runlist = []
247
+ t = Tap::Task.new do |task, a, b, *args|
248
+ runlist << [a, b, args]
249
+ end
250
+
251
+ with_options :debug => true do
252
+ assert_raise(Tap::Support::RunError) do
253
+ t.enq
254
+ app.run
255
+ end
256
+ assert_raise(Tap::Support::RunError) do
257
+ t.enq 1
258
+ app.run
259
+ end
260
+
261
+ t.enq 1, 2
262
+ app.run
263
+ assert_equal [[1, 2, []]], runlist
264
+
265
+ t.enq 1, 2, 3
266
+ app.run
267
+ assert_equal [[1, 2, []], [1, 2, [3]]], runlist
268
+ end
269
+ end
270
+
271
+ #
272
+ # process with default values
273
+ #
274
+
275
+ class ProcessWithDefaultValues < ProcessTestBase
276
+ def process(input=10)
277
+ runlist << input
278
+ end
279
+ end
280
+
281
+ def test_process_with_default_values
282
+ t = ProcessWithDefaultValues.new
283
+
284
+ with_options :debug => true do
285
+ t.enq
286
+ app.run
287
+ assert_equal [10], t.runlist
288
+
289
+ t.enq 1
290
+ app.run
291
+ assert_equal [10, 1], t.runlist
292
+
293
+ assert_raise(Tap::Support::RunError) do
294
+ t.enq 1, 2
295
+ app.run
296
+ end
297
+ end
298
+ end
299
+
300
+ end