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,550 +2,717 @@ require File.join(File.dirname(__FILE__), 'tap_test_helper.rb')
2
2
  require 'tap/root'
3
3
 
4
4
  class RootTest < Test::Unit::TestCase
5
- include Tap::Test::SubsetMethods
6
-
7
- attr_reader :r, :tr
8
-
9
- def setup
10
- # root
11
- @r = Tap::Root.new "./root", {:dir => "dir"}, {:abs => '/abs/path'}
12
-
13
- # test root
14
- @tr = Tap::Root.new test_root, {:lib => "lib"}
15
- end
16
-
17
- def test_root
18
- File.expand_path(File.join(File.dirname(__FILE__), 'root'))
19
- end
20
-
21
- def test_documentation
22
- r = Tap::Root.new test_root, :input => 'in', :output => 'out'
23
-
5
+ include Tap::Test::SubsetMethods
6
+
7
+ attr_reader :r, :tr
8
+
9
+ def setup
10
+ # root
11
+ @r = Tap::Root.new "./root", {:dir => "dir"}, {:abs => '/abs/path'}
12
+
13
+ # test root
14
+ @tr = Tap::Root.new root_dir, {:lib => "lib"}
15
+ end
16
+
17
+ def root_dir
18
+ File.expand_path(File.join(File.dirname(__FILE__), 'root'))
19
+ end
20
+
21
+ def path_root
22
+ path_root = File.expand_path(".")
23
+ while (parent_dir = File.dirname(path_root)) != path_root
24
+ path_root = parent_dir
25
+ end
26
+
27
+ path_root
28
+ end
29
+
30
+ def test_documentation
31
+ r = Tap::Root.new root_dir, :input => 'in', :output => 'out'
32
+
24
33
  # work with directories
25
- assert_equal test_root + '/in', r[:in]
26
- assert_equal test_root + '/out', r[:out]
27
- assert_equal test_root + '/implicit', r[:implicit]
28
-
29
- # # work with filepaths
30
- assert_equal test_root + '/in/path/to/file.txt', fp = r.filepath(:in, 'path/to/file.txt')
31
- assert_equal 'path/to/file.txt', r.relative_filepath(:in, fp)
32
- assert_equal test_root + '/out/path/to/file.txt', r.translate(fp, :in, :out)
34
+ assert_equal root_dir + '/in', r[:input]
35
+ assert_equal root_dir + '/out', r[:output]
36
+ assert_equal root_dir + '/implicit', r['implicit']
37
+
38
+ # expanded paths are returned unchanged
39
+ assert_equal File.expand_path('expanded'), r[File.expand_path('expanded')]
40
+
41
+ # work with filepaths
42
+ assert_equal root_dir + '/in/path/to/file.txt', fp = r.filepath(:input, 'path/to/file.txt')
43
+ assert_equal 'path/to/file.txt', r.relative_filepath(:input, fp)
44
+ assert_equal root_dir + '/out/path/to/file.txt', r.translate(fp, :input, :output)
33
45
 
34
- # # version filepaths
46
+ # version filepaths
35
47
  assert_equal 'path/to/config-1.0.yml', r.version('path/to/config.yml', 1.0)
36
48
  assert_equal 'path/to/config-1.1.yml', r.increment('path/to/config-1.0.yml', 0.1)
37
49
  assert_equal ['path/to/config.yml', "1.1"], r.deversion('path/to/config-1.1.yml')
38
50
 
39
- # # absolute paths can also be aliased.
51
+ # absolute paths can also be aliased.
40
52
  r[:abs, true] = "/absolute/path"
41
53
  assert_equal File.expand_path('/absolute/path/to/file.txt'), r.filepath(:abs, "to", "file.txt")
42
- end
43
-
44
- #
45
- # Tap::Root relative filepath test
46
- #
47
-
48
- def test_relative_filepath_documentation
54
+ end
55
+
56
+ #
57
+ # Tap::Root relative filepath test
58
+ #
59
+
60
+ def test_relative_filepath_documentation
49
61
  assert_equal "path/to/file.txt", Tap::Root.relative_filepath('dir', "dir/path/to/file.txt")
50
62
  end
51
-
52
- def test_class_relative_filepath
53
- assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "./root/dir/file.txt")
54
- assert_equal "nested/file.txt", Tap::Root.relative_filepath('./root/dir', "./root/dir/nested/file.txt")
55
- end
63
+
64
+ def test_class_relative_filepath
65
+ assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "./root/dir/file.txt")
66
+ assert_equal "nested/file.txt", Tap::Root.relative_filepath('./root/dir', "./root/dir/nested/file.txt")
67
+ end
56
68
 
57
- def test_class_relative_filepath_expands_paths
58
- assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "./root/folder/.././dir/file.txt")
59
- assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "root/dir/file.txt")
60
- assert_equal "file.txt", Tap::Root.relative_filepath('root/dir', "./root/dir/file.txt")
61
- end
62
-
63
- def test_class_relative_filepath_raises_error_if_path_is_not_relative_to_dir
64
- assert_raise(RuntimeError) { Tap::Root.relative_filepath('dir', "./root/file.txt") }
65
- end
66
-
67
- def test_class_relative_filepath_returns_expanded_path_if_path_is_not_relative_to_dir_and_not_strict
68
- assert_equal test_root + "/root/file.txt", Tap::Root.relative_filepath('dir', test_root + "/root/folder/.././file.txt", false)
69
- end
70
-
71
- #
72
- # Tap::Root glob test
73
- #
74
-
75
- def test_class_glob_returns_all_unique_files_matching_input_patterns
76
- files = [test_root + "/glob/one.txt", test_root + "/glob/two.txt"]
77
-
78
- assert_equal files, Tap::Root.glob(test_root + "/glob/**/*")
79
- assert_equal files, Tap::Root.glob(test_root + "/glob/one.txt", test_root + "/glob/two.txt")
80
- assert_equal files, Tap::Root.glob(test_root + "/glob/**/*", test_root + "/glob/one.txt", test_root + "/glob/two.txt")
81
- assert_equal [], Tap::Root.glob(test_root + "/glob/three.txt")
69
+ def test_class_relative_filepath_expands_paths
70
+ assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "./root/folder/.././dir/file.txt")
71
+ assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "root/dir/file.txt")
72
+ assert_equal "file.txt", Tap::Root.relative_filepath('root/dir', "./root/dir/file.txt")
73
+ assert_equal "file.txt", Tap::Root.relative_filepath('root/dir', "root/dir/file.txt")
74
+ end
75
+
76
+ def test_class_relative_filepath_raises_error_if_path_is_not_relative_to_dir
77
+ assert_raise(RuntimeError) { Tap::Root.relative_filepath('dir', "./root/file.txt") }
78
+ end
79
+
80
+ def test_class_relative_filepath_path_root
81
+ if self.class.match_platform?("mswin")
82
+ assert path_root =~ /^[A-z]:\/$/
83
+ assert_equal "path/to/file.txt", Tap::Root.relative_filepath(path_root, path_root + "path/to/file.txt")
84
+ else
85
+ assert_equal "path/to/file.txt", Tap::Root.relative_filepath(path_root, path_root + "path/to/file.txt")
86
+ end
87
+ end
88
+
89
+ #
90
+ # Tap::Root glob test
91
+ #
92
+
93
+ def test_class_glob_returns_all_unique_files_matching_input_patterns
94
+ files = [root_dir + "/glob/one.txt", root_dir + "/glob/two.txt"]
95
+
96
+ assert_equal files, Tap::Root.glob(root_dir + "/glob/**/*").sort
97
+ assert_equal files, Tap::Root.glob(root_dir + "/glob/one.txt", root_dir + "/glob/two.txt").sort
98
+ assert_equal files, Tap::Root.glob(root_dir + "/glob/**/*", root_dir + "/glob/one.txt", root_dir + "/glob/two.txt").sort
99
+ assert_equal [], Tap::Root.glob(root_dir + "/glob/three.txt")
82
100
  assert_equal [], Tap::Root.glob()
83
101
  end
84
102
 
85
103
  #
86
- # Tap::Root vglob test
87
- #
88
-
89
- def test_class_vglob_returns_all_versions_matching_file_and_version_pattern
90
- assert_equal 4, Dir.glob(File.join(test_root, 'versions/*')).length
104
+ # Tap::Root vglob test
105
+ #
106
+
107
+ def test_class_vglob_returns_all_versions_matching_file_and_version_pattern
108
+ assert_equal 4, Dir.glob(File.join(root_dir, 'versions/*')).length
91
109
 
92
- assert_equal 3, Dir.glob(File.join(test_root, 'versions/file*.yml')).length
93
- assert_equal Dir.glob(test_root + '/versions/file*.yml').sort, Tap::Root.vglob(test_root + '/versions/file.yml', '*').sort
110
+ assert_equal 3, Dir.glob(File.join(root_dir, 'versions/file*.yml')).length
111
+ assert_equal Dir.glob(root_dir + '/versions/file*.yml').sort, Tap::Root.vglob(root_dir + '/versions/file.yml', '*').sort
94
112
 
95
- assert_equal 2, Dir.glob(File.join(test_root, 'versions/file-0.1*.yml')).length
96
- assert_equal Dir.glob(test_root + '/versions/file-0.1*.yml').sort, Tap::Root.vglob(test_root + '/versions/file.yml', '0.1*').sort
113
+ assert_equal 2, Dir.glob(File.join(root_dir, 'versions/file-0.1*.yml')).length
114
+ assert_equal Dir.glob(root_dir + '/versions/file-0.1*.yml').sort, Tap::Root.vglob(root_dir + '/versions/file.yml', '0.1*').sort
97
115
 
98
- assert_equal 1, Dir.glob(File.join(test_root, 'versions/file-0.1.yml')).length
99
- assert_equal Dir.glob(test_root + '/versions/file-0.1.yml').sort, Tap::Root.vglob(test_root + '/versions/file.yml', '0.1').sort
116
+ assert_equal 1, Dir.glob(File.join(root_dir, 'versions/file-0.1.yml')).length
117
+ assert_equal Dir.glob(root_dir + '/versions/file-0.1.yml').sort, Tap::Root.vglob(root_dir + '/versions/file.yml', '0.1').sort
100
118
 
101
- assert_equal 0, Dir.glob(File.join(test_root, 'versions/file-2.yml')).length
102
- assert_equal [], Tap::Root.vglob(test_root + '/versions/file.yml', '2')
103
- end
119
+ assert_equal 0, Dir.glob(File.join(root_dir, 'versions/file-2.yml')).length
120
+ assert_equal [], Tap::Root.vglob(root_dir + '/versions/file.yml', '2')
121
+ end
104
122
 
105
123
  def test_class_default_vglob_pattern_is_all_versions
106
- expected = Dir.glob(File.join(test_root + '/versions/file*.yml'))
107
- assert_equal expected.sort, Tap::Root.vglob(test_root + '/versions/file.yml').sort
108
- end
109
-
110
- #
111
- # initialize tests
112
- #
113
-
114
- def test_default_root_is_expanded_dir_pwd
115
- r = Tap::Root.new
116
-
117
- assert_equal File.expand_path(Dir.pwd), r.root
118
- assert_equal({}, r.directories)
119
- end
120
-
121
- def test_initialize_root
122
- r = Tap::Root.new "./root", {:dir => "dir", :temp => "tmp"}, {:abs => "/abs/path"}
123
-
124
- assert_equal File.expand_path("./root"), r.root
125
- assert_equal({:dir => "dir", :temp => "tmp"}, r.directories)
126
- assert_equal({:abs => File.expand_path("/abs/path")}, r.absolute_paths)
127
- assert_equal({
128
- 'root' => File.expand_path("./root"),
129
- :root => File.expand_path("./root"),
130
- :dir => File.expand_path("./root/dir"),
131
- :temp => File.expand_path( "./root/tmp"),
132
- :abs => File.expand_path("/abs/path")},
133
- r.paths)
134
- end
135
-
136
- def test_any_object_can_be_used_as_a_directory_alias
137
- r = Tap::Root.new("./root", 'dir' => "str_da", :dir => 'sym_da', 1 => 'n_da')
138
-
139
- assert_equal({
140
- 'root' => File.expand_path("./root"),
141
- :root => File.expand_path("./root"),
142
- 'dir' => File.expand_path("./root/str_da"),
143
- :dir => File.expand_path("./root/sym_da"),
144
- 1 => File.expand_path("./root/n_da")},
145
- r.paths)
146
- end
147
-
148
- #
149
- # set root tests
150
- #
151
-
152
- def test_set_root_resets_paths
153
- r.root = './another'
154
-
155
- assert_equal File.expand_path("./another"), r.root
156
- assert_equal({:dir => "dir"}, r.directories)
157
- assert_equal({
158
- 'root' => File.expand_path("./another"),
159
- :root => File.expand_path("./another"),
160
- :dir => File.expand_path("./another/dir"),
161
- :abs => File.expand_path("/abs/path")},
162
- r.paths)
163
- end
164
-
165
- def test_root_cannot_be_set_through_index
166
- assert_raise(ArgumentError) { r['root'] = './another' }
167
- end
168
-
169
- #
170
- # set directories tests
171
- #
172
-
173
- def test_set_directories
174
- r.directories = {:alt => "dir"}
124
+ expected = Dir.glob(File.join(root_dir + '/versions/file*.yml'))
125
+ assert_equal expected.sort, Tap::Root.vglob(root_dir + '/versions/file.yml').sort
126
+ end
127
+
128
+ #
129
+ # Tap::Root indir test
130
+ #
131
+
132
+ def test_indir_executes_block_in_the_specified_directory
133
+ test_dir = root_dir
134
+ pwd = File.expand_path(Dir.pwd)
135
+
136
+ assert_not_equal pwd, test_dir
137
+ assert File.directory?(test_dir)
138
+
139
+ was_in_block = false
140
+ begin
141
+ res = Tap::Root.indir(test_dir) do
142
+ was_in_block = true
143
+ assert_equal test_dir, File.expand_path(Dir.pwd)
144
+ "result"
145
+ end
146
+ assert_equal "result", res
147
+ ensure
148
+ Dir.chdir(pwd)
149
+ end
150
+
151
+ assert_equal pwd, File.expand_path(Dir.pwd)
152
+ assert was_in_block
153
+ end
154
+
155
+ def test_indir_raises_error_for_non_dir_inputs
156
+ test_dir = root_dir + '/non/existant/dir'
157
+ filepath = root_dir + '/file.txt'
158
+ pwd = File.expand_path(Dir.pwd)
159
+
160
+ assert !File.exists?(root_dir + '/non')
161
+ assert File.exists?(filepath)
162
+ assert File.file?(filepath)
163
+ begin
164
+ assert_raise(RuntimeError) { Tap::Root.indir(filepath) {} }
165
+ assert_raise(RuntimeError) { Tap::Root.indir(filepath) {} }
166
+ ensure
167
+ Dir.chdir(pwd)
168
+ end
169
+
170
+ assert_equal pwd, File.expand_path(Dir.pwd)
171
+ end
172
+
173
+ def test_indir_creates_directory_if_specified
174
+ test_dir = root_dir + '/non/existant/dir'
175
+ pwd = File.expand_path(Dir.pwd)
176
+
177
+ assert_not_equal pwd, test_dir
178
+ assert !File.exists?(root_dir + '/non')
179
+
180
+ was_in_block = false
181
+ begin
182
+ Tap::Root.indir(test_dir, true) do
183
+ was_in_block = true
184
+ assert_equal test_dir, File.expand_path(Dir.pwd)
185
+ assert File.exists?(test_dir)
186
+ end
187
+ ensure
188
+ Dir.chdir(pwd)
189
+ FileUtils.rm_r(root_dir + '/non') if File.exists?(root_dir + '/non')
190
+ end
191
+
192
+ assert_equal pwd, File.expand_path(Dir.pwd)
193
+ assert was_in_block
194
+ end
195
+
196
+ #
197
+ # Tap::Root path_root_type test
198
+ #
199
+
200
+ def test_path_root_type
201
+ case
202
+ when self.class.match_platform?("mswin")
203
+ assert_equal :win, Tap::Root.path_root_type
204
+ when File.expand_path(".")[0] == ?/
205
+ assert_equal :nix, Tap::Root.path_root_type
206
+ else
207
+ assert_equal :unknown, Tap::Root.path_root_type
208
+ end
209
+ end
210
+
211
+ #
212
+ # Tap::Root.expaned_path? test
213
+ #
175
214
 
176
- assert_equal({:alt => "dir"}, r.directories)
177
- assert_equal({
178
- 'root' => File.expand_path("./root"),
179
- :root => File.expand_path("./root"),
180
- :alt => File.expand_path("./root/dir"),
181
- :abs => File.expand_path("/abs/path")},
182
- r.paths)
183
- end
184
-
185
- def test_raise_error_when_trying_to_set_root_through_directories
186
- assert_raise(ArgumentError) { r.directories = {'root' => "another"} }
187
- end
188
-
189
- #
190
- # set absolute paths test
191
- #
215
+ def test_expanded_path_documentation
216
+ assert Tap::Root.expanded_path?("C:/path", :win)
217
+ assert Tap::Root.expanded_path?("c:/path", :win)
218
+ assert Tap::Root.expanded_path?("D:/path", :win)
219
+ assert !Tap::Root.expanded_path?("path", :win)
220
+
221
+ assert Tap::Root.expanded_path?('/path', :nix)
222
+ assert !Tap::Root.expanded_path?('path', :nix)
223
+ end
224
+
225
+ def test_expanded_path
226
+ assert Tap::Root.expanded_path?("C:/path", :win)
227
+ assert Tap::Root.expanded_path?("c:/path", :win)
228
+ assert Tap::Root.expanded_path?("D:/path", :win)
229
+ assert !Tap::Root.expanded_path?("/path", :win)
230
+ assert !Tap::Root.expanded_path?("path", :win)
231
+
232
+ assert Tap::Root.expanded_path?("/path", :nix)
233
+ assert !Tap::Root.expanded_path?("C:/path", :nix)
234
+ assert !Tap::Root.expanded_path?("path", :nix)
235
+
236
+ assert_nil Tap::Root.expanded_path?("C:/path", :other)
237
+ assert_nil Tap::Root.expanded_path?("/path", :other)
238
+ assert_nil Tap::Root.expanded_path?("path", :other)
239
+ end
240
+
241
+ #
242
+ # initialize tests
243
+ #
244
+
245
+ def test_default_root_is_expanded_dir_pwd
246
+ r = Tap::Root.new
247
+
248
+ assert_equal File.expand_path(Dir.pwd), r.root
249
+ assert_equal({}, r.directories)
250
+ end
251
+
252
+ def test_initialize_root
253
+ r = Tap::Root.new "./root", {:dir => "dir", :temp => "tmp"}, {:abs => "/abs/path"}
254
+
255
+ assert_equal File.expand_path("./root"), r.root
256
+ assert_equal({:dir => "dir", :temp => "tmp"}, r.directories)
257
+ assert_equal({:abs => File.expand_path("/abs/path")}, r.absolute_paths)
258
+ assert_equal({
259
+ 'root' => File.expand_path("./root"),
260
+ :root => File.expand_path("./root"),
261
+ :dir => File.expand_path("./root/dir"),
262
+ :temp => File.expand_path( "./root/tmp"),
263
+ :abs => File.expand_path("/abs/path")},
264
+ r.paths)
265
+ end
266
+
267
+ def test_any_object_can_be_used_as_a_directory_alias
268
+ r = Tap::Root.new("./root", 'dir' => "str_da", :dir => 'sym_da', 1 => 'n_da')
269
+
270
+ assert_equal({
271
+ 'root' => File.expand_path("./root"),
272
+ :root => File.expand_path("./root"),
273
+ 'dir' => File.expand_path("./root/str_da"),
274
+ :dir => File.expand_path("./root/sym_da"),
275
+ 1 => File.expand_path("./root/n_da")},
276
+ r.paths)
277
+ end
278
+
279
+ def test_path_root
280
+ case
281
+ when self.class.match_platform?("mswin")
282
+ assert r.path_root =~ /^[A-z]:\/$/i
283
+ when self.class.match_platform?("darwin")
284
+ assert r.path_root == '/'
285
+ else
286
+ expected_path_root = File.expand_path(".")
287
+ while (parent_dir = File.dirname(expected_path_root)) != expected_path_root
288
+ expected_path_root = parent_dir
289
+ end
290
+ assert_equal expected_path_root, r.path_root
291
+ end
292
+ end
192
293
 
193
- def test_set_absolute_paths
194
- r.absolute_paths = {:absolute => "/absolute/path"}
294
+ #
295
+ # set root tests
296
+ #
297
+
298
+ def test_set_root_resets_paths
299
+ r.root = './another'
300
+
301
+ assert_equal File.expand_path("./another"), r.root
302
+ assert_equal({:dir => "dir"}, r.directories)
303
+ assert_equal({
304
+ 'root' => File.expand_path("./another"),
305
+ :root => File.expand_path("./another"),
306
+ :dir => File.expand_path("./another/dir"),
307
+ :abs => File.expand_path("/abs/path")},
308
+ r.paths)
309
+ end
310
+
311
+ def root_dir_cannot_be_set_through_index
312
+ assert_raise(ArgumentError) { r['root'] = './another' }
313
+ end
314
+
315
+ #
316
+ # set directories tests
317
+ #
318
+
319
+ def test_directories_documentation
320
+ assert_equal File.join(r.root, 'alt'), r['alt']
321
+ r.directories = {'alt' => "dir"}
322
+ assert_equal File.join(r.root, 'dir'), r['alt']
323
+ end
324
+
325
+ def test_set_directories
326
+ r.directories = {:alt => "dir"}
195
327
 
196
- assert_equal({:dir => "dir"}, r.directories)
197
- assert_equal({
198
- 'root' => File.expand_path("./root"),
199
- :root => File.expand_path("./root"),
200
- :dir => File.expand_path("./root/dir"),
201
- :absolute => File.expand_path("/absolute/path")},
202
- r.paths)
203
- end
204
-
205
- def test_raise_error_when_trying_to_set_root_through_absolute_paths
206
- assert_raise(ArgumentError) { r.absolute_paths = {'root' => "another"} }
207
- end
208
-
209
- #
210
- # get absolute paths test
211
- #
212
-
213
- def test_absolute_paths_returns_all_non_root_paths_with_no_directory
214
- assert_equal({:abs => File.expand_path("/abs/path")}, r.absolute_paths)
215
-
216
- r.paths[:another] = File.expand_path("/another/path")
217
- assert_equal({
328
+ assert_equal({:alt => "dir"}, r.directories)
329
+ assert_equal({
330
+ 'root' => File.expand_path("./root"),
331
+ :root => File.expand_path("./root"),
332
+ :alt => File.expand_path("./root/dir"),
333
+ :abs => File.expand_path("/abs/path")},
334
+ r.paths)
335
+ end
336
+
337
+ def test_raise_error_when_trying_to_set_root_through_directories
338
+ assert_raise(ArgumentError) { r.directories = {'root' => "another"} }
339
+ end
340
+
341
+ #
342
+ # set absolute paths test
343
+ #
344
+
345
+ def test_absolute_paths_documentation
346
+ assert_equal File.join(r.root, 'abs'), r['abs']
347
+ r.absolute_paths = {'abs' => File.expand_path("/path/to/dir")}
348
+ assert_equal File.expand_path("/path/to/dir"), r['abs']
349
+ end
350
+
351
+ def test_set_absolute_paths
352
+ r.absolute_paths = {:absolute => "/absolute/path"}
353
+
354
+ assert_equal({:dir => "dir"}, r.directories)
355
+ assert_equal({
356
+ 'root' => File.expand_path("./root"),
357
+ :root => File.expand_path("./root"),
358
+ :dir => File.expand_path("./root/dir"),
359
+ :absolute => File.expand_path("/absolute/path")},
360
+ r.paths)
361
+ end
362
+
363
+ def test_raise_error_when_trying_to_set_root_through_absolute_paths
364
+ assert_raise(ArgumentError) { r.absolute_paths = {'root' => "another"} }
365
+ end
366
+
367
+ #
368
+ # get absolute paths test
369
+ #
370
+
371
+ def test_absolute_paths_returns_all_non_root_paths_with_no_directory
372
+ assert_equal({:abs => File.expand_path("/abs/path")}, r.absolute_paths)
373
+
374
+ r.paths[:another] = File.expand_path("/another/path")
375
+ assert_equal({
218
376
  :abs => File.expand_path("/abs/path"),
219
377
  :another => File.expand_path("/another/path")},
220
378
  r.absolute_paths)
221
- end
222
-
223
- #
224
- # assignment tests
225
- #
226
-
227
- def test_assignment_documentation
228
- r = Tap::Root.new test_root
379
+ end
380
+
381
+ #
382
+ # assignment tests
383
+ #
384
+
385
+ def test_assignment_documentation
386
+ r = Tap::Root.new root_dir
229
387
  r[:dir] = 'path/to/dir'
230
- assert_equal test_root + '/path/to/dir', r[:dir]
388
+ assert_equal root_dir + '/path/to/dir', r[:dir]
231
389
 
232
390
  r[:abs, true] = '/abs/path/to/dir'
233
391
  assert_equal File.expand_path('/abs/path/to/dir'), r[:abs]
234
- end
235
-
236
- def test_set_existing_directory_using_assignment
237
- r[:dir] = 'another'
238
-
239
- assert_equal({:dir => "another"}, r.directories)
240
- assert_equal({
241
- 'root' => File.expand_path("./root"),
242
- :root => File.expand_path("./root"),
243
- :dir => File.expand_path("./root/another"),
244
- :abs => File.expand_path("/abs/path")},
245
- r.paths)
246
- end
247
-
248
- def test_set_new_directory_using_assignment
249
- r[:new] = 'new'
392
+ end
393
+
394
+ def test_set_existing_directory_using_assignment
395
+ r[:dir] = 'another'
396
+
397
+ assert_equal({:dir => "another"}, r.directories)
398
+ assert_equal({
399
+ 'root' => File.expand_path("./root"),
400
+ :root => File.expand_path("./root"),
401
+ :dir => File.expand_path("./root/another"),
402
+ :abs => File.expand_path("/abs/path")},
403
+ r.paths)
404
+ end
405
+
406
+ def test_set_new_directory_using_assignment
407
+ r[:new] = 'new'
250
408
 
251
- assert_equal({:dir => "dir", :new => "new"}, r.directories)
252
- assert_equal({
253
- 'root' => File.expand_path("./root"),
254
- :root => File.expand_path("./root"),
255
- :dir => File.expand_path("./root/dir"),
256
- :abs => File.expand_path("/abs/path"),
257
- :new => File.expand_path("./root/new")},
258
- r.paths)
259
- end
409
+ assert_equal({:dir => "dir", :new => "new"}, r.directories)
410
+ assert_equal({
411
+ 'root' => File.expand_path("./root"),
412
+ :root => File.expand_path("./root"),
413
+ :dir => File.expand_path("./root/dir"),
414
+ :abs => File.expand_path("/abs/path"),
415
+ :new => File.expand_path("./root/new")},
416
+ r.paths)
417
+ end
260
418
 
261
419
  def test_absolute_paths_can_be_set_by_specifiying_absolute_true
262
420
  r[:absolute, true] = '/some/absolute/path'
263
421
 
264
- assert_equal({:dir => "dir"}, r.directories)
265
- assert_equal({
266
- 'root' => File.expand_path("./root"),
267
- :root => File.expand_path("./root"),
268
- :dir => File.expand_path("./root/dir"),
269
- :abs => File.expand_path("/abs/path"),
270
- :absolute => File.expand_path('/some/absolute/path')},
271
- r.paths)
422
+ assert_equal({:dir => "dir"}, r.directories)
423
+ assert_equal({
424
+ 'root' => File.expand_path("./root"),
425
+ :root => File.expand_path("./root"),
426
+ :dir => File.expand_path("./root/dir"),
427
+ :abs => File.expand_path("/abs/path"),
428
+ :absolute => File.expand_path('/some/absolute/path')},
429
+ r.paths)
272
430
  end
273
431
 
274
432
  def test_an_absolute_path_is_not_set_if_absolute_false
275
433
  r[:not_absolute, false] = 'not/an/absolute/path'
276
434
 
277
- assert_equal({:dir => "dir", :not_absolute => "not/an/absolute/path"}, r.directories)
278
- assert_equal({
279
- 'root' => File.expand_path("./root"),
280
- :root => File.expand_path("./root"),
281
- :dir => File.expand_path("./root/dir"),
282
- :abs => File.expand_path("/abs/path"),
283
- :not_absolute => File.expand_path("./root/not/an/absolute/path")},
284
- r.paths)
435
+ assert_equal({:dir => "dir", :not_absolute => "not/an/absolute/path"}, r.directories)
436
+ assert_equal({
437
+ 'root' => File.expand_path("./root"),
438
+ :root => File.expand_path("./root"),
439
+ :dir => File.expand_path("./root/dir"),
440
+ :abs => File.expand_path("/abs/path"),
441
+ :not_absolute => File.expand_path("./root/not/an/absolute/path")},
442
+ r.paths)
285
443
  end
286
444
 
287
445
  def test_paths_can_be_unset_with_nil
288
446
  # Non-absolute path
289
447
  r[:dir] = '/some/path'
290
448
  assert_equal({:dir => "/some/path"}, r.directories)
291
- assert_equal({
292
- 'root' => File.expand_path("./root"),
293
- :root => File.expand_path("./root"),
294
- :dir => File.expand_path("./root/some/path"),
295
- :abs => File.expand_path("/abs/path")},
296
- r.paths)
297
-
449
+ assert_equal({
450
+ 'root' => File.expand_path("./root"),
451
+ :root => File.expand_path("./root"),
452
+ :dir => File.expand_path("./root/some/path"),
453
+ :abs => File.expand_path("/abs/path")},
454
+ r.paths)
455
+
298
456
  r[:dir] = nil
299
457
  assert_equal({}, r.directories)
300
- assert_equal({
301
- 'root' => File.expand_path("./root"),
302
- :root => File.expand_path("./root"),
303
- :abs => File.expand_path("/abs/path")},
304
- r.paths)
458
+ assert_equal({
459
+ 'root' => File.expand_path("./root"),
460
+ :root => File.expand_path("./root"),
461
+ :abs => File.expand_path("/abs/path")},
462
+ r.paths)
305
463
 
306
464
  # the same with absolute specified
307
465
  r[:dir] = '/some/path'
308
466
  assert_equal({:dir => "/some/path"}, r.directories)
309
- assert_equal({
310
- 'root' => File.expand_path("./root"),
311
- :root => File.expand_path("./root"),
312
- :dir => File.expand_path("./root/some/path"),
313
- :abs => File.expand_path("/abs/path")},
467
+ assert_equal({
468
+ 'root' => File.expand_path("./root"),
469
+ :root => File.expand_path("./root"),
470
+ :dir => File.expand_path("./root/some/path"),
471
+ :abs => File.expand_path("/abs/path")},
314
472
  r.paths)
315
473
 
316
474
  r[:dir, false] = nil
317
475
  assert_equal({}, r.directories)
318
- assert_equal({
319
- 'root' => File.expand_path("./root"),
320
- :root => File.expand_path("./root"),
321
- :abs => File.expand_path("/abs/path")},
322
- r.paths)
476
+ assert_equal({
477
+ 'root' => File.expand_path("./root"),
478
+ :root => File.expand_path("./root"),
479
+ :abs => File.expand_path("/abs/path")},
480
+ r.paths)
323
481
 
324
482
  # Absolute path
325
483
  r[:abs, true] = '/some/absolute/path'
326
484
  assert_equal({}, r.directories)
327
- assert_equal({
328
- 'root' => File.expand_path("./root"),
329
- :root => File.expand_path("./root"),
330
- :abs => File.expand_path('/some/absolute/path')},
331
- r.paths)
485
+ assert_equal({
486
+ 'root' => File.expand_path("./root"),
487
+ :root => File.expand_path("./root"),
488
+ :abs => File.expand_path('/some/absolute/path')},
489
+ r.paths)
332
490
 
333
491
  r[:abs, true] = nil
334
492
  assert_equal({}, r.directories)
335
- assert_equal({
336
- 'root' => File.expand_path("./root"),
337
- :root => File.expand_path("./root")},
338
- r.paths)
493
+ assert_equal({
494
+ 'root' => File.expand_path("./root"),
495
+ :root => File.expand_path("./root")},
496
+ r.paths)
339
497
 
340
498
  # the same with absolute unspecfied
341
499
  r[:abs, true] = '/some/absolute/path'
342
500
  assert_equal({}, r.directories)
343
- assert_equal({
344
- 'root' => File.expand_path("./root"),
345
- :root => File.expand_path("./root"),
346
- :abs => File.expand_path('/some/absolute/path')},
501
+ assert_equal({
502
+ 'root' => File.expand_path("./root"),
503
+ :root => File.expand_path("./root"),
504
+ :abs => File.expand_path('/some/absolute/path')},
347
505
  r.paths)
348
506
 
349
507
  r[:abs] = nil
350
508
  assert_equal({}, r.directories)
351
- assert_equal({
352
- 'root' => File.expand_path("./root"),
353
- :root => File.expand_path("./root")},
354
- r.paths)
509
+ assert_equal({
510
+ 'root' => File.expand_path("./root"),
511
+ :root => File.expand_path("./root")},
512
+ r.paths)
355
513
  end
356
514
 
357
515
  def test_set_path_expands_filepaths
358
- r[:dir] = "./sub/../dir"
359
- assert_equal File.expand_path("./root/dir"), r.paths[:dir]
360
-
361
- r[:abs, true] = "/./sub/../dir"
362
- assert_equal File.expand_path("/dir"), r.paths[:abs]
363
- end
364
-
365
- #
366
- # retrieve path tests
367
- #
368
-
369
- def test_retrieve_documentation
370
- r = Tap::Root.new test_root
371
- r[:dir] = 'path/to/dir'
372
- assert_equal test_root + '/path/to/dir', r[:dir]
516
+ r[:dir] = "./sub/../dir"
517
+ assert_equal File.expand_path("./root/dir"), r.paths[:dir]
518
+
519
+ r[:abs, true] = "/./sub/../dir"
520
+ assert_equal File.expand_path("/dir"), r.paths[:abs]
521
+ end
522
+
523
+ #
524
+ # retrieve path tests
525
+ #
526
+
527
+ def test_retrieve_documentation
528
+ r = Tap::Root.new root_dir, :dir => 'path/to/dir'
529
+ assert_equal root_dir + '/path/to/dir', r[:dir]
373
530
 
374
- r[:unset] = nil
375
- assert_equal test_root + '/unset', r[:unset]
376
- end
377
-
378
- def test_retrieve_paths
379
- {
380
- :dir => File.expand_path("./root/dir"),
381
- :root => File.expand_path("./root"),
382
- 'root' => File.expand_path("./root"),
383
- :abs => File.expand_path("/abs/path")
384
- }.each_pair do |dir, expected|
385
- assert_equal expected, r[dir]
386
- end
387
- end
388
-
389
- def test_retrieve_path_infers_path_if_path_is_not_set
390
- assert_equal({
391
- 'root' => File.expand_path("./root"),
392
- :root => File.expand_path("./root"),
393
- :dir => File.expand_path("./root/dir"),
394
- :abs => File.expand_path("/abs/path")},
395
- r.paths)
396
- assert_equal File.expand_path("./root/not_set"), r[:not_set]
397
- assert_equal File.expand_path("./root/nested/dir"), r['nested/dir']
398
- end
399
-
400
- def test_retrieve_path_expands_inferred_filepaths
401
- assert_equal File.expand_path("./root/nested/dir"), r['./sub/../nested/dir']
402
- end
531
+ assert_equal root_dir + '/relative/path', r['relative/path']
532
+
533
+ expanded_path = File.expand_path('/expanded/path')
534
+ assert_equal expanded_path, r[expanded_path]
535
+ end
536
+
537
+ def test_retrieve_paths
538
+ {
539
+ :dir => File.expand_path("./root/dir"),
540
+ :root => File.expand_path("./root"),
541
+ 'root' => File.expand_path("./root"),
542
+ :abs => File.expand_path("/abs/path")
543
+ }.each_pair do |dir, expected|
544
+ assert_equal expected, r[dir]
545
+ end
546
+ end
547
+
548
+ def test_retrieve_path_infers_path_if_path_is_not_set
549
+ assert_equal({
550
+ 'root' => File.expand_path("./root"),
551
+ :root => File.expand_path("./root"),
552
+ :dir => File.expand_path("./root/dir"),
553
+ :abs => File.expand_path("/abs/path")},
554
+ r.paths)
555
+ assert_equal File.expand_path("./root/not_set"), r[:not_set]
556
+ assert_equal File.expand_path("./root/nested/dir"), r['nested/dir']
557
+ end
558
+
559
+ def test_retrieve_path_expands_inferred_filepaths
560
+ assert_equal File.expand_path("./root/nested/dir"), r['./sub/../nested/dir']
561
+ end
403
562
 
404
- #
405
- # filepath tests
406
- #
407
-
408
- def test_filepath
409
- assert_equal File.expand_path("./root/dir"), r[:dir]
410
- assert_equal File.expand_path("./root/dir/file.txt"), r.filepath(:dir, "file.txt")
411
- assert_equal File.expand_path("./root/dir/nested/file.txt"), r.filepath(:dir, "nested/file.txt")
412
- end
413
-
414
- def test_filepath_when_path_is_not_set
415
- assert_equal File.expand_path("./root/not_set/file.txt"), r.filepath(:not_set, "file.txt")
416
- assert_equal File.expand_path("./root/folder/subfolder/file.txt"), r.filepath('folder/subfolder', "file.txt")
417
- assert_equal File.expand_path("./root/folder/subfolder/file.txt"), r.filepath('/folder/subfolder', "file.txt")
418
- assert_equal File.expand_path("./root/folder/subfolder/file.txt"), r.filepath('folder/subfolder/', "file.txt")
419
- end
420
-
421
- def test_filepath_expands_paths
422
- assert_equal File.expand_path("./root/dir"), r[:dir]
423
- assert_equal File.expand_path("./root/dir/file.txt"), r.filepath(:dir, "./sub/../file.txt")
424
- assert_equal File.expand_path("./root/dir/nested/file.txt"), r.filepath(:dir, "nested/./sub/../file.txt")
425
- end
426
-
427
- #
428
- # relative filepath tests
429
- #
430
-
431
- def test_relative_filepath
432
- assert_equal "file.txt", r.relative_filepath(:dir, "./root/dir/file.txt")
433
- assert_equal "nested/file.txt", r.relative_filepath(:dir, "./root/dir/nested/file.txt")
434
- assert_equal "file.txt", r.relative_filepath('dir/nested', "./root/dir/nested/file.txt")
435
- assert_equal "file.txt", r.relative_filepath('dir/nested/', "./root/dir/nested/file.txt")
436
- assert_equal "file.txt", r.relative_filepath('/dir/nested', "./root/dir/nested/file.txt")
437
- end
563
+ #
564
+ # filepath tests
565
+ #
566
+
567
+ def test_filepath
568
+ assert_equal File.expand_path("./root/dir"), r[:dir]
569
+ assert_equal File.expand_path("./root/dir/file.txt"), r.filepath(:dir, "file.txt")
570
+ assert_equal File.expand_path("./root/dir/nested/file.txt"), r.filepath(:dir, "nested/file.txt")
571
+ end
572
+
573
+ def test_filepath_when_path_is_not_set
574
+ assert_equal File.expand_path("./root/not_set/file.txt"), r.filepath(:not_set, "file.txt")
575
+ assert_equal File.expand_path("./root/folder/subfolder/file.txt"), r.filepath('folder/subfolder', "file.txt")
576
+ assert_equal File.expand_path("./root/folder/subfolder/file.txt"), r.filepath('folder/subfolder/', "file.txt")
577
+ assert_equal File.expand_path(path_root + "folder/subfolder/file.txt"), r.filepath(path_root + 'folder/subfolder', "file.txt")
578
+ end
579
+
580
+ def test_filepath_expands_paths
581
+ assert_equal File.expand_path("./root/dir"), r[:dir]
582
+ assert_equal File.expand_path("./root/dir/file.txt"), r.filepath(:dir, "./sub/../file.txt")
583
+ assert_equal File.expand_path("./root/dir/nested/file.txt"), r.filepath(:dir, "nested/./sub/../file.txt")
584
+ end
585
+
586
+ #
587
+ # relative filepath tests
588
+ #
589
+
590
+ def test_relative_filepath
591
+ assert_equal "file.txt", r.relative_filepath(:dir, "./root/dir/file.txt")
592
+ assert_equal "nested/file.txt", r.relative_filepath(:dir, "./root/dir/nested/file.txt")
593
+ assert_equal "file.txt", r.relative_filepath('dir/nested', "./root/dir/nested/file.txt")
594
+ assert_equal "file.txt", r.relative_filepath('dir/nested/', "./root/dir/nested/file.txt")
595
+ assert_equal "file.txt", r.relative_filepath(path_root + 'dir/nested', path_root + "dir/nested/file.txt")
596
+ end
438
597
 
439
- def test_relative_filepath_when_path_equals_input
440
- assert_equal "", r.relative_filepath(:dir, "./root/dir")
441
- assert_equal "", r.relative_filepath(:dir, "./root/dir/")
442
- end
443
-
444
- def test_relative_filepath_expands_paths
445
- assert_equal "file.txt", r.relative_filepath(:dir, "./root/folder/.././dir/file.txt")
446
- assert_equal "file.txt", r.relative_filepath(:dir, "root/dir/file.txt")
447
- end
448
-
449
- def test_relative_filepath_when_path_is_not_set
450
- assert_equal "file.txt", r.relative_filepath(:not_set, "./root/not_set/file.txt")
451
- assert_equal "file.txt", r.relative_filepath('folder/subfolder', "./root/folder/subfolder/file.txt")
452
- assert_equal "file.txt", r.relative_filepath('/folder/subfolder', "./root/folder/subfolder/file.txt")
453
- assert_equal "file.txt", r.relative_filepath('folder/subfolder/', "./root/folder/subfolder/file.txt")
454
- end
455
-
456
- def test_relative_filepath_raises_error_if_path_is_not_relative_to_aliased_dir
457
- assert_raise(RuntimeError) { r.relative_filepath(:dir, "./root/file.txt") }
458
- end
459
-
460
- def test_relative_filepath_returns_expanded_path_if_path_is_not_relative_to_aliased_dir_and_not_strict
461
- assert_equal test_root + "/root/file.txt", r.relative_filepath('dir', test_root + "/root/folder/.././file.txt", false)
462
- end
463
-
464
- #
465
- # translate tests
466
- #
467
-
468
- def test_translate_documentation
469
- r = Tap::Root.new '/root_dir'
470
-
471
- fp = r.filepath(:in, 'path/to/file.txt')
472
- assert_equal File.expand_path('/root_dir/in/path/to/file.txt'), fp
598
+ def test_relative_filepath_when_path_equals_input
599
+ assert_equal "", r.relative_filepath(:dir, "./root/dir")
600
+ assert_equal "", r.relative_filepath(:dir, "./root/dir/")
601
+ end
602
+
603
+ def test_relative_filepath_expands_paths
604
+ assert_equal "file.txt", r.relative_filepath(:dir, "./root/folder/.././dir/file.txt")
605
+ assert_equal "file.txt", r.relative_filepath(:dir, "root/dir/file.txt")
606
+ end
607
+
608
+ def test_relative_filepath_when_path_is_not_set
609
+ assert_equal "file.txt", r.relative_filepath(:not_set, "./root/not_set/file.txt")
610
+ assert_equal "file.txt", r.relative_filepath('folder/subfolder', "./root/folder/subfolder/file.txt")
611
+ assert_equal "file.txt", r.relative_filepath('folder/subfolder/', "./root/folder/subfolder/file.txt")
612
+ assert_equal "file.txt", r.relative_filepath(path_root + 'folder/subfolder', path_root + "folder/subfolder/file.txt")
613
+ end
614
+
615
+ def test_relative_filepath_raises_error_if_path_is_not_relative_to_aliased_dir
616
+ assert_raise(RuntimeError) { r.relative_filepath(:dir, "./root/file.txt") }
617
+ end
618
+
619
+ #
620
+ # translate tests
621
+ #
622
+
623
+ def test_translate_documentation
624
+ r = Tap::Root.new '/root_dir'
625
+
626
+ fp = r.filepath(:in, 'path/to/file.txt')
627
+ assert_equal File.expand_path('/root_dir/in/path/to/file.txt'), fp
473
628
  assert_equal File.expand_path('/root_dir/out/path/to/file.txt'), r.translate(fp, :in, :out)
474
- end
475
-
476
- def test_translate
477
- assert_equal File.expand_path("./root/another/file.txt"), r.translate("./root/dir/file.txt", :dir, :another)
478
- assert_equal File.expand_path("./root/another/nested/file.txt"), r.translate("./root/dir/nested/file.txt", :dir, :another)
479
- end
480
-
481
- def test_translate_raises_error_if_path_is_not_relative_to_aliased_input_dir
482
- assert_raise(RuntimeError) { r.translate("./root/dir/file.txt", :not_dir, :another) }
483
- end
484
-
485
- #
486
- # glob tests
487
- #
488
-
489
- def test_glob_returns_all_files_matching_pattern
490
- assert_equal Dir.glob(File.join(test_root, '*')), tr.glob(:root, "*")
491
- assert_equal Dir.glob(File.join(test_root, '*.txt')), tr.glob(:root, "*.txt")
492
- assert_equal Dir.glob(File.join(test_root, 'lib/*')), tr.glob(:lib, "*")
493
- end
629
+ end
630
+
631
+ def test_translate
632
+ assert_equal File.expand_path("./root/another/file.txt"), r.translate("./root/dir/file.txt", :dir, :another)
633
+ assert_equal File.expand_path("./root/another/nested/file.txt"), r.translate("./root/dir/nested/file.txt", :dir, :another)
634
+ end
635
+
636
+ def test_translate_raises_error_if_path_is_not_relative_to_aliased_input_dir
637
+ assert_raise(RuntimeError) { r.translate("./root/dir/file.txt", :not_dir, :another) }
638
+ end
639
+
640
+ #
641
+ # glob tests
642
+ #
643
+
644
+ def test_glob_returns_all_files_matching_pattern
645
+ assert_equal Dir.glob(File.join(root_dir, '*')), tr.glob(:root, "*")
646
+ assert_equal Dir.glob(File.join(root_dir, '*.txt')), tr.glob(:root, "*.txt")
647
+ assert_equal Dir.glob(File.join(root_dir, 'lib/*')), tr.glob(:lib, "*")
648
+ end
494
649
 
495
- def test_default_glob_pattern_is_all_files_and_folders
496
- assert_equal Dir.glob(File.join(test_root, '**/*')), tr.glob(:root)
497
- end
498
-
499
- def test_glob_using_multiple_patterns
500
- yml_files = Dir.glob(File.join(test_root, '**/*.yml'))
501
- txt_files = Dir.glob(File.join(test_root, '**/*.txt'))
502
-
503
- assert_equal(
504
- (yml_files + txt_files).sort,
505
- tr.glob(:root, "**/*.yml", "**/*.txt").sort)
650
+ def test_default_glob_pattern_is_all_files_and_folders
651
+ assert_equal Dir.glob(File.join(root_dir, '**/*')), tr.glob(:root)
652
+ end
653
+
654
+ def test_glob_using_multiple_patterns
655
+ yml_files = Dir.glob(File.join(root_dir, '**/*.yml'))
656
+ txt_files = Dir.glob(File.join(root_dir, '**/*.txt'))
657
+
658
+ assert_equal(
659
+ (yml_files + txt_files).sort,
660
+ tr.glob(:root, "**/*.yml", "**/*.txt").sort)
506
661
  end
507
662
 
508
663
  #
509
- # vglob tests
510
- #
511
-
512
- def test_vglob_returns_all_versions_matching_file_and_version_pattern
513
- assert_equal 4, Dir.glob(File.join(test_root, 'versions/*')).length
664
+ # vglob tests
665
+ #
666
+
667
+ def test_vglob_returns_all_versions_matching_file_and_version_pattern
668
+ assert_equal 4, Dir.glob(File.join(root_dir, 'versions/*')).length
514
669
 
515
- assert_equal 3, Dir.glob(File.join(test_root, 'versions/file*.yml')).length
516
- assert_equal Dir.glob(File.join(test_root, 'versions/file*.yml')).sort, tr.vglob(:versions, 'file.yml', '*').sort
670
+ assert_equal 3, Dir.glob(File.join(root_dir, 'versions/file*.yml')).length
671
+ assert_equal Dir.glob(File.join(root_dir, 'versions/file*.yml')).sort, tr.vglob(:versions, 'file.yml', '*').sort
517
672
 
518
- assert_equal 2, Dir.glob(File.join(test_root, 'versions/file-0.1*.yml')).length
519
- assert_equal Dir.glob(File.join(test_root, 'versions/file-0.1*.yml')).sort, tr.vglob(:versions, 'file.yml', "0.1*").sort
673
+ assert_equal 2, Dir.glob(File.join(root_dir, 'versions/file-0.1*.yml')).length
674
+ assert_equal Dir.glob(File.join(root_dir, 'versions/file-0.1*.yml')).sort, tr.vglob(:versions, 'file.yml', "0.1*").sort
520
675
 
521
- assert_equal 1, Dir.glob(File.join(test_root, 'versions/file-0.1.yml')).length
522
- assert_equal Dir.glob(File.join(test_root, 'versions/file-0.1.yml')).sort, tr.vglob(:versions, 'file.yml', "0.1").sort
676
+ assert_equal 1, Dir.glob(File.join(root_dir, 'versions/file-0.1.yml')).length
677
+ assert_equal Dir.glob(File.join(root_dir, 'versions/file-0.1.yml')).sort, tr.vglob(:versions, 'file.yml', "0.1").sort
523
678
 
524
- assert_equal 0, Dir.glob(File.join(test_root, 'versions/file-2.yml')).length
679
+ assert_equal 0, Dir.glob(File.join(root_dir, 'versions/file-2.yml')).length
525
680
  assert_equal [], tr.vglob(:versions, 'file.yml', "2")
526
- end
681
+ end
527
682
 
528
- def test_default_vglob_pattern_is_all_versions
529
- expected = Dir.glob(File.join(test_root, 'versions/file-*.yml')) + [File.join(test_root, 'versions/file.yml')]
530
- assert_equal expected.sort, tr.vglob(:versions, 'file.yml').sort
531
- end
683
+ def test_default_vglob_pattern_is_all_versions
684
+ expected = Dir.glob(File.join(root_dir, 'versions/file-*.yml')) + [File.join(root_dir, 'versions/file.yml')]
685
+ assert_equal expected.sort, tr.vglob(:versions, 'file.yml').sort
686
+ end
532
687
 
533
688
  def test_nil_vglob_pattern_matches_the_no_version_file
534
- assert_equal [File.join(test_root, 'versions/file.yml')], tr.vglob(:versions, 'file.yml', nil)
535
- assert_equal [File.join(test_root, 'versions/file.yml')], tr.vglob(:versions, 'file.yml', '')
536
- end
537
-
538
- def test_vglob_using_multiple_verson_patterns
539
- expected = [
540
- File.join(test_root, 'versions/file-0.1.2.yml'),
541
- File.join(test_root, 'versions/file-0.1.yml')]
542
-
543
- assert_equal expected.sort, tr.vglob(:versions, "file.yml", "0.1.2", "0.1").sort
544
- end
545
-
546
- def test_vglob_filters_for_unique_files
547
- expected = [File.join(test_root, 'versions/file-0.1.2.yml')]
548
-
549
- assert_equal expected, tr.vglob(:versions, "file.yml", "0.1.2", "0.1.*")
689
+ assert_equal [File.join(root_dir, 'versions/file.yml')], tr.vglob(:versions, 'file.yml', nil)
690
+ assert_equal [File.join(root_dir, 'versions/file.yml')], tr.vglob(:versions, 'file.yml', '')
691
+ end
692
+
693
+ def test_vglob_using_multiple_verson_patterns
694
+ expected = [
695
+ File.join(root_dir, 'versions/file-0.1.2.yml'),
696
+ File.join(root_dir, 'versions/file-0.1.yml')]
697
+
698
+ assert_equal expected.sort, tr.vglob(:versions, "file.yml", "0.1.2", "0.1").sort
699
+ end
700
+
701
+ def test_vglob_filters_for_unique_files
702
+ expected = [File.join(root_dir, 'versions/file-0.1.2.yml')]
703
+
704
+ assert_equal expected, tr.vglob(:versions, "file.yml", "0.1.2", "0.1.*")
705
+ end
706
+
707
+ #
708
+ # benchmarks
709
+ #
710
+
711
+ def test_get_speed
712
+ benchmark_test(20) do |x|
713
+ n = 10000
714
+ x.report("10k root[] ") { n.times { r[:dir] } }
715
+ x.report("10k root[path_root] ") { n.times { r[ path_root + "path/to/file.txt" ] } }
716
+ end
550
717
  end
551
718
  end