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
data/test/test/env_vars_test.rb
CHANGED
@@ -2,47 +2,47 @@ require File.join(File.dirname(__FILE__), '../tap_test_helper.rb')
|
|
2
2
|
|
3
3
|
class EnvVarsTest < Test::Unit::TestCase
|
4
4
|
include Tap::Test::EnvVars
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
# Some platforms (ex Windows) already make ENV case-independent
|
40
|
-
# Filter for the platforms that do not by checking that ENV has both
|
41
|
-
# expected keys
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@env_hold = {}
|
8
|
+
ENV.each_pair do |key, value|
|
9
|
+
@env_hold[key] = value
|
10
|
+
end
|
11
|
+
ENV.clear
|
12
|
+
end
|
13
|
+
|
14
|
+
def teardown
|
15
|
+
ENV.clear
|
16
|
+
@env_hold.each_pair do |key, value|
|
17
|
+
ENV[key] = value
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
#
|
22
|
+
# env test
|
23
|
+
#
|
24
|
+
|
25
|
+
def test_env_access_is_case_insensitive
|
26
|
+
ENV['key1'] = "value"
|
27
|
+
assert_equal 'value', env('key1')
|
28
|
+
assert_equal 'value', env('KEY1')
|
29
|
+
|
30
|
+
ENV['KEY2'] = "VALUE"
|
31
|
+
assert_equal 'VALUE', env('key2')
|
32
|
+
assert_equal 'VALUE', env('KEY2')
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_env_raises_error_if_multiple_values_can_be_selected
|
36
|
+
ENV['key'] = "value"
|
37
|
+
ENV['KEY'] = "VALUE"
|
38
|
+
|
39
|
+
# Some platforms (ex Windows) already make ENV case-independent
|
40
|
+
# Filter for the platforms that do not by checking that ENV has both
|
41
|
+
# expected keys
|
42
42
|
if ENV.length == 2
|
43
|
-
|
44
|
-
|
43
|
+
assert_raise(RuntimeError) { env('key') }
|
44
|
+
assert_raise(RuntimeError) { env('Key') }
|
45
45
|
end
|
46
|
-
|
46
|
+
end
|
47
47
|
|
48
48
|
end
|
data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/one.txt
RENAMED
File without changes
|
data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/two.txt
RENAMED
File without changes
|
data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/one.txt
RENAMED
File without changes
|
data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/two.txt
RENAMED
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
processed file FLUNK
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
file one
|
@@ -0,0 +1 @@
|
|
1
|
+
file two
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
file one
|
@@ -0,0 +1 @@
|
|
1
|
+
file two
|
@@ -0,0 +1 @@
|
|
1
|
+
processed file one
|
@@ -0,0 +1 @@
|
|
1
|
+
processed file two
|
@@ -0,0 +1 @@
|
|
1
|
+
file one
|
@@ -0,0 +1 @@
|
|
1
|
+
file two
|
@@ -0,0 +1 @@
|
|
1
|
+
file one
|
@@ -0,0 +1 @@
|
|
1
|
+
file two
|
@@ -0,0 +1 @@
|
|
1
|
+
test output 1
|
@@ -0,0 +1 @@
|
|
1
|
+
test output 2
|
@@ -0,0 +1 @@
|
|
1
|
+
test input 1
|
@@ -0,0 +1 @@
|
|
1
|
+
test input 2
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '../tap_test_helper.rb')
|
2
|
+
require 'tap/test/file_methods'
|
3
|
+
|
4
|
+
# documentation test
|
5
|
+
class FileMethodsDocTest < Test::Unit::TestCase
|
6
|
+
acts_as_file_test
|
7
|
+
|
8
|
+
def test_something
|
9
|
+
dir = File.expand_path( File.dirname(__FILE__) )
|
10
|
+
assert_equal dir + "/file_methods_doc", trs.root
|
11
|
+
assert_equal dir + "/file_methods_doc/test_something", method_root
|
12
|
+
assert_equal dir + "/file_methods_doc/test_something/input", method_dir(:input)
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_sub
|
16
|
+
assert_files do |input_files|
|
17
|
+
input_files.collect do |filepath|
|
18
|
+
input = File.read(filepath)
|
19
|
+
output_file = method_filepath(:output, File.basename(filepath))
|
20
|
+
|
21
|
+
File.open(output_file, "w") do |f|
|
22
|
+
f << input.gsub(/input/, "output")
|
23
|
+
end
|
24
|
+
|
25
|
+
output_file
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -6,21 +6,21 @@ class FileMethodsTest < Test::Unit::TestCase
|
|
6
6
|
acts_as_file_test
|
7
7
|
|
8
8
|
def test_method_name_returns_test_method_name1
|
9
|
-
assert_equal "test_method_name_returns_test_method_name1",
|
9
|
+
assert_equal "test_method_name_returns_test_method_name1", method_name_str
|
10
10
|
end
|
11
11
|
|
12
12
|
def test_method_name_returns_test_method_name2
|
13
|
-
assert_equal "test_method_name_returns_test_method_name2",
|
13
|
+
assert_equal "test_method_name_returns_test_method_name2", method_name_str
|
14
14
|
end
|
15
15
|
|
16
|
-
|
16
|
+
def test_make_test_directories
|
17
17
|
root = File.expand_path(File.join(File.dirname(__FILE__), "file_methods"))
|
18
18
|
begin
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
19
|
+
assert_equal root, trs[:root]
|
20
|
+
assert_equal({
|
21
|
+
:input => 'input',
|
22
|
+
:output => 'output',
|
23
|
+
:expected => 'expected'}, trs.directories)
|
24
24
|
|
25
25
|
trs.directories.values.each do |dir|
|
26
26
|
assert !File.exists?(File.join(root, "test_make_test_directories", dir.to_s)), dir
|
@@ -35,133 +35,95 @@ class FileMethodsTest < Test::Unit::TestCase
|
|
35
35
|
dir = File.join(File.join(root, "test_make_test_directories"))
|
36
36
|
FileUtils.rm_r dir if File.exists?(dir)
|
37
37
|
end
|
38
|
-
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
|
42
|
-
|
40
|
+
#
|
41
|
+
# method filepath tests
|
42
|
+
#
|
43
43
|
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
input_root = File.join(trs.root,
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
def test_method_dir_adds_method_to_path
|
45
|
+
assert_equal File.join(trs.root, method_name_str, "input"), method_dir(:input)
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_method_filepath_adds_method_to_path
|
49
|
+
input_root = File.join(trs.root, method_name_str, "input")
|
50
|
+
assert_equal File.join(input_root, "file.txt"), method_filepath(:input, 'file.txt')
|
51
|
+
assert_equal File.join(input_root, "folder/file.txt"), method_filepath(:input, 'folder', 'file.txt')
|
52
|
+
end
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
#
|
55
|
+
# method relative filepath tests
|
56
|
+
#
|
57
57
|
|
58
|
-
|
59
|
-
input_root = File.join(trs.root,
|
60
|
-
|
61
|
-
|
62
|
-
|
58
|
+
def test_method_relative_filepath_removes_method_dir
|
59
|
+
input_root = File.join(trs.root, method_name_str, "input")
|
60
|
+
assert_equal 'file.txt', method_relative_filepath(:input, File.join(input_root, "file.txt"))
|
61
|
+
assert_equal 'folder/file.txt', method_relative_filepath(:input, File.join(input_root, "folder/file.txt"))
|
62
|
+
end
|
63
63
|
|
64
|
-
|
65
|
-
input_root = File.join(trs.root,
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
output_root = File.join(trs.root,
|
64
|
+
def test_method_relative_filepath_expands_filepaths
|
65
|
+
input_root = File.join(trs.root, method_name_str, "input")
|
66
|
+
assert_equal 'file.txt', method_relative_filepath(:input, File.join(input_root, "folder/.././file.txt") )
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_method_relative_filepath_raises_error_unless_filepath_begins_with_method_dir
|
70
|
+
assert_raise(RuntimeError) { method_relative_filepath(:input, File.join('some/path', trs[:input], 'file.txt') ) }
|
71
|
+
end
|
72
|
+
|
73
|
+
#
|
74
|
+
# method translate tests
|
75
|
+
#
|
76
|
+
|
77
|
+
def test_method_translate
|
78
|
+
['file.txt', 'folder/file.txt'].each do |path|
|
79
|
+
filepath = File.join(trs.root, method_name_str, "input", path)
|
80
|
+
expected = File.join(trs.root, method_name_str, "output", path)
|
81
|
+
|
82
|
+
assert_equal expected, method_translate(filepath, :input, :output)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
#
|
87
|
+
# method glob tests
|
88
|
+
#
|
89
|
+
|
90
|
+
def test_method_glob
|
91
|
+
{
|
92
|
+
[:expected] => ["file.yml", "file_1.txt", "file_2.txt"],
|
93
|
+
[:expected, "*"] => ["file.yml", "file_1.txt", "file_2.txt"],
|
94
|
+
[:expected, "*.txt"] => ["file_1.txt", "file_2.txt"],
|
95
|
+
[:expected, "*.txt", "*.yml"] => ["file.yml", "file_1.txt", "file_2.txt"]
|
96
|
+
}.each_pair do |testcase, expected|
|
97
|
+
expected.collect! { |file| method_filepath(:expected, file) }
|
98
|
+
|
99
|
+
assert_equal expected.sort, method_glob(*testcase).sort
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
#
|
104
|
+
# output_tempfile test
|
105
|
+
#
|
106
|
+
|
107
|
+
def test_output_tempfile_returns_new_file_in_output_dir
|
108
|
+
output_root = File.join(trs.root, method_name_str, "output")
|
109
|
+
|
110
|
+
filepath =File.join(output_root, "file#{$$}.0")
|
111
|
+
assert_equal filepath, output_tempfile('file')
|
112
|
+
|
113
|
+
filepath = File.join(output_root, "file#{$$}.0")
|
114
|
+
assert_equal filepath, output_tempfile('file')
|
109
115
|
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
assert_equal filepath, tempfile('file')
|
119
|
-
|
120
|
-
FileUtils.touch filepath
|
121
|
-
filepath = File.join(output_root, "file#{$$}.2")
|
122
|
-
assert_equal filepath, tempfile('file')
|
123
|
-
end
|
124
|
-
|
125
|
-
#
|
126
|
-
# files equal test
|
127
|
-
#
|
128
|
-
|
129
|
-
def test_file_compare
|
130
|
-
count = 0
|
131
|
-
each_pair(method_glob(:input, "*1*"), method_glob(:expected, "*1*") ) do |a, b|
|
132
|
-
assert files_equal?(a, b)
|
133
|
-
count += 1
|
134
|
-
end
|
135
|
-
assert_equal 1, count
|
136
|
-
|
137
|
-
each_pair(method_glob(:input, "*2*"), method_glob(:expected, "*2*") ) do |a, b|
|
138
|
-
assert !files_equal?(a, b)
|
139
|
-
count += 1
|
140
|
-
end
|
141
|
-
assert_equal 2, count
|
142
|
-
end
|
143
|
-
|
144
|
-
#
|
145
|
-
# yml equal test
|
146
|
-
#
|
147
|
-
|
148
|
-
def test_yml_compare
|
149
|
-
count = 0
|
150
|
-
each_pair(method_glob(:input, "*1*"), method_glob(:expected, "*1*") ) do |a, b|
|
151
|
-
assert yml_equal?(a, b)
|
152
|
-
count += 1
|
153
|
-
end
|
154
|
-
assert_equal 1, count
|
155
|
-
|
156
|
-
each_pair(method_glob(:input, "*2*"), method_glob(:expected, "*2*") ) do |a, b|
|
157
|
-
assert !yml_equal?(a, b)
|
158
|
-
count += 1
|
159
|
-
end
|
160
|
-
assert_equal 2, count
|
161
|
-
end
|
116
|
+
FileUtils.touch filepath
|
117
|
+
filepath = File.join(output_root, "file#{$$}.1")
|
118
|
+
assert_equal filepath, output_tempfile('file')
|
119
|
+
|
120
|
+
FileUtils.touch filepath
|
121
|
+
filepath = File.join(output_root, "file#{$$}.2")
|
122
|
+
assert_equal filepath, output_tempfile('file')
|
123
|
+
end
|
162
124
|
|
163
125
|
#
|
164
|
-
#
|
126
|
+
# assert_files
|
165
127
|
#
|
166
128
|
|
167
129
|
def setup_file(dir, path, content)
|
@@ -173,32 +135,141 @@ class FileMethodsTest < Test::Unit::TestCase
|
|
173
135
|
path
|
174
136
|
end
|
175
137
|
|
176
|
-
def
|
138
|
+
def test_assert_files
|
139
|
+
setup_file :input, "one.txt", "file one"
|
140
|
+
setup_file :input, "two.txt", "file two"
|
141
|
+
setup_file :expected, "one.txt", "processed file one"
|
142
|
+
setup_file :expected, "two.txt", "processed file two"
|
143
|
+
|
144
|
+
assert_files do |input_files|
|
145
|
+
input_files.collect do |input_file|
|
146
|
+
target = method_filepath(:output, File.basename(input_file))
|
147
|
+
File.open(target, "w") do |file|
|
148
|
+
file << "processed "
|
149
|
+
file << File.read(input_file)
|
150
|
+
end
|
151
|
+
target
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_assert_files_fails_for_missing_expected_file
|
157
|
+
setup_file :input, "one.txt", "file one"
|
158
|
+
setup_file :input, "two.txt", "file two"
|
159
|
+
setup_file :expected, "one.txt", "processed file one"
|
160
|
+
|
161
|
+
failed = false
|
162
|
+
begin
|
163
|
+
assert_files do |input_files|
|
164
|
+
input_files.collect do |input_file|
|
165
|
+
target = method_filepath(:output, File.basename(input_file))
|
166
|
+
File.open(target, "w") do |file|
|
167
|
+
file << "processed "
|
168
|
+
file << File.read(input_file)
|
169
|
+
end
|
170
|
+
target
|
171
|
+
end
|
172
|
+
end
|
173
|
+
rescue
|
174
|
+
failed = true
|
175
|
+
end
|
176
|
+
|
177
|
+
assert failed
|
178
|
+
end
|
179
|
+
|
180
|
+
def test_assert_files_fails_for_missing_output_file
|
177
181
|
setup_file :input, "one.txt", "file one"
|
178
182
|
setup_file :input, "two.txt", "file two"
|
179
183
|
setup_file :expected, "one.txt", "processed file one"
|
180
184
|
setup_file :expected, "two.txt", "processed file two"
|
185
|
+
|
186
|
+
failed = false
|
187
|
+
begin
|
188
|
+
assert_files do |input_files|
|
189
|
+
input_files.collect do |input_file|
|
190
|
+
target = method_filepath(:output, File.basename(input_file))
|
191
|
+
File.open(target, "w") do |file|
|
192
|
+
file << "processed "
|
193
|
+
file << File.read(input_file)
|
194
|
+
end
|
195
|
+
target
|
196
|
+
end.first
|
197
|
+
end
|
198
|
+
rescue
|
199
|
+
failed = true
|
200
|
+
end
|
201
|
+
|
202
|
+
assert failed
|
203
|
+
end
|
204
|
+
|
205
|
+
def test_assert_files_fails_for_different_content
|
206
|
+
setup_file :input, "one.txt", "file one"
|
207
|
+
setup_file :input, "two.txt", "file two"
|
208
|
+
setup_file :expected, "one.txt", "processed file FLUNK"
|
209
|
+
setup_file :expected, "two.txt", "processed file two"
|
181
210
|
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
211
|
+
failed = false
|
212
|
+
begin
|
213
|
+
assert_files do |input_files|
|
214
|
+
input_files.collect do |input_file|
|
215
|
+
target = method_filepath(:output, File.basename(input_file))
|
216
|
+
File.open(target, "w") do |file|
|
217
|
+
file << "processed "
|
218
|
+
file << File.read(input_file)
|
219
|
+
end
|
220
|
+
target
|
221
|
+
end
|
222
|
+
end
|
223
|
+
rescue
|
224
|
+
failed = true
|
225
|
+
end
|
226
|
+
|
227
|
+
assert failed
|
228
|
+
end
|
229
|
+
|
230
|
+
def test_assert_files_fails_for_no_expected_files
|
231
|
+
setup_file :input, "one.txt", "file one"
|
232
|
+
setup_file :input, "two.txt", "file two"
|
233
|
+
|
234
|
+
was_in_block = false
|
235
|
+
failed = false
|
236
|
+
begin
|
237
|
+
assert_files do |input_files|
|
238
|
+
was_in_block = true
|
239
|
+
[]
|
187
240
|
end
|
188
|
-
|
241
|
+
rescue
|
242
|
+
failed = true
|
189
243
|
end
|
244
|
+
|
245
|
+
assert failed
|
246
|
+
assert !was_in_block
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_assert_files_can_have_no_expected_files_if_specified
|
250
|
+
setup_file :input, "one.txt", "file one"
|
251
|
+
setup_file :input, "two.txt", "file two"
|
252
|
+
|
253
|
+
was_in_block = false
|
254
|
+
assert_files :expected_files => [] do |input_files|
|
255
|
+
assert_equal 2, input_files.length
|
256
|
+
was_in_block = true
|
257
|
+
[]
|
258
|
+
end
|
259
|
+
|
260
|
+
assert was_in_block
|
190
261
|
end
|
191
262
|
end
|
192
263
|
|
193
264
|
class FileTestTestWithOptions < Test::Unit::TestCase
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
265
|
+
acts_as_file_test :root => "some/root/dir"
|
266
|
+
|
267
|
+
def test_test_setup
|
268
|
+
assert_equal File.expand_path("some/root/dir"), trs[:root]
|
269
|
+
assert_equal({
|
270
|
+
:input => 'input',
|
271
|
+
:output => 'output',
|
272
|
+
:expected => 'expected'}, trs.directories)
|
273
|
+
end
|
203
274
|
end
|
204
275
|
|