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
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
######################################################
|
|
2
|
-
# App Configurations:
|
|
3
|
-
######################################################
|
|
4
|
-
|
|
5
|
-
directories:
|
|
6
|
-
rel: dir
|
|
7
|
-
|
|
8
|
-
options:
|
|
9
|
-
quiet: true
|
|
10
|
-
|
|
11
|
-
######################################################
|
|
12
|
-
# Env Configurations:
|
|
13
|
-
######################################################
|
|
14
|
-
|
|
15
|
-
load_paths: [lib, rel]
|
|
16
|
-
|
|
17
|
-
command_paths:
|
|
18
|
-
- cmd
|
|
19
|
-
|
|
20
|
-
config_paths: recurse_a.yml
|
|
21
|
-
|
|
22
|
-
before: |
|
|
23
|
-
before
|
data/test/env_test.rb
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'tap_test_helper')
|
|
2
|
-
require 'tap/env'
|
|
3
|
-
|
|
4
|
-
class ConfigurationTest < Test::Unit::TestCase
|
|
5
|
-
include Tap::Env::Configuration
|
|
6
|
-
|
|
7
|
-
acts_as_file_test
|
|
8
|
-
|
|
9
|
-
#
|
|
10
|
-
# read_config test
|
|
11
|
-
#
|
|
12
|
-
|
|
13
|
-
def test_read_config_templates_then_loads_config
|
|
14
|
-
config_file = output_tempfile
|
|
15
|
-
|
|
16
|
-
File.open(config_file, "wb") {|f| f << "sum: <%= 1 + 2 %>" }
|
|
17
|
-
assert_equal({'sum' => 3}, read_config(config_file))
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def test_read_config_returns_empty_hash_for_non_existant_nil_and_false_files
|
|
21
|
-
config_file = output_tempfile
|
|
22
|
-
|
|
23
|
-
assert !File.exists?(config_file)
|
|
24
|
-
assert_equal({}, read_config(config_file))
|
|
25
|
-
|
|
26
|
-
FileUtils.touch(config_file)
|
|
27
|
-
assert_equal({}, read_config(config_file))
|
|
28
|
-
|
|
29
|
-
File.open(config_file, "wb") {|f| f << nil.to_yaml }
|
|
30
|
-
assert_equal(nil, YAML.load_file(config_file))
|
|
31
|
-
assert_equal({}, read_config(config_file))
|
|
32
|
-
|
|
33
|
-
File.open(config_file, "wb") {|f| f << false.to_yaml }
|
|
34
|
-
assert_equal(false, YAML.load_file(config_file))
|
|
35
|
-
assert_equal({}, read_config(config_file))
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
def test_read_config_raises_error_for_non_hash_result
|
|
39
|
-
config_file = output_tempfile
|
|
40
|
-
File.open(config_file, "wb") {|f| f << [].to_yaml }
|
|
41
|
-
|
|
42
|
-
assert_raise(RuntimeError) { read_config(config_file) }
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
#
|
|
46
|
-
# partition_configs test
|
|
47
|
-
#
|
|
48
|
-
|
|
49
|
-
def test_partition_configs
|
|
50
|
-
config = {'before' => :b, 'gems' => :g, 'root' => :r, 'another' => :a}
|
|
51
|
-
|
|
52
|
-
env, app, other = partition_configs(config, ['gems'], ['root', 'another'])
|
|
53
|
-
assert_equal({'gems' => :g}, env)
|
|
54
|
-
assert_equal({'root' => :r, 'another' => :a}, app)
|
|
55
|
-
assert_equal({'before' => :b}, other)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
#
|
|
59
|
-
# join_configs test
|
|
60
|
-
#
|
|
61
|
-
|
|
62
|
-
def test_join_configs
|
|
63
|
-
a = {:a => 1, :b => [1]}
|
|
64
|
-
b = {:a => [2], :b => [1]}
|
|
65
|
-
c = {:c => 1}
|
|
66
|
-
|
|
67
|
-
assert_equal({:a => [1, 2], :b => [1], :c => [1]}, join_configs(a,b,c))
|
|
68
|
-
assert_equal({:a => [2, 1], :b => [1], :c => [1]}, join_configs(c,b,a))
|
|
69
|
-
end
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
class EnvTest < Test::Unit::TestCase
|
|
73
|
-
|
|
74
|
-
acts_as_file_test
|
|
75
|
-
attr_accessor :e
|
|
76
|
-
|
|
77
|
-
def setup
|
|
78
|
-
super
|
|
79
|
-
@e = Tap::Env.instance
|
|
80
|
-
e.reset
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
def teardown
|
|
84
|
-
super
|
|
85
|
-
e.reset
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
#
|
|
89
|
-
# load_env_config test
|
|
90
|
-
#
|
|
91
|
-
|
|
92
|
-
def test_load_env_config
|
|
93
|
-
empty_config = {
|
|
94
|
-
"load_paths" => [],
|
|
95
|
-
"load_once_paths" => [],
|
|
96
|
-
"config_paths" => [],
|
|
97
|
-
"command_paths" => [],
|
|
98
|
-
"gems" => [],
|
|
99
|
-
"generator_paths" => []
|
|
100
|
-
}
|
|
101
|
-
starting_load_paths = $:.uniq
|
|
102
|
-
|
|
103
|
-
assert_equal(empty_config, e.config)
|
|
104
|
-
assert Dependencies.load_paths.empty?
|
|
105
|
-
assert Dependencies.load_once_paths.empty?
|
|
106
|
-
|
|
107
|
-
# test specifying a file
|
|
108
|
-
assert File.exists?(method_filepath('tap.yml'))
|
|
109
|
-
e.load_config(method_filepath('tap.yml'))
|
|
110
|
-
|
|
111
|
-
assert_equal({
|
|
112
|
-
"load_paths" => [method_filepath('lib'), method_filepath('nested/lib')],
|
|
113
|
-
"load_once_paths" => [method_filepath('lop.rb'), method_filepath('nested/lop.rb')],
|
|
114
|
-
"config_paths" => [method_filepath('tap.yml')],
|
|
115
|
-
"command_paths" => [method_filepath('cmd'), method_filepath('nested/cmd')],
|
|
116
|
-
"gems" => [],
|
|
117
|
-
"generator_paths" => [method_filepath('lib/generators')]
|
|
118
|
-
}, e.config)
|
|
119
|
-
|
|
120
|
-
assert_equal [], e.config['load_paths'] - $:
|
|
121
|
-
assert_equal e.config['load_paths'], Dependencies.load_paths
|
|
122
|
-
assert_equal e.config['load_once_paths'], Dependencies.load_once_paths
|
|
123
|
-
|
|
124
|
-
# test specifying a dir
|
|
125
|
-
assert File.exists?(method_filepath('dir', 'tap.yml'))
|
|
126
|
-
e.load_config(method_filepath('dir'))
|
|
127
|
-
|
|
128
|
-
assert_equal({
|
|
129
|
-
"load_paths" => [method_filepath('dir/lib'), method_filepath('dir/nested/lib'), method_filepath('lib'), method_filepath('nested/lib')],
|
|
130
|
-
"load_once_paths" => [ method_filepath('dir/lop.rb'), method_filepath('dir/nested/lop.rb'), method_filepath('lop.rb'), method_filepath('nested/lop.rb')],
|
|
131
|
-
"config_paths" => [method_filepath('tap.yml'), method_filepath('dir', 'tap.yml')],
|
|
132
|
-
"command_paths" => [method_filepath('dir/cmd'), method_filepath('dir/nested/cmd'), method_filepath('cmd'), method_filepath('nested/cmd')],
|
|
133
|
-
"gems" => [],
|
|
134
|
-
"generator_paths" => [method_filepath('dir/lib/generators'), method_filepath('lib/generators')]
|
|
135
|
-
}, e.config)
|
|
136
|
-
|
|
137
|
-
assert_equal [], e.config['load_paths'] - $:
|
|
138
|
-
assert_equal e.config['load_paths'], Dependencies.load_paths
|
|
139
|
-
assert_equal e.config['load_once_paths'], Dependencies.load_once_paths
|
|
140
|
-
|
|
141
|
-
# add extra Dependencies load paths to be sure ONLY the ENV load paths are cleared
|
|
142
|
-
Dependencies.load_paths << 'extra'
|
|
143
|
-
Dependencies.load_once_paths << 'extra'
|
|
144
|
-
|
|
145
|
-
# test reset
|
|
146
|
-
e.reset
|
|
147
|
-
assert_equal(empty_config, e.config)
|
|
148
|
-
assert_equal ['extra'], Dependencies.load_paths
|
|
149
|
-
assert_equal ['extra'], Dependencies.load_once_paths
|
|
150
|
-
assert_equal starting_load_paths, $:
|
|
151
|
-
|
|
152
|
-
# test recursion/config_path loading
|
|
153
|
-
pwd = Dir.pwd
|
|
154
|
-
begin
|
|
155
|
-
Dir.chdir(method_root)
|
|
156
|
-
e.load_config('recurse_a.yml')
|
|
157
|
-
ensure
|
|
158
|
-
Dir.chdir(pwd)
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
assert_equal [method_filepath('lib'), method_filepath('nested/lib')], e.config['load_paths']
|
|
162
|
-
assert_equal [method_filepath('recurse_a.yml'), method_filepath('recurse_b.yml')], e.config['config_paths']
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
#
|
|
166
|
-
# configure test
|
|
167
|
-
#
|
|
168
|
-
|
|
169
|
-
# def test_configure
|
|
170
|
-
# assert e.load_paths.empty?
|
|
171
|
-
# assert e.command_paths.empty?
|
|
172
|
-
# assert e.load_once_paths.empty?
|
|
173
|
-
# assert e.config_paths.empty?
|
|
174
|
-
# assert_nil e.before
|
|
175
|
-
# assert_nil e.after
|
|
176
|
-
# assert_equal Tap::App.instance, e.app
|
|
177
|
-
#
|
|
178
|
-
# pwd = Dir.pwd
|
|
179
|
-
# begin
|
|
180
|
-
# Dir.chdir(method_root)
|
|
181
|
-
# e.configure
|
|
182
|
-
# ensure
|
|
183
|
-
# Dir.chdir(pwd)
|
|
184
|
-
# end
|
|
185
|
-
#
|
|
186
|
-
# app = e.app
|
|
187
|
-
#
|
|
188
|
-
# assert_equal [method_filepath('lib'), method_filepath('dir'), method_filepath('a'), method_filepath('b')], e.load_paths
|
|
189
|
-
# assert_equal [method_filepath('cmd')], e.command_paths
|
|
190
|
-
# assert_equal [], e.load_once_paths
|
|
191
|
-
# assert_equal [method_filepath('tap.yml'), method_filepath('recurse_a.yml'), method_filepath('recurse_b.yml')], e.config_paths
|
|
192
|
-
# assert_equal "before\n", e.before
|
|
193
|
-
# assert_equal nil, e.after
|
|
194
|
-
#
|
|
195
|
-
# assert_equal({'rel' => 'dir'}, app.directories)
|
|
196
|
-
# assert app.options.quiet
|
|
197
|
-
# end
|
|
198
|
-
end
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
config: value
|
|
File without changes
|
|
File without changes
|
data/test/file_task_test.rb
DELETED
|
@@ -1,1291 +0,0 @@
|
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'tap_test_helper')
|
|
2
|
-
require 'tap/file_task'
|
|
3
|
-
|
|
4
|
-
class FileTaskTest < Test::Unit::TestCase
|
|
5
|
-
acts_as_tap_test
|
|
6
|
-
|
|
7
|
-
attr_reader :t
|
|
8
|
-
|
|
9
|
-
def setup
|
|
10
|
-
super
|
|
11
|
-
@t = Tap::FileTask.new
|
|
12
|
-
app.root = trs.root
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def touch_file(path, content=nil)
|
|
16
|
-
FileUtils.mkdir_p(File.dirname(path))
|
|
17
|
-
if content
|
|
18
|
-
File.open(path, "w") {|f| f << content}
|
|
19
|
-
else
|
|
20
|
-
FileUtils.touch(path)
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def test_touch_file
|
|
25
|
-
non_existant_file = method_filepath(:output, "non_existant_file.txt")
|
|
26
|
-
assert !File.exists?(non_existant_file)
|
|
27
|
-
touch_file(non_existant_file)
|
|
28
|
-
assert File.exists?(non_existant_file)
|
|
29
|
-
assert File.file?(non_existant_file)
|
|
30
|
-
assert_equal "", File.read(non_existant_file)
|
|
31
|
-
|
|
32
|
-
non_existant_file = method_filepath(:output, "non_existant_file2.txt")
|
|
33
|
-
assert !File.exists?(non_existant_file)
|
|
34
|
-
touch_file(non_existant_file, "content")
|
|
35
|
-
assert File.exists?(non_existant_file)
|
|
36
|
-
assert File.file?(non_existant_file)
|
|
37
|
-
assert_equal "content", File.read(non_existant_file)
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
#
|
|
41
|
-
# doc tests
|
|
42
|
-
#
|
|
43
|
-
|
|
44
|
-
def test_documentation
|
|
45
|
-
file_one = method_filepath(:output, "file.txt")
|
|
46
|
-
file_two = method_filepath(:output, "path/to/file.txt")
|
|
47
|
-
dir = method_filepath(:output, "some/dir")
|
|
48
|
-
FileUtils.mkdir_p( method_filepath(:output) )
|
|
49
|
-
|
|
50
|
-
File.open(file_one, "w") {|f| f << "original content"}
|
|
51
|
-
t = Tap::FileTask.new do |task|
|
|
52
|
-
task.mkdir(dir)
|
|
53
|
-
task.prepare([file_one, file_two])
|
|
54
|
-
|
|
55
|
-
File.open(file_one, "w") {|f| f << "new content"}
|
|
56
|
-
FileUtils.touch(file_two)
|
|
57
|
-
|
|
58
|
-
raise "error!"
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
begin
|
|
62
|
-
assert !File.exists?(dir)
|
|
63
|
-
assert !File.exists?(file_two)
|
|
64
|
-
t.execute
|
|
65
|
-
flunk "no error raised"
|
|
66
|
-
rescue
|
|
67
|
-
assert_equal "error!", $!.message
|
|
68
|
-
assert !File.exists?(dir)
|
|
69
|
-
assert !File.exists?(file_two)
|
|
70
|
-
assert_equal "original content", File.read(file_one)
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
#
|
|
75
|
-
# dirname tests
|
|
76
|
-
#
|
|
77
|
-
|
|
78
|
-
def test_dirname_returns_default_dirname_by_default
|
|
79
|
-
assert_equal "tap/file_task", t.dirname
|
|
80
|
-
|
|
81
|
-
t = Tap::FileTask.new "batch"
|
|
82
|
-
assert_equal 2, t.batch.size
|
|
83
|
-
t1, t2 = t.batch
|
|
84
|
-
assert_equal "batch_0", t1.dirname
|
|
85
|
-
assert_equal "batch_1", t2.dirname
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def test_dirname_returns_dirname_if_set
|
|
89
|
-
t.dirname = "name"
|
|
90
|
-
assert_equal "name", t.dirname
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
#
|
|
94
|
-
# open tests
|
|
95
|
-
#
|
|
96
|
-
|
|
97
|
-
def test_open_doc
|
|
98
|
-
FileUtils.mkdir_p(method_filepath(:output))
|
|
99
|
-
one_filepath = method_filepath(:output, "one.txt")
|
|
100
|
-
two_filepath = method_filepath(:output, "two.txt")
|
|
101
|
-
|
|
102
|
-
t.open([one_filepath, two_filepath], "w") do |one, two|
|
|
103
|
-
one << "one"
|
|
104
|
-
two << "two"
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
assert_equal "one", File.read(one_filepath)
|
|
108
|
-
assert_equal "two", File.read(two_filepath)
|
|
109
|
-
|
|
110
|
-
#
|
|
111
|
-
filepath = method_filepath(:output, "file.txt")
|
|
112
|
-
t.open(filepath, "w") do |array|
|
|
113
|
-
array.first << "content"
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
assert_equal "content", File.read(filepath)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
def test_open_opens_each_file
|
|
120
|
-
FileUtils.mkdir_p(method_filepath(:output))
|
|
121
|
-
|
|
122
|
-
list = [0, 1].collect do |n|
|
|
123
|
-
path = method_filepath(:output, "#{n}.txt")
|
|
124
|
-
File.open(path, "w") {|f| f << n.to_s}
|
|
125
|
-
path
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
t.open(list) do |files|
|
|
129
|
-
files.each_with_index do |file, n|
|
|
130
|
-
assert_equal File, file.class
|
|
131
|
-
assert_equal n.to_s, file.read
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
def test_open_opens_with_input_mode
|
|
137
|
-
FileUtils.mkdir_p(method_filepath(:output))
|
|
138
|
-
|
|
139
|
-
list = [0, 1].collect do |n|
|
|
140
|
-
path = method_filepath(:output, "#{n}.txt")
|
|
141
|
-
path
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
t.open(list, "w") do |files|
|
|
145
|
-
files.each_with_index do |file, n|
|
|
146
|
-
assert_equal File, file.class
|
|
147
|
-
file << n.to_s
|
|
148
|
-
end
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
list.each_with_index do |file, n|
|
|
152
|
-
assert_equal n.to_s, File.read(file)
|
|
153
|
-
end
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
def test_open_returns_open_files_if_no_block_is_given
|
|
157
|
-
FileUtils.mkdir_p(method_filepath(:output))
|
|
158
|
-
|
|
159
|
-
list = [0, 1].collect do |n|
|
|
160
|
-
path = method_filepath(:output, "#{n}.txt")
|
|
161
|
-
File.open(path, "w") {|f| f << n.to_s}
|
|
162
|
-
path
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
t.open(list).each_with_index do |file, n|
|
|
166
|
-
assert_equal File, file.class
|
|
167
|
-
assert_equal n.to_s, file.read
|
|
168
|
-
file.close
|
|
169
|
-
end
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
#
|
|
173
|
-
# basename test
|
|
174
|
-
#
|
|
175
|
-
|
|
176
|
-
def test_basename_doc
|
|
177
|
-
assert_equal 'file.txt', t.basename('path/to/file.txt')
|
|
178
|
-
assert_equal 'file.html', t.basename('path/to/file.txt', '.html')
|
|
179
|
-
end
|
|
180
|
-
|
|
181
|
-
#
|
|
182
|
-
# inference tests
|
|
183
|
-
#
|
|
184
|
-
|
|
185
|
-
def test_inference_sets_inference_block
|
|
186
|
-
block = lambda {}
|
|
187
|
-
t.inference(&block)
|
|
188
|
-
assert_equal block, t.inference_block
|
|
189
|
-
end
|
|
190
|
-
|
|
191
|
-
def test_inference_can_only_be_set_once
|
|
192
|
-
t.inference {}
|
|
193
|
-
assert_raise(RuntimeError) { t.inference {} }
|
|
194
|
-
assert_raise(RuntimeError) { t.inference }
|
|
195
|
-
end
|
|
196
|
-
|
|
197
|
-
#
|
|
198
|
-
# filepath tests
|
|
199
|
-
#
|
|
200
|
-
|
|
201
|
-
def test_filepath_passes_app_dir_dirname_and_path_to_block
|
|
202
|
-
t.inference do |root, dir, path|
|
|
203
|
-
[root, dir, path]
|
|
204
|
-
end
|
|
205
|
-
|
|
206
|
-
assert_equal "tap/file_task", t.dirname
|
|
207
|
-
assert_equal [app[:dir], "tap/file_task", "path"], t.filepath(:dir, "path")
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
def test_filepath_with_multiple_paths
|
|
211
|
-
t.inference do |root, dir, *paths|
|
|
212
|
-
[root, dir, paths]
|
|
213
|
-
end
|
|
214
|
-
assert_equal [app[:dir], "tap/file_task", ["path", "to", "file"]], t.filepath(:dir, "path", "to", "file")
|
|
215
|
-
end
|
|
216
|
-
|
|
217
|
-
def test_filepath_with_multiple_paths_but_single_path_given
|
|
218
|
-
t.inference do |root, dir, *paths|
|
|
219
|
-
[root, dir, paths]
|
|
220
|
-
end
|
|
221
|
-
assert_equal [app[:dir], "tap/file_task", ["path"]], t.filepath(:dir, "path")
|
|
222
|
-
|
|
223
|
-
t.inference(true) do |root, dir, path_a, path_b|
|
|
224
|
-
[root, dir, path_a, path_b]
|
|
225
|
-
end
|
|
226
|
-
assert_equal [app[:dir], "tap/file_task", "path", nil], t.filepath(:dir, "path")
|
|
227
|
-
end
|
|
228
|
-
|
|
229
|
-
def test_filepath_with_single_path_but_multiple_paths_given
|
|
230
|
-
t.inference do |root, dir, path|
|
|
231
|
-
[root, dir, path]
|
|
232
|
-
end
|
|
233
|
-
assert_equal [app[:dir], "tap/file_task", "path"], t.filepath(:dir, "path", "to", "file")
|
|
234
|
-
end
|
|
235
|
-
|
|
236
|
-
def test_filepath_constructs_path_using_app_filepath_when_inference_block_is_not_set
|
|
237
|
-
assert_nil t.inference_block
|
|
238
|
-
assert_equal(
|
|
239
|
-
app.filepath(:dir, "tap/file_task", "path", "to", "file"),
|
|
240
|
-
t.filepath(:dir, "path", "to", "file"))
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
#
|
|
244
|
-
# backup_filepath test
|
|
245
|
-
#
|
|
246
|
-
|
|
247
|
-
def test_backup_filepath_documentation
|
|
248
|
-
t = Tap::FileTask.new("dir/name", :backup_dir => :backup, :backup_timestamp => "%Y%m%d")
|
|
249
|
-
t.app[:backup] # => "/backup"
|
|
250
|
-
Date.today.to_s # => "2007-08-08"
|
|
251
|
-
|
|
252
|
-
t.backup_filepath("path/to/folder/file.txt") # => "/backup/file_20070808.txt"
|
|
253
|
-
t.backup_filepath("dir/name/folder/file.txt") # => "/backup/folder/file_20070808.txt"
|
|
254
|
-
end
|
|
255
|
-
|
|
256
|
-
def prepare_backup_filepath_with_output_and_timestamp
|
|
257
|
-
timestamp_format = "%Y%m%d"
|
|
258
|
-
timestamp = Time.now.strftime(timestamp_format)
|
|
259
|
-
|
|
260
|
-
t.backup_dir = :output
|
|
261
|
-
t.backup_timestamp = timestamp_format
|
|
262
|
-
|
|
263
|
-
timestamp
|
|
264
|
-
end
|
|
265
|
-
|
|
266
|
-
def test_backup_filepath_infers_filepath_using_backup_dir_and_timestamp
|
|
267
|
-
timestamp = prepare_backup_filepath_with_output_and_timestamp
|
|
268
|
-
|
|
269
|
-
assert_equal(
|
|
270
|
-
app.filepath(:output, t.name, "file_#{timestamp}.txt"),
|
|
271
|
-
t.backup_filepath("file.txt"))
|
|
272
|
-
end
|
|
273
|
-
|
|
274
|
-
def test_backup_dir_can_be_full_path
|
|
275
|
-
timestamp = prepare_backup_filepath_with_output_and_timestamp
|
|
276
|
-
|
|
277
|
-
t.backup_dir = File.expand_path('path/to/backup', Dir.pwd)
|
|
278
|
-
|
|
279
|
-
expected_path = File.join('path/to/backup', t.name,"file_#{timestamp}.txt")
|
|
280
|
-
assert_equal(File.expand_path(expected_path, Dir.pwd), t.backup_filepath("file.txt"))
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
def test_backup_filepath_uses_inference_block
|
|
284
|
-
timestamp = prepare_backup_filepath_with_output_and_timestamp
|
|
285
|
-
|
|
286
|
-
t.inference do |root, dir, path|
|
|
287
|
-
[root, dir, path]
|
|
288
|
-
end
|
|
289
|
-
|
|
290
|
-
assert_equal(
|
|
291
|
-
[app[:output], "tap/file_task", "file_#{timestamp}.txt"],
|
|
292
|
-
t.backup_filepath("file.txt"))
|
|
293
|
-
end
|
|
294
|
-
|
|
295
|
-
def test_backup_filepath_uses_path_relative_to_dirname_if_input_is_relative_to_dirname
|
|
296
|
-
timestamp = prepare_backup_filepath_with_output_and_timestamp
|
|
297
|
-
|
|
298
|
-
t.inference do |root, dir, path|
|
|
299
|
-
[root, dir, path]
|
|
300
|
-
end
|
|
301
|
-
|
|
302
|
-
assert_equal("tap/file_task", t.dirname)
|
|
303
|
-
assert_equal(
|
|
304
|
-
[app[:output], t.name, "path/to/file_#{timestamp}.txt"],
|
|
305
|
-
t.backup_filepath("folder/tap/file_task/path/to/file.txt"))
|
|
306
|
-
end
|
|
307
|
-
|
|
308
|
-
def test_backup_filepath_uses_the_input_basename_if_input_is_not_relative_to_dirname
|
|
309
|
-
timestamp = prepare_backup_filepath_with_output_and_timestamp
|
|
310
|
-
|
|
311
|
-
t.inference do |root, dir, path|
|
|
312
|
-
[root, dir, path]
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
assert_equal(
|
|
316
|
-
[app[:output], t.name, "file_#{timestamp}.txt"],
|
|
317
|
-
t.backup_filepath("path/to/file.txt"))
|
|
318
|
-
end
|
|
319
|
-
|
|
320
|
-
# the SciTE text editor whines and fails for 'words' this long... hence the last part of the test name is commented out
|
|
321
|
-
def test_backup_filepath_does_not_mistake_files_as_folders#_when_checking_if_input_is_relative_to_dirname
|
|
322
|
-
timestamp = prepare_backup_filepath_with_output_and_timestamp
|
|
323
|
-
|
|
324
|
-
t.inference do |root, dir, path|
|
|
325
|
-
[root, dir, path]
|
|
326
|
-
end
|
|
327
|
-
|
|
328
|
-
assert_equal(
|
|
329
|
-
[app[:output], t.name, "file_task_#{timestamp}.txt"],
|
|
330
|
-
t.backup_filepath("folder/tap/file_task.txt"))
|
|
331
|
-
end
|
|
332
|
-
|
|
333
|
-
#
|
|
334
|
-
# uptodate tests
|
|
335
|
-
#
|
|
336
|
-
|
|
337
|
-
def uptodate_test_setup(output_str='')
|
|
338
|
-
of1 = trs.filepath(:root, 'old_file_one.txt')
|
|
339
|
-
of2 = trs.filepath(:root, 'old_file_two.txt')
|
|
340
|
-
|
|
341
|
-
nf1 = output_tempfile('new_file_one.txt')
|
|
342
|
-
File.open(nf1, "w") {|file| file << output_str}
|
|
343
|
-
|
|
344
|
-
nf2 = output_tempfile('new_file_two.txt')
|
|
345
|
-
File.open(nf2, "w") {|file| file << output_str}
|
|
346
|
-
|
|
347
|
-
[of1, of2, nf1, nf2]
|
|
348
|
-
end
|
|
349
|
-
|
|
350
|
-
def test_uptodate_test_setup
|
|
351
|
-
files = uptodate_test_setup
|
|
352
|
-
files.each { |file| assert File.exists?(file), file }
|
|
353
|
-
|
|
354
|
-
of1, of2, nf1, nf2 = files
|
|
355
|
-
assert FileUtils.uptodate?(nf1, [of1])
|
|
356
|
-
assert FileUtils.uptodate?(nf2, [of1])
|
|
357
|
-
assert FileUtils.uptodate?(nf1, [of2])
|
|
358
|
-
assert FileUtils.uptodate?(nf2, [of2])
|
|
359
|
-
end
|
|
360
|
-
|
|
361
|
-
def test_uptodate
|
|
362
|
-
of1, of2, nf1, nf2 = uptodate_test_setup
|
|
363
|
-
|
|
364
|
-
non = trs.filepath(:output, "non_existant_file.txt")
|
|
365
|
-
assert !File.exists?(non)
|
|
366
|
-
|
|
367
|
-
assert t.uptodate?(nf1)
|
|
368
|
-
assert t.uptodate?(nf1, of1)
|
|
369
|
-
assert t.uptodate?(nf1, [of1, of2])
|
|
370
|
-
assert t.uptodate?(nf1, [of1, of2, non])
|
|
371
|
-
assert t.uptodate?([nf1, nf2], of1)
|
|
372
|
-
assert t.uptodate?([nf1, nf2], [of1, of2])
|
|
373
|
-
|
|
374
|
-
assert !t.uptodate?(of1, nf1)
|
|
375
|
-
assert !t.uptodate?(of1, [nf1, nf2])
|
|
376
|
-
assert !t.uptodate?(non, nf1)
|
|
377
|
-
assert !t.uptodate?(non, of1)
|
|
378
|
-
assert !t.uptodate?([nf1, non], of1)
|
|
379
|
-
assert !t.uptodate?([nf1, non], [of1, of2])
|
|
380
|
-
end
|
|
381
|
-
|
|
382
|
-
def test_uptodate_with_up_to_date_config_file
|
|
383
|
-
t = Tap::FileTask.new "configured"
|
|
384
|
-
|
|
385
|
-
of1, of2, nf1, nf2 = uptodate_test_setup
|
|
386
|
-
|
|
387
|
-
non = trs.filepath(:output, "non_existant_file.txt")
|
|
388
|
-
assert !File.exists?(non)
|
|
389
|
-
|
|
390
|
-
assert t.uptodate?(nf1)
|
|
391
|
-
assert t.uptodate?(nf1, of1)
|
|
392
|
-
assert t.uptodate?(nf1, [of1, of2])
|
|
393
|
-
assert t.uptodate?(nf1, [of1, of2, non])
|
|
394
|
-
assert t.uptodate?([nf1, nf2], of1)
|
|
395
|
-
assert t.uptodate?([nf1, nf2], [of1, of2])
|
|
396
|
-
|
|
397
|
-
assert !t.uptodate?(of1, nf1)
|
|
398
|
-
assert !t.uptodate?(of1, [nf1, nf2])
|
|
399
|
-
assert !t.uptodate?(non, nf1)
|
|
400
|
-
assert !t.uptodate?(non, of1)
|
|
401
|
-
assert !t.uptodate?([nf1, non], of1)
|
|
402
|
-
assert !t.uptodate?([nf1, non], [of1, of2])
|
|
403
|
-
end
|
|
404
|
-
|
|
405
|
-
def test_uptodate_with_out_of_date_config_file
|
|
406
|
-
filepath = trs.filepath(:config, "configured-0.1.yml")
|
|
407
|
-
assert !File.exists?(filepath)
|
|
408
|
-
begin
|
|
409
|
-
of1, of2, nf1, nf2 = uptodate_test_setup
|
|
410
|
-
FileUtils.touch(filepath)
|
|
411
|
-
t = Tap::FileTask.new "configured-0.1"
|
|
412
|
-
|
|
413
|
-
assert !t.uptodate?(nf1)
|
|
414
|
-
assert !t.uptodate?(nf1, of1)
|
|
415
|
-
assert !t.uptodate?([nf1, nf2], [of1, of2])
|
|
416
|
-
rescue
|
|
417
|
-
raise $!
|
|
418
|
-
ensure
|
|
419
|
-
FileUtils.rm(filepath) if File.exists?(filepath)
|
|
420
|
-
end
|
|
421
|
-
end
|
|
422
|
-
|
|
423
|
-
def test_uptodate_returns_false_when_force
|
|
424
|
-
of1, of2, nf1, nf2 = uptodate_test_setup
|
|
425
|
-
|
|
426
|
-
assert t.uptodate?(nf1, of1)
|
|
427
|
-
with_options :force => true, :quiet => true do
|
|
428
|
-
assert app.options.force
|
|
429
|
-
assert !t.uptodate?(nf1, of1)
|
|
430
|
-
end
|
|
431
|
-
end
|
|
432
|
-
|
|
433
|
-
#
|
|
434
|
-
# backup tests
|
|
435
|
-
#
|
|
436
|
-
|
|
437
|
-
def test_backup_restore_doc
|
|
438
|
-
FileUtils.mkdir_p(method_filepath(:output))
|
|
439
|
-
FileUtils.mkdir_p(method_filepath(:output))
|
|
440
|
-
|
|
441
|
-
file = method_filepath(:output, "file.txt")
|
|
442
|
-
File.open(file, "w") {|f| f << "file content"}
|
|
443
|
-
|
|
444
|
-
t = Tap::FileTask.new
|
|
445
|
-
t.app[:backup, true] = method_filepath(:backup)
|
|
446
|
-
backed_up_file = t.backup(file).first
|
|
447
|
-
|
|
448
|
-
assert !File.exists?(file)
|
|
449
|
-
assert File.exists?(backed_up_file)
|
|
450
|
-
assert_equal "file content", File.read(backed_up_file)
|
|
451
|
-
|
|
452
|
-
File.open(file, "w") {|f| f << "new content"}
|
|
453
|
-
t.restore(file)
|
|
454
|
-
|
|
455
|
-
assert File.exists?(file)
|
|
456
|
-
assert !File.exists?(backed_up_file)
|
|
457
|
-
assert_equal "file content", File.read(file)
|
|
458
|
-
end
|
|
459
|
-
|
|
460
|
-
def backup_test_setup
|
|
461
|
-
existing_file = method_filepath(:output, "file.txt")
|
|
462
|
-
backup_file = method_filepath(:output, "backup.txt")
|
|
463
|
-
|
|
464
|
-
touch_file(existing_file, "existing content")
|
|
465
|
-
# assure backup_filepath will return backup_file
|
|
466
|
-
t.inference {|root, dir, path| backup_file}
|
|
467
|
-
|
|
468
|
-
[existing_file, backup_file]
|
|
469
|
-
end
|
|
470
|
-
|
|
471
|
-
def test_backup_test_setup
|
|
472
|
-
existing_file, backup_file = backup_test_setup
|
|
473
|
-
|
|
474
|
-
assert File.exists?(existing_file)
|
|
475
|
-
assert !File.exists?(backup_file)
|
|
476
|
-
|
|
477
|
-
assert_equal "existing content", File.read(existing_file)
|
|
478
|
-
assert_equal backup_file, t.backup_filepath(existing_file)
|
|
479
|
-
end
|
|
480
|
-
|
|
481
|
-
def test_backup_moves_filepath_to_backup_filepath
|
|
482
|
-
existing_file, backup_file = backup_test_setup
|
|
483
|
-
|
|
484
|
-
t.backup(existing_file)
|
|
485
|
-
|
|
486
|
-
assert !File.exists?(existing_file)
|
|
487
|
-
assert File.exists?(backup_file)
|
|
488
|
-
assert_equal "existing content", File.read(backup_file)
|
|
489
|
-
end
|
|
490
|
-
|
|
491
|
-
def test_backup_copies_filepath_to_backup_filepath_if_backup_using_copy_is_true
|
|
492
|
-
existing_file, backup_file = backup_test_setup
|
|
493
|
-
|
|
494
|
-
t.backup(existing_file, true)
|
|
495
|
-
|
|
496
|
-
assert File.exists?(existing_file)
|
|
497
|
-
assert File.exists?(backup_file)
|
|
498
|
-
assert FileUtils.compare_file(existing_file, backup_file)
|
|
499
|
-
end
|
|
500
|
-
|
|
501
|
-
def test_backup_registers_expanded_filepath_and_backup_filepath_in_backed_up_files
|
|
502
|
-
existing_file, backup_file = backup_test_setup
|
|
503
|
-
|
|
504
|
-
relative_filepath = Tap::Root.relative_filepath(Dir.pwd, existing_file)
|
|
505
|
-
assert_not_equal existing_file, relative_filepath
|
|
506
|
-
|
|
507
|
-
assert_equal existing_file, File.expand_path(existing_file)
|
|
508
|
-
assert_equal existing_file, File.expand_path(relative_filepath)
|
|
509
|
-
assert_equal backup_file, File.expand_path(backup_file)
|
|
510
|
-
|
|
511
|
-
assert_equal({}, t.backed_up_files)
|
|
512
|
-
t.backup(relative_filepath)
|
|
513
|
-
assert_equal({existing_file => backup_file}, t.backed_up_files)
|
|
514
|
-
end
|
|
515
|
-
|
|
516
|
-
def test_backup_does_nothing_if_filepath_does_not_exist
|
|
517
|
-
existing_file, backup_file = backup_test_setup
|
|
518
|
-
FileUtils.rm(existing_file)
|
|
519
|
-
|
|
520
|
-
assert !File.exists?(existing_file)
|
|
521
|
-
assert !File.exists?(backup_file)
|
|
522
|
-
assert_equal({}, t.backed_up_files)
|
|
523
|
-
|
|
524
|
-
t.backup(existing_file)
|
|
525
|
-
|
|
526
|
-
assert !File.exists?(existing_file)
|
|
527
|
-
assert !File.exists?(backup_file)
|
|
528
|
-
assert_equal({}, t.backed_up_files)
|
|
529
|
-
end
|
|
530
|
-
|
|
531
|
-
def test_backup_acts_on_list_and_returns_backup_files
|
|
532
|
-
existing_file0 = method_filepath(:output, "file0.txt")
|
|
533
|
-
existing_file1 = method_filepath(:output, "file1.txt")
|
|
534
|
-
backup_file0 = method_filepath(:output, "backup0.txt")
|
|
535
|
-
backup_file1 = method_filepath(:output, "backup1.txt")
|
|
536
|
-
|
|
537
|
-
touch_file(existing_file0)
|
|
538
|
-
touch_file(existing_file1)
|
|
539
|
-
t.inference do |root, dir, path|
|
|
540
|
-
path =~ /file0/ ? backup_file0 : backup_file1
|
|
541
|
-
end
|
|
542
|
-
|
|
543
|
-
assert !File.exists?(backup_file0)
|
|
544
|
-
assert !File.exists?(backup_file1)
|
|
545
|
-
|
|
546
|
-
assert_equal [File.expand_path(backup_file0), File.expand_path(backup_file1)], t.backup([existing_file0, existing_file1])
|
|
547
|
-
|
|
548
|
-
assert File.exists?(backup_file0)
|
|
549
|
-
assert File.exists?(backup_file1)
|
|
550
|
-
end
|
|
551
|
-
|
|
552
|
-
def test_backup_raises_error_if_backup_for_file_already_exists
|
|
553
|
-
existing_file, backup_file = backup_test_setup
|
|
554
|
-
t.backup(existing_file, true)
|
|
555
|
-
|
|
556
|
-
assert_raise(RuntimeError) { t.backup(existing_file) }
|
|
557
|
-
end
|
|
558
|
-
|
|
559
|
-
#
|
|
560
|
-
# restore tests
|
|
561
|
-
#
|
|
562
|
-
|
|
563
|
-
def test_restore_restores_backed_up_file_to_original_location_as_listed_in_backed_up_files
|
|
564
|
-
original_file = File.expand_path(method_filepath(:output, 'original/file.txt'))
|
|
565
|
-
backup_file = File.expand_path(method_filepath(:output, 'backup/file.txt'))
|
|
566
|
-
|
|
567
|
-
FileUtils.mkdir_p( File.dirname(original_file) )
|
|
568
|
-
touch_file(backup_file)
|
|
569
|
-
|
|
570
|
-
assert File.exists?(File.dirname(original_file))
|
|
571
|
-
assert !File.exists?(original_file)
|
|
572
|
-
assert File.exists?(backup_file)
|
|
573
|
-
|
|
574
|
-
t.backed_up_files[original_file] = backup_file
|
|
575
|
-
t.restore(original_file)
|
|
576
|
-
|
|
577
|
-
assert File.exists?(original_file)
|
|
578
|
-
assert !File.exists?(backup_file)
|
|
579
|
-
end
|
|
580
|
-
|
|
581
|
-
def test_restore_creates_dirs_as_needed_to_restore_file
|
|
582
|
-
original_file = File.expand_path(method_filepath(:output, 'original/file.txt'))
|
|
583
|
-
backup_file = File.expand_path(method_filepath(:output, 'backup/file.txt'))
|
|
584
|
-
|
|
585
|
-
touch_file(backup_file)
|
|
586
|
-
|
|
587
|
-
assert !File.exists?(File.dirname(original_file))
|
|
588
|
-
assert !File.exists?(original_file)
|
|
589
|
-
assert File.exists?(backup_file)
|
|
590
|
-
|
|
591
|
-
t.backed_up_files[original_file] = backup_file
|
|
592
|
-
t.restore(original_file)
|
|
593
|
-
|
|
594
|
-
assert File.exists?(original_file)
|
|
595
|
-
assert !File.exists?(backup_file)
|
|
596
|
-
end
|
|
597
|
-
|
|
598
|
-
def test_restore_does_nothing_if_the_input_file_is_not_backed_up
|
|
599
|
-
assert !File.exists?("original_file")
|
|
600
|
-
assert t.backed_up_files.empty?
|
|
601
|
-
assert_equal [], t.restore("original_file")
|
|
602
|
-
assert !File.exists?("original_file")
|
|
603
|
-
end
|
|
604
|
-
|
|
605
|
-
def test_restore_removes_backup_dir_using_rmdir
|
|
606
|
-
original_file = File.expand_path(method_filepath(:output, 'original/file.txt'))
|
|
607
|
-
backup_file = File.expand_path(method_filepath(:output, 'backup/file.txt'))
|
|
608
|
-
backup_dir = File.dirname(backup_file)
|
|
609
|
-
|
|
610
|
-
t.mkdir(backup_file)
|
|
611
|
-
assert File.exists?(backup_dir)
|
|
612
|
-
|
|
613
|
-
touch_file(backup_file)
|
|
614
|
-
|
|
615
|
-
t.backed_up_files[original_file] = backup_file
|
|
616
|
-
t.restore(original_file)
|
|
617
|
-
|
|
618
|
-
assert !File.exists?(backup_dir)
|
|
619
|
-
end
|
|
620
|
-
|
|
621
|
-
def test_restore_acts_on_list_and_returns_restored_files
|
|
622
|
-
existing_file0 = File.expand_path(method_filepath(:output, "file0.txt"))
|
|
623
|
-
existing_file1 = File.expand_path(method_filepath(:output, "file1.txt"))
|
|
624
|
-
backup_file0 = File.expand_path(method_filepath(:output, "backup0.txt"))
|
|
625
|
-
backup_file1 = File.expand_path(method_filepath(:output, "backup1.txt"))
|
|
626
|
-
|
|
627
|
-
touch_file(backup_file0)
|
|
628
|
-
touch_file(backup_file1)
|
|
629
|
-
|
|
630
|
-
t.backed_up_files[existing_file0] = backup_file0
|
|
631
|
-
t.backed_up_files[existing_file1] = backup_file1
|
|
632
|
-
|
|
633
|
-
assert !File.exists?(existing_file0)
|
|
634
|
-
assert !File.exists?(existing_file1)
|
|
635
|
-
|
|
636
|
-
assert_equal [existing_file0, existing_file1], t.restore([existing_file0, existing_file1])
|
|
637
|
-
|
|
638
|
-
assert File.exists?(existing_file0)
|
|
639
|
-
assert File.exists?(existing_file1)
|
|
640
|
-
end
|
|
641
|
-
|
|
642
|
-
#
|
|
643
|
-
# mkdir tests
|
|
644
|
-
#
|
|
645
|
-
|
|
646
|
-
def test_mkdir_documentation
|
|
647
|
-
dir_one = method_filepath(:output, "path/to/dir")
|
|
648
|
-
dir_two = method_filepath(:output, "path/to/another")
|
|
649
|
-
|
|
650
|
-
t = Tap::FileTask.new do |task, inputs|
|
|
651
|
-
assert !File.exists?(method_filepath(:output, "path"))
|
|
652
|
-
|
|
653
|
-
task.mkdir(dir_one)
|
|
654
|
-
assert File.exists?(dir_one)
|
|
655
|
-
|
|
656
|
-
FileUtils.mkdir(dir_two)
|
|
657
|
-
assert File.exists?(dir_two)
|
|
658
|
-
|
|
659
|
-
raise "error!"
|
|
660
|
-
end
|
|
661
|
-
|
|
662
|
-
begin
|
|
663
|
-
t.execute(nil)
|
|
664
|
-
flunk "no error raised"
|
|
665
|
-
rescue
|
|
666
|
-
assert_equal "error!", $!.message
|
|
667
|
-
assert !File.exists?(dir_one)
|
|
668
|
-
assert File.exists?(dir_two)
|
|
669
|
-
end
|
|
670
|
-
end
|
|
671
|
-
|
|
672
|
-
def test_mkdir_creates_dir_if_it_does_not_exist
|
|
673
|
-
dir = method_filepath(:output, 'path/to/non_existant_folder')
|
|
674
|
-
FileUtils.mkdir_p(File.dirname(dir))
|
|
675
|
-
assert !File.exists?(dir)
|
|
676
|
-
|
|
677
|
-
t.mkdir(dir)
|
|
678
|
-
assert File.exists?(dir)
|
|
679
|
-
end
|
|
680
|
-
|
|
681
|
-
def test_mkdir_creates_parent_dirs_if_they_do_not_exist
|
|
682
|
-
dir = method_filepath(:output, 'path/to/non_existant_folder')
|
|
683
|
-
assert !File.exists?(method_filepath(:output))
|
|
684
|
-
|
|
685
|
-
t.mkdir(dir)
|
|
686
|
-
assert File.exists?(dir)
|
|
687
|
-
end
|
|
688
|
-
|
|
689
|
-
def test_mkdir_registers_expanded_dir_and_all_non_existing_parent_dirs_in_added_files
|
|
690
|
-
dir = method_filepath(:output, 'path/to/non_existant_folder')
|
|
691
|
-
assert_equal [], t.added_files
|
|
692
|
-
|
|
693
|
-
relative_dir = Tap::Root.relative_filepath(Dir.pwd, dir)
|
|
694
|
-
assert_not_equal dir, relative_dir
|
|
695
|
-
assert_equal dir, File.expand_path(relative_dir)
|
|
696
|
-
|
|
697
|
-
t.mkdir(relative_dir)
|
|
698
|
-
|
|
699
|
-
expected = [
|
|
700
|
-
method_root,
|
|
701
|
-
method_filepath(:output),
|
|
702
|
-
method_filepath(:output, 'path'),
|
|
703
|
-
method_filepath(:output, 'path/to'),
|
|
704
|
-
method_filepath(:output, 'path/to/non_existant_folder')
|
|
705
|
-
]
|
|
706
|
-
|
|
707
|
-
assert_equal expected, t.added_files
|
|
708
|
-
end
|
|
709
|
-
|
|
710
|
-
def test_mkdir_acts_on_and_returns_list
|
|
711
|
-
dir = method_filepath(:output, 'path')
|
|
712
|
-
another = method_filepath(:output, 'another')
|
|
713
|
-
|
|
714
|
-
assert !File.exists?(dir)
|
|
715
|
-
assert !File.exists?(another)
|
|
716
|
-
|
|
717
|
-
assert_equal [dir, another], t.mkdir([dir, another])
|
|
718
|
-
|
|
719
|
-
assert File.exists?(dir)
|
|
720
|
-
assert File.exists?(another)
|
|
721
|
-
end
|
|
722
|
-
|
|
723
|
-
#
|
|
724
|
-
# rmdir tests
|
|
725
|
-
#
|
|
726
|
-
|
|
727
|
-
def test_rmdir_documentation
|
|
728
|
-
dir_one = method_filepath(:output, 'path')
|
|
729
|
-
dir_two = method_filepath(:output, 'path/to/dir')
|
|
730
|
-
FileUtils.mkdir_p( method_filepath(:output) )
|
|
731
|
-
|
|
732
|
-
t = Tap::FileTask.new
|
|
733
|
-
assert !File.exists?(dir_one)
|
|
734
|
-
FileUtils.mkdir(dir_one)
|
|
735
|
-
|
|
736
|
-
t.mkdir(dir_two)
|
|
737
|
-
assert File.exists?(dir_two)
|
|
738
|
-
|
|
739
|
-
t.rmdir(dir_two)
|
|
740
|
-
assert File.exists?(dir_one)
|
|
741
|
-
assert !File.exists?(method_filepath(:output, 'path/to'))
|
|
742
|
-
end
|
|
743
|
-
|
|
744
|
-
def test_rmdir_removes_dir_if_made_by_the_task
|
|
745
|
-
dir = method_filepath(:output, 'path/to/non_existant_folder')
|
|
746
|
-
existing_dir = method_filepath(:output, 'path/to')
|
|
747
|
-
|
|
748
|
-
FileUtils.mkdir_p(existing_dir)
|
|
749
|
-
assert File.exists?(existing_dir)
|
|
750
|
-
assert !File.exists?(dir)
|
|
751
|
-
|
|
752
|
-
t.mkdir(dir)
|
|
753
|
-
assert File.exists?(dir)
|
|
754
|
-
|
|
755
|
-
t.rmdir(dir)
|
|
756
|
-
assert File.exists?(existing_dir)
|
|
757
|
-
assert !File.exists?(dir)
|
|
758
|
-
end
|
|
759
|
-
|
|
760
|
-
def test_rmdir_removes_parent_dirs_if_made_by_the_task
|
|
761
|
-
dir = method_filepath(:output, 'path/to/non/existant/folder')
|
|
762
|
-
root_parent_dir = method_filepath(:output, 'path/to')
|
|
763
|
-
existing_dir = method_filepath(:output, 'path')
|
|
764
|
-
|
|
765
|
-
FileUtils.mkdir_p(existing_dir)
|
|
766
|
-
assert File.exists?(existing_dir)
|
|
767
|
-
assert !File.exists?(root_parent_dir)
|
|
768
|
-
|
|
769
|
-
t.mkdir(dir)
|
|
770
|
-
assert File.exists?(dir)
|
|
771
|
-
|
|
772
|
-
t.rmdir(dir)
|
|
773
|
-
assert File.exists?(existing_dir)
|
|
774
|
-
assert !File.exists?(root_parent_dir)
|
|
775
|
-
end
|
|
776
|
-
|
|
777
|
-
def test_rmdir_does_not_remove_if_dir_was_not_made_by_task
|
|
778
|
-
dir = method_filepath(:output, 'path/to/non_existant_folder')
|
|
779
|
-
|
|
780
|
-
FileUtils.mkdir_p(dir)
|
|
781
|
-
assert File.exists?(dir)
|
|
782
|
-
|
|
783
|
-
t.rmdir(dir)
|
|
784
|
-
assert File.exists?(dir)
|
|
785
|
-
end
|
|
786
|
-
|
|
787
|
-
def test_rmdir_does_not_remove_if_folder_is_not_empty
|
|
788
|
-
dir = method_filepath(:output, 'path/to/folder')
|
|
789
|
-
not_empty_dir = method_filepath(:output, 'path/to')
|
|
790
|
-
|
|
791
|
-
t.mkdir(dir)
|
|
792
|
-
assert File.exists?(dir)
|
|
793
|
-
|
|
794
|
-
touch_file File.join(not_empty_dir, "file.txt")
|
|
795
|
-
|
|
796
|
-
t.rmdir(dir)
|
|
797
|
-
assert File.exists?(not_empty_dir)
|
|
798
|
-
assert !File.exists?(dir)
|
|
799
|
-
end
|
|
800
|
-
|
|
801
|
-
def test_rmdir_checks_for_hidden_files_as_well_as_regular_files
|
|
802
|
-
dir = method_filepath(:output, 'path/to/folder')
|
|
803
|
-
not_empty_dir = method_filepath(:output, 'path/to')
|
|
804
|
-
|
|
805
|
-
t.mkdir(dir)
|
|
806
|
-
assert File.exists?(dir)
|
|
807
|
-
|
|
808
|
-
touch_file File.join(not_empty_dir, ".hidden_file")
|
|
809
|
-
|
|
810
|
-
t.rmdir(dir)
|
|
811
|
-
assert File.exists?(not_empty_dir)
|
|
812
|
-
assert !File.exists?(dir)
|
|
813
|
-
end
|
|
814
|
-
|
|
815
|
-
def test_rmdir_clears_added_files_of_removed_dirs
|
|
816
|
-
dir = method_filepath(:output, 'path/to/folder')
|
|
817
|
-
|
|
818
|
-
FileUtils.mkdir_p(method_filepath(:output))
|
|
819
|
-
assert_equal [], t.added_files
|
|
820
|
-
|
|
821
|
-
t.mkdir(dir)
|
|
822
|
-
assert_equal [
|
|
823
|
-
File.expand_path(method_filepath(:output, 'path')),
|
|
824
|
-
File.expand_path(method_filepath(:output, 'path/to')),
|
|
825
|
-
File.expand_path(method_filepath(:output, 'path/to/folder'))], t.added_files
|
|
826
|
-
|
|
827
|
-
# touch a file so the 'path' folder isn't removed
|
|
828
|
-
touch_file method_filepath(:output, 'path/file.txt')
|
|
829
|
-
|
|
830
|
-
t.rmdir(dir)
|
|
831
|
-
assert_equal [
|
|
832
|
-
File.expand_path(method_filepath(:output, 'path'))], t.added_files
|
|
833
|
-
end
|
|
834
|
-
|
|
835
|
-
def test_rmdir_acts_on_and_returns_expanded_list_of_removed_dirs
|
|
836
|
-
dir = method_filepath(:output, 'path')
|
|
837
|
-
another = method_filepath(:output, 'another')
|
|
838
|
-
not_removed = method_filepath(:output, 'not')
|
|
839
|
-
removed = method_filepath(:output, 'not/removed')
|
|
840
|
-
|
|
841
|
-
t.mkdir([dir, another, not_removed, removed])
|
|
842
|
-
# touch a file so the not_removed folder isn't removed
|
|
843
|
-
touch_file method_filepath(:output, 'not/file.txt')
|
|
844
|
-
|
|
845
|
-
expected = [dir, another, removed].collect {|d| File.expand_path(d)}
|
|
846
|
-
assert_equal expected, t.rmdir([dir, another, not_removed, removed])
|
|
847
|
-
end
|
|
848
|
-
|
|
849
|
-
#
|
|
850
|
-
# prepare tests
|
|
851
|
-
#
|
|
852
|
-
|
|
853
|
-
def test_prepare_documentation
|
|
854
|
-
file_one = method_filepath(:output, "file.txt")
|
|
855
|
-
file_two = method_filepath(:output, "path/to/file.txt")
|
|
856
|
-
FileUtils.mkdir_p( method_filepath(:output) )
|
|
857
|
-
|
|
858
|
-
File.open(file_one, "w") {|f| f << "original content"}
|
|
859
|
-
t = Tap::FileTask.new do |task, inputs|
|
|
860
|
-
assert !File.exists?(method_filepath(:output, "path"))
|
|
861
|
-
|
|
862
|
-
# backup... prepare parent dirs... prepare for restore
|
|
863
|
-
task.prepare([file_one, file_two])
|
|
864
|
-
|
|
865
|
-
File.open(file_one, "w") {|f| f << "new content"}
|
|
866
|
-
FileUtils.touch(file_two)
|
|
867
|
-
|
|
868
|
-
raise "error!"
|
|
869
|
-
end
|
|
870
|
-
|
|
871
|
-
begin
|
|
872
|
-
t.execute(nil)
|
|
873
|
-
flunk "no error raised"
|
|
874
|
-
rescue
|
|
875
|
-
assert_equal "error!", $!.message
|
|
876
|
-
assert File.exists?(file_one)
|
|
877
|
-
assert_equal "original content", File.read(file_one)
|
|
878
|
-
assert !File.exists?(method_filepath(:output, "path"))
|
|
879
|
-
end
|
|
880
|
-
end
|
|
881
|
-
|
|
882
|
-
def test_prepare_acts_on_and_returns_list
|
|
883
|
-
filepath = "file.txt"
|
|
884
|
-
another = "another.txt"
|
|
885
|
-
assert_equal [filepath, another], t.prepare([filepath, another])
|
|
886
|
-
end
|
|
887
|
-
|
|
888
|
-
def test_prepare_backs_up_existing_files_and_creates_non_existant_dirs
|
|
889
|
-
existing_file = method_filepath(:output, "path/to/existing/file.txt")
|
|
890
|
-
non_existant_file = method_filepath(:output, "path/to/non/existant/file.txt")
|
|
891
|
-
touch_file(existing_file, "existing content")
|
|
892
|
-
|
|
893
|
-
# be sure inference leads files to an output dir, for cleanup
|
|
894
|
-
removal_path = method_filepath(:output, 'removal')
|
|
895
|
-
t.inference {|root, dir, path| removal_path}
|
|
896
|
-
|
|
897
|
-
assert File.exists?(existing_file)
|
|
898
|
-
assert !File.exists?(non_existant_file)
|
|
899
|
-
|
|
900
|
-
files = [existing_file, non_existant_file]
|
|
901
|
-
t.prepare(files)
|
|
902
|
-
|
|
903
|
-
# check neither of the files exist at this point
|
|
904
|
-
# and the parent dirs all exist
|
|
905
|
-
files.each do |file|
|
|
906
|
-
assert !File.exists?(file)
|
|
907
|
-
assert File.exists?(File.dirname(file))
|
|
908
|
-
end
|
|
909
|
-
|
|
910
|
-
# check the existing file was backed up
|
|
911
|
-
assert_equal({File.expand_path(existing_file) => File.expand_path(removal_path)}, t.backed_up_files)
|
|
912
|
-
assert_equal "existing content", File.read(removal_path)
|
|
913
|
-
end
|
|
914
|
-
|
|
915
|
-
def test_prepare_adds_list_to_added_files
|
|
916
|
-
existing_file = method_filepath(:output, "path/to/existing/file.txt")
|
|
917
|
-
non_existant_file = method_filepath(:output, "path/to/non/existant/file.txt")
|
|
918
|
-
touch_file(existing_file)
|
|
919
|
-
|
|
920
|
-
# be sure inference leads files to an output dir, for cleanup
|
|
921
|
-
removal_path = method_filepath(:output, 'removal')
|
|
922
|
-
t.inference {|root, dir, path| File.join(removal_path, path) }
|
|
923
|
-
|
|
924
|
-
assert_equal([], t.added_files)
|
|
925
|
-
assert File.exists?(existing_file)
|
|
926
|
-
assert !File.exists?(non_existant_file)
|
|
927
|
-
assert !File.exists?(removal_path)
|
|
928
|
-
|
|
929
|
-
files = [existing_file, non_existant_file]
|
|
930
|
-
t.prepare(files)
|
|
931
|
-
|
|
932
|
-
expected = [
|
|
933
|
-
removal_path, # added by backup of existing_file
|
|
934
|
-
method_filepath(:output, 'path/to/non'), # added by mkdir
|
|
935
|
-
method_filepath(:output, 'path/to/non/existant'), # added by mkdir
|
|
936
|
-
existing_file, # added by prepare
|
|
937
|
-
non_existant_file # added by prepare
|
|
938
|
-
].collect do |dir|
|
|
939
|
-
File.expand_path(dir)
|
|
940
|
-
end
|
|
941
|
-
|
|
942
|
-
assert_equal expected, t.added_files
|
|
943
|
-
end
|
|
944
|
-
|
|
945
|
-
#
|
|
946
|
-
# rm tests
|
|
947
|
-
#
|
|
948
|
-
|
|
949
|
-
def test_rm_documentation
|
|
950
|
-
dir = method_filepath(:output, 'path')
|
|
951
|
-
file = method_filepath(:output, 'path/to/file.txt')
|
|
952
|
-
FileUtils.mkdir_p( method_filepath(:output) )
|
|
953
|
-
|
|
954
|
-
t = Tap::FileTask.new
|
|
955
|
-
assert !File.exists?(dir)
|
|
956
|
-
FileUtils.mkdir(dir)
|
|
957
|
-
|
|
958
|
-
t.prepare(file)
|
|
959
|
-
FileUtils.touch(file)
|
|
960
|
-
assert File.exists?(file)
|
|
961
|
-
|
|
962
|
-
t.rm(file)
|
|
963
|
-
assert File.exists?(dir)
|
|
964
|
-
assert !File.exists?(method_filepath(:output, 'path/to'))
|
|
965
|
-
end
|
|
966
|
-
|
|
967
|
-
def test_rm_removes_file_and_parent_dirs_if_made_by_the_task
|
|
968
|
-
file = method_filepath(:output, 'path/to/file.txt')
|
|
969
|
-
parent_dir = method_filepath(:output, 'path/to')
|
|
970
|
-
existing_dir = method_filepath(:output, 'path')
|
|
971
|
-
FileUtils.mkdir_p existing_dir
|
|
972
|
-
|
|
973
|
-
assert File.exists?(existing_dir)
|
|
974
|
-
assert !File.exists?(file)
|
|
975
|
-
|
|
976
|
-
t.prepare file
|
|
977
|
-
touch_file(file)
|
|
978
|
-
assert File.exists?(file)
|
|
979
|
-
|
|
980
|
-
t.rm(file)
|
|
981
|
-
assert File.exists?(existing_dir)
|
|
982
|
-
assert !File.exists?(parent_dir)
|
|
983
|
-
assert !File.exists?(file)
|
|
984
|
-
end
|
|
985
|
-
|
|
986
|
-
def test_rm_removes_parent_dirs_even_if_file_does_not_exist
|
|
987
|
-
file = method_filepath(:output, 'path/to/file.txt')
|
|
988
|
-
parent_dir = method_filepath(:output, 'path/to')
|
|
989
|
-
existing_dir = method_filepath(:output, 'path')
|
|
990
|
-
FileUtils.mkdir_p existing_dir
|
|
991
|
-
|
|
992
|
-
assert File.exists?(existing_dir)
|
|
993
|
-
assert !File.exists?(file)
|
|
994
|
-
|
|
995
|
-
t.prepare file
|
|
996
|
-
assert !File.exists?(file)
|
|
997
|
-
|
|
998
|
-
t.rm(file)
|
|
999
|
-
assert File.exists?(existing_dir)
|
|
1000
|
-
assert !File.exists?(parent_dir)
|
|
1001
|
-
end
|
|
1002
|
-
|
|
1003
|
-
def test_rm_does_not_remove_file_if_not_made_by_the_task
|
|
1004
|
-
file = method_filepath(:output, 'path/to/file.txt')
|
|
1005
|
-
|
|
1006
|
-
touch_file(file)
|
|
1007
|
-
assert File.exists?(file)
|
|
1008
|
-
|
|
1009
|
-
t.rm(file)
|
|
1010
|
-
assert File.exists?(file)
|
|
1011
|
-
end
|
|
1012
|
-
|
|
1013
|
-
def test_rm_clears_added_files_of_removed_files
|
|
1014
|
-
file0 = method_filepath(:output, 'file0.txt')
|
|
1015
|
-
file1 = method_filepath(:output, 'file1.txt')
|
|
1016
|
-
|
|
1017
|
-
FileUtils.mkdir_p(method_filepath(:output))
|
|
1018
|
-
assert_equal [], t.added_files
|
|
1019
|
-
|
|
1020
|
-
t.prepare([file0,file1])
|
|
1021
|
-
assert_equal [
|
|
1022
|
-
File.expand_path(method_filepath(:output, 'file0.txt')),
|
|
1023
|
-
File.expand_path(method_filepath(:output, 'file1.txt'))], t.added_files
|
|
1024
|
-
|
|
1025
|
-
t.rm(file0)
|
|
1026
|
-
assert_equal [
|
|
1027
|
-
File.expand_path(method_filepath(:output, 'file1.txt'))], t.added_files
|
|
1028
|
-
end
|
|
1029
|
-
|
|
1030
|
-
def test_rm_acts_on_and_returns_expanded_list_of_removed_files_and_dirs
|
|
1031
|
-
file = method_filepath(:output, 'file.txt')
|
|
1032
|
-
another = method_filepath(:output, 'another.txt')
|
|
1033
|
-
not_removed = method_filepath(:output, 'not')
|
|
1034
|
-
removed = method_filepath(:output, 'not/removed.txt')
|
|
1035
|
-
|
|
1036
|
-
t.prepare([file, another, removed])
|
|
1037
|
-
# touch a file so the not_removed folder isn't removed
|
|
1038
|
-
touch_file method_filepath(:output, 'not/file.txt')
|
|
1039
|
-
|
|
1040
|
-
expected = [file, another, removed].collect {|f| File.expand_path(f)}
|
|
1041
|
-
assert_equal expected, t.rm([file, another, removed])
|
|
1042
|
-
end
|
|
1043
|
-
|
|
1044
|
-
#
|
|
1045
|
-
# execute tests
|
|
1046
|
-
#
|
|
1047
|
-
|
|
1048
|
-
def setup_execute_test(&block)
|
|
1049
|
-
existing_file = method_filepath(:output, "path/to/existing/file.txt")
|
|
1050
|
-
non_existant_dir = method_filepath(:output, "path/to/non/existing")
|
|
1051
|
-
non_existant_file = File.join(non_existant_dir, "file.txt")
|
|
1052
|
-
backup_file = method_filepath(:output, "backup/file.txt")
|
|
1053
|
-
|
|
1054
|
-
touch_file(existing_file, "original content")
|
|
1055
|
-
@t = Tap::FileTask.new do |task, input|
|
|
1056
|
-
task.prepare([existing_file, non_existant_file])
|
|
1057
|
-
|
|
1058
|
-
block.call if block_given?
|
|
1059
|
-
end
|
|
1060
|
-
# inference leads to the backup_file
|
|
1061
|
-
@t.inference do |root, dir, path|
|
|
1062
|
-
backup_file
|
|
1063
|
-
end
|
|
1064
|
-
|
|
1065
|
-
[existing_file, backup_file, non_existant_dir, non_existant_file]
|
|
1066
|
-
end
|
|
1067
|
-
|
|
1068
|
-
def test_setup_execute_test
|
|
1069
|
-
existing_file, backup_file, non_existant_dir, non_existant_file = setup_execute_test do
|
|
1070
|
-
assert !File.exists?(non_existant_file)
|
|
1071
|
-
assert File.exists?(non_existant_dir)
|
|
1072
|
-
assert File.exists?(backup_file)
|
|
1073
|
-
assert_equal "original content", File.read(backup_file)
|
|
1074
|
-
end
|
|
1075
|
-
t.execute(nil)
|
|
1076
|
-
end
|
|
1077
|
-
|
|
1078
|
-
def test_execute_restores_backups_and_removes_added_files_on_error
|
|
1079
|
-
was_in_execute = false
|
|
1080
|
-
existing_file, backup_file, non_existant_dir, non_existant_file = setup_execute_test do
|
|
1081
|
-
was_in_execute = true
|
|
1082
|
-
raise "error"
|
|
1083
|
-
end
|
|
1084
|
-
|
|
1085
|
-
assert_raise(RuntimeError) { t.execute(nil) }
|
|
1086
|
-
|
|
1087
|
-
# check the existing file was restored
|
|
1088
|
-
assert was_in_execute
|
|
1089
|
-
assert File.exists?(existing_file)
|
|
1090
|
-
assert !File.exists?(non_existant_dir)
|
|
1091
|
-
assert !File.exists?(backup_file)
|
|
1092
|
-
assert_equal "original content", File.read(existing_file)
|
|
1093
|
-
assert t.added_files.empty?
|
|
1094
|
-
assert t.backed_up_files.empty?
|
|
1095
|
-
end
|
|
1096
|
-
|
|
1097
|
-
def test_execute_does_not_restore_backups_if_rollback_on_error_is_false
|
|
1098
|
-
was_in_execute = false
|
|
1099
|
-
existing_file, backup_file, non_existant_dir, non_existant_file = setup_execute_test do
|
|
1100
|
-
was_in_execute = true
|
|
1101
|
-
raise "error"
|
|
1102
|
-
end
|
|
1103
|
-
|
|
1104
|
-
t.rollback_on_error = false
|
|
1105
|
-
assert_raise(RuntimeError) { t.execute(nil) }
|
|
1106
|
-
|
|
1107
|
-
# check the existing file was NOT restored
|
|
1108
|
-
assert was_in_execute
|
|
1109
|
-
assert !File.exists?(existing_file)
|
|
1110
|
-
assert File.exists?(non_existant_dir)
|
|
1111
|
-
assert File.exists?(backup_file)
|
|
1112
|
-
assert_equal "original content", File.read(backup_file)
|
|
1113
|
-
assert !t.added_files.empty?
|
|
1114
|
-
assert !t.backed_up_files.empty?
|
|
1115
|
-
end
|
|
1116
|
-
|
|
1117
|
-
# def test_execute_removes_backed_up_files_if_cleanup_after_execute_is_true
|
|
1118
|
-
# was_in_execute = false
|
|
1119
|
-
# existing_file, backup_file, non_existant_dir, non_existant_file = setup_execute_test do
|
|
1120
|
-
# was_in_execute = true
|
|
1121
|
-
# touch_file(existing_file, "new content")
|
|
1122
|
-
# end
|
|
1123
|
-
#
|
|
1124
|
-
# t.cleanup_after_execute = true
|
|
1125
|
-
# t.execute(nil)
|
|
1126
|
-
#
|
|
1127
|
-
# # check the backup file was removed and that
|
|
1128
|
-
# # there was no restore (no error was raised)
|
|
1129
|
-
# assert was_in_execute
|
|
1130
|
-
# assert File.exists?(existing_file)
|
|
1131
|
-
# assert_equal "new content", File.read(existing_file)
|
|
1132
|
-
# assert !File.exists?(backup_file)
|
|
1133
|
-
# assert !File.exists?(File.dirname(backup_file))
|
|
1134
|
-
# assert !t.added_files.empty?
|
|
1135
|
-
# assert !t.added_files.include?(backup_file)
|
|
1136
|
-
# assert t.backed_up_files.empty?
|
|
1137
|
-
# end
|
|
1138
|
-
|
|
1139
|
-
# def test_execute_restores_backups_on_error_even_if_cleanup_after_execute_is_true
|
|
1140
|
-
# was_in_execute = false
|
|
1141
|
-
# existing_file, backup_file, non_existant_dir, non_existant_file = setup_execute_test do
|
|
1142
|
-
# was_in_execute = true
|
|
1143
|
-
# touch_file(existing_file, "new content")
|
|
1144
|
-
# raise "error"
|
|
1145
|
-
# end
|
|
1146
|
-
#
|
|
1147
|
-
# t.cleanup_after_execute = true
|
|
1148
|
-
# assert_raise(RuntimeError) { t.execute(nil) }
|
|
1149
|
-
#
|
|
1150
|
-
# # check the existing file was restored and
|
|
1151
|
-
# # backup file was removed
|
|
1152
|
-
# assert was_in_execute
|
|
1153
|
-
# assert File.exists?(existing_file)
|
|
1154
|
-
# assert_equal "original content", File.read(existing_file)
|
|
1155
|
-
# assert !File.exists?(backup_file)
|
|
1156
|
-
# assert !File.exists?(File.dirname(backup_file))
|
|
1157
|
-
# assert t.added_files.empty?
|
|
1158
|
-
# assert t.backed_up_files.empty?
|
|
1159
|
-
# end
|
|
1160
|
-
|
|
1161
|
-
def test_execute_does_not_rollback_results_from_prior_successful_executions
|
|
1162
|
-
existing_file = method_filepath(:output, "path/to/existing/file.txt")
|
|
1163
|
-
non_existant_dir = method_filepath(:output, "path/to/non/existing")
|
|
1164
|
-
non_existant_file = File.join(non_existant_dir, "file.txt")
|
|
1165
|
-
backup_file = method_filepath(:output, "backup/file.txt")
|
|
1166
|
-
|
|
1167
|
-
touch_file(existing_file, "original content")
|
|
1168
|
-
count = 0
|
|
1169
|
-
@t = Tap::FileTask.new do |task, input|
|
|
1170
|
-
if count > 0
|
|
1171
|
-
count = 2
|
|
1172
|
-
raise "error"
|
|
1173
|
-
else
|
|
1174
|
-
count = 1
|
|
1175
|
-
task.prepare([existing_file, non_existant_file])
|
|
1176
|
-
touch_file(existing_file, "new content")
|
|
1177
|
-
end
|
|
1178
|
-
end
|
|
1179
|
-
|
|
1180
|
-
# inference leads to the backup_file
|
|
1181
|
-
@t.inference do |root, dir, path|
|
|
1182
|
-
backup_file
|
|
1183
|
-
end
|
|
1184
|
-
|
|
1185
|
-
# assert !t.cleanup_after_execute
|
|
1186
|
-
|
|
1187
|
-
assert_nothing_raised { t.execute(nil) }
|
|
1188
|
-
assert_equal 1, count
|
|
1189
|
-
assert File.exists?(existing_file)
|
|
1190
|
-
assert_equal "new content", File.read(existing_file)
|
|
1191
|
-
assert File.exists?(non_existant_dir)
|
|
1192
|
-
assert File.exists?(backup_file)
|
|
1193
|
-
assert_equal "original content", File.read(backup_file)
|
|
1194
|
-
|
|
1195
|
-
assert_raise(RuntimeError) { t.execute(nil) }
|
|
1196
|
-
|
|
1197
|
-
# check the existing file was NOT restored
|
|
1198
|
-
assert_equal 2, count
|
|
1199
|
-
assert File.exists?(existing_file)
|
|
1200
|
-
assert_equal "new content", File.read(existing_file)
|
|
1201
|
-
assert File.exists?(non_existant_dir)
|
|
1202
|
-
assert File.exists?(backup_file)
|
|
1203
|
-
assert_equal "original content", File.read(backup_file)
|
|
1204
|
-
end
|
|
1205
|
-
|
|
1206
|
-
#
|
|
1207
|
-
# test execute with multiple files
|
|
1208
|
-
#
|
|
1209
|
-
|
|
1210
|
-
def setup_multiple_file_execute_test(&block)
|
|
1211
|
-
existing_files = [0,1].collect do |n|
|
|
1212
|
-
path = method_filepath(:output, "path/to/existing/file#{n}.txt")
|
|
1213
|
-
touch_file path, n.to_s
|
|
1214
|
-
path
|
|
1215
|
-
end
|
|
1216
|
-
|
|
1217
|
-
non_existant_files = [0,1].collect do |n|
|
|
1218
|
-
method_filepath(:output, "path/to/non/existing/file#{n}.txt")
|
|
1219
|
-
end
|
|
1220
|
-
|
|
1221
|
-
@t = Tap::FileTask.new do |task, input|
|
|
1222
|
-
task.prepare(existing_files + non_existant_files)
|
|
1223
|
-
block.call if block_given?
|
|
1224
|
-
end
|
|
1225
|
-
# inference leads to an output_dir
|
|
1226
|
-
@t.inference do |root, dir, path|
|
|
1227
|
-
method_filepath(:output, 'backup', path)
|
|
1228
|
-
end
|
|
1229
|
-
|
|
1230
|
-
[existing_files, non_existant_files]
|
|
1231
|
-
end
|
|
1232
|
-
|
|
1233
|
-
def test_setup_multiple_file_execute_test
|
|
1234
|
-
existing_files, non_existant_files = setup_multiple_file_execute_test do
|
|
1235
|
-
(existing_files + existing_files).each do |file|
|
|
1236
|
-
assert !File.exists?(file)
|
|
1237
|
-
assert File.exists?(File.dirname(file))
|
|
1238
|
-
end
|
|
1239
|
-
end
|
|
1240
|
-
t.execute(nil)
|
|
1241
|
-
end
|
|
1242
|
-
|
|
1243
|
-
def test_execute_restore_and_removal_with_multiple_files
|
|
1244
|
-
was_in_execute = false
|
|
1245
|
-
existing_files, non_existant_files = setup_multiple_file_execute_test do
|
|
1246
|
-
was_in_execute = true
|
|
1247
|
-
(existing_files + non_existant_files) .each do |file|
|
|
1248
|
-
touch_file file, "new content"
|
|
1249
|
-
end
|
|
1250
|
-
raise "error"
|
|
1251
|
-
end
|
|
1252
|
-
|
|
1253
|
-
assert !File.exists?(method_filepath(:output, 'backup'))
|
|
1254
|
-
assert_raise(RuntimeError) { t.execute(nil) }
|
|
1255
|
-
|
|
1256
|
-
# check existing files were restored, made files and backups removed.
|
|
1257
|
-
assert was_in_execute
|
|
1258
|
-
existing_files.each_with_index do |existing_file, n|
|
|
1259
|
-
assert File.exists?(existing_file)
|
|
1260
|
-
assert_equal n.to_s, File.read(existing_file)
|
|
1261
|
-
end
|
|
1262
|
-
non_existant_files.each do |non_existing_file|
|
|
1263
|
-
assert !File.exists?(non_existing_file)
|
|
1264
|
-
end
|
|
1265
|
-
assert !File.exists?(method_filepath(:output, 'backup'))
|
|
1266
|
-
end
|
|
1267
|
-
|
|
1268
|
-
# def test_execute_cleanup_after_execute_with_multiple_files
|
|
1269
|
-
# was_in_execute = false
|
|
1270
|
-
# existing_files, non_existant_files = setup_multiple_file_execute_test do
|
|
1271
|
-
# was_in_execute = true
|
|
1272
|
-
# (existing_files + non_existant_files) .each do |file|
|
|
1273
|
-
# touch_file file, "new content"
|
|
1274
|
-
# end
|
|
1275
|
-
# end
|
|
1276
|
-
#
|
|
1277
|
-
# assert !File.exists?(method_filepath(:output, 'backup'))
|
|
1278
|
-
#
|
|
1279
|
-
# t.cleanup_after_execute = true
|
|
1280
|
-
# t.execute(nil)
|
|
1281
|
-
#
|
|
1282
|
-
# # check existing files were restored, made files and backups removed.
|
|
1283
|
-
# assert was_in_execute
|
|
1284
|
-
# (existing_files + non_existant_files).each do |file|
|
|
1285
|
-
# assert File.exists?(file)
|
|
1286
|
-
# assert_equal "new content", File.read(file)
|
|
1287
|
-
# end
|
|
1288
|
-
# assert !File.exists?(method_filepath(:output, 'backup'))
|
|
1289
|
-
# end
|
|
1290
|
-
|
|
1291
|
-
end
|