tap 0.9.1 → 0.10.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 +37 -30
- data/MIT-LICENSE +1 -1
- data/README +92 -44
- data/bin/tap +62 -75
- data/cmd/console.rb +42 -0
- data/cmd/destroy.rb +16 -0
- data/cmd/generate.rb +16 -0
- data/cmd/run.rb +126 -0
- data/doc/Class Reference +362 -0
- data/doc/Command Reference +153 -0
- data/doc/Tutorial +237 -0
- data/lib/tap.rb +6 -45
- data/lib/tap/app.rb +126 -500
- data/lib/tap/constants.rb +2 -29
- data/lib/tap/env.rb +555 -250
- data/lib/tap/file_task.rb +60 -103
- data/lib/tap/generator/base.rb +109 -0
- data/lib/tap/generator/destroy.rb +37 -0
- data/lib/tap/generator/generate.rb +61 -0
- data/lib/tap/generator/generators/command/command_generator.rb +16 -12
- data/lib/tap/generator/generators/command/templates/command.erb +13 -19
- data/lib/tap/generator/generators/config/config_generator.rb +18 -27
- data/lib/tap/generator/generators/config/templates/doc.erb +12 -0
- data/lib/tap/generator/generators/config/templates/nodoc.erb +8 -0
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +16 -11
- data/lib/tap/generator/generators/file_task/templates/file.txt +11 -2
- data/lib/tap/generator/generators/file_task/templates/result.yml +6 -0
- data/lib/tap/generator/generators/file_task/templates/task.erb +24 -31
- data/lib/tap/generator/generators/file_task/templates/test.erb +18 -22
- data/lib/tap/generator/generators/root/root_generator.rb +45 -31
- data/lib/tap/generator/generators/root/templates/Rakefile +64 -41
- data/lib/tap/generator/generators/root/templates/gemspec +27 -0
- data/lib/tap/generator/generators/root/templates/tapfile +8 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +0 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +1 -1
- data/lib/tap/generator/generators/root/templates/test/tapfile_test.rb +15 -0
- data/lib/tap/generator/generators/task/task_generator.rb +21 -28
- data/lib/tap/generator/generators/task/templates/task.erb +13 -23
- data/lib/tap/generator/generators/task/templates/test.erb +15 -18
- data/lib/tap/generator/manifest.rb +14 -0
- data/lib/tap/patches/rake/rake_test_loader.rb +0 -0
- data/lib/tap/patches/rake/testtask.rb +0 -0
- data/lib/tap/patches/ruby19/backtrace_filter.rb +0 -0
- data/lib/tap/patches/ruby19/parsedate.rb +0 -0
- data/lib/tap/root.rb +260 -21
- data/lib/tap/support/aggregator.rb +11 -11
- data/lib/tap/support/assignments.rb +172 -0
- data/lib/tap/support/audit.rb +20 -18
- data/lib/tap/support/batchable.rb +21 -10
- data/lib/tap/support/batchable_class.rb +107 -0
- data/lib/tap/support/class_configuration.rb +154 -239
- data/lib/tap/support/command_line.rb +97 -102
- data/lib/tap/support/comment.rb +270 -0
- data/lib/tap/support/configurable.rb +86 -65
- data/lib/tap/support/configurable_class.rb +296 -0
- data/lib/tap/support/configuration.rb +122 -0
- data/lib/tap/support/constant.rb +70 -0
- data/lib/tap/support/constant_utils.rb +127 -0
- data/lib/tap/support/declarations.rb +111 -0
- data/lib/tap/support/executable.rb +30 -17
- data/lib/tap/support/executable_queue.rb +0 -0
- data/lib/tap/support/framework.rb +71 -0
- data/lib/tap/support/framework_class.rb +199 -0
- data/lib/tap/support/instance_configuration.rb +147 -0
- data/lib/tap/support/lazydoc.rb +428 -0
- data/lib/tap/support/manifest.rb +89 -0
- data/lib/tap/support/run_error.rb +0 -0
- data/lib/tap/support/shell_utils.rb +33 -9
- data/lib/tap/support/summary.rb +30 -0
- data/lib/tap/support/tdoc.rb +339 -134
- data/lib/tap/support/tdoc/tdoc_html_generator.rb +0 -0
- data/lib/tap/support/tdoc/tdoc_html_template.rb +0 -0
- data/lib/tap/support/templater.rb +180 -0
- data/lib/tap/support/validation.rb +409 -76
- data/lib/tap/support/versions.rb +5 -3
- data/lib/tap/task.rb +78 -174
- data/lib/tap/tasks/dump.rb +56 -0
- data/lib/tap/tasks/rake.rb +93 -0
- data/lib/tap/test.rb +3 -3
- data/lib/tap/test/env_vars.rb +2 -2
- data/lib/tap/test/file_methods.rb +19 -20
- data/lib/tap/test/script_methods.rb +144 -0
- data/lib/tap/test/subset_methods.rb +1 -1
- data/lib/tap/test/tap_methods.rb +28 -62
- data/lib/tap/workflow.rb +22 -39
- metadata +48 -179
- data/Basic Overview +0 -151
- data/Command Reference +0 -99
- data/Rakefile +0 -127
- data/Tutorial +0 -287
- data/lib/tap/cmd/console.rb +0 -31
- data/lib/tap/cmd/destroy.rb +0 -20
- data/lib/tap/cmd/generate.rb +0 -20
- data/lib/tap/cmd/run.rb +0 -151
- data/lib/tap/dump.rb +0 -57
- data/lib/tap/generator.rb +0 -91
- data/lib/tap/generator/generators/command/USAGE +0 -6
- data/lib/tap/generator/generators/config/USAGE +0 -21
- data/lib/tap/generator/generators/config/templates/config.erb +0 -1
- data/lib/tap/generator/generators/file_task/USAGE +0 -3
- data/lib/tap/generator/generators/file_task/templates/file.yml +0 -3
- data/lib/tap/generator/generators/generator/USAGE +0 -0
- data/lib/tap/generator/generators/generator/generator_generator.rb +0 -21
- data/lib/tap/generator/generators/generator/templates/generator.erb +0 -32
- data/lib/tap/generator/generators/generator/templates/usage.erb +0 -1
- data/lib/tap/generator/generators/root/USAGE +0 -0
- data/lib/tap/generator/generators/root/templates/ReadMe.txt +0 -0
- data/lib/tap/generator/generators/root/templates/tap.yml +0 -80
- data/lib/tap/generator/generators/task/USAGE +0 -3
- data/lib/tap/generator/generators/workflow/USAGE +0 -0
- data/lib/tap/generator/generators/workflow/templates/task.erb +0 -16
- data/lib/tap/generator/generators/workflow/templates/test.erb +0 -7
- data/lib/tap/generator/generators/workflow/workflow_generator.rb +0 -6
- data/lib/tap/generator/options.rb +0 -26
- data/lib/tap/generator/usage.rb +0 -26
- data/lib/tap/support/batchable_methods.rb +0 -34
- data/lib/tap/support/command_line_methods.rb +0 -76
- data/lib/tap/support/configurable_methods.rb +0 -224
- data/lib/tap/support/logger.rb +0 -88
- data/lib/tap/support/rake.rb +0 -43
- data/lib/tap/support/tdoc/config_attr.rb +0 -362
- data/test/app/config/another/task.yml +0 -1
- data/test/app/config/batch.yml +0 -2
- data/test/app/config/empty.yml +0 -0
- data/test/app/config/erb.yml +0 -2
- data/test/app/config/some/task.yml +0 -1
- data/test/app/config/template.yml +0 -2
- data/test/app/config/version-0.1.yml +0 -1
- data/test/app/config/version.yml +0 -1
- data/test/app/lib/app_test_task.rb +0 -3
- data/test/app_test.rb +0 -1849
- data/test/env/test_configure/recurse_a.yml +0 -2
- data/test/env/test_configure/recurse_b.yml +0 -2
- data/test/env/test_configure/tap.yml +0 -23
- data/test/env/test_load_env_config/dir/tap.yml +0 -3
- data/test/env/test_load_env_config/recurse_a.yml +0 -2
- data/test/env/test_load_env_config/recurse_b.yml +0 -2
- data/test/env/test_load_env_config/tap.yml +0 -3
- data/test/env_test.rb +0 -198
- data/test/file_task/config/batch.yml +0 -2
- data/test/file_task/config/configured.yml +0 -1
- data/test/file_task/old_file_one.txt +0 -0
- data/test/file_task/old_file_two.txt +0 -0
- data/test/file_task_test.rb +0 -1291
- data/test/root/alt_lib/alt_module.rb +0 -4
- data/test/root/file.txt +0 -0
- data/test/root/glob/one.txt +0 -0
- data/test/root/glob/two.txt +0 -0
- data/test/root/lib/absolute_alt_filepath.rb +0 -2
- data/test/root/lib/alternative_filepath.rb +0 -2
- data/test/root/lib/another_module.rb +0 -2
- data/test/root/lib/nested/some_module.rb +0 -4
- data/test/root/lib/no_module_included.rb +0 -0
- data/test/root/lib/some/module.rb +0 -4
- data/test/root/lib/some_class.rb +0 -2
- data/test/root/lib/some_module.rb +0 -3
- data/test/root/load_path/load_path_module.rb +0 -2
- data/test/root/load_path/skip_module.rb +0 -2
- data/test/root/mtime/older.txt +0 -0
- data/test/root/unload/full_path.rb +0 -2
- data/test/root/unload/loaded_by_nested.rb +0 -2
- data/test/root/unload/nested/nested_load.rb +0 -6
- data/test/root/unload/nested/nested_with_ext.rb +0 -4
- data/test/root/unload/nested/relative_path.rb +0 -4
- data/test/root/unload/older.rb +0 -2
- data/test/root/unload/unload_base.rb +0 -9
- data/test/root/versions/another.yml +0 -0
- data/test/root/versions/file-0.1.2.yml +0 -0
- data/test/root/versions/file-0.1.yml +0 -0
- data/test/root/versions/file.yml +0 -0
- data/test/root_test.rb +0 -718
- data/test/support/aggregator_test.rb +0 -99
- data/test/support/audit_test.rb +0 -445
- data/test/support/batchable_test.rb +0 -74
- data/test/support/class_configuration_test.rb +0 -331
- data/test/support/command_line_test.rb +0 -58
- data/test/support/configurable/config/configured.yml +0 -2
- data/test/support/configurable_test.rb +0 -295
- data/test/support/executable_queue_test.rb +0 -103
- data/test/support/executable_test.rb +0 -38
- data/test/support/logger_test.rb +0 -31
- data/test/support/rake_test.rb +0 -37
- data/test/support/shell_utils_test.rb +0 -24
- data/test/support/tdoc_test.rb +0 -370
- data/test/support/validation_test.rb +0 -54
- data/test/support/versions_test.rb +0 -103
- data/test/tap_test_helper.rb +0 -57
- data/test/tap_test_suite.rb +0 -7
- data/test/task/config/batch.yml +0 -2
- data/test/task/config/batched.yml +0 -2
- data/test/task/config/configured.yml +0 -1
- data/test/task/config/example.yml +0 -1
- data/test/task_base_test.rb +0 -24
- data/test/task_syntax_test.rb +0 -300
- data/test/task_test.rb +0 -320
- data/test/test/env_vars_test.rb +0 -48
- data/test/test/file_methods/test_assert_files/expected/one.txt +0 -1
- data/test/test/file_methods/test_assert_files/expected/two.txt +0 -1
- data/test/test/file_methods/test_assert_files/input/one.txt +0 -1
- data/test/test/file_methods/test_assert_files/input/two.txt +0 -1
- data/test/test/file_methods/test_assert_files_can_have_no_expected_files_if_specified/input/one.txt +0 -1
- data/test/test/file_methods/test_assert_files_can_have_no_expected_files_if_specified/input/two.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/one.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/two.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_different_content/input/one.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_different_content/input/two.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/expected/one.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/one.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/two.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/one.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/two.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/one.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/two.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/one.txt +0 -1
- data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/two.txt +0 -1
- 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/file_methods_doc/test_sub/expected/one.txt +0 -1
- data/test/test/file_methods_doc/test_sub/expected/two.txt +0 -1
- data/test/test/file_methods_doc/test_sub/input/one.txt +0 -1
- data/test/test/file_methods_doc/test_sub/input/two.txt +0 -1
- data/test/test/file_methods_doc_test.rb +0 -29
- data/test/test/file_methods_test.rb +0 -275
- data/test/test/subset_methods_test.rb +0 -171
- data/test/test/tap_methods/test_assert_files/expected/task/name/a.txt +0 -1
- data/test/test/tap_methods/test_assert_files/expected/task/name/b.txt +0 -1
- data/test/test/tap_methods/test_assert_files/input/a.txt +0 -1
- data/test/test/tap_methods/test_assert_files/input/b.txt +0 -1
- data/test/test/tap_methods_test.rb +0 -399
- data/test/workflow_test.rb +0 -120
- data/vendor/rails_generator.rb +0 -56
- data/vendor/rails_generator/base.rb +0 -263
- data/vendor/rails_generator/commands.rb +0 -581
- data/vendor/rails_generator/generated_attribute.rb +0 -42
- data/vendor/rails_generator/lookup.rb +0 -209
- data/vendor/rails_generator/manifest.rb +0 -53
- data/vendor/rails_generator/options.rb +0 -143
- data/vendor/rails_generator/scripts.rb +0 -83
- data/vendor/rails_generator/scripts/destroy.rb +0 -7
- data/vendor/rails_generator/scripts/generate.rb +0 -7
- data/vendor/rails_generator/scripts/update.rb +0 -12
- data/vendor/rails_generator/simple_logger.rb +0 -46
- data/vendor/rails_generator/spec.rb +0 -44
data/test/root/file.txt
DELETED
|
File without changes
|
data/test/root/glob/one.txt
DELETED
|
File without changes
|
data/test/root/glob/two.txt
DELETED
|
File without changes
|
|
File without changes
|
data/test/root/lib/some_class.rb
DELETED
data/test/root/mtime/older.txt
DELETED
|
File without changes
|
data/test/root/unload/older.rb
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
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
|
data/test/root/versions/file.yml
DELETED
|
File without changes
|
data/test/root_test.rb
DELETED
|
@@ -1,718 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'tap_test_helper.rb')
|
|
2
|
-
require 'tap/root'
|
|
3
|
-
|
|
4
|
-
class RootTest < Test::Unit::TestCase
|
|
5
|
-
include Tap::Test::SubsetMethods
|
|
6
|
-
|
|
7
|
-
attr_reader :r, :tr
|
|
8
|
-
|
|
9
|
-
def setup
|
|
10
|
-
# root
|
|
11
|
-
@r = Tap::Root.new "./root", {:dir => "dir"}, {:abs => '/abs/path'}
|
|
12
|
-
|
|
13
|
-
# test root
|
|
14
|
-
@tr = Tap::Root.new 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
|
-
|
|
33
|
-
# work with directories
|
|
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)
|
|
45
|
-
|
|
46
|
-
# version filepaths
|
|
47
|
-
assert_equal 'path/to/config-1.0.yml', r.version('path/to/config.yml', 1.0)
|
|
48
|
-
assert_equal 'path/to/config-1.1.yml', r.increment('path/to/config-1.0.yml', 0.1)
|
|
49
|
-
assert_equal ['path/to/config.yml', "1.1"], r.deversion('path/to/config-1.1.yml')
|
|
50
|
-
|
|
51
|
-
# absolute paths can also be aliased.
|
|
52
|
-
r[:abs, true] = "/absolute/path"
|
|
53
|
-
assert_equal File.expand_path('/absolute/path/to/file.txt'), r.filepath(:abs, "to", "file.txt")
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
#
|
|
57
|
-
# Tap::Root relative filepath test
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
def test_relative_filepath_documentation
|
|
61
|
-
assert_equal "path/to/file.txt", Tap::Root.relative_filepath('dir', "dir/path/to/file.txt")
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
def test_class_relative_filepath
|
|
65
|
-
assert_equal "file.txt", Tap::Root.relative_filepath('./root/dir', "./root/dir/file.txt")
|
|
66
|
-
assert_equal "nested/file.txt", Tap::Root.relative_filepath('./root/dir', "./root/dir/nested/file.txt")
|
|
67
|
-
end
|
|
68
|
-
|
|
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")
|
|
100
|
-
assert_equal [], Tap::Root.glob()
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
#
|
|
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
|
|
109
|
-
|
|
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
|
|
112
|
-
|
|
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
|
|
115
|
-
|
|
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
|
|
118
|
-
|
|
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
|
|
122
|
-
|
|
123
|
-
def test_class_default_vglob_pattern_is_all_versions
|
|
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
|
-
#
|
|
214
|
-
|
|
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
|
|
293
|
-
|
|
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"}
|
|
327
|
-
|
|
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({
|
|
376
|
-
:abs => File.expand_path("/abs/path"),
|
|
377
|
-
:another => File.expand_path("/another/path")},
|
|
378
|
-
r.absolute_paths)
|
|
379
|
-
end
|
|
380
|
-
|
|
381
|
-
#
|
|
382
|
-
# assignment tests
|
|
383
|
-
#
|
|
384
|
-
|
|
385
|
-
def test_assignment_documentation
|
|
386
|
-
r = Tap::Root.new root_dir
|
|
387
|
-
r[:dir] = 'path/to/dir'
|
|
388
|
-
assert_equal root_dir + '/path/to/dir', r[:dir]
|
|
389
|
-
|
|
390
|
-
r[:abs, true] = '/abs/path/to/dir'
|
|
391
|
-
assert_equal File.expand_path('/abs/path/to/dir'), r[:abs]
|
|
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'
|
|
408
|
-
|
|
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
|
|
418
|
-
|
|
419
|
-
def test_absolute_paths_can_be_set_by_specifiying_absolute_true
|
|
420
|
-
r[:absolute, true] = '/some/absolute/path'
|
|
421
|
-
|
|
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)
|
|
430
|
-
end
|
|
431
|
-
|
|
432
|
-
def test_an_absolute_path_is_not_set_if_absolute_false
|
|
433
|
-
r[:not_absolute, false] = 'not/an/absolute/path'
|
|
434
|
-
|
|
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)
|
|
443
|
-
end
|
|
444
|
-
|
|
445
|
-
def test_paths_can_be_unset_with_nil
|
|
446
|
-
# Non-absolute path
|
|
447
|
-
r[:dir] = '/some/path'
|
|
448
|
-
assert_equal({:dir => "/some/path"}, r.directories)
|
|
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
|
-
|
|
456
|
-
r[:dir] = nil
|
|
457
|
-
assert_equal({}, r.directories)
|
|
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)
|
|
463
|
-
|
|
464
|
-
# the same with absolute specified
|
|
465
|
-
r[:dir] = '/some/path'
|
|
466
|
-
assert_equal({:dir => "/some/path"}, r.directories)
|
|
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")},
|
|
472
|
-
r.paths)
|
|
473
|
-
|
|
474
|
-
r[:dir, false] = nil
|
|
475
|
-
assert_equal({}, r.directories)
|
|
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)
|
|
481
|
-
|
|
482
|
-
# Absolute path
|
|
483
|
-
r[:abs, true] = '/some/absolute/path'
|
|
484
|
-
assert_equal({}, r.directories)
|
|
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)
|
|
490
|
-
|
|
491
|
-
r[:abs, true] = nil
|
|
492
|
-
assert_equal({}, r.directories)
|
|
493
|
-
assert_equal({
|
|
494
|
-
'root' => File.expand_path("./root"),
|
|
495
|
-
:root => File.expand_path("./root")},
|
|
496
|
-
r.paths)
|
|
497
|
-
|
|
498
|
-
# the same with absolute unspecfied
|
|
499
|
-
r[:abs, true] = '/some/absolute/path'
|
|
500
|
-
assert_equal({}, r.directories)
|
|
501
|
-
assert_equal({
|
|
502
|
-
'root' => File.expand_path("./root"),
|
|
503
|
-
:root => File.expand_path("./root"),
|
|
504
|
-
:abs => File.expand_path('/some/absolute/path')},
|
|
505
|
-
r.paths)
|
|
506
|
-
|
|
507
|
-
r[:abs] = nil
|
|
508
|
-
assert_equal({}, r.directories)
|
|
509
|
-
assert_equal({
|
|
510
|
-
'root' => File.expand_path("./root"),
|
|
511
|
-
:root => File.expand_path("./root")},
|
|
512
|
-
r.paths)
|
|
513
|
-
end
|
|
514
|
-
|
|
515
|
-
def test_set_path_expands_filepaths
|
|
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]
|
|
530
|
-
|
|
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
|
|
562
|
-
|
|
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
|
|
597
|
-
|
|
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
|
|
628
|
-
assert_equal File.expand_path('/root_dir/out/path/to/file.txt'), r.translate(fp, :in, :out)
|
|
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
|
|
649
|
-
|
|
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)
|
|
661
|
-
end
|
|
662
|
-
|
|
663
|
-
#
|
|
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
|
|
669
|
-
|
|
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
|
|
672
|
-
|
|
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
|
|
675
|
-
|
|
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
|
|
678
|
-
|
|
679
|
-
assert_equal 0, Dir.glob(File.join(root_dir, 'versions/file-2.yml')).length
|
|
680
|
-
assert_equal [], tr.vglob(:versions, 'file.yml', "2")
|
|
681
|
-
end
|
|
682
|
-
|
|
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
|
|
687
|
-
|
|
688
|
-
def test_nil_vglob_pattern_matches_the_no_version_file
|
|
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
|
|
717
|
-
end
|
|
718
|
-
end
|