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
@@ -2,47 +2,47 @@ require File.join(File.dirname(__FILE__), '../tap_test_helper.rb')
2
2
 
3
3
  class EnvVarsTest < Test::Unit::TestCase
4
4
  include Tap::Test::EnvVars
5
-
6
- def setup
7
- @env_hold = {}
8
- ENV.each_pair do |key, value|
9
- @env_hold[key] = value
10
- end
11
- ENV.clear
12
- end
13
-
14
- def teardown
15
- ENV.clear
16
- @env_hold.each_pair do |key, value|
17
- ENV[key] = value
18
- end
19
- end
20
-
21
- #
22
- # env test
23
- #
24
-
25
- def test_env_access_is_case_insensitive
26
- ENV['key1'] = "value"
27
- assert_equal 'value', env('key1')
28
- assert_equal 'value', env('KEY1')
29
-
30
- ENV['KEY2'] = "VALUE"
31
- assert_equal 'VALUE', env('key2')
32
- assert_equal 'VALUE', env('KEY2')
33
- end
34
-
35
- def test_env_raises_error_if_multiple_values_can_be_selected
36
- ENV['key'] = "value"
37
- ENV['KEY'] = "VALUE"
38
-
39
- # Some platforms (ex Windows) already make ENV case-independent
40
- # Filter for the platforms that do not by checking that ENV has both
41
- # expected keys
5
+
6
+ def setup
7
+ @env_hold = {}
8
+ ENV.each_pair do |key, value|
9
+ @env_hold[key] = value
10
+ end
11
+ ENV.clear
12
+ end
13
+
14
+ def teardown
15
+ ENV.clear
16
+ @env_hold.each_pair do |key, value|
17
+ ENV[key] = value
18
+ end
19
+ end
20
+
21
+ #
22
+ # env test
23
+ #
24
+
25
+ def test_env_access_is_case_insensitive
26
+ ENV['key1'] = "value"
27
+ assert_equal 'value', env('key1')
28
+ assert_equal 'value', env('KEY1')
29
+
30
+ ENV['KEY2'] = "VALUE"
31
+ assert_equal 'VALUE', env('key2')
32
+ assert_equal 'VALUE', env('KEY2')
33
+ end
34
+
35
+ def test_env_raises_error_if_multiple_values_can_be_selected
36
+ ENV['key'] = "value"
37
+ ENV['KEY'] = "VALUE"
38
+
39
+ # Some platforms (ex Windows) already make ENV case-independent
40
+ # Filter for the platforms that do not by checking that ENV has both
41
+ # expected keys
42
42
  if ENV.length == 2
43
- assert_raise(RuntimeError) { env('key') }
44
- assert_raise(RuntimeError) { env('Key') }
43
+ assert_raise(RuntimeError) { env('key') }
44
+ assert_raise(RuntimeError) { env('Key') }
45
45
  end
46
- end
46
+ end
47
47
 
48
48
  end
@@ -0,0 +1,29 @@
1
+ require File.join(File.dirname(__FILE__), '../tap_test_helper.rb')
2
+ require 'tap/test/file_methods'
3
+
4
+ # documentation test
5
+ class FileMethodsDocTest < Test::Unit::TestCase
6
+ acts_as_file_test
7
+
8
+ def test_something
9
+ dir = File.expand_path( File.dirname(__FILE__) )
10
+ assert_equal dir + "/file_methods_doc", trs.root
11
+ assert_equal dir + "/file_methods_doc/test_something", method_root
12
+ assert_equal dir + "/file_methods_doc/test_something/input", method_dir(:input)
13
+ end
14
+
15
+ def test_sub
16
+ assert_files do |input_files|
17
+ input_files.collect do |filepath|
18
+ input = File.read(filepath)
19
+ output_file = method_filepath(:output, File.basename(filepath))
20
+
21
+ File.open(output_file, "w") do |f|
22
+ f << input.gsub(/input/, "output")
23
+ end
24
+
25
+ output_file
26
+ end
27
+ end
28
+ end
29
+ end
@@ -6,21 +6,21 @@ class FileMethodsTest < Test::Unit::TestCase
6
6
  acts_as_file_test
7
7
 
8
8
  def test_method_name_returns_test_method_name1
9
- assert_equal "test_method_name_returns_test_method_name1", method_name
9
+ assert_equal "test_method_name_returns_test_method_name1", method_name_str
10
10
  end
11
11
 
12
12
  def test_method_name_returns_test_method_name2
13
- assert_equal "test_method_name_returns_test_method_name2", method_name
13
+ assert_equal "test_method_name_returns_test_method_name2", method_name_str
14
14
  end
15
15
 
16
- def test_make_test_directories
16
+ def test_make_test_directories
17
17
  root = File.expand_path(File.join(File.dirname(__FILE__), "file_methods"))
18
18
  begin
19
- assert_equal root, trs[:root]
20
- assert_equal({
21
- :input => 'input',
22
- :output => 'output',
23
- :expected => 'expected'}, trs.directories)
19
+ assert_equal root, trs[:root]
20
+ assert_equal({
21
+ :input => 'input',
22
+ :output => 'output',
23
+ :expected => 'expected'}, trs.directories)
24
24
 
25
25
  trs.directories.values.each do |dir|
26
26
  assert !File.exists?(File.join(root, "test_make_test_directories", dir.to_s)), dir
@@ -35,133 +35,95 @@ class FileMethodsTest < Test::Unit::TestCase
35
35
  dir = File.join(File.join(root, "test_make_test_directories"))
36
36
  FileUtils.rm_r dir if File.exists?(dir)
37
37
  end
38
- end
38
+ end
39
39
 
40
- #
41
- # method filepath tests
42
- #
40
+ #
41
+ # method filepath tests
42
+ #
43
43
 
44
- def test_method_dir_adds_method_to_path
45
- assert_equal File.join(trs.root, method_name, "input"), method_dir(:input)
46
- end
47
-
48
- def test_method_filepath_adds_method_to_path
49
- input_root = File.join(trs.root, method_name, "input")
50
- assert_equal File.join(input_root, "file.txt"), method_filepath(:input, 'file.txt')
51
- assert_equal File.join(input_root, "folder/file.txt"), method_filepath(:input, 'folder', 'file.txt')
52
- end
44
+ def test_method_dir_adds_method_to_path
45
+ assert_equal File.join(trs.root, method_name_str, "input"), method_dir(:input)
46
+ end
47
+
48
+ def test_method_filepath_adds_method_to_path
49
+ input_root = File.join(trs.root, method_name_str, "input")
50
+ assert_equal File.join(input_root, "file.txt"), method_filepath(:input, 'file.txt')
51
+ assert_equal File.join(input_root, "folder/file.txt"), method_filepath(:input, 'folder', 'file.txt')
52
+ end
53
53
 
54
- #
55
- # method relative filepath tests
56
- #
54
+ #
55
+ # method relative filepath tests
56
+ #
57
57
 
58
- def test_method_relative_filepath_removes_method_dir
59
- input_root = File.join(trs.root, method_name, "input")
60
- assert_equal 'file.txt', method_relative_filepath(:input, File.join(input_root, "file.txt"))
61
- assert_equal 'folder/file.txt', method_relative_filepath(:input, File.join(input_root, "folder/file.txt"))
62
- end
58
+ def test_method_relative_filepath_removes_method_dir
59
+ input_root = File.join(trs.root, method_name_str, "input")
60
+ assert_equal 'file.txt', method_relative_filepath(:input, File.join(input_root, "file.txt"))
61
+ assert_equal 'folder/file.txt', method_relative_filepath(:input, File.join(input_root, "folder/file.txt"))
62
+ end
63
63
 
64
- def test_method_relative_filepath_expands_filepaths
65
- input_root = File.join(trs.root, method_name, "input")
66
- assert_equal 'file.txt', method_relative_filepath(:input, File.join(input_root, "folder/.././file.txt") )
67
- end
68
-
69
- def test_method_relative_filepath_raises_error_unless_filepath_begins_with_method_dir
70
- assert_raise(RuntimeError) { method_relative_filepath(:input, File.join('some/path', trs[:input], 'file.txt') ) }
71
- end
72
-
73
- #
74
- # method translate tests
75
- #
76
-
77
- def test_method_translate
78
- ['file.txt', 'folder/file.txt'].each do |path|
79
- filepath = File.join(trs.root, method_name, "input", path)
80
- expected = File.join(trs.root, method_name, "output", path)
81
-
82
- assert_equal expected, method_translate(filepath, :input, :output)
83
- end
84
- end
85
-
86
- #
87
- # method glob tests
88
- #
89
-
90
- def test_method_glob
91
- {
92
- [:expected] => ["file.yml", "file_1.txt", "file_2.txt"],
93
- [:expected, "*"] => ["file.yml", "file_1.txt", "file_2.txt"],
94
- [:expected, "*.txt"] => ["file_1.txt", "file_2.txt"],
95
- [:expected, "*.txt", "*.yml"] => ["file.yml", "file_1.txt", "file_2.txt"]
96
- }.each_pair do |testcase, expected|
97
- expected.collect! { |file| method_filepath(:expected, file) }
98
-
99
- assert_equal expected.sort, method_glob(*testcase).sort
100
- end
101
- end
102
-
103
- #
104
- # tempfile test
105
- #
106
-
107
- def test_tempfile_returns_new_file_in_output_dir
108
- output_root = File.join(trs.root, method_name, "output")
64
+ def test_method_relative_filepath_expands_filepaths
65
+ input_root = File.join(trs.root, method_name_str, "input")
66
+ assert_equal 'file.txt', method_relative_filepath(:input, File.join(input_root, "folder/.././file.txt") )
67
+ end
68
+
69
+ def test_method_relative_filepath_raises_error_unless_filepath_begins_with_method_dir
70
+ assert_raise(RuntimeError) { method_relative_filepath(:input, File.join('some/path', trs[:input], 'file.txt') ) }
71
+ end
72
+
73
+ #
74
+ # method translate tests
75
+ #
76
+
77
+ def test_method_translate
78
+ ['file.txt', 'folder/file.txt'].each do |path|
79
+ filepath = File.join(trs.root, method_name_str, "input", path)
80
+ expected = File.join(trs.root, method_name_str, "output", path)
81
+
82
+ assert_equal expected, method_translate(filepath, :input, :output)
83
+ end
84
+ end
85
+
86
+ #
87
+ # method glob tests
88
+ #
89
+
90
+ def test_method_glob
91
+ {
92
+ [:expected] => ["file.yml", "file_1.txt", "file_2.txt"],
93
+ [:expected, "*"] => ["file.yml", "file_1.txt", "file_2.txt"],
94
+ [:expected, "*.txt"] => ["file_1.txt", "file_2.txt"],
95
+ [:expected, "*.txt", "*.yml"] => ["file.yml", "file_1.txt", "file_2.txt"]
96
+ }.each_pair do |testcase, expected|
97
+ expected.collect! { |file| method_filepath(:expected, file) }
98
+
99
+ assert_equal expected.sort, method_glob(*testcase).sort
100
+ end
101
+ end
102
+
103
+ #
104
+ # output_tempfile test
105
+ #
106
+
107
+ def test_output_tempfile_returns_new_file_in_output_dir
108
+ output_root = File.join(trs.root, method_name_str, "output")
109
+
110
+ filepath =File.join(output_root, "file#{$$}.0")
111
+ assert_equal filepath, output_tempfile('file')
112
+
113
+ filepath = File.join(output_root, "file#{$$}.0")
114
+ assert_equal filepath, output_tempfile('file')
109
115
 
110
- filepath =File.join(output_root, "file#{$$}.0")
111
- assert_equal filepath, tempfile('file')
112
-
113
- filepath = File.join(output_root, "file#{$$}.0")
114
- assert_equal filepath, tempfile('file')
115
-
116
- FileUtils.touch filepath
117
- filepath = File.join(output_root, "file#{$$}.1")
118
- assert_equal filepath, tempfile('file')
119
-
120
- FileUtils.touch filepath
121
- filepath = File.join(output_root, "file#{$$}.2")
122
- assert_equal filepath, tempfile('file')
123
- end
124
-
125
- #
126
- # files equal test
127
- #
128
-
129
- def test_file_compare
130
- count = 0
131
- each_pair(method_glob(:input, "*1*"), method_glob(:expected, "*1*") ) do |a, b|
132
- assert files_equal?(a, b)
133
- count += 1
134
- end
135
- assert_equal 1, count
136
-
137
- each_pair(method_glob(:input, "*2*"), method_glob(:expected, "*2*") ) do |a, b|
138
- assert !files_equal?(a, b)
139
- count += 1
140
- end
141
- assert_equal 2, count
142
- end
143
-
144
- #
145
- # yml equal test
146
- #
147
-
148
- def test_yml_compare
149
- count = 0
150
- each_pair(method_glob(:input, "*1*"), method_glob(:expected, "*1*") ) do |a, b|
151
- assert yml_equal?(a, b)
152
- count += 1
153
- end
154
- assert_equal 1, count
155
-
156
- each_pair(method_glob(:input, "*2*"), method_glob(:expected, "*2*") ) do |a, b|
157
- assert !yml_equal?(a, b)
158
- count += 1
159
- end
160
- assert_equal 2, count
161
- end
116
+ FileUtils.touch filepath
117
+ filepath = File.join(output_root, "file#{$$}.1")
118
+ assert_equal filepath, output_tempfile('file')
119
+
120
+ FileUtils.touch filepath
121
+ filepath = File.join(output_root, "file#{$$}.2")
122
+ assert_equal filepath, output_tempfile('file')
123
+ end
162
124
 
163
125
  #
164
- # assert_output_files_equal
126
+ # assert_files
165
127
  #
166
128
 
167
129
  def setup_file(dir, path, content)
@@ -173,32 +135,141 @@ class FileMethodsTest < Test::Unit::TestCase
173
135
  path
174
136
  end
175
137
 
176
- def test_assert_output_files_equal
138
+ def test_assert_files
139
+ setup_file :input, "one.txt", "file one"
140
+ setup_file :input, "two.txt", "file two"
141
+ setup_file :expected, "one.txt", "processed file one"
142
+ setup_file :expected, "two.txt", "processed file two"
143
+
144
+ assert_files do |input_files|
145
+ input_files.collect do |input_file|
146
+ target = method_filepath(:output, File.basename(input_file))
147
+ File.open(target, "w") do |file|
148
+ file << "processed "
149
+ file << File.read(input_file)
150
+ end
151
+ target
152
+ end
153
+ end
154
+ end
155
+
156
+ def test_assert_files_fails_for_missing_expected_file
157
+ setup_file :input, "one.txt", "file one"
158
+ setup_file :input, "two.txt", "file two"
159
+ setup_file :expected, "one.txt", "processed file one"
160
+
161
+ failed = false
162
+ begin
163
+ assert_files do |input_files|
164
+ input_files.collect do |input_file|
165
+ target = method_filepath(:output, File.basename(input_file))
166
+ File.open(target, "w") do |file|
167
+ file << "processed "
168
+ file << File.read(input_file)
169
+ end
170
+ target
171
+ end
172
+ end
173
+ rescue
174
+ failed = true
175
+ end
176
+
177
+ assert failed
178
+ end
179
+
180
+ def test_assert_files_fails_for_missing_output_file
177
181
  setup_file :input, "one.txt", "file one"
178
182
  setup_file :input, "two.txt", "file two"
179
183
  setup_file :expected, "one.txt", "processed file one"
180
184
  setup_file :expected, "two.txt", "processed file two"
185
+
186
+ failed = false
187
+ begin
188
+ assert_files do |input_files|
189
+ input_files.collect do |input_file|
190
+ target = method_filepath(:output, File.basename(input_file))
191
+ File.open(target, "w") do |file|
192
+ file << "processed "
193
+ file << File.read(input_file)
194
+ end
195
+ target
196
+ end.first
197
+ end
198
+ rescue
199
+ failed = true
200
+ end
201
+
202
+ assert failed
203
+ end
204
+
205
+ def test_assert_files_fails_for_different_content
206
+ setup_file :input, "one.txt", "file one"
207
+ setup_file :input, "two.txt", "file two"
208
+ setup_file :expected, "one.txt", "processed file FLUNK"
209
+ setup_file :expected, "two.txt", "processed file two"
181
210
 
182
- assert_output_files_equal(:iterate_inputs => true) do |input_file|
183
- target = method_filepath(:output, File.basename(input_file))
184
- File.open(target, "w") do |file|
185
- file << "processed "
186
- file << File.read(input_file)
211
+ failed = false
212
+ begin
213
+ assert_files do |input_files|
214
+ input_files.collect do |input_file|
215
+ target = method_filepath(:output, File.basename(input_file))
216
+ File.open(target, "w") do |file|
217
+ file << "processed "
218
+ file << File.read(input_file)
219
+ end
220
+ target
221
+ end
222
+ end
223
+ rescue
224
+ failed = true
225
+ end
226
+
227
+ assert failed
228
+ end
229
+
230
+ def test_assert_files_fails_for_no_expected_files
231
+ setup_file :input, "one.txt", "file one"
232
+ setup_file :input, "two.txt", "file two"
233
+
234
+ was_in_block = false
235
+ failed = false
236
+ begin
237
+ assert_files do |input_files|
238
+ was_in_block = true
239
+ []
187
240
  end
188
- target
241
+ rescue
242
+ failed = true
189
243
  end
244
+
245
+ assert failed
246
+ assert !was_in_block
247
+ end
248
+
249
+ def test_assert_files_can_have_no_expected_files_if_specified
250
+ setup_file :input, "one.txt", "file one"
251
+ setup_file :input, "two.txt", "file two"
252
+
253
+ was_in_block = false
254
+ assert_files :expected_files => [] do |input_files|
255
+ assert_equal 2, input_files.length
256
+ was_in_block = true
257
+ []
258
+ end
259
+
260
+ assert was_in_block
190
261
  end
191
262
  end
192
263
 
193
264
  class FileTestTestWithOptions < Test::Unit::TestCase
194
- acts_as_file_test :root => "some/root/dir"
195
-
196
- def test_test_setup
197
- assert_equal File.expand_path("some/root/dir"), trs[:root]
198
- assert_equal({
199
- :input => 'input',
200
- :output => 'output',
201
- :expected => 'expected'}, trs.directories)
202
- end
265
+ acts_as_file_test :root => "some/root/dir"
266
+
267
+ def test_test_setup
268
+ assert_equal File.expand_path("some/root/dir"), trs[:root]
269
+ assert_equal({
270
+ :input => 'input',
271
+ :output => 'output',
272
+ :expected => 'expected'}, trs.directories)
273
+ end
203
274
  end
204
275