tap 0.7.9 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History +28 -0
- data/MIT-LICENSE +1 -1
- data/README +71 -43
- data/Rakefile +81 -64
- data/Tutorial +235 -0
- data/bin/tap +80 -44
- data/lib/tap.rb +41 -12
- data/lib/tap/app.rb +243 -246
- data/lib/tap/file_task.rb +357 -118
- data/lib/tap/generator.rb +88 -29
- data/lib/tap/generator/generators/config/config_generator.rb +4 -2
- data/lib/tap/generator/generators/config/templates/config.erb +1 -2
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +3 -18
- data/lib/tap/generator/generators/file_task/templates/task.erb +22 -15
- data/lib/tap/generator/generators/file_task/templates/test.erb +13 -2
- data/{test/test/inference_methods/test_assert_files_exist/input/input_1.txt → lib/tap/generator/generators/generator/USAGE} +0 -0
- data/lib/tap/generator/generators/generator/generator_generator.rb +21 -0
- data/lib/tap/generator/generators/generator/templates/generator.erb +23 -0
- data/lib/tap/generator/generators/generator/templates/usage.erb +1 -0
- data/{test/test/inference_methods/test_assert_files_exist/input/input_2.txt → lib/tap/generator/generators/package/USAGE} +0 -0
- data/lib/tap/generator/generators/package/package_generator.rb +38 -0
- data/lib/tap/generator/generators/package/templates/package.erb +186 -0
- data/lib/tap/generator/generators/root/root_generator.rb +14 -9
- data/lib/tap/generator/generators/root/templates/Rakefile +20 -14
- data/{test/test/inference_methods/test_infer_glob/expected/file.yml → lib/tap/generator/generators/root/templates/ReadMe.txt} +0 -0
- data/lib/tap/generator/generators/root/templates/tap.yml +82 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +0 -1
- data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +2 -1
- data/{test/test/inference_methods/test_infer_glob/expected/file_1.txt → lib/tap/generator/generators/script/USAGE} +0 -0
- data/lib/tap/generator/generators/script/script_generator.rb +17 -0
- data/lib/tap/generator/generators/script/templates/script.erb +42 -0
- data/lib/tap/generator/generators/task/task_generator.rb +1 -1
- data/lib/tap/generator/generators/task/templates/task.erb +24 -16
- data/lib/tap/generator/generators/task/templates/test.erb +13 -17
- data/lib/tap/generator/generators/workflow/templates/task.erb +10 -10
- data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
- data/lib/tap/generator/generators/workflow/workflow_generator.rb +3 -18
- data/lib/tap/root.rb +108 -146
- data/lib/tap/script.rb +362 -0
- data/lib/tap/script/console.rb +28 -0
- data/lib/tap/script/destroy.rb +13 -1
- data/lib/tap/script/generate.rb +13 -1
- data/lib/tap/script/run.rb +100 -57
- data/lib/tap/support/batch_queue.rb +0 -3
- data/lib/tap/support/logger.rb +6 -3
- data/lib/tap/support/rake.rb +54 -0
- data/lib/tap/support/task_configuration.rb +169 -0
- data/lib/tap/support/tdoc.rb +198 -0
- data/lib/tap/support/tdoc/config_attr.rb +338 -0
- data/lib/tap/support/tdoc/tdoc_html_generator.rb +38 -0
- data/lib/tap/support/tdoc/tdoc_html_template.rb +42 -0
- data/lib/tap/support/versions.rb +33 -1
- data/lib/tap/task.rb +339 -227
- data/lib/tap/test.rb +86 -128
- data/lib/tap/test/env_vars.rb +16 -5
- data/lib/tap/test/file_methods.rb +373 -0
- data/lib/tap/test/subset_methods.rb +299 -180
- data/lib/tap/version.rb +2 -1
- data/lib/tap/workflow.rb +2 -0
- data/test/app/lib/app_test_task.rb +1 -0
- data/test/app_test.rb +327 -83
- data/test/check/binding_eval.rb +23 -0
- data/test/check/define_method_check.rb +22 -0
- data/test/check/dependencies_check.rb +175 -0
- data/test/check/inheritance_check.rb +22 -0
- data/test/file_task_test.rb +524 -291
- data/test/{test/inference_methods/test_infer_glob/expected/file_2.txt → root/glob/one.txt} +0 -0
- data/test/root/glob/two.txt +0 -0
- data/test/root_test.rb +330 -262
- data/test/script_test.rb +194 -0
- data/test/support/audit_test.rb +5 -2
- data/test/support/combinator_test.rb +10 -10
- data/test/support/rake_test.rb +35 -0
- data/test/support/task_configuration_test.rb +272 -0
- data/test/support/tdoc_test.rb +363 -0
- data/test/support/templater_test.rb +2 -2
- data/test/support/versions_test.rb +32 -0
- data/test/tap_test_helper.rb +39 -0
- data/test/task_base_test.rb +115 -0
- data/test/task_class_test.rb +56 -4
- data/test/task_execute_test.rb +29 -0
- data/test/task_test.rb +89 -70
- data/test/test/env_vars_test.rb +48 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/file.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/folder/file.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/input/file.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/input/folder/file.txt +0 -0
- data/test/test/file_methods/test_assert_files_exist/input/input_1.txt +0 -0
- data/test/test/file_methods/test_assert_files_exist/input/input_2.txt +0 -0
- data/test/test/file_methods/test_assert_output_files_equal/expected/one.txt +1 -0
- data/test/test/file_methods/test_assert_output_files_equal/expected/two.txt +1 -0
- data/test/test/file_methods/test_assert_output_files_equal/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_output_files_equal/input/two.txt +1 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_1.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_2.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_1.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_2.txt +0 -0
- data/test/test/file_methods/test_infer_glob/expected/file.yml +0 -0
- data/test/test/file_methods/test_infer_glob/expected/file_1.txt +0 -0
- data/test/test/file_methods/test_infer_glob/expected/file_2.txt +0 -0
- data/test/test/file_methods/test_method_glob/expected/file.yml +0 -0
- data/test/test/file_methods/test_method_glob/expected/file_1.txt +0 -0
- data/test/test/file_methods/test_method_glob/expected/file_2.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_1.yml +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_2.yml +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_1.yml +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_2.yml +0 -0
- data/test/test/file_methods_test.rb +204 -0
- data/test/test/subset_methods_test.rb +93 -33
- data/test/test/test_assert_expected_result_files/expected/task/name/a.txt +1 -0
- data/test/test/test_assert_expected_result_files/expected/task/name/b.txt +1 -0
- data/test/test/test_assert_expected_result_files/input/a.txt +1 -0
- data/test/test/test_assert_expected_result_files/input/b.txt +1 -0
- data/test/test/test_file_task_test/expected/one.txt +1 -0
- data/test/test/test_file_task_test/expected/two.txt +1 -0
- data/test/test/test_file_task_test/input/one.txt +1 -0
- data/test/test/test_file_task_test/input/two.txt +1 -0
- data/test/test_test.rb +143 -3
- data/test/workflow_test.rb +2 -0
- data/vendor/rails_generator.rb +56 -0
- data/vendor/rails_generator/base.rb +263 -0
- data/vendor/rails_generator/commands.rb +581 -0
- data/vendor/rails_generator/generated_attribute.rb +42 -0
- data/vendor/rails_generator/lookup.rb +209 -0
- data/vendor/rails_generator/manifest.rb +53 -0
- data/vendor/rails_generator/options.rb +143 -0
- data/vendor/rails_generator/scripts.rb +83 -0
- data/vendor/rails_generator/scripts/destroy.rb +7 -0
- data/vendor/rails_generator/scripts/generate.rb +7 -0
- data/vendor/rails_generator/scripts/update.rb +12 -0
- data/vendor/rails_generator/simple_logger.rb +46 -0
- data/vendor/rails_generator/spec.rb +44 -0
- metadata +180 -196
- data/lib/tap/generator/generators/root/templates/app.yml +0 -19
- data/lib/tap/generator/generators/root/templates/config/process_tap_request.yml +0 -4
- data/lib/tap/generator/generators/root/templates/lib/process_tap_request.rb +0 -26
- data/lib/tap/generator/generators/root/templates/public/images/nav.jpg +0 -0
- data/lib/tap/generator/generators/root/templates/public/stylesheets/color.css +0 -57
- data/lib/tap/generator/generators/root/templates/public/stylesheets/layout.css +0 -108
- data/lib/tap/generator/generators/root/templates/public/stylesheets/normalize.css +0 -40
- data/lib/tap/generator/generators/root/templates/public/stylesheets/typography.css +0 -21
- data/lib/tap/generator/generators/root/templates/server/config/environment.rb +0 -60
- data/lib/tap/generator/generators/root/templates/server/lib/tasks/clear_database_prerequisites.rake +0 -5
- data/lib/tap/generator/generators/root/templates/server/test/test_helper.rb +0 -53
- data/lib/tap/script/server.rb +0 -12
- data/lib/tap/support/rap.rb +0 -38
- data/lib/tap/test/inference_methods.rb +0 -298
- data/test/task/config/task_with_config.yml +0 -1
- data/test/test/inference_methods_test.rb +0 -311
|
File without changes
|
|
File without changes
|
data/test/root_test.rb
CHANGED
|
@@ -1,72 +1,54 @@
|
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'tap_test_helper.rb')
|
|
2
2
|
require 'tap/root'
|
|
3
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
4
|
class RootTest < Test::Unit::TestCase
|
|
13
5
|
include Tap::Test::SubsetMethods
|
|
14
6
|
|
|
15
|
-
attr_reader :
|
|
7
|
+
attr_reader :r, :tr
|
|
16
8
|
|
|
17
9
|
def setup
|
|
18
|
-
|
|
19
|
-
@
|
|
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"}
|
|
20
15
|
end
|
|
21
16
|
|
|
22
|
-
def
|
|
23
|
-
File.join(File.dirname(__FILE__), 'root')
|
|
17
|
+
def test_root
|
|
18
|
+
File.expand_path(File.join(File.dirname(__FILE__), 'root'))
|
|
24
19
|
end
|
|
25
20
|
|
|
26
21
|
def test_documentation
|
|
27
|
-
|
|
22
|
+
r = Tap::Root.new test_root, :input => 'in', :output => 'out'
|
|
28
23
|
|
|
29
24
|
# work with directories
|
|
30
|
-
assert_equal
|
|
31
|
-
assert_equal
|
|
32
|
-
assert_equal
|
|
25
|
+
assert_equal test_root + '/in', r[:in]
|
|
26
|
+
assert_equal test_root + '/out', r[:out]
|
|
27
|
+
assert_equal test_root + '/implicit', r[:implicit]
|
|
33
28
|
|
|
34
29
|
# # work with filepaths
|
|
35
|
-
assert_equal
|
|
36
|
-
assert_equal 'path/to/file.txt',
|
|
37
|
-
assert_equal
|
|
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)
|
|
38
33
|
|
|
39
34
|
# # version filepaths
|
|
40
|
-
assert_equal 'path/to/config-1.0.yml',
|
|
41
|
-
assert_equal 'path/to/config-1.1.yml',
|
|
42
|
-
assert_equal ['path/to/config.yml', "1.1"],
|
|
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')
|
|
35
|
+
assert_equal 'path/to/config-1.0.yml', r.version('path/to/config.yml', 1.0)
|
|
36
|
+
assert_equal 'path/to/config-1.1.yml', r.increment('path/to/config-1.0.yml', 0.1)
|
|
37
|
+
assert_equal ['path/to/config.yml', "1.1"], r.deversion('path/to/config-1.1.yml')
|
|
51
38
|
|
|
52
|
-
# #
|
|
53
|
-
|
|
54
|
-
|
|
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')
|
|
39
|
+
# # absolute paths can also be aliased.
|
|
40
|
+
r[:abs, true] = "/absolute/path"
|
|
41
|
+
assert_equal File.expand_path('/absolute/path/to/file.txt'), r.filepath(:abs, "to", "file.txt")
|
|
64
42
|
end
|
|
65
43
|
|
|
66
44
|
#
|
|
67
45
|
# Tap::Root relative filepath test
|
|
68
46
|
#
|
|
69
47
|
|
|
48
|
+
def test_relative_filepath_documentation
|
|
49
|
+
assert_equal "path/to/file.txt", Tap::Root.relative_filepath('dir', "dir/path/to/file.txt")
|
|
50
|
+
end
|
|
51
|
+
|
|
70
52
|
def test_class_relative_filepath
|
|
71
53
|
assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "./root/dir/file.txt")
|
|
72
54
|
assert_equal "nested/file.txt", Tap::Root.relative_filepath('./root/dir', "./root/dir/nested/file.txt")
|
|
@@ -82,46 +64,85 @@ class RootTest < Test::Unit::TestCase
|
|
|
82
64
|
assert_raise(RuntimeError) { Tap::Root.relative_filepath('dir', "./root/file.txt") }
|
|
83
65
|
end
|
|
84
66
|
|
|
85
|
-
def
|
|
86
|
-
assert_equal "
|
|
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")
|
|
82
|
+
assert_equal [], Tap::Root.glob()
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
#
|
|
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
|
|
91
|
+
|
|
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
|
|
94
|
+
|
|
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
|
|
97
|
+
|
|
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
|
|
100
|
+
|
|
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')
|
|
87
103
|
end
|
|
88
104
|
|
|
105
|
+
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
|
+
|
|
89
110
|
#
|
|
90
111
|
# initialize tests
|
|
91
112
|
#
|
|
92
113
|
|
|
93
|
-
def
|
|
94
|
-
|
|
114
|
+
def test_default_root_is_expanded_dir_pwd
|
|
115
|
+
r = Tap::Root.new
|
|
95
116
|
|
|
96
|
-
assert_equal Dir.pwd,
|
|
97
|
-
assert_equal({},
|
|
117
|
+
assert_equal File.expand_path(Dir.pwd), r.root
|
|
118
|
+
assert_equal({}, r.directories)
|
|
98
119
|
end
|
|
99
120
|
|
|
100
121
|
def test_initialize_root
|
|
101
|
-
|
|
122
|
+
r = Tap::Root.new "./root", {:dir => "dir", :temp => "tmp"}, {:abs => "/abs/path"}
|
|
102
123
|
|
|
103
|
-
assert_equal "./root",
|
|
104
|
-
assert_equal({:dir => "dir", :temp => "tmp"},
|
|
105
|
-
assert_equal({:abs => "/abs/path"},
|
|
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)
|
|
106
127
|
assert_equal({
|
|
107
|
-
'root' => "./root",
|
|
108
|
-
:root =>
|
|
109
|
-
:dir =>
|
|
110
|
-
:temp => "./root/tmp",
|
|
111
|
-
:abs =>
|
|
112
|
-
|
|
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)
|
|
113
134
|
end
|
|
114
135
|
|
|
115
|
-
def
|
|
116
|
-
|
|
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')
|
|
117
138
|
|
|
118
139
|
assert_equal({
|
|
119
|
-
'root' => "./root",
|
|
120
|
-
:root =>
|
|
121
|
-
'dir' =>
|
|
122
|
-
:dir =>
|
|
123
|
-
1 =>
|
|
124
|
-
|
|
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)
|
|
125
146
|
end
|
|
126
147
|
|
|
127
148
|
#
|
|
@@ -129,50 +150,60 @@ class RootTest < Test::Unit::TestCase
|
|
|
129
150
|
#
|
|
130
151
|
|
|
131
152
|
def test_set_root_resets_paths
|
|
132
|
-
|
|
153
|
+
r.root = './another'
|
|
133
154
|
|
|
134
|
-
assert_equal "./another",
|
|
135
|
-
assert_equal({:dir => "dir"},
|
|
155
|
+
assert_equal File.expand_path("./another"), r.root
|
|
156
|
+
assert_equal({:dir => "dir"}, r.directories)
|
|
136
157
|
assert_equal({
|
|
137
|
-
'root' => "./another",
|
|
138
|
-
:root =>
|
|
139
|
-
:dir =>
|
|
140
|
-
:abs =>
|
|
141
|
-
|
|
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)
|
|
142
163
|
end
|
|
143
164
|
|
|
144
165
|
def test_root_cannot_be_set_through_index
|
|
145
|
-
assert_raise(ArgumentError) {
|
|
166
|
+
assert_raise(ArgumentError) { r['root'] = './another' }
|
|
146
167
|
end
|
|
147
168
|
|
|
148
169
|
#
|
|
149
170
|
# set directories tests
|
|
150
171
|
#
|
|
151
|
-
|
|
172
|
+
|
|
152
173
|
def test_set_directories
|
|
153
|
-
|
|
174
|
+
r.directories = {:alt => "dir"}
|
|
154
175
|
|
|
155
|
-
assert_equal({:alt => "dir"},
|
|
156
|
-
assert_equal({
|
|
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)
|
|
157
183
|
end
|
|
158
184
|
|
|
159
185
|
def test_raise_error_when_trying_to_set_root_through_directories
|
|
160
|
-
assert_raise(ArgumentError) {
|
|
186
|
+
assert_raise(ArgumentError) { r.directories = {'root' => "another"} }
|
|
161
187
|
end
|
|
162
188
|
|
|
163
189
|
#
|
|
164
190
|
# set absolute paths test
|
|
165
191
|
#
|
|
166
|
-
|
|
192
|
+
|
|
167
193
|
def test_set_absolute_paths
|
|
168
|
-
|
|
194
|
+
r.absolute_paths = {:absolute => "/absolute/path"}
|
|
169
195
|
|
|
170
|
-
assert_equal({:dir => "dir"},
|
|
171
|
-
assert_equal({
|
|
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)
|
|
172
203
|
end
|
|
173
204
|
|
|
174
205
|
def test_raise_error_when_trying_to_set_root_through_absolute_paths
|
|
175
|
-
assert_raise(ArgumentError) {
|
|
206
|
+
assert_raise(ArgumentError) { r.absolute_paths = {'root' => "another"} }
|
|
176
207
|
end
|
|
177
208
|
|
|
178
209
|
#
|
|
@@ -180,124 +211,194 @@ class RootTest < Test::Unit::TestCase
|
|
|
180
211
|
#
|
|
181
212
|
|
|
182
213
|
def test_absolute_paths_returns_all_non_root_paths_with_no_directory
|
|
183
|
-
assert_equal({:abs => "/abs/path"},
|
|
214
|
+
assert_equal({:abs => File.expand_path("/abs/path")}, r.absolute_paths)
|
|
184
215
|
|
|
185
|
-
|
|
186
|
-
assert_equal({
|
|
216
|
+
r.paths[:another] = File.expand_path("/another/path")
|
|
217
|
+
assert_equal({
|
|
218
|
+
:abs => File.expand_path("/abs/path"),
|
|
219
|
+
:another => File.expand_path("/another/path")},
|
|
220
|
+
r.absolute_paths)
|
|
187
221
|
end
|
|
188
222
|
|
|
189
223
|
#
|
|
190
|
-
#
|
|
224
|
+
# assignment tests
|
|
191
225
|
#
|
|
192
226
|
|
|
193
|
-
def
|
|
194
|
-
|
|
227
|
+
def test_assignment_documentation
|
|
228
|
+
r = Tap::Root.new test_root
|
|
229
|
+
r[:dir] = 'path/to/dir'
|
|
230
|
+
assert_equal test_root + '/path/to/dir', r[:dir]
|
|
231
|
+
|
|
232
|
+
r[:abs, true] = '/abs/path/to/dir'
|
|
233
|
+
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'
|
|
195
238
|
|
|
196
|
-
assert_equal({:dir => "another"},
|
|
239
|
+
assert_equal({:dir => "another"}, r.directories)
|
|
197
240
|
assert_equal({
|
|
198
|
-
'root' => "./root",
|
|
199
|
-
:root =>
|
|
200
|
-
:dir =>
|
|
201
|
-
:abs =>
|
|
202
|
-
|
|
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)
|
|
203
246
|
end
|
|
204
247
|
|
|
205
|
-
def
|
|
206
|
-
|
|
248
|
+
def test_set_new_directory_using_assignment
|
|
249
|
+
r[:new] = 'new'
|
|
207
250
|
|
|
208
|
-
assert_equal({:dir => "dir", :new => "new"},
|
|
251
|
+
assert_equal({:dir => "dir", :new => "new"}, r.directories)
|
|
209
252
|
assert_equal({
|
|
210
|
-
'root' => "./root",
|
|
211
|
-
:root =>
|
|
212
|
-
:dir =>
|
|
213
|
-
:abs =>
|
|
214
|
-
:new =>
|
|
215
|
-
|
|
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)
|
|
216
259
|
end
|
|
217
260
|
|
|
218
261
|
def test_absolute_paths_can_be_set_by_specifiying_absolute_true
|
|
219
|
-
|
|
262
|
+
r[:absolute, true] = '/some/absolute/path'
|
|
220
263
|
|
|
221
|
-
assert_equal({:dir => "dir"},
|
|
264
|
+
assert_equal({:dir => "dir"}, r.directories)
|
|
222
265
|
assert_equal({
|
|
223
|
-
'root' => "./root",
|
|
224
|
-
:root =>
|
|
225
|
-
:dir =>
|
|
226
|
-
:abs =>
|
|
227
|
-
:absolute => '/some/absolute/path'},
|
|
228
|
-
|
|
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)
|
|
229
272
|
end
|
|
230
273
|
|
|
231
274
|
def test_an_absolute_path_is_not_set_if_absolute_false
|
|
232
|
-
|
|
275
|
+
r[:not_absolute, false] = 'not/an/absolute/path'
|
|
233
276
|
|
|
234
|
-
assert_equal({:dir => "dir", :not_absolute => "not/an/absolute/path"},
|
|
277
|
+
assert_equal({:dir => "dir", :not_absolute => "not/an/absolute/path"}, r.directories)
|
|
235
278
|
assert_equal({
|
|
236
|
-
'root' => "./root",
|
|
237
|
-
:root =>
|
|
238
|
-
:dir =>
|
|
239
|
-
:abs =>
|
|
240
|
-
:not_absolute => "./root/not/an/absolute/path"},
|
|
241
|
-
|
|
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)
|
|
242
285
|
end
|
|
243
286
|
|
|
244
287
|
def test_paths_can_be_unset_with_nil
|
|
245
288
|
# Non-absolute path
|
|
246
|
-
|
|
247
|
-
assert_equal({:dir => "/some/path"},
|
|
248
|
-
assert_equal({
|
|
289
|
+
r[:dir] = '/some/path'
|
|
290
|
+
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)
|
|
249
297
|
|
|
250
|
-
|
|
251
|
-
assert_equal({},
|
|
252
|
-
assert_equal({
|
|
298
|
+
r[:dir] = nil
|
|
299
|
+
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)
|
|
253
305
|
|
|
254
|
-
#
|
|
255
|
-
|
|
256
|
-
assert_equal({:dir => "/some/path"},
|
|
257
|
-
assert_equal({
|
|
306
|
+
# the same with absolute specified
|
|
307
|
+
r[:dir] = '/some/path'
|
|
308
|
+
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")},
|
|
314
|
+
r.paths)
|
|
258
315
|
|
|
259
|
-
|
|
260
|
-
assert_equal({},
|
|
261
|
-
assert_equal({
|
|
316
|
+
r[:dir, false] = nil
|
|
317
|
+
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)
|
|
262
323
|
|
|
263
324
|
# Absolute path
|
|
264
|
-
|
|
265
|
-
assert_equal({},
|
|
266
|
-
assert_equal({
|
|
325
|
+
r[:abs, true] = '/some/absolute/path'
|
|
326
|
+
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)
|
|
267
332
|
|
|
268
|
-
|
|
269
|
-
assert_equal({},
|
|
270
|
-
assert_equal({
|
|
333
|
+
r[:abs, true] = nil
|
|
334
|
+
assert_equal({}, r.directories)
|
|
335
|
+
assert_equal({
|
|
336
|
+
'root' => File.expand_path("./root"),
|
|
337
|
+
:root => File.expand_path("./root")},
|
|
338
|
+
r.paths)
|
|
271
339
|
|
|
272
|
-
#
|
|
273
|
-
|
|
274
|
-
assert_equal({},
|
|
275
|
-
assert_equal({
|
|
340
|
+
# the same with absolute unspecfied
|
|
341
|
+
r[:abs, true] = '/some/absolute/path'
|
|
342
|
+
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')},
|
|
347
|
+
r.paths)
|
|
276
348
|
|
|
277
|
-
|
|
278
|
-
assert_equal({},
|
|
279
|
-
assert_equal({
|
|
349
|
+
r[:abs] = nil
|
|
350
|
+
assert_equal({}, r.directories)
|
|
351
|
+
assert_equal({
|
|
352
|
+
'root' => File.expand_path("./root"),
|
|
353
|
+
:root => File.expand_path("./root")},
|
|
354
|
+
r.paths)
|
|
280
355
|
end
|
|
281
356
|
|
|
357
|
+
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
|
+
|
|
282
365
|
#
|
|
283
366
|
# retrieve path tests
|
|
284
367
|
#
|
|
285
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]
|
|
373
|
+
|
|
374
|
+
r[:unset] = nil
|
|
375
|
+
assert_equal test_root + '/unset', r[:unset]
|
|
376
|
+
end
|
|
377
|
+
|
|
286
378
|
def test_retrieve_paths
|
|
287
|
-
|
|
288
|
-
:dir =>
|
|
289
|
-
:root =>
|
|
290
|
-
'root' => "./root",
|
|
291
|
-
:abs => "/abs/path"
|
|
292
|
-
|
|
293
|
-
assert_equal expected,
|
|
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]
|
|
294
386
|
end
|
|
295
387
|
end
|
|
296
388
|
|
|
297
|
-
def
|
|
298
|
-
assert_equal({
|
|
299
|
-
|
|
300
|
-
|
|
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']
|
|
301
402
|
end
|
|
302
403
|
|
|
303
404
|
#
|
|
@@ -305,16 +406,22 @@ class RootTest < Test::Unit::TestCase
|
|
|
305
406
|
#
|
|
306
407
|
|
|
307
408
|
def test_filepath
|
|
308
|
-
assert_equal "./root/dir",
|
|
309
|
-
assert_equal "./root/dir/file.txt",
|
|
310
|
-
assert_equal "./root/dir/nested/file.txt",
|
|
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")
|
|
311
412
|
end
|
|
312
413
|
|
|
313
414
|
def test_filepath_when_path_is_not_set
|
|
314
|
-
assert_equal "./root/not_set/file.txt",
|
|
315
|
-
assert_equal "./root/folder/subfolder/file.txt",
|
|
316
|
-
|
|
317
|
-
assert_equal "./root/folder/subfolder/file.txt",
|
|
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")
|
|
318
425
|
end
|
|
319
426
|
|
|
320
427
|
#
|
|
@@ -322,45 +429,57 @@ class RootTest < Test::Unit::TestCase
|
|
|
322
429
|
#
|
|
323
430
|
|
|
324
431
|
def test_relative_filepath
|
|
325
|
-
assert_equal "file.txt",
|
|
326
|
-
assert_equal "nested/file.txt",
|
|
327
|
-
assert_equal "file.txt",
|
|
328
|
-
assert_equal "file.txt",
|
|
329
|
-
assert_equal "file.txt",
|
|
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")
|
|
330
437
|
end
|
|
331
438
|
|
|
332
439
|
def test_relative_filepath_when_path_equals_input
|
|
333
|
-
assert_equal "",
|
|
334
|
-
assert_equal "",
|
|
440
|
+
assert_equal "", r.relative_filepath(:dir, "./root/dir")
|
|
441
|
+
assert_equal "", r.relative_filepath(:dir, "./root/dir/")
|
|
335
442
|
end
|
|
336
443
|
|
|
337
444
|
def test_relative_filepath_expands_paths
|
|
338
|
-
assert_equal "file.txt",
|
|
339
|
-
assert_equal "file.txt",
|
|
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")
|
|
340
447
|
end
|
|
341
448
|
|
|
342
449
|
def test_relative_filepath_when_path_is_not_set
|
|
343
|
-
assert_equal "file.txt",
|
|
344
|
-
assert_equal "file.txt",
|
|
345
|
-
assert_equal "file.txt",
|
|
346
|
-
assert_equal "file.txt",
|
|
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")
|
|
347
454
|
end
|
|
348
455
|
|
|
349
|
-
def
|
|
350
|
-
assert_raise(RuntimeError) {
|
|
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") }
|
|
351
458
|
end
|
|
352
459
|
|
|
353
|
-
def
|
|
354
|
-
assert_equal "
|
|
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)
|
|
355
462
|
end
|
|
356
463
|
|
|
357
464
|
#
|
|
358
465
|
# translate tests
|
|
359
466
|
#
|
|
360
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
|
|
473
|
+
assert_equal File.expand_path('/root_dir/out/path/to/file.txt'), r.translate(fp, :in, :out)
|
|
474
|
+
end
|
|
475
|
+
|
|
361
476
|
def test_translate
|
|
362
|
-
assert_equal "./root/another/file.txt",
|
|
363
|
-
assert_equal "./root/another/nested/file.txt",
|
|
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) }
|
|
364
483
|
end
|
|
365
484
|
|
|
366
485
|
#
|
|
@@ -368,22 +487,22 @@ class RootTest < Test::Unit::TestCase
|
|
|
368
487
|
#
|
|
369
488
|
|
|
370
489
|
def test_glob_returns_all_files_matching_pattern
|
|
371
|
-
assert_equal Dir.glob(File.join(
|
|
372
|
-
assert_equal Dir.glob(File.join(
|
|
373
|
-
assert_equal Dir.glob(File.join(
|
|
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, "*")
|
|
374
493
|
end
|
|
375
494
|
|
|
376
495
|
def test_default_glob_pattern_is_all_files_and_folders
|
|
377
|
-
assert_equal Dir.glob(File.join(
|
|
496
|
+
assert_equal Dir.glob(File.join(test_root, '**/*')), tr.glob(:root)
|
|
378
497
|
end
|
|
379
498
|
|
|
380
499
|
def test_glob_using_multiple_patterns
|
|
381
|
-
yml_files = Dir.glob(File.join(
|
|
382
|
-
txt_files = Dir.glob(File.join(
|
|
500
|
+
yml_files = Dir.glob(File.join(test_root, '**/*.yml'))
|
|
501
|
+
txt_files = Dir.glob(File.join(test_root, '**/*.txt'))
|
|
383
502
|
|
|
384
503
|
assert_equal(
|
|
385
504
|
(yml_files + txt_files).sort,
|
|
386
|
-
|
|
505
|
+
tr.glob(:root, "**/*.yml", "**/*.txt").sort)
|
|
387
506
|
end
|
|
388
507
|
|
|
389
508
|
#
|
|
@@ -391,93 +510,42 @@ class RootTest < Test::Unit::TestCase
|
|
|
391
510
|
#
|
|
392
511
|
|
|
393
512
|
def test_vglob_returns_all_versions_matching_file_and_version_pattern
|
|
394
|
-
assert_equal 4, Dir.glob(File.join(
|
|
513
|
+
assert_equal 4, Dir.glob(File.join(test_root, 'versions/*')).length
|
|
395
514
|
|
|
396
|
-
assert_equal 3, Dir.glob(File.join(
|
|
397
|
-
assert_equal Dir.glob(File.join(
|
|
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
|
|
398
517
|
|
|
399
|
-
assert_equal 2, Dir.glob(File.join(
|
|
400
|
-
assert_equal Dir.glob(File.join(
|
|
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
|
|
401
520
|
|
|
402
|
-
assert_equal 1, Dir.glob(File.join(
|
|
403
|
-
assert_equal Dir.glob(File.join(
|
|
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
|
|
404
523
|
|
|
405
|
-
assert_equal 0, Dir.glob(File.join(
|
|
406
|
-
assert_equal [],
|
|
524
|
+
assert_equal 0, Dir.glob(File.join(test_root, 'versions/file-2.yml')).length
|
|
525
|
+
assert_equal [], tr.vglob(:versions, 'file.yml', "2")
|
|
407
526
|
end
|
|
408
527
|
|
|
409
528
|
def test_default_vglob_pattern_is_all_versions
|
|
410
|
-
|
|
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
|
|
411
531
|
end
|
|
412
532
|
|
|
413
533
|
def test_nil_vglob_pattern_matches_the_no_version_file
|
|
414
|
-
assert_equal [File.join(
|
|
415
|
-
assert_equal [File.join(
|
|
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', '')
|
|
416
536
|
end
|
|
417
537
|
|
|
418
538
|
def test_vglob_using_multiple_verson_patterns
|
|
419
539
|
expected = [
|
|
420
|
-
File.join(
|
|
421
|
-
File.join(
|
|
540
|
+
File.join(test_root, 'versions/file-0.1.2.yml'),
|
|
541
|
+
File.join(test_root, 'versions/file-0.1.yml')]
|
|
422
542
|
|
|
423
|
-
assert_equal expected,
|
|
543
|
+
assert_equal expected.sort, tr.vglob(:versions, "file.yml", "0.1.2", "0.1").sort
|
|
424
544
|
end
|
|
425
545
|
|
|
426
546
|
def test_vglob_filters_for_unique_files
|
|
427
|
-
expected = [File.join(
|
|
547
|
+
expected = [File.join(test_root, 'versions/file-0.1.2.yml')]
|
|
428
548
|
|
|
429
|
-
assert_equal expected,
|
|
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)
|
|
549
|
+
assert_equal expected, tr.vglob(:versions, "file.yml", "0.1.2", "0.1.*")
|
|
457
550
|
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
551
|
end
|