tap 0.8.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Basic Overview +151 -0
- data/Command Reference +99 -0
- data/History +24 -0
- data/MIT-LICENSE +1 -1
- data/README +29 -57
- data/Rakefile +30 -37
- data/Tutorial +243 -191
- data/bin/tap +66 -35
- data/lib/tap.rb +47 -29
- data/lib/tap/app.rb +700 -342
- data/lib/tap/{script → cmd}/console.rb +0 -0
- data/lib/tap/{script → cmd}/destroy.rb +0 -0
- data/lib/tap/{script → cmd}/generate.rb +0 -0
- data/lib/tap/cmd/run.rb +156 -0
- data/lib/tap/constants.rb +4 -0
- data/lib/tap/dump.rb +57 -0
- data/lib/tap/env.rb +316 -0
- data/lib/tap/file_task.rb +106 -109
- data/lib/tap/generator.rb +4 -1
- data/lib/tap/generator/generators/command/USAGE +6 -0
- data/lib/tap/generator/generators/command/command_generator.rb +17 -0
- data/lib/tap/generator/generators/{script/templates/script.erb → command/templates/command.erb} +10 -10
- data/lib/tap/generator/generators/config/USAGE +21 -0
- data/lib/tap/generator/generators/config/config_generator.rb +17 -7
- data/lib/tap/generator/generators/file_task/USAGE +3 -0
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +16 -0
- data/lib/tap/generator/generators/file_task/templates/file.txt +2 -0
- data/lib/tap/generator/generators/file_task/templates/file.yml +3 -0
- data/lib/tap/generator/generators/file_task/templates/task.erb +26 -20
- data/lib/tap/generator/generators/file_task/templates/test.erb +20 -10
- data/lib/tap/generator/generators/generator/generator_generator.rb +1 -1
- data/lib/tap/generator/generators/generator/templates/generator.erb +21 -12
- data/lib/tap/generator/generators/root/templates/Rakefile +33 -24
- data/lib/tap/generator/generators/root/templates/tap.yml +28 -31
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +1 -0
- data/lib/tap/generator/generators/task/USAGE +3 -0
- data/lib/tap/generator/generators/task/task_generator.rb +18 -5
- data/lib/tap/generator/generators/task/templates/task.erb +7 -12
- data/lib/tap/generator/generators/task/templates/test.erb +10 -11
- data/lib/tap/generator/generators/workflow/templates/task.erb +1 -1
- data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
- data/lib/tap/patches/rake/rake_test_loader.rb +8 -0
- data/lib/tap/patches/rake/testtask.rb +55 -0
- data/lib/tap/patches/ruby19/backtrace_filter.rb +51 -0
- data/lib/tap/patches/ruby19/parsedate.rb +16 -0
- data/lib/tap/root.rb +172 -67
- data/lib/tap/script.rb +70 -336
- data/lib/tap/support/aggregator.rb +55 -0
- data/lib/tap/support/audit.rb +281 -280
- data/lib/tap/support/batchable.rb +59 -0
- data/lib/tap/support/class_configuration.rb +279 -0
- data/lib/tap/support/configurable.rb +92 -0
- data/lib/tap/support/configurable_methods.rb +296 -0
- data/lib/tap/support/executable.rb +98 -0
- data/lib/tap/support/executable_queue.rb +82 -0
- data/lib/tap/support/logger.rb +9 -15
- data/lib/tap/support/rake.rb +43 -54
- data/lib/tap/support/run_error.rb +32 -13
- data/lib/tap/support/shell_utils.rb +47 -0
- data/lib/tap/support/tdoc.rb +9 -8
- data/lib/tap/support/tdoc/config_attr.rb +40 -16
- data/lib/tap/support/validation.rb +77 -0
- data/lib/tap/support/versions.rb +36 -36
- data/lib/tap/task.rb +276 -482
- data/lib/tap/test.rb +20 -261
- data/lib/tap/test/env_vars.rb +7 -5
- data/lib/tap/test/file_methods.rb +126 -121
- data/lib/tap/test/subset_methods.rb +86 -45
- data/lib/tap/test/tap_methods.rb +271 -0
- data/lib/tap/workflow.rb +174 -46
- data/test/app/config/another/task.yml +1 -0
- data/test/app/config/erb.yml +2 -1
- data/test/app/config/some/task.yml +1 -0
- data/test/app/config/template.yml +2 -6
- data/test/app_test.rb +1241 -1008
- data/test/env/test_configure/recurse_a.yml +2 -0
- data/test/env/test_configure/recurse_b.yml +2 -0
- data/test/env/test_configure/tap.yml +23 -0
- data/test/env/test_load_env_config/dir/tap.yml +3 -0
- data/test/env/test_load_env_config/recurse_a.yml +2 -0
- data/test/env/test_load_env_config/recurse_b.yml +2 -0
- data/test/env/test_load_env_config/tap.yml +3 -0
- data/test/env_test.rb +198 -0
- data/test/file_task_test.rb +70 -53
- data/{lib/tap/generator/generators/package/USAGE → test/root/file.txt} +0 -0
- data/test/root_test.rb +621 -454
- data/test/script_test.rb +38 -174
- data/test/support/aggregator_test.rb +99 -0
- data/test/support/audit_test.rb +409 -416
- data/test/support/batchable_test.rb +74 -0
- data/test/support/{task_configuration_test.rb → class_configuration_test.rb} +106 -47
- data/test/{task/config/overriding.yml → support/configurable/config/configured.yml} +0 -0
- data/test/support/configurable_test.rb +295 -0
- data/test/support/executable_queue_test.rb +103 -0
- data/test/support/executable_test.rb +38 -0
- data/test/support/logger_test.rb +17 -17
- data/test/support/rake_test.rb +4 -2
- data/test/support/shell_utils_test.rb +24 -0
- data/test/support/tdoc_test.rb +265 -258
- data/test/support/validation_test.rb +54 -0
- data/test/support/versions_test.rb +38 -38
- data/test/tap_test_helper.rb +19 -5
- data/test/tap_test_suite.rb +5 -2
- data/test/task_base_test.rb +13 -104
- data/test/task_syntax_test.rb +300 -0
- data/test/task_test.rb +258 -381
- data/test/test/env_vars_test.rb +40 -40
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/one.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/two.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/one.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/two.txt +0 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/one.txt +0 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/two.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/one.txt +1 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_different_content}/expected/two.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/input/two.txt +1 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_missing_expected_file}/expected/one.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/two.txt +1 -0
- data/test/test/file_methods_doc/test_sub/expected/one.txt +1 -0
- data/test/test/file_methods_doc/test_sub/expected/two.txt +1 -0
- data/test/test/file_methods_doc/test_sub/input/one.txt +1 -0
- data/test/test/file_methods_doc/test_sub/input/two.txt +1 -0
- data/test/test/file_methods_doc_test.rb +29 -0
- data/test/test/file_methods_test.rb +214 -143
- data/test/test/subset_methods_test.rb +111 -115
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/a.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/b.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/a.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/b.txt +0 -0
- data/test/test/tap_methods_test.rb +399 -0
- data/test/workflow_test.rb +101 -91
- metadata +86 -70
- data/lib/tap/generator/generators/package/package_generator.rb +0 -38
- data/lib/tap/generator/generators/package/templates/package.erb +0 -186
- data/lib/tap/generator/generators/script/USAGE +0 -0
- data/lib/tap/generator/generators/script/script_generator.rb +0 -17
- data/lib/tap/script/run.rb +0 -154
- data/lib/tap/support/batch_queue.rb +0 -162
- data/lib/tap/support/combinator.rb +0 -114
- data/lib/tap/support/task_configuration.rb +0 -169
- data/lib/tap/support/template.rb +0 -81
- data/lib/tap/support/templater.rb +0 -155
- data/lib/tap/version.rb +0 -4
- data/test/app/config/addition_template.yml +0 -6
- data/test/app_class_test.rb +0 -33
- data/test/check/binding_eval.rb +0 -23
- data/test/check/define_method_check.rb +0 -22
- data/test/check/dependencies_check.rb +0 -175
- data/test/check/inheritance_check.rb +0 -22
- data/test/support/batch_queue_test.rb +0 -320
- data/test/support/combinator_test.rb +0 -249
- data/test/support/template_test.rb +0 -122
- data/test/support/templater/erb.txt +0 -2
- data/test/support/templater/erb.yml +0 -2
- data/test/support/templater/somefile.txt +0 -2
- data/test/support/templater_test.rb +0 -192
- data/test/task/config/template.yml +0 -4
- data/test/task_class_test.rb +0 -170
- data/test/task_execute_test.rb +0 -262
- data/test/test/file_methods/test_assert_expected/expected/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/expected/folder/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/input/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/input/folder/file.txt +0 -1
- 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_file_compare/expected/output_1.txt +0 -3
- data/test/test/file_methods/test_file_compare/expected/output_2.txt +0 -1
- data/test/test/file_methods/test_file_compare/input/input_1.txt +0 -3
- data/test/test/file_methods/test_file_compare/input/input_2.txt +0 -3
- 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_yml_compare/expected/output_1.yml +0 -6
- data/test/test/file_methods/test_yml_compare/expected/output_2.yml +0 -6
- data/test/test/file_methods/test_yml_compare/input/input_1.yml +0 -4
- data/test/test/file_methods/test_yml_compare/input/input_2.yml +0 -4
- data/test/test_test.rb +0 -373
|
File without changes
|
data/test/root_test.rb
CHANGED
|
@@ -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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
26
|
-
assert_equal
|
|
27
|
-
assert_equal
|
|
28
|
-
|
|
29
|
-
#
|
|
30
|
-
assert_equal
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
assert_equal 4, Dir.glob(File.join(
|
|
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(
|
|
93
|
-
assert_equal Dir.glob(
|
|
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(
|
|
96
|
-
assert_equal Dir.glob(
|
|
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(
|
|
99
|
-
assert_equal Dir.glob(
|
|
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(
|
|
102
|
-
assert_equal [], Tap::Root.vglob(
|
|
103
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
194
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
r = Tap::Root.new
|
|
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
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
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
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
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
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
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
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
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
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
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
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
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
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
r = Tap::Root.new
|
|
371
|
-
|
|
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[
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
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
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
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
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
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
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
assert_equal 4, Dir.glob(File.join(
|
|
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(
|
|
516
|
-
assert_equal Dir.glob(File.join(
|
|
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(
|
|
519
|
-
assert_equal Dir.glob(File.join(
|
|
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(
|
|
522
|
-
assert_equal Dir.glob(File.join(
|
|
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(
|
|
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
|
-
|
|
681
|
+
end
|
|
527
682
|
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
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
|
-
|
|
535
|
-
assert_equal [File.join(
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
File.join(
|
|
541
|
-
File.join(
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
end
|
|
545
|
-
|
|
546
|
-
def test_vglob_filters_for_unique_files
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
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
|