tap 0.7.9 → 0.8.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 +28 -0
- data/MIT-LICENSE +1 -1
- data/README +71 -43
- data/Rakefile +81 -64
- data/Tutorial +235 -0
- data/bin/tap +80 -44
- data/lib/tap.rb +41 -12
- data/lib/tap/app.rb +243 -246
- data/lib/tap/file_task.rb +357 -118
- data/lib/tap/generator.rb +88 -29
- data/lib/tap/generator/generators/config/config_generator.rb +4 -2
- data/lib/tap/generator/generators/config/templates/config.erb +1 -2
- data/lib/tap/generator/generators/file_task/file_task_generator.rb +3 -18
- data/lib/tap/generator/generators/file_task/templates/task.erb +22 -15
- data/lib/tap/generator/generators/file_task/templates/test.erb +13 -2
- data/{test/test/inference_methods/test_assert_files_exist/input/input_1.txt → lib/tap/generator/generators/generator/USAGE} +0 -0
- data/lib/tap/generator/generators/generator/generator_generator.rb +21 -0
- data/lib/tap/generator/generators/generator/templates/generator.erb +23 -0
- data/lib/tap/generator/generators/generator/templates/usage.erb +1 -0
- data/{test/test/inference_methods/test_assert_files_exist/input/input_2.txt → lib/tap/generator/generators/package/USAGE} +0 -0
- data/lib/tap/generator/generators/package/package_generator.rb +38 -0
- data/lib/tap/generator/generators/package/templates/package.erb +186 -0
- data/lib/tap/generator/generators/root/root_generator.rb +14 -9
- data/lib/tap/generator/generators/root/templates/Rakefile +20 -14
- data/{test/test/inference_methods/test_infer_glob/expected/file.yml → lib/tap/generator/generators/root/templates/ReadMe.txt} +0 -0
- data/lib/tap/generator/generators/root/templates/tap.yml +82 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +0 -1
- data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +2 -1
- data/{test/test/inference_methods/test_infer_glob/expected/file_1.txt → lib/tap/generator/generators/script/USAGE} +0 -0
- data/lib/tap/generator/generators/script/script_generator.rb +17 -0
- data/lib/tap/generator/generators/script/templates/script.erb +42 -0
- data/lib/tap/generator/generators/task/task_generator.rb +1 -1
- data/lib/tap/generator/generators/task/templates/task.erb +24 -16
- data/lib/tap/generator/generators/task/templates/test.erb +13 -17
- data/lib/tap/generator/generators/workflow/templates/task.erb +10 -10
- data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
- data/lib/tap/generator/generators/workflow/workflow_generator.rb +3 -18
- data/lib/tap/root.rb +108 -146
- data/lib/tap/script.rb +362 -0
- data/lib/tap/script/console.rb +28 -0
- data/lib/tap/script/destroy.rb +13 -1
- data/lib/tap/script/generate.rb +13 -1
- data/lib/tap/script/run.rb +100 -57
- data/lib/tap/support/batch_queue.rb +0 -3
- data/lib/tap/support/logger.rb +6 -3
- data/lib/tap/support/rake.rb +54 -0
- data/lib/tap/support/task_configuration.rb +169 -0
- data/lib/tap/support/tdoc.rb +198 -0
- data/lib/tap/support/tdoc/config_attr.rb +338 -0
- data/lib/tap/support/tdoc/tdoc_html_generator.rb +38 -0
- data/lib/tap/support/tdoc/tdoc_html_template.rb +42 -0
- data/lib/tap/support/versions.rb +33 -1
- data/lib/tap/task.rb +339 -227
- data/lib/tap/test.rb +86 -128
- data/lib/tap/test/env_vars.rb +16 -5
- data/lib/tap/test/file_methods.rb +373 -0
- data/lib/tap/test/subset_methods.rb +299 -180
- data/lib/tap/version.rb +2 -1
- data/lib/tap/workflow.rb +2 -0
- data/test/app/lib/app_test_task.rb +1 -0
- data/test/app_test.rb +327 -83
- data/test/check/binding_eval.rb +23 -0
- data/test/check/define_method_check.rb +22 -0
- data/test/check/dependencies_check.rb +175 -0
- data/test/check/inheritance_check.rb +22 -0
- data/test/file_task_test.rb +524 -291
- data/test/{test/inference_methods/test_infer_glob/expected/file_2.txt → root/glob/one.txt} +0 -0
- data/test/root/glob/two.txt +0 -0
- data/test/root_test.rb +330 -262
- data/test/script_test.rb +194 -0
- data/test/support/audit_test.rb +5 -2
- data/test/support/combinator_test.rb +10 -10
- data/test/support/rake_test.rb +35 -0
- data/test/support/task_configuration_test.rb +272 -0
- data/test/support/tdoc_test.rb +363 -0
- data/test/support/templater_test.rb +2 -2
- data/test/support/versions_test.rb +32 -0
- data/test/tap_test_helper.rb +39 -0
- data/test/task_base_test.rb +115 -0
- data/test/task_class_test.rb +56 -4
- data/test/task_execute_test.rb +29 -0
- data/test/task_test.rb +89 -70
- data/test/test/env_vars_test.rb +48 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/file.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/expected/folder/file.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/input/file.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_assert_expected/input/folder/file.txt +0 -0
- 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_assert_output_files_equal/expected/one.txt +1 -0
- data/test/test/file_methods/test_assert_output_files_equal/expected/two.txt +1 -0
- data/test/test/file_methods/test_assert_output_files_equal/input/one.txt +1 -0
- data/test/test/file_methods/test_assert_output_files_equal/input/two.txt +1 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_1.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/expected/output_2.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_1.txt +0 -0
- data/test/test/{inference_methods → file_methods}/test_file_compare/input/input_2.txt +0 -0
- 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_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/{inference_methods → file_methods}/test_yml_compare/expected/output_1.yml +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/expected/output_2.yml +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_1.yml +0 -0
- data/test/test/{inference_methods → file_methods}/test_yml_compare/input/input_2.yml +0 -0
- data/test/test/file_methods_test.rb +204 -0
- data/test/test/subset_methods_test.rb +93 -33
- data/test/test/test_assert_expected_result_files/expected/task/name/a.txt +1 -0
- data/test/test/test_assert_expected_result_files/expected/task/name/b.txt +1 -0
- data/test/test/test_assert_expected_result_files/input/a.txt +1 -0
- data/test/test/test_assert_expected_result_files/input/b.txt +1 -0
- data/test/test/test_file_task_test/expected/one.txt +1 -0
- data/test/test/test_file_task_test/expected/two.txt +1 -0
- data/test/test/test_file_task_test/input/one.txt +1 -0
- data/test/test/test_file_task_test/input/two.txt +1 -0
- data/test/test_test.rb +143 -3
- data/test/workflow_test.rb +2 -0
- data/vendor/rails_generator.rb +56 -0
- data/vendor/rails_generator/base.rb +263 -0
- data/vendor/rails_generator/commands.rb +581 -0
- data/vendor/rails_generator/generated_attribute.rb +42 -0
- data/vendor/rails_generator/lookup.rb +209 -0
- data/vendor/rails_generator/manifest.rb +53 -0
- data/vendor/rails_generator/options.rb +143 -0
- data/vendor/rails_generator/scripts.rb +83 -0
- data/vendor/rails_generator/scripts/destroy.rb +7 -0
- data/vendor/rails_generator/scripts/generate.rb +7 -0
- data/vendor/rails_generator/scripts/update.rb +12 -0
- data/vendor/rails_generator/simple_logger.rb +46 -0
- data/vendor/rails_generator/spec.rb +44 -0
- metadata +180 -196
- data/lib/tap/generator/generators/root/templates/app.yml +0 -19
- data/lib/tap/generator/generators/root/templates/config/process_tap_request.yml +0 -4
- data/lib/tap/generator/generators/root/templates/lib/process_tap_request.rb +0 -26
- data/lib/tap/generator/generators/root/templates/public/images/nav.jpg +0 -0
- data/lib/tap/generator/generators/root/templates/public/stylesheets/color.css +0 -57
- data/lib/tap/generator/generators/root/templates/public/stylesheets/layout.css +0 -108
- data/lib/tap/generator/generators/root/templates/public/stylesheets/normalize.css +0 -40
- data/lib/tap/generator/generators/root/templates/public/stylesheets/typography.css +0 -21
- data/lib/tap/generator/generators/root/templates/server/config/environment.rb +0 -60
- data/lib/tap/generator/generators/root/templates/server/lib/tasks/clear_database_prerequisites.rake +0 -5
- data/lib/tap/generator/generators/root/templates/server/test/test_helper.rb +0 -53
- data/lib/tap/script/server.rb +0 -12
- data/lib/tap/support/rap.rb +0 -38
- data/lib/tap/test/inference_methods.rb +0 -298
- data/test/task/config/task_with_config.yml +0 -1
- data/test/test/inference_methods_test.rb +0 -311
data/test/script_test.rb
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'tap_test_helper')
|
|
2
|
+
require 'tap/script'
|
|
3
|
+
|
|
4
|
+
class ScriptConfigTest < Test::Unit::TestCase
|
|
5
|
+
include Tap
|
|
6
|
+
|
|
7
|
+
acts_as_tap_test
|
|
8
|
+
|
|
9
|
+
#
|
|
10
|
+
# class default tests
|
|
11
|
+
#
|
|
12
|
+
|
|
13
|
+
def test_defaults
|
|
14
|
+
assert_equal({
|
|
15
|
+
:gems => [],
|
|
16
|
+
:load_once_paths => [],
|
|
17
|
+
:load_paths => ["lib"],
|
|
18
|
+
:script_paths => ["script"]},
|
|
19
|
+
ScriptConfig.defaults)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
#
|
|
23
|
+
# class spec_filepath test
|
|
24
|
+
#
|
|
25
|
+
|
|
26
|
+
def test_spec_filepath
|
|
27
|
+
assert_equal "tapspec.yml", ScriptConfig.spec_filepath
|
|
28
|
+
assert_equal "path/to/dir/tapspec.yml", ScriptConfig.spec_filepath("path/to/dir")
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
#
|
|
32
|
+
# default script config
|
|
33
|
+
#
|
|
34
|
+
|
|
35
|
+
def test_default_script_config
|
|
36
|
+
config = ScriptConfig.new
|
|
37
|
+
assert config.kind_of?(OpenStruct)
|
|
38
|
+
assert_equal({
|
|
39
|
+
:gems => [],
|
|
40
|
+
:gemspecs => [],
|
|
41
|
+
:load_once_paths => [],
|
|
42
|
+
:load_paths => [app["lib"]],
|
|
43
|
+
:script_paths => [app["script"]]},
|
|
44
|
+
config.marshal_dump)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def test_script_config_with_inputs
|
|
48
|
+
config = ScriptConfig.new :key => 'value', :load_paths => ['lib', 'test']
|
|
49
|
+
|
|
50
|
+
assert_equal({
|
|
51
|
+
:gems => [],
|
|
52
|
+
:gemspecs => [],
|
|
53
|
+
:load_once_paths => [],
|
|
54
|
+
:load_paths => [app["lib"], app['test']],
|
|
55
|
+
:script_paths => [app["script"]],
|
|
56
|
+
:key => 'value'},
|
|
57
|
+
config.marshal_dump)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def test_single_arguments_are_allowed
|
|
61
|
+
config = ScriptConfig.new(
|
|
62
|
+
:load_paths => "alt",
|
|
63
|
+
:load_once_paths => "once")
|
|
64
|
+
|
|
65
|
+
assert_equal({
|
|
66
|
+
:gems => [],
|
|
67
|
+
:gemspecs => [],
|
|
68
|
+
:load_once_paths => [app["once"]],
|
|
69
|
+
:load_paths => [app["alt"]],
|
|
70
|
+
:script_paths => [app["script"]]},
|
|
71
|
+
config.marshal_dump)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_gemspecs_and_paths_are_collected_for_the_specified_gem
|
|
75
|
+
config = ScriptConfig.new :gems => 'activesupport'
|
|
76
|
+
spec = Gem.loaded_specs["activesupport"]
|
|
77
|
+
|
|
78
|
+
assert_equal 'activesupport', config.gems
|
|
79
|
+
assert_equal [spec], config.gemspecs
|
|
80
|
+
assert_equal [app['lib'], File.join(spec.full_gem_path, 'lib')], config.load_paths
|
|
81
|
+
assert_equal [app['script'], File.join(spec.full_gem_path, 'script')], config.script_paths
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
#
|
|
85
|
+
# TODO -- find a way to test the gem loading behavior,
|
|
86
|
+
# especially when the tapspec contains nested gems
|
|
87
|
+
# and when the tapspec contains unsafe filepaths
|
|
88
|
+
#
|
|
89
|
+
|
|
90
|
+
#
|
|
91
|
+
# TODO -- test scripts
|
|
92
|
+
#
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
class ScriptTest < Test::Unit::TestCase
|
|
96
|
+
|
|
97
|
+
acts_as_tap_test
|
|
98
|
+
|
|
99
|
+
def setup
|
|
100
|
+
super
|
|
101
|
+
@load_path_hold = $LOAD_PATH.dup
|
|
102
|
+
Dependencies.load_paths.clear
|
|
103
|
+
Dependencies.load_once_paths.clear
|
|
104
|
+
|
|
105
|
+
script.reset
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def teardown
|
|
109
|
+
super
|
|
110
|
+
$LOAD_PATH.clear
|
|
111
|
+
$LOAD_PATH.concat @load_path_hold
|
|
112
|
+
Dependencies.load_paths.clear
|
|
113
|
+
Dependencies.load_once_paths.clear
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
def script
|
|
117
|
+
Tap::Script.instance
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def tap_lib_dir
|
|
121
|
+
File.expand_path(File.dirname(__FILE__) + "/../lib")
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
#
|
|
125
|
+
# configure_app tests
|
|
126
|
+
#
|
|
127
|
+
|
|
128
|
+
def test_configure_returns_an_appropriate_script_config
|
|
129
|
+
config = script.configure_app
|
|
130
|
+
|
|
131
|
+
assert_equal [], config.gemspecs
|
|
132
|
+
assert_equal [], config.load_once_paths
|
|
133
|
+
assert_equal [tap_lib_dir, app['lib']], config.load_paths
|
|
134
|
+
assert_equal [app['script']], config.script_paths
|
|
135
|
+
|
|
136
|
+
config = script.configure_app :load_paths => ['alt'], :key => 'value'
|
|
137
|
+
|
|
138
|
+
assert_equal [], config.gemspecs
|
|
139
|
+
assert_equal [], config.load_once_paths
|
|
140
|
+
assert_equal [tap_lib_dir, app['alt']], config.load_paths
|
|
141
|
+
assert_equal [app['script']], config.script_paths
|
|
142
|
+
assert_equal 'value', config.key
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_configure_app_sets_default_load_and_script_paths
|
|
146
|
+
assert !$LOAD_PATH.include?( app['lib'] )
|
|
147
|
+
assert_equal [], Dependencies.load_paths
|
|
148
|
+
assert_equal [], Dependencies.load_once_paths
|
|
149
|
+
|
|
150
|
+
script.configure_app
|
|
151
|
+
|
|
152
|
+
assert $LOAD_PATH.include?( app['lib'] )
|
|
153
|
+
|
|
154
|
+
assert_equal [tap_lib_dir, app['lib']], Dependencies.load_paths
|
|
155
|
+
assert_equal [], Dependencies.load_once_paths
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
def test_configure_app_resolves_aliases_and_sets_paths
|
|
159
|
+
app['lib'] = "alt_lib"
|
|
160
|
+
app['script'] = "alt_script"
|
|
161
|
+
app['load_once'] = "load/once/lib"
|
|
162
|
+
|
|
163
|
+
assert !$LOAD_PATH.include?( app['lib'] )
|
|
164
|
+
assert_equal [], Dependencies.load_paths
|
|
165
|
+
assert_equal [], Dependencies.load_once_paths
|
|
166
|
+
|
|
167
|
+
script.configure_app(
|
|
168
|
+
:load_paths => ["lib", "load_once"],
|
|
169
|
+
:load_once_paths => ["load_once"],
|
|
170
|
+
:script_paths => ['script'])
|
|
171
|
+
|
|
172
|
+
assert $LOAD_PATH.include?( app['lib'] )
|
|
173
|
+
assert $LOAD_PATH.include?( app['load_once'] )
|
|
174
|
+
|
|
175
|
+
assert_equal [tap_lib_dir, app['lib'], app['load_once']], Dependencies.load_paths
|
|
176
|
+
assert_equal [app['load_once']], Dependencies.load_once_paths
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def test_configure_app_raises_error_if_load_once_path_is_not_a_load_path
|
|
180
|
+
assert_raise(RuntimeError) do
|
|
181
|
+
script.configure_app(
|
|
182
|
+
:load_paths => [],
|
|
183
|
+
:load_once_paths => ["lib"])
|
|
184
|
+
end
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
#
|
|
188
|
+
# split_to_length test
|
|
189
|
+
#
|
|
190
|
+
|
|
191
|
+
# def test_split_to_length
|
|
192
|
+
# assert_equal ["a a a a", "aaa aa ","a "], Tap::Script.split_to_length("a a a a aaa aa \na", 7)
|
|
193
|
+
# end
|
|
194
|
+
end
|
data/test/support/audit_test.rb
CHANGED
|
@@ -394,6 +394,9 @@ class AuditTest < Test::Unit::TestCase
|
|
|
394
394
|
#
|
|
395
395
|
|
|
396
396
|
def test_documentation
|
|
397
|
+
# reset the app, in case it is in an unexpected state
|
|
398
|
+
Tap::App.instance = nil
|
|
399
|
+
|
|
397
400
|
# part 1
|
|
398
401
|
audit = Audit.new(3)
|
|
399
402
|
audit._record(:a, 4)
|
|
@@ -436,8 +439,8 @@ class AuditTest < Test::Unit::TestCase
|
|
|
436
439
|
|
|
437
440
|
# part 4
|
|
438
441
|
t = Tap::Task.new do |task, input|
|
|
439
|
-
|
|
440
|
-
|
|
442
|
+
assert_equal Fixnum, input.class
|
|
443
|
+
input += 1
|
|
441
444
|
end
|
|
442
445
|
|
|
443
446
|
results = t.execute(3)
|
|
@@ -26,11 +26,11 @@ class CombinatorTest < Test::Unit::TestCase
|
|
|
26
26
|
assert_equal [], c.a
|
|
27
27
|
assert_equal [], c.b
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
{
|
|
30
30
|
[[1], [2,3], [3, [4]]] =>[[[1]], [[2], [3]], [[3],[[4]]]], # arrays have each element arrayified
|
|
31
31
|
[nil, nil, nil] => [[], [], []], # nil returns an empty array
|
|
32
32
|
[[], [{:one => 1},nil], nil] => [[], [[{:one => 1}],[nil]], []] # mixture
|
|
33
|
-
|
|
33
|
+
}.each_pair do |sets, expected|
|
|
34
34
|
c = Combinator.new(*sets)
|
|
35
35
|
assert_equal expected[0], c.a
|
|
36
36
|
assert_equal Combinator, c.b.class
|
|
@@ -40,11 +40,11 @@ class CombinatorTest < Test::Unit::TestCase
|
|
|
40
40
|
end
|
|
41
41
|
|
|
42
42
|
def test_initialize_raises_error_unless_sets_are_all_arrays_combinators_or_nil
|
|
43
|
-
|
|
43
|
+
[
|
|
44
44
|
[1],
|
|
45
45
|
[[], 1],
|
|
46
46
|
[1,[]]
|
|
47
|
-
|
|
47
|
+
].each do |sets|
|
|
48
48
|
assert_raise(ArgumentError) { Combinator.new(*sets) }
|
|
49
49
|
end
|
|
50
50
|
end
|
|
@@ -54,14 +54,14 @@ class CombinatorTest < Test::Unit::TestCase
|
|
|
54
54
|
#
|
|
55
55
|
|
|
56
56
|
def test_sets_returns_input_sets_minus_nil_or_empty_arrays
|
|
57
|
-
|
|
57
|
+
[
|
|
58
58
|
[],
|
|
59
59
|
[[1]],
|
|
60
60
|
[[1], [2]],
|
|
61
61
|
[[1], [2,3], [4,5,6]],
|
|
62
62
|
[[1], [2,[3]], [4,5,6]],
|
|
63
63
|
[[1], nil, [], [4,5,6], nil]
|
|
64
|
-
|
|
64
|
+
].each do |sets|
|
|
65
65
|
expected = sets.reject {|s| s.nil? || s.empty? }
|
|
66
66
|
assert_equal expected, Combinator.new(*sets).sets, PP.singleline_pp(sets, "")
|
|
67
67
|
end
|
|
@@ -72,7 +72,7 @@ class CombinatorTest < Test::Unit::TestCase
|
|
|
72
72
|
#
|
|
73
73
|
|
|
74
74
|
def test_length
|
|
75
|
-
|
|
75
|
+
{
|
|
76
76
|
[] => 0,
|
|
77
77
|
[[1]] => 1,
|
|
78
78
|
[[1], [2]] => 1,
|
|
@@ -84,7 +84,7 @@ class CombinatorTest < Test::Unit::TestCase
|
|
|
84
84
|
[[1,2], [3,4]] => 4,
|
|
85
85
|
[[1,2], [3,4], [5,6]] => 8,
|
|
86
86
|
[[1,2], nil, [3,4], [], [5,6]] => 8
|
|
87
|
-
|
|
87
|
+
}.each_pair do |sets, expected|
|
|
88
88
|
assert_equal expected, Combinator.new(*sets).length, PP.singleline_pp(sets, "")
|
|
89
89
|
end
|
|
90
90
|
end
|
|
@@ -94,7 +94,7 @@ class CombinatorTest < Test::Unit::TestCase
|
|
|
94
94
|
#
|
|
95
95
|
|
|
96
96
|
def test_each
|
|
97
|
-
|
|
97
|
+
{
|
|
98
98
|
[[1]] => [[1]],
|
|
99
99
|
[[1], [2]] => [[1,2]],
|
|
100
100
|
[[1],[2],[3]] => [[1,2,3]],
|
|
@@ -105,7 +105,7 @@ class CombinatorTest < Test::Unit::TestCase
|
|
|
105
105
|
[[1,2], [3,4]] => [[1,3],[1,4],[2,3],[2,4]],
|
|
106
106
|
[[1,2], [3,4], [5,6]] => [[1,3,5],[1,3,6],[1,4,5],[1,4,6],[2,3,5],[2,3,6],[2,4,5],[2,4,6]],
|
|
107
107
|
[[1,2], nil, [3,4], [], [5,6]] => [[1,3,5],[1,3,6],[1,4,5],[1,4,6],[2,3,5],[2,3,6],[2,4,5],[2,4,6]]
|
|
108
|
-
|
|
108
|
+
}.each_pair do |set, expected|
|
|
109
109
|
comb = Combinator.new(*set)
|
|
110
110
|
|
|
111
111
|
combinations = []
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../tap_test_helper')
|
|
2
|
+
|
|
3
|
+
class RakeTest < Test::Unit::TestCase
|
|
4
|
+
acts_as_tap_test
|
|
5
|
+
|
|
6
|
+
def test_tap_with_rake
|
|
7
|
+
extended_test do
|
|
8
|
+
require 'tap/support/rake'
|
|
9
|
+
app.extend Tap::Support::Rake
|
|
10
|
+
|
|
11
|
+
runlist = []
|
|
12
|
+
t1 = task :task => [:prerequisite] do
|
|
13
|
+
runlist << :task
|
|
14
|
+
end
|
|
15
|
+
t2 = task :prerequisite do
|
|
16
|
+
runlist << :prerequisite
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
assert_equal [], runlist
|
|
20
|
+
app.run(:task)
|
|
21
|
+
assert_equal [:prerequisite, :task], runlist
|
|
22
|
+
|
|
23
|
+
# notice the tasks do not get re-run
|
|
24
|
+
app.run(:task)
|
|
25
|
+
assert_equal [:prerequisite, :task], runlist
|
|
26
|
+
|
|
27
|
+
# check that Rake still works natively
|
|
28
|
+
t1.instance_variable_set("@already_invoked", false)
|
|
29
|
+
t2.instance_variable_set("@already_invoked", false)
|
|
30
|
+
|
|
31
|
+
Rake.application.lookup(:task).invoke
|
|
32
|
+
assert_equal [:prerequisite, :task, :prerequisite, :task], runlist
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../tap_test_helper')
|
|
2
|
+
require 'tap/support/task_configuration'
|
|
3
|
+
require 'tap/task'
|
|
4
|
+
|
|
5
|
+
# for documentation test
|
|
6
|
+
class BaseTask < Tap::Task
|
|
7
|
+
config :one, 1
|
|
8
|
+
end
|
|
9
|
+
class SubTask < BaseTask
|
|
10
|
+
config :one, 'one'
|
|
11
|
+
config :two, 'two'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
class TaskConfigurationTest < Test::Unit::TestCase
|
|
15
|
+
include Tap::Support
|
|
16
|
+
|
|
17
|
+
def test_initialization
|
|
18
|
+
c = TaskConfiguration.new
|
|
19
|
+
assert_equal({}, c.declarations)
|
|
20
|
+
assert_equal({}, c.default)
|
|
21
|
+
assert_equal({}, c.attributes)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# format_yaml tests
|
|
26
|
+
#
|
|
27
|
+
|
|
28
|
+
def test_format_yaml_with_single_class
|
|
29
|
+
cc = TaskConfiguration.new
|
|
30
|
+
cc.declare('one', TaskConfigurationTest)
|
|
31
|
+
cc.set('one', 1)
|
|
32
|
+
|
|
33
|
+
yaml = cc.format_yaml
|
|
34
|
+
expected = %Q{
|
|
35
|
+
# TaskConfigurationTest configuration
|
|
36
|
+
one: 1
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
assert_equal expected[1..-1], yaml
|
|
40
|
+
assert_equal({'one' => 1}, YAML.load(yaml))
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def test_format_stringifies_keys
|
|
44
|
+
cc = TaskConfiguration.new
|
|
45
|
+
cc.declare(:one, TaskConfigurationTest)
|
|
46
|
+
cc.set(:one, 1)
|
|
47
|
+
|
|
48
|
+
yaml = cc.format_yaml
|
|
49
|
+
expected = %Q{
|
|
50
|
+
# TaskConfigurationTest configuration
|
|
51
|
+
one: 1
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
assert_equal expected[1..-1], yaml
|
|
55
|
+
assert_equal({'one' => 1}, YAML.load(yaml))
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
class Hold
|
|
59
|
+
def test_format_yaml_with_desc
|
|
60
|
+
cc = TaskConfiguration.new
|
|
61
|
+
cc.declare('one', TaskConfigurationTest)
|
|
62
|
+
cc.set('one', 1, :desc => "comment")
|
|
63
|
+
|
|
64
|
+
yaml = cc.format_yaml
|
|
65
|
+
expected = %Q{
|
|
66
|
+
# TaskConfigurationTest configuration
|
|
67
|
+
one: 1 # comment
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
assert_equal expected[1..-1], yaml
|
|
71
|
+
assert_equal({'one' => 1}, YAML.load(yaml))
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def test_format_yaml_with_long_desc
|
|
75
|
+
cc = TaskConfiguration.new
|
|
76
|
+
cc.declare('one', TaskConfigurationTest)
|
|
77
|
+
cc.set('one', 1, :desc => 'comment longer than some twenty chars')
|
|
78
|
+
|
|
79
|
+
yaml = cc.format_yaml
|
|
80
|
+
expected = %Q{
|
|
81
|
+
# TaskConfigurationTest configuration
|
|
82
|
+
# comment longer than some twenty chars
|
|
83
|
+
one: 1
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
assert_equal expected[1..-1], yaml
|
|
87
|
+
assert_equal({'one' => 1}, YAML.load(yaml))
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_format_yaml_with_long_value
|
|
91
|
+
cc = TaskConfiguration.new(['one', 'value longer than some twenty chars', 'comment', TaskConfigurationTest])
|
|
92
|
+
yaml = cc.format_yaml
|
|
93
|
+
expected = %Q{
|
|
94
|
+
# TaskConfigurationTest configuration
|
|
95
|
+
# comment
|
|
96
|
+
one: value longer than some twenty chars
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
assert_equal expected[1..-1], yaml
|
|
100
|
+
assert_equal({'one' => 'value longer than some twenty chars'}, YAML.load(yaml))
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
# def test_format_yaml_with_nil_value
|
|
104
|
+
# cc = TaskConfiguration.new(['one', nil, 'comment', TaskConfigurationTest])
|
|
105
|
+
# yaml = cc.format_yaml
|
|
106
|
+
# expected = %Q{
|
|
107
|
+
# # TaskConfigurationTest configuration
|
|
108
|
+
# #one: # comment
|
|
109
|
+
# }
|
|
110
|
+
#
|
|
111
|
+
# assert_equal expected[1..-1], yaml
|
|
112
|
+
# assert_equal(false, YAML.load(yaml))
|
|
113
|
+
# end
|
|
114
|
+
|
|
115
|
+
def test_format_yaml_with_multiline_comment
|
|
116
|
+
cc = TaskConfiguration.new(['one', 1, "multiline\ncomment", TaskConfigurationTest])
|
|
117
|
+
yaml = cc.format_yaml
|
|
118
|
+
expected = %Q{
|
|
119
|
+
# TaskConfigurationTest configuration
|
|
120
|
+
# multiline
|
|
121
|
+
# comment
|
|
122
|
+
one: 1
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
assert_equal expected[1..-1], yaml
|
|
126
|
+
assert_equal({'one' => 1}, YAML.load(yaml))
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def test_format_yaml_with_multiline_value
|
|
130
|
+
cc = TaskConfiguration.new(['one', [1,2,3], "comment", TaskConfigurationTest])
|
|
131
|
+
yaml = cc.format_yaml
|
|
132
|
+
expected = %Q{
|
|
133
|
+
# TaskConfigurationTest configuration
|
|
134
|
+
# comment
|
|
135
|
+
one:
|
|
136
|
+
- 1
|
|
137
|
+
- 2
|
|
138
|
+
- 3
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
assert_equal expected[1..-1], yaml
|
|
142
|
+
assert_equal({'one' => [1,2,3]}, YAML.load(yaml))
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
def test_format_yaml_with_multiple_classes
|
|
146
|
+
cc = TaskConfiguration.new(
|
|
147
|
+
['one', 1, '', TaskConfigurationTest],
|
|
148
|
+
['one', 'one', 'integer', AnotherClass],
|
|
149
|
+
['two', {'key' => 'value'}, 'hash', AnotherClass],
|
|
150
|
+
['three', [1,2,3], "multiline\narray", AnotherClass])
|
|
151
|
+
yaml = cc.format_yaml
|
|
152
|
+
expected = %Q{
|
|
153
|
+
# TaskConfigurationTest configuration
|
|
154
|
+
one: one # integer
|
|
155
|
+
|
|
156
|
+
# TaskConfigurationTest::AnotherClass configurations
|
|
157
|
+
# hash
|
|
158
|
+
two:
|
|
159
|
+
key: value
|
|
160
|
+
# multiline
|
|
161
|
+
# array
|
|
162
|
+
three:
|
|
163
|
+
- 1
|
|
164
|
+
- 2
|
|
165
|
+
- 3
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
assert_equal expected[1..-1], yaml
|
|
169
|
+
assert_equal({'one' => 'one', 'two' => {'key' => 'value'}, 'three' => [1,2,3]}, YAML.load(yaml))
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
class Hold
|
|
174
|
+
|
|
175
|
+
# def test_documentation
|
|
176
|
+
# assert_equal({:one => 1}, BaseTask.configurations.hash)
|
|
177
|
+
# assert_equal({:one => 'one', :two => 'two'}, SubTask.configurations.hash)
|
|
178
|
+
#
|
|
179
|
+
# assert_equal "# BaseTask configuration\none: 1\n", BaseTask.configurations.format_yaml
|
|
180
|
+
#
|
|
181
|
+
# expected = %Q{
|
|
182
|
+
# # BaseTask configuration
|
|
183
|
+
# one: one # the first configuration
|
|
184
|
+
#
|
|
185
|
+
# # SubTask configuration
|
|
186
|
+
# two: two # the second configuration
|
|
187
|
+
# }
|
|
188
|
+
# assert_equal expected[1..-1], SubTask.configurations.format_yaml
|
|
189
|
+
# end
|
|
190
|
+
|
|
191
|
+
#
|
|
192
|
+
# add configurations
|
|
193
|
+
#
|
|
194
|
+
|
|
195
|
+
class AnotherClass
|
|
196
|
+
end
|
|
197
|
+
|
|
198
|
+
def test_add
|
|
199
|
+
cc = TaskConfiguration.new
|
|
200
|
+
cc.add(:key, 'value', TaskConfigurationTest)
|
|
201
|
+
|
|
202
|
+
assert_equal [[:key, 'value', TaskConfigurationTest]], cc.declarations
|
|
203
|
+
assert_equal({:key => 'value'}, cc.hash)
|
|
204
|
+
|
|
205
|
+
cc.add(:key, 'new value', AnotherClass)
|
|
206
|
+
assert_equal [
|
|
207
|
+
[:key, 'value', TaskConfigurationTest],
|
|
208
|
+
[:key, 'new value', AnotherClass]
|
|
209
|
+
], cc.declarations
|
|
210
|
+
assert_equal({:key => 'new value'}, cc.hash)
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def test_add_symbolizes_keys
|
|
214
|
+
cc = TaskConfiguration.new
|
|
215
|
+
cc.add('key', 'value', TaskConfigurationTest)
|
|
216
|
+
|
|
217
|
+
assert_equal [[:key, 'value', TaskConfigurationTest]], cc.declarations
|
|
218
|
+
assert_equal({:key => 'value'}, cc.hash)
|
|
219
|
+
end
|
|
220
|
+
|
|
221
|
+
# def test_add_raises_error_if_declarations_are_not_correct
|
|
222
|
+
# cc = TaskConfiguration.new
|
|
223
|
+
# assert_raise(ArgumentError) { cc.add(:key, 'value')}
|
|
224
|
+
# assert_raise(ArgumentError) { cc.add([:key, 'value'])}
|
|
225
|
+
# end
|
|
226
|
+
|
|
227
|
+
#
|
|
228
|
+
# remove configurations
|
|
229
|
+
#
|
|
230
|
+
|
|
231
|
+
def test_remove
|
|
232
|
+
cc = TaskConfiguration.new(
|
|
233
|
+
[:one, 1, TaskConfigurationTest],
|
|
234
|
+
[:one, 'one', AnotherClass],
|
|
235
|
+
[:two, 'two', AnotherClass],
|
|
236
|
+
[:three, 'three', AnotherClass])
|
|
237
|
+
|
|
238
|
+
assert_equal 4, cc.declarations.length
|
|
239
|
+
assert_equal({:one => 'one', :two => 'two', :three => 'three'}, cc.hash)
|
|
240
|
+
|
|
241
|
+
cc.remove(:one, :three)
|
|
242
|
+
assert_equal [[:two, 'two', AnotherClass]], cc.declarations
|
|
243
|
+
assert_equal({:two => 'two'}, cc.hash)
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
def test_remove_symbolizes_inputs
|
|
247
|
+
cc = TaskConfiguration.new([:key, 'value', TaskConfigurationTest])
|
|
248
|
+
cc.remove('key')
|
|
249
|
+
assert_equal [], cc.declarations
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
#
|
|
253
|
+
# merge test
|
|
254
|
+
#
|
|
255
|
+
|
|
256
|
+
# def test_merge
|
|
257
|
+
# c1 = TaskConfiguration.new([:one, 1, '', TaskConfigurationTest])
|
|
258
|
+
# c2 = c1.merge([
|
|
259
|
+
# [:one, 'one', '', AnotherClass],
|
|
260
|
+
# [:two, 'two', '', AnotherClass]])
|
|
261
|
+
#
|
|
262
|
+
# assert_not_equal c1.object_id, c2.object_id
|
|
263
|
+
#
|
|
264
|
+
# assert_equal [[:one, 1, '', TaskConfigurationTest]], c1.declarations
|
|
265
|
+
# assert_equal [
|
|
266
|
+
# [:one, 1, '', TaskConfigurationTest],
|
|
267
|
+
# [:one, 'one', '', AnotherClass],
|
|
268
|
+
# [:two, 'two', '', AnotherClass]], c2.declarations
|
|
269
|
+
# end
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
end
|