tap 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Basic Overview +151 -0
- data/Command Reference +99 -0
- data/History +24 -0
- data/MIT-LICENSE +1 -1
- data/README +29 -57
- data/Rakefile +30 -37
- data/Tutorial +243 -191
- data/bin/tap +66 -35
- data/lib/tap.rb +47 -29
- data/lib/tap/app.rb +700 -342
- data/lib/tap/{script → cmd}/console.rb +0 -0
- data/lib/tap/{script → cmd}/destroy.rb +0 -0
- data/lib/tap/{script → cmd}/generate.rb +0 -0
- data/lib/tap/cmd/run.rb +156 -0
- data/lib/tap/constants.rb +4 -0
- data/lib/tap/dump.rb +57 -0
- data/lib/tap/env.rb +316 -0
- data/lib/tap/file_task.rb +106 -109
- data/lib/tap/generator.rb +4 -1
- data/lib/tap/generator/generators/command/USAGE +6 -0
- data/lib/tap/generator/generators/command/command_generator.rb +17 -0
- data/lib/tap/generator/generators/{script/templates/script.erb → command/templates/command.erb} +10 -10
- data/lib/tap/generator/generators/config/USAGE +21 -0
- data/lib/tap/generator/generators/config/config_generator.rb +17 -7
- data/lib/tap/generator/generators/file_task/USAGE +3 -0
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +16 -0
- data/lib/tap/generator/generators/file_task/templates/file.txt +2 -0
- data/lib/tap/generator/generators/file_task/templates/file.yml +3 -0
- data/lib/tap/generator/generators/file_task/templates/task.erb +26 -20
- data/lib/tap/generator/generators/file_task/templates/test.erb +20 -10
- data/lib/tap/generator/generators/generator/generator_generator.rb +1 -1
- data/lib/tap/generator/generators/generator/templates/generator.erb +21 -12
- data/lib/tap/generator/generators/root/templates/Rakefile +33 -24
- data/lib/tap/generator/generators/root/templates/tap.yml +28 -31
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +1 -0
- data/lib/tap/generator/generators/task/USAGE +3 -0
- data/lib/tap/generator/generators/task/task_generator.rb +18 -5
- data/lib/tap/generator/generators/task/templates/task.erb +7 -12
- data/lib/tap/generator/generators/task/templates/test.erb +10 -11
- data/lib/tap/generator/generators/workflow/templates/task.erb +1 -1
- data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
- data/lib/tap/patches/rake/rake_test_loader.rb +8 -0
- data/lib/tap/patches/rake/testtask.rb +55 -0
- data/lib/tap/patches/ruby19/backtrace_filter.rb +51 -0
- data/lib/tap/patches/ruby19/parsedate.rb +16 -0
- data/lib/tap/root.rb +172 -67
- data/lib/tap/script.rb +70 -336
- data/lib/tap/support/aggregator.rb +55 -0
- data/lib/tap/support/audit.rb +281 -280
- data/lib/tap/support/batchable.rb +59 -0
- data/lib/tap/support/class_configuration.rb +279 -0
- data/lib/tap/support/configurable.rb +92 -0
- data/lib/tap/support/configurable_methods.rb +296 -0
- data/lib/tap/support/executable.rb +98 -0
- data/lib/tap/support/executable_queue.rb +82 -0
- data/lib/tap/support/logger.rb +9 -15
- data/lib/tap/support/rake.rb +43 -54
- data/lib/tap/support/run_error.rb +32 -13
- data/lib/tap/support/shell_utils.rb +47 -0
- data/lib/tap/support/tdoc.rb +9 -8
- data/lib/tap/support/tdoc/config_attr.rb +40 -16
- data/lib/tap/support/validation.rb +77 -0
- data/lib/tap/support/versions.rb +36 -36
- data/lib/tap/task.rb +276 -482
- data/lib/tap/test.rb +20 -261
- data/lib/tap/test/env_vars.rb +7 -5
- data/lib/tap/test/file_methods.rb +126 -121
- data/lib/tap/test/subset_methods.rb +86 -45
- data/lib/tap/test/tap_methods.rb +271 -0
- data/lib/tap/workflow.rb +174 -46
- data/test/app/config/another/task.yml +1 -0
- data/test/app/config/erb.yml +2 -1
- data/test/app/config/some/task.yml +1 -0
- data/test/app/config/template.yml +2 -6
- data/test/app_test.rb +1241 -1008
- data/test/env/test_configure/recurse_a.yml +2 -0
- data/test/env/test_configure/recurse_b.yml +2 -0
- data/test/env/test_configure/tap.yml +23 -0
- data/test/env/test_load_env_config/dir/tap.yml +3 -0
- data/test/env/test_load_env_config/recurse_a.yml +2 -0
- data/test/env/test_load_env_config/recurse_b.yml +2 -0
- data/test/env/test_load_env_config/tap.yml +3 -0
- data/test/env_test.rb +198 -0
- data/test/file_task_test.rb +70 -53
- data/{lib/tap/generator/generators/package/USAGE → test/root/file.txt} +0 -0
- data/test/root_test.rb +621 -454
- data/test/script_test.rb +38 -174
- data/test/support/aggregator_test.rb +99 -0
- data/test/support/audit_test.rb +409 -416
- data/test/support/batchable_test.rb +74 -0
- data/test/support/{task_configuration_test.rb → class_configuration_test.rb} +106 -47
- data/test/{task/config/overriding.yml → support/configurable/config/configured.yml} +0 -0
- data/test/support/configurable_test.rb +295 -0
- data/test/support/executable_queue_test.rb +103 -0
- data/test/support/executable_test.rb +38 -0
- data/test/support/logger_test.rb +17 -17
- data/test/support/rake_test.rb +4 -2
- data/test/support/shell_utils_test.rb +24 -0
- data/test/support/tdoc_test.rb +265 -258
- data/test/support/validation_test.rb +54 -0
- data/test/support/versions_test.rb +38 -38
- data/test/tap_test_helper.rb +19 -5
- data/test/tap_test_suite.rb +5 -2
- data/test/task_base_test.rb +13 -104
- data/test/task_syntax_test.rb +300 -0
- data/test/task_test.rb +258 -381
- data/test/test/env_vars_test.rb +40 -40
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/one.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/two.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/one.txt +0 -0
- data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/two.txt +0 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/one.txt +0 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/two.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/one.txt +1 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_different_content}/expected/two.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_different_content/input/two.txt +1 -0
- data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_missing_expected_file}/expected/one.txt +0 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/two.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/two.txt +1 -0
- data/test/test/file_methods_doc/test_sub/expected/one.txt +1 -0
- data/test/test/file_methods_doc/test_sub/expected/two.txt +1 -0
- data/test/test/file_methods_doc/test_sub/input/one.txt +1 -0
- data/test/test/file_methods_doc/test_sub/input/two.txt +1 -0
- data/test/test/file_methods_doc_test.rb +29 -0
- data/test/test/file_methods_test.rb +214 -143
- data/test/test/subset_methods_test.rb +111 -115
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/a.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/b.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/a.txt +0 -0
- data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/b.txt +0 -0
- data/test/test/tap_methods_test.rb +399 -0
- data/test/workflow_test.rb +101 -91
- metadata +86 -70
- data/lib/tap/generator/generators/package/package_generator.rb +0 -38
- data/lib/tap/generator/generators/package/templates/package.erb +0 -186
- data/lib/tap/generator/generators/script/USAGE +0 -0
- data/lib/tap/generator/generators/script/script_generator.rb +0 -17
- data/lib/tap/script/run.rb +0 -154
- data/lib/tap/support/batch_queue.rb +0 -162
- data/lib/tap/support/combinator.rb +0 -114
- data/lib/tap/support/task_configuration.rb +0 -169
- data/lib/tap/support/template.rb +0 -81
- data/lib/tap/support/templater.rb +0 -155
- data/lib/tap/version.rb +0 -4
- data/test/app/config/addition_template.yml +0 -6
- data/test/app_class_test.rb +0 -33
- data/test/check/binding_eval.rb +0 -23
- data/test/check/define_method_check.rb +0 -22
- data/test/check/dependencies_check.rb +0 -175
- data/test/check/inheritance_check.rb +0 -22
- data/test/support/batch_queue_test.rb +0 -320
- data/test/support/combinator_test.rb +0 -249
- data/test/support/template_test.rb +0 -122
- data/test/support/templater/erb.txt +0 -2
- data/test/support/templater/erb.yml +0 -2
- data/test/support/templater/somefile.txt +0 -2
- data/test/support/templater_test.rb +0 -192
- data/test/task/config/template.yml +0 -4
- data/test/task_class_test.rb +0 -170
- data/test/task_execute_test.rb +0 -262
- data/test/test/file_methods/test_assert_expected/expected/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/expected/folder/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/input/file.txt +0 -1
- data/test/test/file_methods/test_assert_expected/input/folder/file.txt +0 -1
- data/test/test/file_methods/test_assert_files_exist/input/input_1.txt +0 -0
- data/test/test/file_methods/test_assert_files_exist/input/input_2.txt +0 -0
- data/test/test/file_methods/test_file_compare/expected/output_1.txt +0 -3
- data/test/test/file_methods/test_file_compare/expected/output_2.txt +0 -1
- data/test/test/file_methods/test_file_compare/input/input_1.txt +0 -3
- data/test/test/file_methods/test_file_compare/input/input_2.txt +0 -3
- data/test/test/file_methods/test_infer_glob/expected/file.yml +0 -0
- data/test/test/file_methods/test_infer_glob/expected/file_1.txt +0 -0
- data/test/test/file_methods/test_infer_glob/expected/file_2.txt +0 -0
- data/test/test/file_methods/test_yml_compare/expected/output_1.yml +0 -6
- data/test/test/file_methods/test_yml_compare/expected/output_2.yml +0 -6
- data/test/test/file_methods/test_yml_compare/input/input_1.yml +0 -4
- data/test/test/file_methods/test_yml_compare/input/input_2.yml +0 -4
- data/test/test_test.rb +0 -373
@@ -0,0 +1,23 @@
|
|
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
ADDED
@@ -0,0 +1,198 @@
|
|
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
|
data/test/file_task_test.rb
CHANGED
@@ -9,6 +9,7 @@ class FileTaskTest < Test::Unit::TestCase
|
|
9
9
|
def setup
|
10
10
|
super
|
11
11
|
@t = Tap::FileTask.new
|
12
|
+
app.root = trs.root
|
12
13
|
end
|
13
14
|
|
14
15
|
def touch_file(path, content=nil)
|
@@ -47,7 +48,7 @@ class FileTaskTest < Test::Unit::TestCase
|
|
47
48
|
FileUtils.mkdir_p( method_filepath(:output) )
|
48
49
|
|
49
50
|
File.open(file_one, "w") {|f| f << "original content"}
|
50
|
-
t = Tap::FileTask.new do |task
|
51
|
+
t = Tap::FileTask.new do |task|
|
51
52
|
task.mkdir(dir)
|
52
53
|
task.prepare([file_one, file_two])
|
53
54
|
|
@@ -60,7 +61,7 @@ class FileTaskTest < Test::Unit::TestCase
|
|
60
61
|
begin
|
61
62
|
assert !File.exists?(dir)
|
62
63
|
assert !File.exists?(file_two)
|
63
|
-
t.execute
|
64
|
+
t.execute
|
64
65
|
flunk "no error raised"
|
65
66
|
rescue
|
66
67
|
assert_equal "error!", $!.message
|
@@ -69,105 +70,113 @@ class FileTaskTest < Test::Unit::TestCase
|
|
69
70
|
assert_equal "original content", File.read(file_one)
|
70
71
|
end
|
71
72
|
end
|
72
|
-
|
73
|
-
|
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
|
+
#
|
74
94
|
# open tests
|
75
95
|
#
|
76
|
-
|
96
|
+
|
77
97
|
def test_open_doc
|
78
98
|
FileUtils.mkdir_p(method_filepath(:output))
|
79
99
|
one_filepath = method_filepath(:output, "one.txt")
|
80
100
|
two_filepath = method_filepath(:output, "two.txt")
|
81
|
-
|
82
|
-
|
101
|
+
|
102
|
+
t.open([one_filepath, two_filepath], "w") do |one, two|
|
83
103
|
one << "one"
|
84
104
|
two << "two"
|
85
105
|
end
|
86
|
-
|
106
|
+
|
87
107
|
assert_equal "one", File.read(one_filepath)
|
88
108
|
assert_equal "two", File.read(two_filepath)
|
89
|
-
|
109
|
+
|
90
110
|
#
|
91
111
|
filepath = method_filepath(:output, "file.txt")
|
92
|
-
|
112
|
+
t.open(filepath, "w") do |array|
|
93
113
|
array.first << "content"
|
94
114
|
end
|
95
|
-
|
115
|
+
|
96
116
|
assert_equal "content", File.read(filepath)
|
97
117
|
end
|
98
|
-
|
118
|
+
|
99
119
|
def test_open_opens_each_file
|
100
120
|
FileUtils.mkdir_p(method_filepath(:output))
|
101
|
-
|
121
|
+
|
102
122
|
list = [0, 1].collect do |n|
|
103
123
|
path = method_filepath(:output, "#{n}.txt")
|
104
124
|
File.open(path, "w") {|f| f << n.to_s}
|
105
125
|
path
|
106
126
|
end
|
107
|
-
|
108
|
-
|
127
|
+
|
128
|
+
t.open(list) do |files|
|
109
129
|
files.each_with_index do |file, n|
|
110
130
|
assert_equal File, file.class
|
111
131
|
assert_equal n.to_s, file.read
|
112
132
|
end
|
113
133
|
end
|
114
134
|
end
|
115
|
-
|
135
|
+
|
116
136
|
def test_open_opens_with_input_mode
|
117
137
|
FileUtils.mkdir_p(method_filepath(:output))
|
118
|
-
|
138
|
+
|
119
139
|
list = [0, 1].collect do |n|
|
120
140
|
path = method_filepath(:output, "#{n}.txt")
|
121
141
|
path
|
122
142
|
end
|
123
|
-
|
124
|
-
|
143
|
+
|
144
|
+
t.open(list, "w") do |files|
|
125
145
|
files.each_with_index do |file, n|
|
126
146
|
assert_equal File, file.class
|
127
147
|
file << n.to_s
|
128
148
|
end
|
129
149
|
end
|
130
|
-
|
150
|
+
|
131
151
|
list.each_with_index do |file, n|
|
132
152
|
assert_equal n.to_s, File.read(file)
|
133
153
|
end
|
134
154
|
end
|
135
|
-
|
155
|
+
|
136
156
|
def test_open_returns_open_files_if_no_block_is_given
|
137
157
|
FileUtils.mkdir_p(method_filepath(:output))
|
138
|
-
|
158
|
+
|
139
159
|
list = [0, 1].collect do |n|
|
140
160
|
path = method_filepath(:output, "#{n}.txt")
|
141
161
|
File.open(path, "w") {|f| f << n.to_s}
|
142
162
|
path
|
143
163
|
end
|
144
|
-
|
145
|
-
|
146
|
-
open_files.each_with_index do |file, n|
|
164
|
+
|
165
|
+
t.open(list).each_with_index do |file, n|
|
147
166
|
assert_equal File, file.class
|
148
167
|
assert_equal n.to_s, file.read
|
149
168
|
file.close
|
150
169
|
end
|
151
170
|
end
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
assert_equal 2, t.batch.size
|
162
|
-
t1, t2 = t.batch
|
163
|
-
assert_equal "batch_0", t1.dirname
|
164
|
-
assert_equal "batch_1", t2.dirname
|
165
|
-
end
|
166
|
-
|
167
|
-
def test_dirname_returns_dirname_if_set
|
168
|
-
t.dirname = "name"
|
169
|
-
assert_equal "name", t.dirname
|
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
|
171
180
|
|
172
181
|
#
|
173
182
|
# inference tests
|
@@ -235,9 +244,8 @@ class FileTaskTest < Test::Unit::TestCase
|
|
235
244
|
# backup_filepath test
|
236
245
|
#
|
237
246
|
|
238
|
-
def
|
239
|
-
|
240
|
-
t = FileTask.new("dir/name", :backup_dir => :backup, :backup_timestamp => "%Y%m%d")
|
247
|
+
def test_backup_filepath_documentation
|
248
|
+
t = Tap::FileTask.new("dir/name", :backup_dir => :backup, :backup_timestamp => "%Y%m%d")
|
241
249
|
t.app[:backup] # => "/backup"
|
242
250
|
Date.today.to_s # => "2007-08-08"
|
243
251
|
|
@@ -262,7 +270,16 @@ class FileTaskTest < Test::Unit::TestCase
|
|
262
270
|
app.filepath(:output, t.name, "file_#{timestamp}.txt"),
|
263
271
|
t.backup_filepath("file.txt"))
|
264
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)
|
265
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
|
+
|
266
283
|
def test_backup_filepath_uses_inference_block
|
267
284
|
timestamp = prepare_backup_filepath_with_output_and_timestamp
|
268
285
|
|
@@ -321,10 +338,10 @@ class FileTaskTest < Test::Unit::TestCase
|
|
321
338
|
of1 = trs.filepath(:root, 'old_file_one.txt')
|
322
339
|
of2 = trs.filepath(:root, 'old_file_two.txt')
|
323
340
|
|
324
|
-
nf1 =
|
341
|
+
nf1 = output_tempfile('new_file_one.txt')
|
325
342
|
File.open(nf1, "w") {|file| file << output_str}
|
326
343
|
|
327
|
-
nf2 =
|
344
|
+
nf2 = output_tempfile('new_file_two.txt')
|
328
345
|
File.open(nf2, "w") {|file| file << output_str}
|
329
346
|
|
330
347
|
[of1, of2, nf1, nf2]
|
@@ -335,10 +352,10 @@ class FileTaskTest < Test::Unit::TestCase
|
|
335
352
|
files.each { |file| assert File.exists?(file), file }
|
336
353
|
|
337
354
|
of1, of2, nf1, nf2 = files
|
338
|
-
assert FileUtils.uptodate?(nf1, of1)
|
339
|
-
assert FileUtils.uptodate?(nf2, of1)
|
340
|
-
assert FileUtils.uptodate?(nf1, of2)
|
341
|
-
assert FileUtils.uptodate?(nf2, of2)
|
355
|
+
assert FileUtils.uptodate?(nf1, [of1])
|
356
|
+
assert FileUtils.uptodate?(nf2, [of1])
|
357
|
+
assert FileUtils.uptodate?(nf1, [of2])
|
358
|
+
assert FileUtils.uptodate?(nf2, [of2])
|
342
359
|
end
|
343
360
|
|
344
361
|
def test_uptodate
|