tap 0.7.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. data/MIT-LICENSE +21 -0
  2. data/README +71 -0
  3. data/Rakefile +117 -0
  4. data/bin/tap +63 -0
  5. data/lib/tap.rb +15 -0
  6. data/lib/tap/app.rb +739 -0
  7. data/lib/tap/file_task.rb +354 -0
  8. data/lib/tap/generator.rb +29 -0
  9. data/lib/tap/generator/generators/config/USAGE +0 -0
  10. data/lib/tap/generator/generators/config/config_generator.rb +23 -0
  11. data/lib/tap/generator/generators/config/templates/config.erb +2 -0
  12. data/lib/tap/generator/generators/file_task/USAGE +0 -0
  13. data/lib/tap/generator/generators/file_task/file_task_generator.rb +21 -0
  14. data/lib/tap/generator/generators/file_task/templates/task.erb +27 -0
  15. data/lib/tap/generator/generators/file_task/templates/test.erb +12 -0
  16. data/lib/tap/generator/generators/root/USAGE +0 -0
  17. data/lib/tap/generator/generators/root/root_generator.rb +36 -0
  18. data/lib/tap/generator/generators/root/templates/Rakefile +48 -0
  19. data/lib/tap/generator/generators/root/templates/app.yml +19 -0
  20. data/lib/tap/generator/generators/root/templates/config/process_tap_request.yml +4 -0
  21. data/lib/tap/generator/generators/root/templates/lib/process_tap_request.rb +26 -0
  22. data/lib/tap/generator/generators/root/templates/public/images/nav.jpg +0 -0
  23. data/lib/tap/generator/generators/root/templates/public/stylesheets/color.css +57 -0
  24. data/lib/tap/generator/generators/root/templates/public/stylesheets/layout.css +108 -0
  25. data/lib/tap/generator/generators/root/templates/public/stylesheets/normalize.css +40 -0
  26. data/lib/tap/generator/generators/root/templates/public/stylesheets/typography.css +21 -0
  27. data/lib/tap/generator/generators/root/templates/server/config/environment.rb +60 -0
  28. data/lib/tap/generator/generators/root/templates/server/lib/tasks/clear_database_prerequisites.rake +5 -0
  29. data/lib/tap/generator/generators/root/templates/server/test/test_helper.rb +53 -0
  30. data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +3 -0
  31. data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +4 -0
  32. data/lib/tap/generator/generators/task/USAGE +0 -0
  33. data/lib/tap/generator/generators/task/task_generator.rb +21 -0
  34. data/lib/tap/generator/generators/task/templates/task.erb +21 -0
  35. data/lib/tap/generator/generators/task/templates/test.erb +29 -0
  36. data/lib/tap/generator/generators/workflow/USAGE +0 -0
  37. data/lib/tap/generator/generators/workflow/templates/task.erb +16 -0
  38. data/lib/tap/generator/generators/workflow/templates/test.erb +7 -0
  39. data/lib/tap/generator/generators/workflow/workflow_generator.rb +21 -0
  40. data/lib/tap/generator/options.rb +26 -0
  41. data/lib/tap/generator/usage.rb +26 -0
  42. data/lib/tap/root.rb +275 -0
  43. data/lib/tap/script/console.rb +7 -0
  44. data/lib/tap/script/destroy.rb +8 -0
  45. data/lib/tap/script/generate.rb +8 -0
  46. data/lib/tap/script/run.rb +111 -0
  47. data/lib/tap/script/server.rb +12 -0
  48. data/lib/tap/support/audit.rb +415 -0
  49. data/lib/tap/support/batch_queue.rb +165 -0
  50. data/lib/tap/support/combinator.rb +114 -0
  51. data/lib/tap/support/logger.rb +91 -0
  52. data/lib/tap/support/rap.rb +38 -0
  53. data/lib/tap/support/run_error.rb +20 -0
  54. data/lib/tap/support/template.rb +81 -0
  55. data/lib/tap/support/templater.rb +155 -0
  56. data/lib/tap/support/versions.rb +63 -0
  57. data/lib/tap/task.rb +448 -0
  58. data/lib/tap/test.rb +320 -0
  59. data/lib/tap/test/env_vars.rb +16 -0
  60. data/lib/tap/test/inference_methods.rb +298 -0
  61. data/lib/tap/test/subset_methods.rb +260 -0
  62. data/lib/tap/version.rb +3 -0
  63. data/lib/tap/workflow.rb +73 -0
  64. data/test/app/config/addition_template.yml +6 -0
  65. data/test/app/config/batch.yml +2 -0
  66. data/test/app/config/empty.yml +0 -0
  67. data/test/app/config/erb.yml +1 -0
  68. data/test/app/config/template.yml +6 -0
  69. data/test/app/config/version-0.1.yml +1 -0
  70. data/test/app/config/version.yml +1 -0
  71. data/test/app/lib/app_test_task.rb +2 -0
  72. data/test/app_class_test.rb +33 -0
  73. data/test/app_test.rb +1372 -0
  74. data/test/file_task/config/batch.yml +2 -0
  75. data/test/file_task/config/configured.yml +1 -0
  76. data/test/file_task/old_file_one.txt +0 -0
  77. data/test/file_task/old_file_two.txt +0 -0
  78. data/test/file_task_test.rb +1041 -0
  79. data/test/root/alt_lib/alt_module.rb +4 -0
  80. data/test/root/lib/absolute_alt_filepath.rb +2 -0
  81. data/test/root/lib/alternative_filepath.rb +2 -0
  82. data/test/root/lib/another_module.rb +2 -0
  83. data/test/root/lib/nested/some_module.rb +4 -0
  84. data/test/root/lib/no_module_included.rb +0 -0
  85. data/test/root/lib/some/module.rb +4 -0
  86. data/test/root/lib/some_class.rb +2 -0
  87. data/test/root/lib/some_module.rb +3 -0
  88. data/test/root/load_path/load_path_module.rb +2 -0
  89. data/test/root/load_path/skip_module.rb +2 -0
  90. data/test/root/mtime/older.txt +0 -0
  91. data/test/root/unload/full_path.rb +2 -0
  92. data/test/root/unload/loaded_by_nested.rb +2 -0
  93. data/test/root/unload/nested/nested_load.rb +6 -0
  94. data/test/root/unload/nested/nested_with_ext.rb +4 -0
  95. data/test/root/unload/nested/relative_path.rb +4 -0
  96. data/test/root/unload/older.rb +2 -0
  97. data/test/root/unload/unload_base.rb +9 -0
  98. data/test/root/versions/another.yml +0 -0
  99. data/test/root/versions/file-0.1.2.yml +0 -0
  100. data/test/root/versions/file-0.1.yml +0 -0
  101. data/test/root/versions/file.yml +0 -0
  102. data/test/root_test.rb +483 -0
  103. data/test/support/audit_test.rb +449 -0
  104. data/test/support/batch_queue_test.rb +320 -0
  105. data/test/support/combinator_test.rb +249 -0
  106. data/test/support/logger_test.rb +31 -0
  107. data/test/support/template_test.rb +122 -0
  108. data/test/support/templater/erb.txt +2 -0
  109. data/test/support/templater/erb.yml +2 -0
  110. data/test/support/templater/somefile.txt +2 -0
  111. data/test/support/templater_test.rb +192 -0
  112. data/test/support/versions_test.rb +71 -0
  113. data/test/tap_test_helper.rb +4 -0
  114. data/test/tap_test_suite.rb +4 -0
  115. data/test/task/config/batch.yml +2 -0
  116. data/test/task/config/batched.yml +2 -0
  117. data/test/task/config/configured.yml +1 -0
  118. data/test/task/config/example.yml +1 -0
  119. data/test/task/config/overriding.yml +2 -0
  120. data/test/task/config/task_with_config.yml +1 -0
  121. data/test/task/config/template.yml +4 -0
  122. data/test/task_class_test.rb +118 -0
  123. data/test/task_execute_test.rb +233 -0
  124. data/test/task_test.rb +424 -0
  125. data/test/test/inference_methods/test_assert_expected/expected/file.txt +1 -0
  126. data/test/test/inference_methods/test_assert_expected/expected/folder/file.txt +1 -0
  127. data/test/test/inference_methods/test_assert_expected/input/file.txt +1 -0
  128. data/test/test/inference_methods/test_assert_expected/input/folder/file.txt +1 -0
  129. data/test/test/inference_methods/test_assert_files_exist/input/input_1.txt +0 -0
  130. data/test/test/inference_methods/test_assert_files_exist/input/input_2.txt +0 -0
  131. data/test/test/inference_methods/test_file_compare/expected/output_1.txt +3 -0
  132. data/test/test/inference_methods/test_file_compare/expected/output_2.txt +1 -0
  133. data/test/test/inference_methods/test_file_compare/input/input_1.txt +3 -0
  134. data/test/test/inference_methods/test_file_compare/input/input_2.txt +3 -0
  135. data/test/test/inference_methods/test_infer_glob/expected/file.yml +0 -0
  136. data/test/test/inference_methods/test_infer_glob/expected/file_1.txt +0 -0
  137. data/test/test/inference_methods/test_infer_glob/expected/file_2.txt +0 -0
  138. data/test/test/inference_methods/test_yml_compare/expected/output_1.yml +6 -0
  139. data/test/test/inference_methods/test_yml_compare/expected/output_2.yml +6 -0
  140. data/test/test/inference_methods/test_yml_compare/input/input_1.yml +4 -0
  141. data/test/test/inference_methods/test_yml_compare/input/input_2.yml +4 -0
  142. data/test/test/inference_methods_test.rb +311 -0
  143. data/test/test/subset_methods_test.rb +115 -0
  144. data/test/test_test.rb +233 -0
  145. data/test/workflow_test.rb +108 -0
  146. metadata +274 -0
@@ -0,0 +1,4 @@
1
+ # =:Key:Value
2
+ #
3
+ module AltModule
4
+ end
@@ -0,0 +1,2 @@
1
+ module AbsoluteAlternativeFilepathModule
2
+ end
@@ -0,0 +1,2 @@
1
+ module AlternativeFilepathModule
2
+ end
@@ -0,0 +1,2 @@
1
+ module AnotherModule
2
+ end
@@ -0,0 +1,4 @@
1
+ module Nested
2
+ module SomeModule
3
+ end
4
+ end
File without changes
@@ -0,0 +1,4 @@
1
+ module Some
2
+ module Module
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ class SomeClass
2
+ end
@@ -0,0 +1,3 @@
1
+ module SomeModule
2
+ end
3
+ puts "in some module"
@@ -0,0 +1,2 @@
1
+ module LoadPathModule
2
+ end
@@ -0,0 +1,2 @@
1
+ module SkipModule
2
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ module FullPath
2
+ end
@@ -0,0 +1,2 @@
1
+ module LoadedByNested
2
+ end
@@ -0,0 +1,6 @@
1
+ require File.dirname(__FILE__) + "/../loaded_by_nested.rb"
2
+
3
+ module Nested
4
+ module NestedLoad
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ module Nested
2
+ module NestedWithExt
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Nested
2
+ module RelativePath
3
+ end
4
+ end
@@ -0,0 +1,2 @@
1
+ module Older
2
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + "/full_path.rb")
2
+ require File.dirname(__FILE__) + "/../unload/nested/relative_path.rb"
3
+
4
+ # these will be loaded when the nested directory is on the load path
5
+ require "nested_load"
6
+ require "nested_with_ext.rb"
7
+
8
+ module UnloadBase
9
+ end
File without changes
File without changes
File without changes
File without changes
data/test/root_test.rb ADDED
@@ -0,0 +1,483 @@
1
+ require File.join(File.dirname(__FILE__), 'tap_test_helper.rb')
2
+ require 'tap/root'
3
+
4
+ #SomeModule
5
+ #[Object, :SomeModule, "some_module", nil]
6
+
7
+ #Dependencies.load_paths << File.join(File.dirname(__FILE__), 'root', 'lib')
8
+ #puts Object.const_get "SomeModule"
9
+ #Dependencies.clear
10
+ #puts SomeModule
11
+
12
+ class RootTest < Test::Unit::TestCase
13
+ include Tap::Test::SubsetMethods
14
+
15
+ attr_reader :ifs, :rfs
16
+
17
+ def setup
18
+ @ifs = Tap::Root.new "./root", {:dir => "dir"}, {:abs => '/abs/path'}
19
+ @rfs = Tap::Root.new root, {:lib => "lib"}
20
+ end
21
+
22
+ def root
23
+ File.join(File.dirname(__FILE__), 'root')
24
+ end
25
+
26
+ def test_documentation
27
+ root = Tap::Root.new self.root, :input => 'in', :output => 'out'
28
+
29
+ # work with directories
30
+ assert_equal self.root + '/in', root[:in]
31
+ assert_equal self.root + '/out', root[:out]
32
+ assert_equal self.root + '/implicit', root[:implicit]
33
+
34
+ # # work with filepaths
35
+ assert_equal self.root + '/in/path/to/file.txt', fp = root.filepath(:in, 'path/to/file.txt')
36
+ assert_equal 'path/to/file.txt', root.relative_filepath(:in, fp)
37
+ assert_equal self.root + '/out/path/to/file.txt', root.translate(fp, :in, :out)
38
+
39
+ # # version filepaths
40
+ assert_equal 'path/to/config-1.0.yml', root.version('path/to/config.yml', 1.0)
41
+ assert_equal 'path/to/config-1.1.yml', root.increment('path/to/config-1.0.yml', 0.1)
42
+ assert_equal ['path/to/config.yml', "1.1"], root.deversion('path/to/config-1.1.yml')
43
+
44
+ # # work with modules...
45
+ #assert_equal self.root + '/lib/some/module.rb', mp = root.module_filepath(:lib, 'Some::Module')
46
+
47
+ # # loading them...
48
+ #assert_equal false, Some.const_defined?('Module') # differs from example because Some is defined in another test
49
+ #assert_equal root.lookup_module('Some::Module'), Some::Module
50
+ #assert_equal true, Some.const_defined?('Module')
51
+
52
+ # # and unloading them!
53
+ #assert_equal ["Some::Module"], root.unload_modules
54
+ #assert_equal false, Some.const_defined?('Module') # differs from example because Some is defined in another test
55
+
56
+ ##
57
+ assert_equal "path/to/file.txt", Tap::Root.relative_filepath('dir', "dir/path/to/file.txt")
58
+
59
+ #assert_equal 'some/module_name.rb', Tap::Root.module_filepath('Some::ModuleName')
60
+ #assert_equal 'some/module_name.rb', Tap::Root.module_filepath('some/module_name.rb')
61
+
62
+ #assert_equal 'Some::ModuleName', Tap::Root.module_name('some/module_name.rb')
63
+ #assert_equal 'Some::ModuleName', Tap::Root.module_name('Some::ModuleName')
64
+ end
65
+
66
+ #
67
+ # Tap::Root relative filepath test
68
+ #
69
+
70
+ def test_class_relative_filepath
71
+ assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "./root/dir/file.txt")
72
+ assert_equal "nested/file.txt", Tap::Root.relative_filepath('./root/dir', "./root/dir/nested/file.txt")
73
+ end
74
+
75
+ def test_class_relative_filepath_expands_paths
76
+ assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "./root/folder/.././dir/file.txt")
77
+ assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "root/dir/file.txt")
78
+ assert_equal "file.txt", Tap::Root.relative_filepath('root/dir', "./root/dir/file.txt")
79
+ end
80
+
81
+ def test_class_relative_filepath_raises_error_if_path_is_not_relative_to_dir
82
+ assert_raise(RuntimeError) { Tap::Root.relative_filepath('dir', "./root/file.txt") }
83
+ end
84
+
85
+ def test_class_relative_filepath_returns_path_if_path_is_not_relative_to_dir_and_not_strict
86
+ assert_equal "./root/file.txt", Tap::Root.relative_filepath('dir', "./root/file.txt", false)
87
+ end
88
+
89
+ #
90
+ # initialize tests
91
+ #
92
+
93
+ def test_defualt_root_is_dir_pwd
94
+ ifs = Tap::Root.new
95
+
96
+ assert_equal Dir.pwd, ifs.root
97
+ assert_equal({}, ifs.directories)
98
+ end
99
+
100
+ def test_initialize_root
101
+ ifs = Tap::Root.new "./root", {:dir => "dir", :temp => "tmp"}, {:abs => "/abs/path"}
102
+
103
+ assert_equal "./root", ifs.root
104
+ assert_equal({:dir => "dir", :temp => "tmp"}, ifs.directories)
105
+ assert_equal({:abs => "/abs/path"}, ifs.absolute_paths)
106
+ assert_equal({
107
+ 'root' => "./root",
108
+ :root => "./root",
109
+ :dir => "./root/dir",
110
+ :temp => "./root/tmp",
111
+ :abs => "/abs/path"},
112
+ ifs.paths)
113
+ end
114
+
115
+ def test_initialize_can_use_any_object_as_key
116
+ ifs = Tap::Root.new("./root", 'dir' => "str_dir", :dir => 'sym_dir', 1 => 'n_dir')
117
+
118
+ assert_equal({
119
+ 'root' => "./root",
120
+ :root => "./root",
121
+ 'dir' => "./root/str_dir",
122
+ :dir => "./root/sym_dir",
123
+ 1 => "./root/n_dir"},
124
+ ifs.paths)
125
+ end
126
+
127
+ #
128
+ # set root tests
129
+ #
130
+
131
+ def test_set_root_resets_paths
132
+ ifs.root = './another'
133
+
134
+ assert_equal "./another", ifs.root
135
+ assert_equal({:dir => "dir"}, ifs.directories)
136
+ assert_equal({
137
+ 'root' => "./another",
138
+ :root => "./another",
139
+ :dir => "./another/dir",
140
+ :abs => "/abs/path"},
141
+ ifs.paths)
142
+ end
143
+
144
+ def test_root_cannot_be_set_through_index
145
+ assert_raise(ArgumentError) { ifs['root'] = './another' }
146
+ end
147
+
148
+ #
149
+ # set directories tests
150
+ #
151
+
152
+ def test_set_directories
153
+ ifs.directories = {:alt => "dir"}
154
+
155
+ assert_equal({:alt => "dir"}, ifs.directories)
156
+ assert_equal({'root' => "./root", :root => "./root", :alt => "./root/dir", :abs => "/abs/path"}, ifs.paths)
157
+ end
158
+
159
+ def test_raise_error_when_trying_to_set_root_through_directories
160
+ assert_raise(ArgumentError) { ifs.directories = {'root' => "another"} }
161
+ end
162
+
163
+ #
164
+ # set absolute paths test
165
+ #
166
+
167
+ def test_set_absolute_paths
168
+ ifs.absolute_paths = {:absolute => "/absolute/path"}
169
+
170
+ assert_equal({:dir => "dir"}, ifs.directories)
171
+ assert_equal({'root' => "./root", :root => "./root", :dir => "./root/dir", :absolute => "/absolute/path"}, ifs.paths)
172
+ end
173
+
174
+ def test_raise_error_when_trying_to_set_root_through_absolute_paths
175
+ assert_raise(ArgumentError) { ifs.absolute_paths = {'root' => "another"} }
176
+ end
177
+
178
+ #
179
+ # get absolute paths test
180
+ #
181
+
182
+ def test_absolute_paths_returns_all_non_root_paths_with_no_directory
183
+ assert_equal({:abs => "/abs/path"}, ifs.absolute_paths)
184
+
185
+ ifs.paths[:another] = "/another/path"
186
+ assert_equal({:abs => "/abs/path", :another => "/another/path"}, ifs.absolute_paths)
187
+ end
188
+
189
+ #
190
+ # set path tests
191
+ #
192
+
193
+ def test_set_existing_directory_using_index
194
+ ifs[:dir] = 'another'
195
+
196
+ assert_equal({:dir => "another"}, ifs.directories)
197
+ assert_equal({
198
+ 'root' => "./root",
199
+ :root => "./root",
200
+ :dir => "./root/another",
201
+ :abs => "/abs/path"},
202
+ ifs.paths)
203
+ end
204
+
205
+ def test_set_new_directory_using_index
206
+ ifs[:new] = 'new'
207
+
208
+ assert_equal({:dir => "dir", :new => "new"}, ifs.directories)
209
+ assert_equal({
210
+ 'root' => "./root",
211
+ :root => "./root",
212
+ :dir => "./root/dir",
213
+ :abs => "/abs/path",
214
+ :new => "./root/new"},
215
+ ifs.paths)
216
+ end
217
+
218
+ def test_absolute_paths_can_be_set_by_specifiying_absolute_true
219
+ ifs[:absolute, true] = '/some/absolute/path'
220
+
221
+ assert_equal({:dir => "dir"}, ifs.directories)
222
+ assert_equal({
223
+ 'root' => "./root",
224
+ :root => "./root",
225
+ :dir => "./root/dir",
226
+ :abs => "/abs/path",
227
+ :absolute => '/some/absolute/path'},
228
+ ifs.paths)
229
+ end
230
+
231
+ def test_an_absolute_path_is_not_set_if_absolute_false
232
+ ifs[:not_absolute, false] = 'not/an/absolute/path'
233
+
234
+ assert_equal({:dir => "dir", :not_absolute => "not/an/absolute/path"}, ifs.directories)
235
+ assert_equal({
236
+ 'root' => "./root",
237
+ :root => "./root",
238
+ :dir => "./root/dir",
239
+ :abs => "/abs/path",
240
+ :not_absolute => "./root/not/an/absolute/path"},
241
+ ifs.paths)
242
+ end
243
+
244
+ def test_paths_can_be_unset_with_nil
245
+ # Non-absolute path
246
+ ifs[:dir] = '/some/path'
247
+ assert_equal({:dir => "/some/path"}, ifs.directories)
248
+ assert_equal({'root' => "./root", :root => "./root", :dir => "./root/some/path", :abs => "/abs/path"}, ifs.paths)
249
+
250
+ ifs[:dir] = nil
251
+ assert_equal({}, ifs.directories)
252
+ assert_equal({'root' => "./root", :root => "./root", :abs => "/abs/path"}, ifs.paths)
253
+
254
+ # Now with absolute specified
255
+ ifs[:dir] = '/some/path'
256
+ assert_equal({:dir => "/some/path"}, ifs.directories)
257
+ assert_equal({'root' => "./root", :root => "./root", :dir => "./root/some/path", :abs => "/abs/path"}, ifs.paths)
258
+
259
+ ifs[:dir, false] = nil
260
+ assert_equal({}, ifs.directories)
261
+ assert_equal({'root' => "./root", :root => "./root", :abs => "/abs/path"}, ifs.paths)
262
+
263
+ # Absolute path
264
+ ifs[:abs, true] = '/some/absolute/path'
265
+ assert_equal({}, ifs.directories)
266
+ assert_equal({'root' => "./root", :root => "./root", :abs => '/some/absolute/path'}, ifs.paths)
267
+
268
+ ifs[:abs, true] = nil
269
+ assert_equal({}, ifs.directories)
270
+ assert_equal({'root' => "./root", :root => "./root"}, ifs.paths)
271
+
272
+ # Now with absolute unspecfied
273
+ ifs[:abs, true] = '/some/absolute/path'
274
+ assert_equal({}, ifs.directories)
275
+ assert_equal({'root' => "./root", :root => "./root", :abs => '/some/absolute/path'}, ifs.paths)
276
+
277
+ ifs[:abs] = nil
278
+ assert_equal({}, ifs.directories)
279
+ assert_equal({'root' => "./root", :root => "./root"}, ifs.paths)
280
+ end
281
+
282
+ #
283
+ # retrieve path tests
284
+ #
285
+
286
+ def test_retrieve_paths
287
+ case_test(
288
+ :dir => "./root/dir",
289
+ :root => "./root",
290
+ 'root' => "./root",
291
+ :abs => "/abs/path"
292
+ ) do |dir, expected|
293
+ assert_equal expected, ifs[dir]
294
+ end
295
+ end
296
+
297
+ def test_retrieve_path_guesses_path_if_path_is_not_set
298
+ assert_equal({'root' => "./root", :root => "./root", :dir => "./root/dir", :abs => "/abs/path"}, ifs.paths)
299
+ assert_equal "./root/not_set", ifs[:not_set]
300
+ assert_equal "./root/nested/dir", ifs['nested/dir']
301
+ end
302
+
303
+ #
304
+ # filepath tests
305
+ #
306
+
307
+ def test_filepath
308
+ assert_equal "./root/dir", ifs[:dir]
309
+ assert_equal "./root/dir/file.txt", ifs.filepath(:dir, "file.txt")
310
+ assert_equal "./root/dir/nested/file.txt", ifs.filepath(:dir, "nested/file.txt")
311
+ end
312
+
313
+ def test_filepath_when_path_is_not_set
314
+ assert_equal "./root/not_set/file.txt", ifs.filepath(:not_set, "file.txt")
315
+ assert_equal "./root/folder/subfolder/file.txt", ifs.filepath('folder/subfolder', "file.txt")
316
+ #assert_equal "./root/folder/subfolder/file.txt", ifs.filepath('/folder/subfolder', "file.txt")
317
+ assert_equal "./root/folder/subfolder/file.txt", ifs.filepath('folder/subfolder/', "file.txt")
318
+ end
319
+
320
+ #
321
+ # relative filepath tests
322
+ #
323
+
324
+ def test_relative_filepath
325
+ assert_equal "file.txt", ifs.relative_filepath(:dir, "./root/dir/file.txt")
326
+ assert_equal "nested/file.txt", ifs.relative_filepath(:dir, "./root/dir/nested/file.txt")
327
+ assert_equal "file.txt", ifs.relative_filepath('dir/nested', "./root/dir/nested/file.txt")
328
+ assert_equal "file.txt", ifs.relative_filepath('dir/nested/', "./root/dir/nested/file.txt")
329
+ assert_equal "file.txt", ifs.relative_filepath('/dir/nested', "./root/dir/nested/file.txt")
330
+ end
331
+
332
+ def test_relative_filepath_when_path_equals_input
333
+ assert_equal "", ifs.relative_filepath(:dir, "./root/dir")
334
+ assert_equal "", ifs.relative_filepath(:dir, "./root/dir/")
335
+ end
336
+
337
+ def test_relative_filepath_expands_paths
338
+ assert_equal "file.txt", ifs.relative_filepath(:dir, "./root/folder/.././dir/file.txt")
339
+ assert_equal "file.txt", ifs.relative_filepath(:dir, "root/dir/file.txt")
340
+ end
341
+
342
+ def test_relative_filepath_when_path_is_not_set
343
+ assert_equal "file.txt", ifs.relative_filepath(:not_set, "./root/not_set/file.txt")
344
+ assert_equal "file.txt", ifs.relative_filepath('folder/subfolder', "./root/folder/subfolder/file.txt")
345
+ assert_equal "file.txt", ifs.relative_filepath('/folder/subfolder', "./root/folder/subfolder/file.txt")
346
+ assert_equal "file.txt", ifs.relative_filepath('folder/subfolder/', "./root/folder/subfolder/file.txt")
347
+ end
348
+
349
+ def test_relative_filepath_raises_error_if_path_is_not_relative_to_dir
350
+ assert_raise(RuntimeError) { ifs.relative_filepath(:dir, "./root/file.txt") }
351
+ end
352
+
353
+ def test_relative_filepath_returns_path_if_path_is_not_relative_to_dir_and_not_strict
354
+ assert_equal "./root/file.txt", ifs.relative_filepath('dir', "./root/file.txt", false)
355
+ end
356
+
357
+ #
358
+ # translate tests
359
+ #
360
+
361
+ def test_translate
362
+ assert_equal "./root/another/file.txt", ifs.translate("./root/dir/file.txt", :dir, :another)
363
+ assert_equal "./root/another/nested/file.txt", ifs.translate("./root/dir/nested/file.txt", :dir, :another)
364
+ end
365
+
366
+ #
367
+ # glob tests
368
+ #
369
+
370
+ def test_glob_returns_all_files_matching_pattern
371
+ assert_equal Dir.glob(File.join(root, '*')), rfs.glob(:root, "*")
372
+ assert_equal Dir.glob(File.join(root, '*.txt')), rfs.glob(:root, "*.txt")
373
+ assert_equal Dir.glob(File.join(root, 'lib/*')), rfs.glob(:lib, "*")
374
+ end
375
+
376
+ def test_default_glob_pattern_is_all_files_and_folders
377
+ assert_equal Dir.glob(File.join(root, '**/*')), rfs.glob(:root)
378
+ end
379
+
380
+ def test_glob_using_multiple_patterns
381
+ yml_files = Dir.glob(File.join(root, '**/*.yml'))
382
+ txt_files = Dir.glob(File.join(root, '**/*.txt'))
383
+
384
+ assert_equal(
385
+ (yml_files + txt_files).sort,
386
+ rfs.glob(:root, "**/*.yml", "**/*.txt").sort)
387
+ end
388
+
389
+ #
390
+ # vglob tests
391
+ #
392
+
393
+ def test_vglob_returns_all_versions_matching_file_and_version_pattern
394
+ assert_equal 4, Dir.glob(File.join(root, 'versions/*')).length
395
+
396
+ assert_equal 3, Dir.glob(File.join(root, 'versions/file*.yml')).length
397
+ assert_equal Dir.glob(File.join(root, 'versions/file*.yml')), rfs.vglob(:versions, 'file.yml', '*')
398
+
399
+ assert_equal 2, Dir.glob(File.join(root, 'versions/file-0.1*.yml')).length
400
+ assert_equal Dir.glob(File.join(root, 'versions/file-0.1*.yml')), rfs.vglob(:versions, 'file.yml', "0.1*")
401
+
402
+ assert_equal 1, Dir.glob(File.join(root, 'versions/file-0.1.yml')).length
403
+ assert_equal Dir.glob(File.join(root, 'versions/file-0.1.yml')), rfs.vglob(:versions, 'file.yml', "0.1")
404
+
405
+ assert_equal 0, Dir.glob(File.join(root, 'versions/file-2.yml')).length
406
+ assert_equal [], rfs.vglob(:versions, 'file.yml', "2")
407
+ end
408
+
409
+ def test_default_vglob_pattern_is_all_versions
410
+ assert_equal Dir.glob(File.join(root, 'versions/file-*.yml')) + [File.join(root, 'versions/file.yml')], rfs.vglob(:versions, 'file.yml')
411
+ end
412
+
413
+ def test_nil_vglob_pattern_matches_the_no_version_file
414
+ assert_equal [File.join(root, 'versions/file.yml')], rfs.vglob(:versions, 'file.yml', nil)
415
+ assert_equal [File.join(root, 'versions/file.yml')], rfs.vglob(:versions, 'file.yml', '')
416
+ end
417
+
418
+ def test_vglob_using_multiple_verson_patterns
419
+ expected = [
420
+ File.join(root, 'versions/file-0.1.2.yml'),
421
+ File.join(root, 'versions/file-0.1.yml')]
422
+
423
+ assert_equal expected, rfs.vglob(:versions, "file.yml", "0.1.2", "0.1")
424
+ end
425
+
426
+ def test_vglob_filters_for_unique_files
427
+ expected = [File.join(root, 'versions/file-0.1.2.yml')]
428
+
429
+ assert_equal expected, rfs.vglob(:versions, "file.yml", "0.1.2", "0.1.*")
430
+ end
431
+
432
+
433
+ #
434
+ # mtime tests
435
+ #
436
+
437
+ def test_mtime_returns_timestamp_of_most_recently_modifed_file_under_dir
438
+ not_in_dir = File.join(root, 'one.txt')
439
+ older_in_dir = File.join(root, 'mtime', 'older.txt')
440
+ newer_in_dir = File.join(root, 'mtime', 'newer.txt')
441
+ assert !File.exists?(newer_in_dir)
442
+
443
+ begin
444
+ File.open(newer_in_dir, 'w') {|f| f << "newer"}
445
+
446
+ files = [not_in_dir, older_in_dir, newer_in_dir]
447
+ assert_equal File.mtime(newer_in_dir), rfs.mtime('mtime', *files)
448
+ assert_equal File.mtime(newer_in_dir), rfs.mtime('mtime', *files.reverse)
449
+ ensure
450
+ File.delete(newer_in_dir) if File.exists?(newer_in_dir)
451
+ end
452
+ end
453
+
454
+ def test_mtime_returns_nil_if_no_files_are_under_dir
455
+ not_in_dir = File.join(root, 'one.txt')
456
+ assert_equal nil, rfs.mtime('mtime', not_in_dir)
457
+ end
458
+
459
+ #
460
+ # MISSING! open, write_to, read_from tests
461
+ #
462
+
463
+ #
464
+ # mkpaths tests
465
+ #
466
+
467
+ def test_mkpaths
468
+ root_dir = File.join(root, "mkpath_test")
469
+ rfs = Tap::Root.new(root_dir, :config => 'config')
470
+
471
+ assert !File.exists?(rfs[:root])
472
+ assert !File.exists?(rfs[:config])
473
+
474
+ begin
475
+ rfs.mkpaths
476
+
477
+ assert File.exists?(rfs[:root])
478
+ assert File.exists?(rfs[:config])
479
+ ensure
480
+ FileUtils.rm_r(root_dir)
481
+ end
482
+ end
483
+ end