tap 0.8.0 → 0.9.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 (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
@@ -3,125 +3,121 @@ require 'tap/test/subset_methods'
3
3
 
4
4
  class SubsetMethodsTest < Test::Unit::TestCase
5
5
  include Tap::Test::SubsetMethods
6
- include Benchmark
7
-
8
- def setup
9
- @env_hold = {}
10
- ENV.each_pair do |key, value|
11
- @env_hold[key] = value
12
- end
13
- ENV.clear
14
- end
15
-
16
- def teardown
17
- ENV.clear
18
- @env_hold.each_pair do |key, value|
19
- ENV[key] = value
20
- end
21
- end
22
-
23
- #
24
- # env_true test
25
- #
26
-
27
- def test_env_true_is_true_if_var_is_true
28
- assert !ENV['type']
29
- assert !env_true?('type')
30
-
31
- ENV['type'] = "false"
32
- assert !env_true?('type')
33
-
34
- ENV['type'] = "true"
35
- assert env_true?('type')
36
-
37
- ENV['type'] = "True"
38
- assert env_true?('type')
39
-
40
- ENV['type'] = "TRUE"
41
- assert env_true?('type')
42
- end
43
-
44
- #
45
- # extended_test test
46
- #
47
-
48
- def test_extended_test_runs_only_if_extended_true
49
- was_in_test = false
50
- extended_test { was_in_test = true }
51
- assert !was_in_test
52
-
53
- ENV['EXTENDED'] = 'true'
54
- extended_test { was_in_test = true }
55
- assert was_in_test
56
- end
57
-
58
- #
59
- # condition test
60
- #
61
-
62
- condition(:is_true) {true}
63
- condition(:is_false) {false}
64
-
65
- def test_conditional_test_runs_only_if_all_conditions_are_true
66
- test_ran = false
67
- condition_test(:is_true) { test_ran = true}
68
- assert test_ran
69
-
70
- test_ran = false
71
- condition_test(:is_false) { test_ran = true}
72
- assert !test_ran
73
-
74
- test_ran = false
75
- condition_test(:is_true, :is_false) { test_ran = true}
76
- assert !test_ran
77
- end
78
-
79
- #
80
- # benchmark_test test
81
- #
82
-
83
- # TODO - find a way to test this is a quiet fashion
84
-
85
- #
86
- # run subset test
87
- #
88
-
89
- def test_run_subset_true_if_ENV_type_is_true
90
- assert_equal false, run_subset?('type')
91
-
92
- ENV['type'] = "true"
93
- assert_equal true, run_subset?('type')
94
- end
6
+ include Benchmark
7
+
8
+ def setup
9
+ @env_hold = {}
10
+ ENV.each_pair do |key, value|
11
+ @env_hold[key] = value
12
+ end
13
+ ENV.clear
14
+ end
15
+
16
+ def teardown
17
+ ENV.clear
18
+ @env_hold.each_pair do |key, value|
19
+ ENV[key] = value
20
+ end
21
+ end
22
+
23
+ #
24
+ # env_true test
25
+ #
26
+
27
+ def test_env_true_is_true_if_var_is_true
28
+ assert !ENV['type']
29
+ assert !env_true?('type')
30
+
31
+ ENV['type'] = "false"
32
+ assert !env_true?('type')
33
+
34
+ ENV['type'] = "true"
35
+ assert env_true?('type')
36
+
37
+ ENV['type'] = "True"
38
+ assert env_true?('type')
39
+
40
+ ENV['type'] = "TRUE"
41
+ assert env_true?('type')
42
+ end
43
+
44
+ #
45
+ # extended_test test
46
+ #
47
+
48
+ def test_extended_test_runs_only_if_extended_true
49
+ was_in_test = false
50
+ extended_test { was_in_test = true }
51
+ assert !was_in_test
52
+
53
+ ENV['EXTENDED'] = 'true'
54
+ extended_test { was_in_test = true }
55
+ assert was_in_test
56
+ end
57
+
58
+ #
59
+ # condition test
60
+ #
61
+
62
+ condition(:is_true) {true}
63
+ condition(:is_false) {false}
64
+
65
+ def test_conditional_test_runs_only_if_all_conditions_are_true
66
+ test_ran = false
67
+ condition_test(:is_true) { test_ran = true}
68
+ assert test_ran
69
+
70
+ test_ran = false
71
+ condition_test(:is_false) { test_ran = true}
72
+ assert !test_ran
73
+
74
+ test_ran = false
75
+ condition_test(:is_true, :is_false) { test_ran = true}
76
+ assert !test_ran
77
+ end
78
+
79
+ #
80
+ # benchmark_test test
81
+ #
82
+
83
+ # TODO - find a way to test this is a quiet fashion
84
+
85
+ #
86
+ # run subset test
87
+ #
88
+
89
+ def test_run_subset_true_if_ENV_type_is_true
90
+ assert_equal false, run_subset?('type')
91
+
92
+ ENV['type'] = "true"
93
+ assert_equal true, run_subset?('type')
94
+ end
95
95
 
96
- def test_run_subset_true_if_ENV_all_is_true
97
- ENV['ALL'] = "true"
98
- assert_equal true, run_subset?('type')
99
- end
96
+ def test_run_subset_true_if_ENV_all_is_true
97
+ ENV['ALL'] = "true"
98
+ assert_equal true, run_subset?('type')
99
+ end
100
100
 
101
- #
102
- # match_regexp test
103
- #
104
-
105
- def test_match_regexp
106
- [1, [1,2]].each do |input|
107
- ENV['type'] = "1"
108
- assert_equal true, match_regexp?('type', input)
109
- end
110
-
111
- ["one", ["one", "two"]].each do |input|
112
- ENV['type'] = "one"
113
- assert_equal true, match_regexp?('type', input)
114
- end
115
- end
101
+ #
102
+ # match_regexp test
103
+ #
104
+
105
+ def test_match_regexp
106
+ ENV['type'] = "one.*"
107
+ assert_equal true, match_regexp?('type', "one")
108
+ assert_equal true, match_regexp?('type', "one_two")
109
+ assert_equal true, match_regexp?('type', "two_one")
110
+ assert_equal false, match_regexp?('type', "non")
111
+ end
116
112
 
117
- def test_match_regexp_returns_true_if_ENV_all_true
118
- ENV['ALL'] = "true"
119
- assert_equal true, match_regexp?('type', 1, "default")
120
- end
113
+ def test_match_regexp_returns_true_if_ENV_all_true
114
+ ENV['ALL'] = "true"
115
+ assert_equal true, match_regexp?('type', "str", "default")
116
+ end
121
117
 
122
- def test_match_regexp_returns_default_unless_ENV_type_is_set
123
- assert_equal "default", match_regexp?('type', 1, "default")
124
- end
118
+ def test_match_regexp_returns_default_unless_ENV_type_is_set
119
+ assert_equal "default", match_regexp?('type', "str", "default")
120
+ end
125
121
  end
126
122
 
127
123
  class SkippedTest < Test::Unit::TestCase
@@ -0,0 +1,399 @@
1
+ require File.dirname(__FILE__) + '/../tap_test_helper'
2
+ require 'tap/test'
3
+
4
+ class TestSetupTest < Test::Unit::TestCase
5
+ acts_as_tap_test(
6
+ :root => "alt/root",
7
+ :directories => {:input => "alt/input"})
8
+
9
+ #
10
+ # basic tests
11
+ #
12
+
13
+ def test_setup_with_options
14
+ assert_equal @app, app
15
+ assert_equal Tap::App.instance, app
16
+ assert_equal File.expand_path("./alt/root/test_setup_with_options"), File.expand_path(app[:root])
17
+ assert_equal File.expand_path("./alt/root/test_setup_with_options/alt/input"), File.expand_path(app[:input])
18
+ end
19
+ end
20
+
21
+ class TapMethodsTest < Test::Unit::TestCase
22
+ include TapTestMethods
23
+ acts_as_tap_test
24
+
25
+ #
26
+ # basic tests
27
+ #
28
+
29
+ def test_setup
30
+ assert runlist.empty?
31
+ assert_equal @app, app
32
+ assert_equal Tap::App.instance, app
33
+ assert_equal File.expand_path(File.dirname(__FILE__) + "/tap_methods/test_setup"), File.expand_path(app[:root])
34
+ assert_equal File.expand_path(File.dirname(__FILE__) + "/tap_methods/test_setup/input"), File.expand_path(app[:input])
35
+ end
36
+
37
+ def test_clear_runlist_empties_runlist
38
+ runlist << 1
39
+ assert !runlist.empty?
40
+
41
+ clear_runlist
42
+ assert runlist.empty?
43
+ end
44
+
45
+ def test_add_one_procedure_adds_input_to_runlist_and_returns_input_plus_one
46
+ input = 1
47
+ output = add_one.call(nil, input)
48
+ assert_equal 2, output
49
+ assert_equal [1], runlist
50
+ end
51
+
52
+ #
53
+ # assert_audit test
54
+ #
55
+
56
+ def test_assert_audit_doc
57
+ a = Tap::Support::Audit.new
58
+ a._record(:a, 'a')
59
+ a._record(:b, 'b')
60
+
61
+ e = ExpAudit[[:a, 'a'], [:b, 'b']]
62
+ assert_audit_equal(e, a)
63
+
64
+ a = Tap::Support::Audit.new
65
+ a._record(:a, 'a')
66
+ a._record(:b, 'b')
67
+
68
+ e = ExpAudit[
69
+ lambda {|source, value| source == :a && value == 'a'},
70
+ [:b, 'b']]
71
+ assert_audit_equal(e, a)
72
+
73
+ a = Tap::Support::Audit.new
74
+ a._record(:a, 'a')
75
+ a._record(:b, 'b')
76
+
77
+ b = Tap::Support::Audit.new
78
+ b._record(:c, 'c')
79
+ b._record(:d, 'd')
80
+
81
+ c = Tap::Support::Audit.merge(a,b)
82
+ c._record(:e, 'e')
83
+ c._record(:f, 'f')
84
+
85
+ ea = ExpAudit[[:a, "a"], [:b, "b"]]
86
+ eb = ExpAudit[[:c, "c"], [:d, "d"]]
87
+ e = ExpAudit[ExpMerge[ea, eb], [:e, "e"], [:f, "f"]]
88
+
89
+ assert_audit_equal(e, c)
90
+
91
+ ea = ExpAudit[[:a, "a"], [:b, "FLUNK"]]
92
+ eb = ExpAudit[[:c, "c"], [:d, "d"]]
93
+ e = ExpAudit[ExpMerge[ea, eb], [:e, "e"], [:f, "f"]]
94
+
95
+ flunked = false
96
+ begin
97
+ assert_audit_equal(e, c)
98
+ rescue
99
+ assert $!.message =~ /unequal record 0:0:1\./
100
+ flunked = true
101
+ end
102
+
103
+ assert flunked
104
+
105
+ assert_equal ExpAudit[ExpMerge[ea, eb], [:e, "e"], [:f, "f"]], e
106
+ assert_equal ExpMerge[ea, eb], e[0]
107
+ assert_equal ExpAudit[[:a, "a"], [:b, "FLUNK"]], e[0][0]
108
+ assert_equal [:b, "FLUNK"], e[0][0][1]
109
+ end
110
+
111
+ def test_assert_audit_equal
112
+ a = Tap::Support::Audit.new(nil, nil)
113
+ a._record(:a, 'a')
114
+ a._record(:b, 'b')
115
+
116
+ e = ExpAudit[[nil, nil], [:a, 'a'], [:b, 'b']]
117
+ assert_audit_equal(e, a)
118
+
119
+ begin
120
+ e = ExpAudit[[nil, nil], [:a, 'FLUNK'], [:b, 'b']]
121
+ assert_audit_equal(e, a)
122
+
123
+ flunk "audits should not have been equal"
124
+ rescue
125
+ assert_equal "unequal record 1.\n<[:a, \"FLUNK\"]> expected but was\n<[:a, \"a\"]>.", $!.message
126
+ end
127
+ end
128
+
129
+ def test_assert_audit_equal_with_procs
130
+ a = Tap::Support::Audit.new(nil, nil)
131
+ a._record(:a, 'a')
132
+ a._record(:b, 'b')
133
+
134
+ e = ExpAudit[
135
+ lambda {|source, value| source == nil && value == nil},
136
+ lambda {|source, value| source == :a && value == 'a'},
137
+ lambda {|source, value| source == :b && value == 'b'}]
138
+ assert_audit_equal(e, a)
139
+
140
+ begin
141
+ e = ExpAudit[
142
+ lambda {|source, value| source == nil && value == nil},
143
+ lambda {|source, value| source == :a && value == 'FLUNK'},
144
+ lambda {|source, value| source == :b && value == 'b'}]
145
+ assert_audit_equal(e, a)
146
+
147
+ flunk "audits should not have been equal"
148
+ rescue
149
+ assert_equal "unconfirmed record 1.\n<false> is not true.", $!.message
150
+ end
151
+ end
152
+
153
+ def test_assert_audit_equal_for_merge
154
+ a = Tap::Support::Audit.new(nil, nil)
155
+ a._record(:a, 'a')
156
+ a._record(:b, 'b')
157
+
158
+ b = Tap::Support::Audit.new(nil, nil)
159
+ b._record(:c, 'c')
160
+ b._record(:d, 'd')
161
+
162
+ c = Tap::Support::Audit.merge(a,b)
163
+ c._record(:e, 'e')
164
+ c._record(:f, 'f')
165
+
166
+ ea = ExpAudit[[nil, nil], [:a, "a"], [:b, "b"]]
167
+ eb = ExpAudit[[nil, nil], [:c, "c"], [:d, "d"]]
168
+ e = ExpAudit[ExpMerge[ea, eb], [:e, "e"], [:f, "f"]]
169
+
170
+ assert_audit_equal(e, c)
171
+
172
+ begin
173
+ ea = ExpAudit[[nil, nil], [:a, "FLUNK"], [:b, "b"]]
174
+ eb = ExpAudit[[nil, nil], [:c, "c"], [:d, "d"]]
175
+ e = ExpAudit[ExpMerge[ea, eb], [:e, "e"], [:f, "f"]]
176
+ assert_audit_equal(e, c)
177
+ flunk "audits should not have been equal"
178
+ rescue
179
+ assert_equal "unequal record 0:0:1.\n<[:a, \"FLUNK\"]> expected but was\n<[:a, \"a\"]>.", $!.message
180
+ end
181
+ end
182
+
183
+ def new_audit(letter, n=0)
184
+ a = Tap::Support::Audit.new(nil, nil)
185
+ 1.upto(n) {|i| a._record(letter, "#{letter}#{i}")}
186
+ a
187
+ end
188
+
189
+ def test_assert_audit_equal_for_nested_merge_with_procs
190
+ a = new_audit(:a, 1)
191
+ b = new_audit(:b, 1)
192
+ c = Tap::Support::Audit.merge(a,b)
193
+ 1.upto(1) {|i| c._record(:c, "c#{i}")}
194
+
195
+ d = new_audit(:d, 1)
196
+ e = new_audit(:e, 1)
197
+ f = Tap::Support::Audit.merge(d, e, 'x1', 'y1', 'z1')
198
+ 1.upto(1) {|i| f._record(:f, "f#{i}")}
199
+
200
+ g = Tap::Support::Audit.merge(c, f)
201
+ 1.upto(1) {|i| g._record(:g, "g#{i}")}
202
+
203
+ ea = ExpAudit[[nil, nil], [:a, 'a1']]
204
+ eb = ExpAudit[[nil, nil], [:b, 'b1']]
205
+ ec = ExpAudit[ExpMerge[ea, eb], lambda {|source, value| source == :c && value == 'c1'}]
206
+
207
+ ed = ExpAudit[[nil, nil], [:d, 'd1']]
208
+ ee = ExpAudit[[nil, nil], [:e, 'e1']]
209
+ ex1 = ExpAudit[lambda {|source, value| source == nil && value == 'x1'}]
210
+ ey1 = ExpAudit[[nil, 'y1']]
211
+ ez1 = ExpAudit[[nil, 'z1']]
212
+ ef = ExpAudit[ExpMerge[ed, ee, ex1, ey1, ez1], [:f, 'f1']]
213
+
214
+ eg = ExpAudit[ExpMerge[ec, ef], [:g, 'g1']]
215
+ assert_audit_equal(eg, g)
216
+
217
+ begin
218
+ ea = ExpAudit[[nil, nil], [:a, 'a1']]
219
+ eb = ExpAudit[[nil, nil], [:b, 'b1']]
220
+ ec = ExpAudit[ExpMerge[ea, eb], lambda {|source, value| source == :c && value == 'c1'}]
221
+
222
+ ed = ExpAudit[[nil, nil], [:d, 'd1']]
223
+ ee = ExpAudit[[nil, nil], [:e, 'e1']]
224
+ ex1 = ExpAudit[lambda {|source, value| source == nil && value == 'FLUNK'}]
225
+ ey1 = ExpAudit[[nil, 'y1']]
226
+ ez1 = ExpAudit[[nil, 'z1']]
227
+ ef = ExpAudit[ExpMerge[ed, ee, ex1, ey1, ez1], [:f, 'f1']]
228
+
229
+ eg = ExpAudit[ExpMerge[ec, ef], [:g, 'g1']]
230
+ assert_audit_equal(eg, g)
231
+ rescue
232
+ assert_equal "unconfirmed record 0:1:0:2:0.\n<false> is not true.", $!.message
233
+ end
234
+ end
235
+
236
+ # TODO -- test length check for assert_audit_equal
237
+
238
+ #
239
+ # with options
240
+ #
241
+
242
+ def test_with_options_doc
243
+ app.options.one = 1
244
+ app.options.two = 2
245
+
246
+ assert_equal({:one => 1, :two => 2}, app.options.marshal_dump)
247
+ with_options(:one => 'one', :quiet => false) do
248
+ assert_equal({:one => 'one', :two => 2, :debug => true, :quiet => false}, app.options.marshal_dump)
249
+ end
250
+ assert_equal({:one => 1, :two => 2}, app.options.marshal_dump)
251
+ end
252
+
253
+ def test_with_options_merges_new_and_default_options_with_existing_for_block
254
+ app.options.one = 1
255
+ app.options.two = 2
256
+
257
+ assert_equal({:one => 1, :two => 2}, app.options.marshal_dump)
258
+ with_options(:one => 'one') do
259
+ assert_equal({:one => 'one', :two => 2, :debug => true, :quiet => true}, app.options.marshal_dump)
260
+ end
261
+ assert_equal({:one => 1, :two => 2}, app.options.marshal_dump)
262
+ end
263
+
264
+ def test_with_options_does_not_merge_if_merge_with_existing_is_false
265
+ app.options.one = 1
266
+ app.options.two = 2
267
+
268
+ assert_equal({:one => 1, :two => 2}, app.options.marshal_dump)
269
+ with_options({:one => 'one'}, app, false) do
270
+ assert_equal({:one => 'one', :debug => true, :quiet => true}, app.options.marshal_dump)
271
+ end
272
+ assert_equal({:one => 1, :two => 2}, app.options.marshal_dump)
273
+ end
274
+
275
+ #
276
+ # with config
277
+ #
278
+
279
+ def test_with_config_doc
280
+ app = Tap::App.new(:directories => {:dir => 'dir', :alt => 'alt_dir'})
281
+ tmp_config = {
282
+ :directories => {:alt => 'another', :new => 'new_dir'},
283
+ :options => {:one => 1, :quiet => false}}
284
+
285
+ with_config(tmp_config, app) do
286
+ assert_equal({:dir => 'dir', :alt => 'another', :new => 'new_dir'}, app.directories)
287
+ assert_equal({:one => 1, :debug => true, :quiet => false}, app.options.marshal_dump)
288
+ end
289
+ assert_equal({:dir => 'dir', :alt => 'alt_dir'}, app.directories)
290
+ assert_equal({}, app.options.marshal_dump)
291
+ end
292
+
293
+ def test_with_config_merges_new_config_with_existing_for_block
294
+ config = {
295
+ :root => File.expand_path("root"),
296
+ :directories => {:dir => 'dir', :alt => 'alt_dir'},
297
+ :options => {:one => 1, :two => 2}}
298
+ logger_config ={
299
+ :device => app.logger.logdev.dev,
300
+ :level => app.logger.level,
301
+ :datetime_format => app.logger.datetime_format}
302
+
303
+ full_config = config.merge(
304
+ :absolute_paths => {},
305
+ :logger => logger_config)
306
+ modified_config = {
307
+ :root => File.expand_path("root"),
308
+ :directories => {:dir => 'another', :new => 'new_dir', :alt => 'alt_dir'},
309
+ :options => {:one => 'one', :two => 2, :debug => true, :quiet => true},
310
+ :absolute_paths => {:abs => File.expand_path('abs')},
311
+ :logger => logger_config}
312
+
313
+ app.reconfigure(full_config)
314
+
315
+ assert_equal(full_config, app.config)
316
+ with_config(
317
+ :directories => {:dir => 'another', :new => 'new_dir'},
318
+ :options => {:one => 'one'},
319
+ :absolute_paths => {:abs => 'abs'}
320
+ ) do
321
+ assert_equal(modified_config, app.config)
322
+ end
323
+ assert_equal(full_config, app.config)
324
+ end
325
+
326
+ def test_with_config_does_not_merge_if_merge_with_existing_is_false
327
+ config = {
328
+ :root => File.expand_path("root"),
329
+ :directories => {:dir => 'dir', :alt => 'alt_dir'},
330
+ :options => {:one => 1, :two => 2}}
331
+ logger_config ={
332
+ :device => app.logger.logdev.dev,
333
+ :level => app.logger.level,
334
+ :datetime_format => app.logger.datetime_format}
335
+
336
+ full_config = config.merge(
337
+ :absolute_paths => {},
338
+ :logger => logger_config)
339
+ modified_config = {
340
+ :root => File.expand_path("root"),
341
+ :directories => {:dir => 'another', :new => 'new_dir'},
342
+ :options => {:one => 'one', :debug => true, :quiet => true},
343
+ :absolute_paths => {:abs => File.expand_path('abs')},
344
+ :logger => logger_config}
345
+
346
+ app.reconfigure(full_config)
347
+
348
+ assert_equal(full_config, app.config)
349
+ with_config(
350
+ {:directories => {:dir => 'another', :new => 'new_dir'},
351
+ :options => {:one => 'one'},
352
+ :absolute_paths => {:abs => 'abs'}},
353
+ app,
354
+ false
355
+ ) do
356
+ assert_equal(modified_config, app.config)
357
+ end
358
+ assert_equal(full_config, app.config)
359
+ end
360
+
361
+ def test_nested_with_config
362
+ with_config(:options => {:one => 'one'}) do
363
+ assert_equal 'one', app.options.one
364
+ with_config(:options => {:one => 'two'}) do
365
+ assert_equal 'two', app.options.one
366
+ end
367
+ assert_equal 'one', app.options.one
368
+ end
369
+ end
370
+
371
+ #
372
+ # assert_files
373
+ #
374
+
375
+ def test_assert_files
376
+ t = Tap::FileTask.new("task/name") do |task, input_file|
377
+ output_file = task.filepath(:data, File.basename(input_file))
378
+ content = "#{File.read(input_file)}content"
379
+
380
+ assert_equal method_filepath(:output, "task/name", File.basename(input_file)), output_file
381
+
382
+ task.prepare(output_file)
383
+ File.open(output_file, "wb") {|f| f << content}
384
+ output_file
385
+ end
386
+
387
+ was_in_block = false
388
+ with_config :options => {:debug => true}, :directories => {:data => 'output'} do
389
+ assert_files do |input_files|
390
+ was_in_block = true
391
+ input_files.collect {|input_file| t.execute(input_file)}
392
+ end
393
+ end
394
+
395
+ assert was_in_block
396
+ end
397
+
398
+ end
399
+