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,74 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../tap_test_helper')
|
2
|
+
require 'tap/support/batchable'
|
3
|
+
|
4
|
+
class BatchableTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
class BatchableClass
|
7
|
+
include Tap::Support::Batchable
|
8
|
+
def initialize
|
9
|
+
@batch = []
|
10
|
+
initialize_batch_obj
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
attr_accessor :t
|
15
|
+
|
16
|
+
def setup
|
17
|
+
@t = BatchableClass.new
|
18
|
+
end
|
19
|
+
|
20
|
+
#
|
21
|
+
# batch test
|
22
|
+
#
|
23
|
+
|
24
|
+
def test_batch_documentation
|
25
|
+
t1 = Tap::Task.new
|
26
|
+
t2 = Tap::Task.new
|
27
|
+
t3 = t2.initialize_batch_obj
|
28
|
+
|
29
|
+
Tap::Support::Batchable.batch(t1, t2)
|
30
|
+
assert_equal [t1,t2,t3], t3.batch
|
31
|
+
end
|
32
|
+
|
33
|
+
#
|
34
|
+
# batched? test
|
35
|
+
#
|
36
|
+
|
37
|
+
def test_batched_returns_true_if_batch_size_is_greater_than_one
|
38
|
+
assert !t.batched?
|
39
|
+
assert_equal 1, t.batch.size
|
40
|
+
|
41
|
+
t1 = t.initialize_batch_obj
|
42
|
+
|
43
|
+
assert t.batched?
|
44
|
+
assert t1.batched?
|
45
|
+
end
|
46
|
+
|
47
|
+
#
|
48
|
+
# batch_index test
|
49
|
+
#
|
50
|
+
|
51
|
+
def test_batch_index_returns_the_index_of_the_task_in_batch
|
52
|
+
t1 = t.initialize_batch_obj
|
53
|
+
|
54
|
+
assert_equal [t, t1], t.batch
|
55
|
+
assert_equal 0, t.batch_index
|
56
|
+
assert_equal 1, t1.batch_index
|
57
|
+
end
|
58
|
+
|
59
|
+
#
|
60
|
+
# initialize_batch_obj test
|
61
|
+
#
|
62
|
+
|
63
|
+
def test_created_batch_tasks_are_added_to_and_share_the_same_execute_batch
|
64
|
+
assert_equal [t], t.batch
|
65
|
+
|
66
|
+
t1 = t.initialize_batch_obj
|
67
|
+
t2 = t1.initialize_batch_obj
|
68
|
+
|
69
|
+
assert_equal [t, t1, t2], t.batch
|
70
|
+
assert_equal t.batch.object_id, t1.batch.object_id
|
71
|
+
assert_equal t.batch.object_id, t2.batch.object_id
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -1,24 +1,85 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), '../tap_test_helper')
|
2
|
-
require 'tap/support/
|
3
|
-
require 'tap/
|
2
|
+
require 'tap/support/class_configuration'
|
3
|
+
require 'tap/support/validation'
|
4
|
+
require 'tap/support/configurable_methods'
|
5
|
+
require 'tap/support/tdoc'
|
6
|
+
require 'tap/support/configurable'
|
4
7
|
|
5
8
|
# for documentation test
|
6
|
-
class BaseTask
|
9
|
+
class BaseTask
|
10
|
+
include Tap::Support::Configurable
|
7
11
|
config :one, 1
|
8
12
|
end
|
9
13
|
class SubTask < BaseTask
|
10
14
|
config :one, 'one'
|
11
15
|
config :two, 'two'
|
12
16
|
end
|
17
|
+
class MergeTask < BaseTask
|
18
|
+
config :three, 'three'
|
19
|
+
config_merge SubTask
|
20
|
+
end
|
21
|
+
class ValidationTask < Tap::Task
|
22
|
+
config :one, 'one', &c.check(String)
|
23
|
+
config :two, 'two', &c.yaml(/two/, Integer)
|
24
|
+
config :three, 'three' do |v|
|
25
|
+
v =~ /three/ ? v.upcase : raise("not three")
|
26
|
+
end
|
27
|
+
end
|
13
28
|
|
14
|
-
class
|
29
|
+
class ClassConfigurationTest < Test::Unit::TestCase
|
15
30
|
include Tap::Support
|
16
31
|
|
32
|
+
def test_config_merge
|
33
|
+
t = MergeTask.new
|
34
|
+
assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t.config)
|
35
|
+
assert t.respond_to?(:two)
|
36
|
+
yaml = MergeTask.configurations.format_yaml
|
37
|
+
expected = %Q{
|
38
|
+
# BaseTask configuration
|
39
|
+
one: one
|
40
|
+
|
41
|
+
# MergeTask configuration
|
42
|
+
three: three
|
43
|
+
|
44
|
+
# SubTask configuration
|
45
|
+
two: two
|
46
|
+
}
|
47
|
+
|
48
|
+
assert_equal expected[1..-1], yaml
|
49
|
+
assert_equal({'one' => 'one', 'two' => 'two', 'three' => 'three'}, YAML.load(yaml))
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_config_validations
|
53
|
+
t = ValidationTask.new
|
54
|
+
assert_equal({:one => 'one', :two => 'two', :three => 'THREE'}, t.config)
|
55
|
+
|
56
|
+
t.one = 'two'
|
57
|
+
assert_equal 'two', t.one
|
58
|
+
assert_raise(Validation::ValidationError) { t.one = 1 }
|
59
|
+
|
60
|
+
t.two = "two"
|
61
|
+
assert_equal 'two', t.two
|
62
|
+
t.two = 2
|
63
|
+
assert_equal 2, t.two
|
64
|
+
t.two = "2"
|
65
|
+
assert_equal 2, t.two
|
66
|
+
assert_raise(Validation::ValidationError) { t.two = 'three' }
|
67
|
+
assert_raise(Validation::ValidationError) { t.two = 2.2 }
|
68
|
+
|
69
|
+
t.three = "three"
|
70
|
+
assert_equal 'THREE', t.three
|
71
|
+
assert_raise(RuntimeError) { t.three = 'THREE' }
|
72
|
+
end
|
73
|
+
|
17
74
|
def test_initialization
|
18
|
-
c =
|
19
|
-
|
75
|
+
c = ClassConfiguration.new ClassConfigurationTest
|
76
|
+
|
77
|
+
assert_equal ClassConfigurationTest, c.receiver
|
78
|
+
assert_equal [], c.declarations
|
79
|
+
assert_equal [[c.receiver, []]], c.declarations_array
|
20
80
|
assert_equal({}, c.default)
|
21
|
-
assert_equal({}, c.
|
81
|
+
assert_equal({}, c.unprocessed_default)
|
82
|
+
assert_equal({}, c.process_blocks)
|
22
83
|
end
|
23
84
|
|
24
85
|
#
|
@@ -26,13 +87,12 @@ class TaskConfigurationTest < Test::Unit::TestCase
|
|
26
87
|
#
|
27
88
|
|
28
89
|
def test_format_yaml_with_single_class
|
29
|
-
cc =
|
30
|
-
cc.
|
31
|
-
cc.set('one', 1)
|
90
|
+
cc = ClassConfiguration.new ClassConfigurationTest
|
91
|
+
cc.add('one', 1)
|
32
92
|
|
33
93
|
yaml = cc.format_yaml
|
34
94
|
expected = %Q{
|
35
|
-
#
|
95
|
+
# ClassConfigurationTest configuration
|
36
96
|
one: 1
|
37
97
|
}
|
38
98
|
|
@@ -41,13 +101,12 @@ one: 1
|
|
41
101
|
end
|
42
102
|
|
43
103
|
def test_format_stringifies_keys
|
44
|
-
cc =
|
45
|
-
cc.
|
46
|
-
cc.set(:one, 1)
|
104
|
+
cc = ClassConfiguration.new ClassConfigurationTest
|
105
|
+
cc.add(:one, 1)
|
47
106
|
|
48
107
|
yaml = cc.format_yaml
|
49
108
|
expected = %Q{
|
50
|
-
#
|
109
|
+
# ClassConfigurationTest configuration
|
51
110
|
one: 1
|
52
111
|
}
|
53
112
|
|
@@ -57,13 +116,13 @@ one: 1
|
|
57
116
|
end
|
58
117
|
class Hold
|
59
118
|
def test_format_yaml_with_desc
|
60
|
-
cc =
|
61
|
-
cc.declare('one',
|
119
|
+
cc = ClassConfiguration.new
|
120
|
+
cc.declare('one', ClassConfigurationTest)
|
62
121
|
cc.set('one', 1, :desc => "comment")
|
63
122
|
|
64
123
|
yaml = cc.format_yaml
|
65
124
|
expected = %Q{
|
66
|
-
#
|
125
|
+
# ClassConfigurationTest configuration
|
67
126
|
one: 1 # comment
|
68
127
|
}
|
69
128
|
|
@@ -72,13 +131,13 @@ one: 1 # comment
|
|
72
131
|
end
|
73
132
|
|
74
133
|
def test_format_yaml_with_long_desc
|
75
|
-
cc =
|
76
|
-
cc.declare('one',
|
134
|
+
cc = ClassConfiguration.new
|
135
|
+
cc.declare('one', ClassConfigurationTest)
|
77
136
|
cc.set('one', 1, :desc => 'comment longer than some twenty chars')
|
78
137
|
|
79
138
|
yaml = cc.format_yaml
|
80
139
|
expected = %Q{
|
81
|
-
#
|
140
|
+
# ClassConfigurationTest configuration
|
82
141
|
# comment longer than some twenty chars
|
83
142
|
one: 1
|
84
143
|
}
|
@@ -88,10 +147,10 @@ one: 1
|
|
88
147
|
end
|
89
148
|
|
90
149
|
def test_format_yaml_with_long_value
|
91
|
-
cc =
|
150
|
+
cc = ClassConfiguration.new(['one', 'value longer than some twenty chars', 'comment', ClassConfigurationTest])
|
92
151
|
yaml = cc.format_yaml
|
93
152
|
expected = %Q{
|
94
|
-
#
|
153
|
+
# ClassConfigurationTest configuration
|
95
154
|
# comment
|
96
155
|
one: value longer than some twenty chars
|
97
156
|
}
|
@@ -101,10 +160,10 @@ one: value longer than some twenty chars
|
|
101
160
|
end
|
102
161
|
|
103
162
|
# def test_format_yaml_with_nil_value
|
104
|
-
# cc =
|
163
|
+
# cc = ClassConfiguration.new(['one', nil, 'comment', ClassConfigurationTest])
|
105
164
|
# yaml = cc.format_yaml
|
106
165
|
# expected = %Q{
|
107
|
-
# #
|
166
|
+
# # ClassConfigurationTest configuration
|
108
167
|
# #one: # comment
|
109
168
|
# }
|
110
169
|
#
|
@@ -113,10 +172,10 @@ one: value longer than some twenty chars
|
|
113
172
|
# end
|
114
173
|
|
115
174
|
def test_format_yaml_with_multiline_comment
|
116
|
-
cc =
|
175
|
+
cc = ClassConfiguration.new(['one', 1, "multiline\ncomment", ClassConfigurationTest])
|
117
176
|
yaml = cc.format_yaml
|
118
177
|
expected = %Q{
|
119
|
-
#
|
178
|
+
# ClassConfigurationTest configuration
|
120
179
|
# multiline
|
121
180
|
# comment
|
122
181
|
one: 1
|
@@ -127,10 +186,10 @@ one: 1
|
|
127
186
|
end
|
128
187
|
|
129
188
|
def test_format_yaml_with_multiline_value
|
130
|
-
cc =
|
189
|
+
cc = ClassConfiguration.new(['one', [1,2,3], "comment", ClassConfigurationTest])
|
131
190
|
yaml = cc.format_yaml
|
132
191
|
expected = %Q{
|
133
|
-
#
|
192
|
+
# ClassConfigurationTest configuration
|
134
193
|
# comment
|
135
194
|
one:
|
136
195
|
- 1
|
@@ -143,17 +202,17 @@ one:
|
|
143
202
|
end
|
144
203
|
|
145
204
|
def test_format_yaml_with_multiple_classes
|
146
|
-
cc =
|
147
|
-
['one', 1, '',
|
205
|
+
cc = ClassConfiguration.new(
|
206
|
+
['one', 1, '', ClassConfigurationTest],
|
148
207
|
['one', 'one', 'integer', AnotherClass],
|
149
208
|
['two', {'key' => 'value'}, 'hash', AnotherClass],
|
150
209
|
['three', [1,2,3], "multiline\narray", AnotherClass])
|
151
210
|
yaml = cc.format_yaml
|
152
211
|
expected = %Q{
|
153
|
-
#
|
212
|
+
# ClassConfigurationTest configuration
|
154
213
|
one: one # integer
|
155
214
|
|
156
|
-
#
|
215
|
+
# ClassConfigurationTest::AnotherClass configurations
|
157
216
|
# hash
|
158
217
|
two:
|
159
218
|
key: value
|
@@ -196,30 +255,30 @@ class Hold
|
|
196
255
|
end
|
197
256
|
|
198
257
|
def test_add
|
199
|
-
cc =
|
200
|
-
cc.add(:key, 'value',
|
258
|
+
cc = ClassConfiguration.new
|
259
|
+
cc.add(:key, 'value', ClassConfigurationTest)
|
201
260
|
|
202
|
-
assert_equal [[:key, 'value',
|
261
|
+
assert_equal [[:key, 'value', ClassConfigurationTest]], cc.declarations
|
203
262
|
assert_equal({:key => 'value'}, cc.hash)
|
204
263
|
|
205
264
|
cc.add(:key, 'new value', AnotherClass)
|
206
265
|
assert_equal [
|
207
|
-
[:key, 'value',
|
266
|
+
[:key, 'value', ClassConfigurationTest],
|
208
267
|
[:key, 'new value', AnotherClass]
|
209
268
|
], cc.declarations
|
210
269
|
assert_equal({:key => 'new value'}, cc.hash)
|
211
270
|
end
|
212
271
|
|
213
272
|
def test_add_symbolizes_keys
|
214
|
-
cc =
|
215
|
-
cc.add('key', 'value',
|
273
|
+
cc = ClassConfiguration.new
|
274
|
+
cc.add('key', 'value', ClassConfigurationTest)
|
216
275
|
|
217
|
-
assert_equal [[:key, 'value',
|
276
|
+
assert_equal [[:key, 'value', ClassConfigurationTest]], cc.declarations
|
218
277
|
assert_equal({:key => 'value'}, cc.hash)
|
219
278
|
end
|
220
279
|
|
221
280
|
# def test_add_raises_error_if_declarations_are_not_correct
|
222
|
-
# cc =
|
281
|
+
# cc = ClassConfiguration.new
|
223
282
|
# assert_raise(ArgumentError) { cc.add(:key, 'value')}
|
224
283
|
# assert_raise(ArgumentError) { cc.add([:key, 'value'])}
|
225
284
|
# end
|
@@ -229,8 +288,8 @@ class Hold
|
|
229
288
|
#
|
230
289
|
|
231
290
|
def test_remove
|
232
|
-
cc =
|
233
|
-
[:one, 1,
|
291
|
+
cc = ClassConfiguration.new(
|
292
|
+
[:one, 1, ClassConfigurationTest],
|
234
293
|
[:one, 'one', AnotherClass],
|
235
294
|
[:two, 'two', AnotherClass],
|
236
295
|
[:three, 'three', AnotherClass])
|
@@ -244,7 +303,7 @@ class Hold
|
|
244
303
|
end
|
245
304
|
|
246
305
|
def test_remove_symbolizes_inputs
|
247
|
-
cc =
|
306
|
+
cc = ClassConfiguration.new([:key, 'value', ClassConfigurationTest])
|
248
307
|
cc.remove('key')
|
249
308
|
assert_equal [], cc.declarations
|
250
309
|
end
|
@@ -254,16 +313,16 @@ class Hold
|
|
254
313
|
#
|
255
314
|
|
256
315
|
# def test_merge
|
257
|
-
# c1 =
|
316
|
+
# c1 = ClassConfiguration.new([:one, 1, '', ClassConfigurationTest])
|
258
317
|
# c2 = c1.merge([
|
259
318
|
# [:one, 'one', '', AnotherClass],
|
260
319
|
# [:two, 'two', '', AnotherClass]])
|
261
320
|
#
|
262
321
|
# assert_not_equal c1.object_id, c2.object_id
|
263
322
|
#
|
264
|
-
# assert_equal [[:one, 1, '',
|
323
|
+
# assert_equal [[:one, 1, '', ClassConfigurationTest]], c1.declarations
|
265
324
|
# assert_equal [
|
266
|
-
# [:one, 1, '',
|
325
|
+
# [:one, 1, '', ClassConfigurationTest],
|
267
326
|
# [:one, 'one', '', AnotherClass],
|
268
327
|
# [:two, 'two', '', AnotherClass]], c2.declarations
|
269
328
|
# end
|
File without changes
|
@@ -0,0 +1,295 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../tap_test_helper')
|
2
|
+
require 'tap/support/class_configuration'
|
3
|
+
require 'tap/support/validation'
|
4
|
+
require 'tap/support/configurable_methods'
|
5
|
+
require 'tap/support/tdoc'
|
6
|
+
require 'tap/support/configurable'
|
7
|
+
|
8
|
+
# for documentation test
|
9
|
+
# class BaseTask
|
10
|
+
# include Tap::Support::Configurable
|
11
|
+
# config :one, 1
|
12
|
+
# end
|
13
|
+
# class SubTask < BaseTask
|
14
|
+
# config :one, 'one'
|
15
|
+
# config :two, 'two'
|
16
|
+
# end
|
17
|
+
#
|
18
|
+
|
19
|
+
class ConfigurableTest < Test::Unit::TestCase
|
20
|
+
acts_as_tap_test
|
21
|
+
|
22
|
+
class ConfigurableClassWithNoConfigs
|
23
|
+
include Tap::Support::Configurable
|
24
|
+
end
|
25
|
+
|
26
|
+
class ConfigurableClass
|
27
|
+
include Tap::Support::Configurable
|
28
|
+
|
29
|
+
config :one, 'one'
|
30
|
+
config :two, 'two'
|
31
|
+
config :three, 'three'
|
32
|
+
end
|
33
|
+
|
34
|
+
def setup
|
35
|
+
super
|
36
|
+
app.root = trs.root
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_configurable_doc
|
40
|
+
t = ConfigurableClass.new
|
41
|
+
assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t.config)
|
42
|
+
end
|
43
|
+
|
44
|
+
#
|
45
|
+
# include test
|
46
|
+
#
|
47
|
+
|
48
|
+
def test_include_extends_class_with_ConfigurableMethods
|
49
|
+
assert ConfigurableClassWithNoConfigs.kind_of?(Tap::Support::ConfigurableMethods)
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# default_name test
|
54
|
+
#
|
55
|
+
|
56
|
+
def test_default_name
|
57
|
+
assert_equal "configurable_test/configurable_class", ConfigurableClass.default_name
|
58
|
+
end
|
59
|
+
|
60
|
+
#
|
61
|
+
# name test
|
62
|
+
#
|
63
|
+
|
64
|
+
def test_name_is_initialized_to_class_default_name_unless_specified
|
65
|
+
assert_equal ConfigurableClass.default_name, ConfigurableClass.new.name
|
66
|
+
assert_equal "alt", ConfigurableClass.new("alt").name
|
67
|
+
end
|
68
|
+
|
69
|
+
# config_file test
|
70
|
+
#
|
71
|
+
|
72
|
+
def test_config_file_is_app_config_filepath_when_config_file_exist
|
73
|
+
t = ConfigurableClass.new "configured"
|
74
|
+
app_config_filepath = app.config_filepath("configured")
|
75
|
+
|
76
|
+
assert_equal File.join(t.app['config'], "configured.yml"),app_config_filepath
|
77
|
+
assert File.exists?(app_config_filepath)
|
78
|
+
assert_equal app.config_filepath("configured"), t.config_file
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_config_file_is_nil_for_nil_input_names
|
82
|
+
t = ConfigurableClass.new
|
83
|
+
assert_equal nil, t.config_file
|
84
|
+
|
85
|
+
t = ConfigurableClass.new nil
|
86
|
+
assert_equal nil, t.config_file
|
87
|
+
end
|
88
|
+
|
89
|
+
#
|
90
|
+
# config tests
|
91
|
+
#
|
92
|
+
|
93
|
+
class SampleClass
|
94
|
+
include Tap::Support::Configurable
|
95
|
+
|
96
|
+
config :key, 'value'
|
97
|
+
config_reader
|
98
|
+
config :reader_only
|
99
|
+
end
|
100
|
+
|
101
|
+
class ValidatingClass
|
102
|
+
include Tap::Support::Configurable
|
103
|
+
|
104
|
+
config :one, 'one', &c.check(String)
|
105
|
+
config :two, 'two' do |v|
|
106
|
+
v.upcase
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_config_doc
|
111
|
+
t = SampleClass.new
|
112
|
+
assert t.respond_to?(:reader_only)
|
113
|
+
assert !t.respond_to?(:reader_only=)
|
114
|
+
|
115
|
+
assert_equal({:key => 'value', :reader_only => nil}, t.config)
|
116
|
+
assert_equal 'value', t.key
|
117
|
+
t.key = 'another'
|
118
|
+
assert_equal({:key => 'another', :reader_only => nil}, t.config)
|
119
|
+
|
120
|
+
t = ValidatingClass.new
|
121
|
+
assert_equal({:one => 'one', :two => 'TWO'}, t.config)
|
122
|
+
assert_raise(Tap::Support::Validation::ValidationError) { t.one = 1 }
|
123
|
+
assert_raise(Tap::Support::Validation::ValidationError) { t.config = {:one => 1} }
|
124
|
+
|
125
|
+
t.config = {:one => 'str', :two => 'str'}
|
126
|
+
assert_equal({:one => 'str', :two => 'STR'}, t.config)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_config_sets_config
|
130
|
+
t = ConfigurableClassWithNoConfigs.new
|
131
|
+
assert_equal({}, t.config)
|
132
|
+
t.config = {:key => 'value'}
|
133
|
+
assert_equal({:key => 'value'}, t.config)
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_config_merges_default_config_and_overrides
|
137
|
+
t = ConfigurableClass.new "configured"
|
138
|
+
assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t.class.configurations.default)
|
139
|
+
assert_equal({:one => 'one', :two => 'TWO', :three => 'THREE'}, t.config)
|
140
|
+
|
141
|
+
t.config = {:three => 3}
|
142
|
+
assert_equal({:one => 'one', :two => 'two', :three => 3}, t.config)
|
143
|
+
end
|
144
|
+
|
145
|
+
class ConfigurableClassWithManyConfigs
|
146
|
+
include Tap::Support::Configurable
|
147
|
+
|
148
|
+
config :one, 'one'
|
149
|
+
|
150
|
+
declare_config
|
151
|
+
config :two, 'two'
|
152
|
+
|
153
|
+
config_reader
|
154
|
+
config :three, 'three'
|
155
|
+
|
156
|
+
config_writer
|
157
|
+
config :four, 'four'
|
158
|
+
|
159
|
+
config_accessor
|
160
|
+
config :five, 'five'
|
161
|
+
|
162
|
+
declare_config :six
|
163
|
+
config_reader :seven
|
164
|
+
config_writer :eight
|
165
|
+
config_accessor :nine
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_config_with_many_configs
|
169
|
+
t = ConfigurableClassWithManyConfigs.new
|
170
|
+
|
171
|
+
assert_equal({
|
172
|
+
:one => 'one', :six => nil,
|
173
|
+
:two => 'two', :seven => nil,
|
174
|
+
:three => 'three', :eight => nil,
|
175
|
+
:four => 'four', :nine => nil,
|
176
|
+
:five => 'five'},
|
177
|
+
t.config)
|
178
|
+
|
179
|
+
# readers only
|
180
|
+
[:three, :seven].each do |config|
|
181
|
+
assert t.respond_to?(config)
|
182
|
+
assert !t.respond_to?("#{config}=")
|
183
|
+
end
|
184
|
+
|
185
|
+
# writers only
|
186
|
+
[:four, :eight].each do |config|
|
187
|
+
assert !t.respond_to?(config)
|
188
|
+
assert t.respond_to?("#{config}=")
|
189
|
+
end
|
190
|
+
|
191
|
+
# both
|
192
|
+
[:one, :five, :nine].each do |config|
|
193
|
+
assert t.respond_to?(config)
|
194
|
+
assert t.respond_to?("#{config}=")
|
195
|
+
end
|
196
|
+
|
197
|
+
# neither
|
198
|
+
[:two, :six].each do |config|
|
199
|
+
assert !t.respond_to?(config)
|
200
|
+
assert !t.respond_to?("#{config}=")
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
#
|
205
|
+
# test subclass behavior
|
206
|
+
#
|
207
|
+
|
208
|
+
class DeclarationClass
|
209
|
+
include Tap::Support::Configurable
|
210
|
+
|
211
|
+
declare_config
|
212
|
+
|
213
|
+
config :one, 1
|
214
|
+
config :two, 2
|
215
|
+
config :three, 3
|
216
|
+
|
217
|
+
config_accessor :one
|
218
|
+
config_writer :two
|
219
|
+
config_reader :three
|
220
|
+
end
|
221
|
+
|
222
|
+
class DeclarationSubClass < DeclarationClass
|
223
|
+
config :one, "one"
|
224
|
+
config :four, 4
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_config_accessors_are_inherited
|
228
|
+
t = DeclarationSubClass.new
|
229
|
+
|
230
|
+
assert t.respond_to?(:one)
|
231
|
+
assert t.respond_to?("one=")
|
232
|
+
assert !t.respond_to?(:two)
|
233
|
+
assert t.respond_to?("two=")
|
234
|
+
assert t.respond_to?(:three)
|
235
|
+
assert !t.respond_to?("three=")
|
236
|
+
|
237
|
+
assert t.respond_to?(:four)
|
238
|
+
assert t.respond_to?("four=")
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_class_configurations_are_inherited_but_can_be_overridden
|
242
|
+
assert_equal([
|
243
|
+
[DeclarationClass, [:one, :two, :three]],
|
244
|
+
[DeclarationSubClass, [:four]]
|
245
|
+
], DeclarationSubClass.configurations.declarations_array)
|
246
|
+
|
247
|
+
assert_equal({:one => 1, :two => 2, :three => 3}, DeclarationClass.configurations.default)
|
248
|
+
assert_equal({:one => 'one', :two => 2, :three => 3, :four => 4}, DeclarationSubClass.configurations.default)
|
249
|
+
|
250
|
+
t = DeclarationSubClass.new
|
251
|
+
assert_equal({:one => 'one', :two => 2, :three => 3, :four => 4}, t.config)
|
252
|
+
end
|
253
|
+
|
254
|
+
#
|
255
|
+
# initialize_batch_obj test
|
256
|
+
#
|
257
|
+
|
258
|
+
def test_initialize_batch_obj_merges_default_config_and_overrides
|
259
|
+
t = ConfigurableClass.new "configured", :three => 3
|
260
|
+
assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t.class.configurations.default)
|
261
|
+
assert_equal({:one => 'one', :two => 'TWO', :three => 3}, t.config)
|
262
|
+
|
263
|
+
t1 = t.initialize_batch_obj
|
264
|
+
assert_equal({:one => 'one', :two => 'two', :three => 'three'}, t1.config)
|
265
|
+
|
266
|
+
t2 = t.initialize_batch_obj(nil, {:three => 3})
|
267
|
+
assert_equal({:one => 'one', :two => 'two', :three => 3}, t2.config)
|
268
|
+
end
|
269
|
+
|
270
|
+
|
271
|
+
# include Tap::Support
|
272
|
+
#
|
273
|
+
# def test_config_validations
|
274
|
+
# t = ValidationTask.new
|
275
|
+
# assert_equal({:one => 'one', :two => 'two', :three => 'THREE'}, t.config)
|
276
|
+
#
|
277
|
+
# t.one = 'two'
|
278
|
+
# assert_equal 'two', t.one
|
279
|
+
# assert_raise(Validation::ValidationError) { t.one = 1 }
|
280
|
+
#
|
281
|
+
# t.two = "two"
|
282
|
+
# assert_equal 'two', t.two
|
283
|
+
# t.two = 2
|
284
|
+
# assert_equal 2, t.two
|
285
|
+
# t.two = "2"
|
286
|
+
# assert_equal 2, t.two
|
287
|
+
# assert_raise(Validation::ValidationError) { t.two = 'three' }
|
288
|
+
# assert_raise(Validation::ValidationError) { t.two = 2.2 }
|
289
|
+
#
|
290
|
+
# t.three = "three"
|
291
|
+
# assert_equal 'THREE', t.three
|
292
|
+
# assert_raise(RuntimeError) { t.three = 'THREE' }
|
293
|
+
# end
|
294
|
+
|
295
|
+
end
|