tap 0.8.0 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (185) hide show
  1. data/Basic Overview +151 -0
  2. data/Command Reference +99 -0
  3. data/History +24 -0
  4. data/MIT-LICENSE +1 -1
  5. data/README +29 -57
  6. data/Rakefile +30 -37
  7. data/Tutorial +243 -191
  8. data/bin/tap +66 -35
  9. data/lib/tap.rb +47 -29
  10. data/lib/tap/app.rb +700 -342
  11. data/lib/tap/{script → cmd}/console.rb +0 -0
  12. data/lib/tap/{script → cmd}/destroy.rb +0 -0
  13. data/lib/tap/{script → cmd}/generate.rb +0 -0
  14. data/lib/tap/cmd/run.rb +156 -0
  15. data/lib/tap/constants.rb +4 -0
  16. data/lib/tap/dump.rb +57 -0
  17. data/lib/tap/env.rb +316 -0
  18. data/lib/tap/file_task.rb +106 -109
  19. data/lib/tap/generator.rb +4 -1
  20. data/lib/tap/generator/generators/command/USAGE +6 -0
  21. data/lib/tap/generator/generators/command/command_generator.rb +17 -0
  22. data/lib/tap/generator/generators/{script/templates/script.erb → command/templates/command.erb} +10 -10
  23. data/lib/tap/generator/generators/config/USAGE +21 -0
  24. data/lib/tap/generator/generators/config/config_generator.rb +17 -7
  25. data/lib/tap/generator/generators/file_task/USAGE +3 -0
  26. data/lib/tap/generator/generators/file_task/file_task_generator.rb +16 -0
  27. data/lib/tap/generator/generators/file_task/templates/file.txt +2 -0
  28. data/lib/tap/generator/generators/file_task/templates/file.yml +3 -0
  29. data/lib/tap/generator/generators/file_task/templates/task.erb +26 -20
  30. data/lib/tap/generator/generators/file_task/templates/test.erb +20 -10
  31. data/lib/tap/generator/generators/generator/generator_generator.rb +1 -1
  32. data/lib/tap/generator/generators/generator/templates/generator.erb +21 -12
  33. data/lib/tap/generator/generators/root/templates/Rakefile +33 -24
  34. data/lib/tap/generator/generators/root/templates/tap.yml +28 -31
  35. data/lib/tap/generator/generators/root/templates/test/tap_test_helper.rb +1 -0
  36. data/lib/tap/generator/generators/task/USAGE +3 -0
  37. data/lib/tap/generator/generators/task/task_generator.rb +18 -5
  38. data/lib/tap/generator/generators/task/templates/task.erb +7 -12
  39. data/lib/tap/generator/generators/task/templates/test.erb +10 -11
  40. data/lib/tap/generator/generators/workflow/templates/task.erb +1 -1
  41. data/lib/tap/generator/generators/workflow/templates/test.erb +1 -1
  42. data/lib/tap/patches/rake/rake_test_loader.rb +8 -0
  43. data/lib/tap/patches/rake/testtask.rb +55 -0
  44. data/lib/tap/patches/ruby19/backtrace_filter.rb +51 -0
  45. data/lib/tap/patches/ruby19/parsedate.rb +16 -0
  46. data/lib/tap/root.rb +172 -67
  47. data/lib/tap/script.rb +70 -336
  48. data/lib/tap/support/aggregator.rb +55 -0
  49. data/lib/tap/support/audit.rb +281 -280
  50. data/lib/tap/support/batchable.rb +59 -0
  51. data/lib/tap/support/class_configuration.rb +279 -0
  52. data/lib/tap/support/configurable.rb +92 -0
  53. data/lib/tap/support/configurable_methods.rb +296 -0
  54. data/lib/tap/support/executable.rb +98 -0
  55. data/lib/tap/support/executable_queue.rb +82 -0
  56. data/lib/tap/support/logger.rb +9 -15
  57. data/lib/tap/support/rake.rb +43 -54
  58. data/lib/tap/support/run_error.rb +32 -13
  59. data/lib/tap/support/shell_utils.rb +47 -0
  60. data/lib/tap/support/tdoc.rb +9 -8
  61. data/lib/tap/support/tdoc/config_attr.rb +40 -16
  62. data/lib/tap/support/validation.rb +77 -0
  63. data/lib/tap/support/versions.rb +36 -36
  64. data/lib/tap/task.rb +276 -482
  65. data/lib/tap/test.rb +20 -261
  66. data/lib/tap/test/env_vars.rb +7 -5
  67. data/lib/tap/test/file_methods.rb +126 -121
  68. data/lib/tap/test/subset_methods.rb +86 -45
  69. data/lib/tap/test/tap_methods.rb +271 -0
  70. data/lib/tap/workflow.rb +174 -46
  71. data/test/app/config/another/task.yml +1 -0
  72. data/test/app/config/erb.yml +2 -1
  73. data/test/app/config/some/task.yml +1 -0
  74. data/test/app/config/template.yml +2 -6
  75. data/test/app_test.rb +1241 -1008
  76. data/test/env/test_configure/recurse_a.yml +2 -0
  77. data/test/env/test_configure/recurse_b.yml +2 -0
  78. data/test/env/test_configure/tap.yml +23 -0
  79. data/test/env/test_load_env_config/dir/tap.yml +3 -0
  80. data/test/env/test_load_env_config/recurse_a.yml +2 -0
  81. data/test/env/test_load_env_config/recurse_b.yml +2 -0
  82. data/test/env/test_load_env_config/tap.yml +3 -0
  83. data/test/env_test.rb +198 -0
  84. data/test/file_task_test.rb +70 -53
  85. data/{lib/tap/generator/generators/package/USAGE → test/root/file.txt} +0 -0
  86. data/test/root_test.rb +621 -454
  87. data/test/script_test.rb +38 -174
  88. data/test/support/aggregator_test.rb +99 -0
  89. data/test/support/audit_test.rb +409 -416
  90. data/test/support/batchable_test.rb +74 -0
  91. data/test/support/{task_configuration_test.rb → class_configuration_test.rb} +106 -47
  92. data/test/{task/config/overriding.yml → support/configurable/config/configured.yml} +0 -0
  93. data/test/support/configurable_test.rb +295 -0
  94. data/test/support/executable_queue_test.rb +103 -0
  95. data/test/support/executable_test.rb +38 -0
  96. data/test/support/logger_test.rb +17 -17
  97. data/test/support/rake_test.rb +4 -2
  98. data/test/support/shell_utils_test.rb +24 -0
  99. data/test/support/tdoc_test.rb +265 -258
  100. data/test/support/validation_test.rb +54 -0
  101. data/test/support/versions_test.rb +38 -38
  102. data/test/tap_test_helper.rb +19 -5
  103. data/test/tap_test_suite.rb +5 -2
  104. data/test/task_base_test.rb +13 -104
  105. data/test/task_syntax_test.rb +300 -0
  106. data/test/task_test.rb +258 -381
  107. data/test/test/env_vars_test.rb +40 -40
  108. data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/one.txt +0 -0
  109. data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/expected/two.txt +0 -0
  110. data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/one.txt +0 -0
  111. data/test/test/file_methods/{test_assert_output_files_equal → test_assert_files}/input/two.txt +0 -0
  112. data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/one.txt +0 -0
  113. data/test/test/{test_file_task_test → file_methods/test_assert_files_can_have_no_expected_files_if_specified}/input/two.txt +0 -0
  114. data/test/test/file_methods/test_assert_files_fails_for_different_content/expected/one.txt +1 -0
  115. data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_different_content}/expected/two.txt +0 -0
  116. data/test/test/file_methods/test_assert_files_fails_for_different_content/input/one.txt +1 -0
  117. data/test/test/file_methods/test_assert_files_fails_for_different_content/input/two.txt +1 -0
  118. data/test/test/{test_file_task_test → file_methods/test_assert_files_fails_for_missing_expected_file}/expected/one.txt +0 -0
  119. data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/one.txt +1 -0
  120. data/test/test/file_methods/test_assert_files_fails_for_missing_expected_file/input/two.txt +1 -0
  121. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/one.txt +1 -0
  122. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/expected/two.txt +1 -0
  123. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/one.txt +1 -0
  124. data/test/test/file_methods/test_assert_files_fails_for_missing_output_file/input/two.txt +1 -0
  125. data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/one.txt +1 -0
  126. data/test/test/file_methods/test_assert_files_fails_for_no_expected_files/input/two.txt +1 -0
  127. data/test/test/file_methods_doc/test_sub/expected/one.txt +1 -0
  128. data/test/test/file_methods_doc/test_sub/expected/two.txt +1 -0
  129. data/test/test/file_methods_doc/test_sub/input/one.txt +1 -0
  130. data/test/test/file_methods_doc/test_sub/input/two.txt +1 -0
  131. data/test/test/file_methods_doc_test.rb +29 -0
  132. data/test/test/file_methods_test.rb +214 -143
  133. data/test/test/subset_methods_test.rb +111 -115
  134. data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/a.txt +0 -0
  135. data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/expected/task/name/b.txt +0 -0
  136. data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/a.txt +0 -0
  137. data/test/test/{test_assert_expected_result_files → tap_methods/test_assert_files}/input/b.txt +0 -0
  138. data/test/test/tap_methods_test.rb +399 -0
  139. data/test/workflow_test.rb +101 -91
  140. metadata +86 -70
  141. data/lib/tap/generator/generators/package/package_generator.rb +0 -38
  142. data/lib/tap/generator/generators/package/templates/package.erb +0 -186
  143. data/lib/tap/generator/generators/script/USAGE +0 -0
  144. data/lib/tap/generator/generators/script/script_generator.rb +0 -17
  145. data/lib/tap/script/run.rb +0 -154
  146. data/lib/tap/support/batch_queue.rb +0 -162
  147. data/lib/tap/support/combinator.rb +0 -114
  148. data/lib/tap/support/task_configuration.rb +0 -169
  149. data/lib/tap/support/template.rb +0 -81
  150. data/lib/tap/support/templater.rb +0 -155
  151. data/lib/tap/version.rb +0 -4
  152. data/test/app/config/addition_template.yml +0 -6
  153. data/test/app_class_test.rb +0 -33
  154. data/test/check/binding_eval.rb +0 -23
  155. data/test/check/define_method_check.rb +0 -22
  156. data/test/check/dependencies_check.rb +0 -175
  157. data/test/check/inheritance_check.rb +0 -22
  158. data/test/support/batch_queue_test.rb +0 -320
  159. data/test/support/combinator_test.rb +0 -249
  160. data/test/support/template_test.rb +0 -122
  161. data/test/support/templater/erb.txt +0 -2
  162. data/test/support/templater/erb.yml +0 -2
  163. data/test/support/templater/somefile.txt +0 -2
  164. data/test/support/templater_test.rb +0 -192
  165. data/test/task/config/template.yml +0 -4
  166. data/test/task_class_test.rb +0 -170
  167. data/test/task_execute_test.rb +0 -262
  168. data/test/test/file_methods/test_assert_expected/expected/file.txt +0 -1
  169. data/test/test/file_methods/test_assert_expected/expected/folder/file.txt +0 -1
  170. data/test/test/file_methods/test_assert_expected/input/file.txt +0 -1
  171. data/test/test/file_methods/test_assert_expected/input/folder/file.txt +0 -1
  172. data/test/test/file_methods/test_assert_files_exist/input/input_1.txt +0 -0
  173. data/test/test/file_methods/test_assert_files_exist/input/input_2.txt +0 -0
  174. data/test/test/file_methods/test_file_compare/expected/output_1.txt +0 -3
  175. data/test/test/file_methods/test_file_compare/expected/output_2.txt +0 -1
  176. data/test/test/file_methods/test_file_compare/input/input_1.txt +0 -3
  177. data/test/test/file_methods/test_file_compare/input/input_2.txt +0 -3
  178. data/test/test/file_methods/test_infer_glob/expected/file.yml +0 -0
  179. data/test/test/file_methods/test_infer_glob/expected/file_1.txt +0 -0
  180. data/test/test/file_methods/test_infer_glob/expected/file_2.txt +0 -0
  181. data/test/test/file_methods/test_yml_compare/expected/output_1.yml +0 -6
  182. data/test/test/file_methods/test_yml_compare/expected/output_2.yml +0 -6
  183. data/test/test/file_methods/test_yml_compare/input/input_1.yml +0 -4
  184. data/test/test/file_methods/test_yml_compare/input/input_2.yml +0 -4
  185. data/test/test_test.rb +0 -373
@@ -0,0 +1,103 @@
1
+ require File.join(File.dirname(__FILE__), '../tap_test_helper')
2
+ require 'tap/support/executable_queue'
3
+
4
+ class ExecutableQueueTest < Test::Unit::TestCase
5
+ include Tap::Support
6
+
7
+ attr_accessor :m, :queue
8
+
9
+ def setup
10
+ @m = Object.new.extend Executable
11
+ @queue = ExecutableQueue.new
12
+ end
13
+
14
+ #
15
+ # initialization tests
16
+ #
17
+
18
+ def test_initialize
19
+ q = ExecutableQueue.new
20
+ assert q.empty?
21
+ end
22
+
23
+ #
24
+ # size, clear, empty? tests
25
+ #
26
+
27
+ def test_size_return_number_of_tasks
28
+ assert_equal 0, queue.size
29
+ queue.enq m, []
30
+ assert_equal 1, queue.size
31
+ end
32
+
33
+ def test_empty_is_true_if_tasks_is_empty
34
+ assert queue.empty?
35
+ queue.enq m, []
36
+ assert !queue.empty?
37
+ end
38
+
39
+ def test_clear_resets_tasks_and_task_inputs
40
+ assert_equal([], queue.to_a)
41
+
42
+ queue.enq m, []
43
+ queue.clear
44
+
45
+ assert_equal([], queue.to_a)
46
+ end
47
+
48
+ def test_clear_returns_existing_queue_as_an_array
49
+ assert_equal([], queue.to_a)
50
+
51
+ queue.enq m, []
52
+ assert_equal [[m, []]], queue.clear
53
+ end
54
+
55
+ #
56
+ # queue test
57
+ #
58
+
59
+ def test_enq_pushes_task_and_inputs_onto_queue
60
+ assert_equal [], queue.to_a
61
+
62
+ queue.enq(m, [1])
63
+ assert_equal [[m,[1]]], queue.to_a
64
+
65
+ queue.enq(m, [2])
66
+ assert_equal [[m,[1]], [m,[2]]], queue.to_a
67
+ end
68
+
69
+ def test_enq_raises_error_for_non_task_methods
70
+ assert_raise(RuntimeError) { queue.enq(method(:setup), [1]) }
71
+ end
72
+
73
+ #
74
+ # unshift test
75
+ #
76
+
77
+ def test_unshift
78
+ assert_equal [], queue.to_a
79
+
80
+ queue.unshift(m, [1])
81
+ assert_equal [[m,[1]]], queue.to_a
82
+
83
+ queue.unshift(m, [2])
84
+ assert_equal [[m,[2]], [m,[1]]], queue.to_a
85
+ end
86
+
87
+ def test_unshift_raises_error_for_non_task_methods
88
+ assert_raise(RuntimeError) { queue.unshift(method(:setup), [1]) }
89
+ end
90
+
91
+ #
92
+ # deq test
93
+ #
94
+
95
+ def test_deq
96
+ queue.enq(m, [1])
97
+ queue.enq(m, [2])
98
+
99
+ assert_equal [m, [1]], queue.deq
100
+ assert_equal [m, [2]], queue.deq
101
+ end
102
+
103
+ end
@@ -0,0 +1,38 @@
1
+ require File.join(File.dirname(__FILE__), '../tap_test_helper')
2
+ require 'tap/support/executable'
3
+
4
+ class ExecutableTest < Test::Unit::TestCase
5
+ include Tap
6
+
7
+ attr_accessor :m
8
+
9
+ def setup
10
+ @m = Tap::Support::Executable.initialize(Object.new, :object_id)
11
+ end
12
+
13
+ #
14
+ # initialization tests
15
+ #
16
+
17
+ def test_initialization
18
+ assert !m.multithread
19
+ assert_nil m.on_complete_block
20
+ end
21
+
22
+ #
23
+ # on_complete block test
24
+ #
25
+
26
+ def test_on_complete_sets_on_complete_block
27
+ block = lambda {}
28
+ m.on_complete(&block)
29
+ assert_equal block, m.on_complete_block
30
+ end
31
+
32
+ def test_on_complete_can_only_be_set_once
33
+ m.on_complete {}
34
+ assert_raise(RuntimeError) { m.on_complete {} }
35
+ assert_raise(RuntimeError) { m.on_complete }
36
+ end
37
+
38
+ end
@@ -3,29 +3,29 @@ require 'tap/support/logger'
3
3
  require 'stringio'
4
4
 
5
5
  class LoggerTest < Test::Unit::TestCase
6
- include Tap
6
+ include Tap
7
7
 
8
- #
9
- # logger tests
10
- #
11
-
12
- def test_logger
13
- output = StringIO.new('')
14
- logger = Logger.new(output).extend Support::Logger
15
- logger.datetime_format = '%H:%M:%S'
16
- logger.subject 'message'
17
-
18
- assert output.string =~ /^\s+I\[\d\d:\d\d:\d\d\]\s+subject\s+message/, output.string
19
- end
8
+ #
9
+ # logger tests
10
+ #
11
+
12
+ def test_logger
13
+ output = StringIO.new('')
14
+ logger = Logger.new(output).extend Support::Logger
15
+ logger.datetime_format = '%H:%M:%S'
16
+ logger.subject 'message'
17
+
18
+ assert output.string =~ /^\s+I\[\d\d:\d\d:\d\d\]\s+subject\s+message/, output.string
19
+ end
20
20
 
21
21
  def test_logdev_returns_the_log_device
22
- [StringIO.new(''), STDOUT].each do |device|
23
- logger = Logger.new(device)
22
+ [StringIO.new(''), STDOUT].each do |device|
23
+ logger = Logger.new(device)
24
24
  assert !logger.respond_to?(:logdev)
25
25
 
26
26
  logger.extend Support::Logger
27
27
  assert_equal Logger::LogDevice, logger.logdev.class
28
- assert_equal device, logger.logdev.dev
28
+ assert_equal device, logger.logdev.dev
29
29
  end
30
- end
30
+ end
31
31
  end
@@ -17,11 +17,13 @@ class RakeTest < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  assert_equal [], runlist
20
- app.run(:task)
20
+ app.task(:task).enq
21
+ app.run
21
22
  assert_equal [:prerequisite, :task], runlist
22
23
 
23
24
  # notice the tasks do not get re-run
24
- app.run(:task)
25
+ app.task(:task).enq
26
+ app.run
25
27
  assert_equal [:prerequisite, :task], runlist
26
28
 
27
29
  # check that Rake still works natively
@@ -0,0 +1,24 @@
1
+ require File.join(File.dirname(__FILE__), '../tap_test_helper')
2
+ require 'tap/support/shell_utils'
3
+
4
+ class ShellUtilsTest < Test::Unit::TestCase
5
+ include Tap::Support::ShellUtils
6
+
7
+ #
8
+ # capture_sh test
9
+ #
10
+
11
+ def test_capture_sh
12
+ assert_equal "hello\n", capture_sh('echo hello')
13
+ end
14
+
15
+ def test_capture_sh_with_block
16
+ was_in_block = false
17
+ result = capture_sh('echo hello') do |ok, status|
18
+ assert ok
19
+ was_in_block = true
20
+ end
21
+ assert_equal "hello\n", result
22
+ assert was_in_block
23
+ end
24
+ end
@@ -9,6 +9,7 @@ require File.join(File.dirname(__FILE__), '../tap_test_helper')
9
9
  class TaskDocumentation < Tap::Task
10
10
  config :c_nodoc, 'value' # :nodoc:
11
11
  config(:c_accessor, 'value') # c_accessor
12
+ config(:c_validation, 'value') {|value| } # c_validation
12
13
 
13
14
  config_reader
14
15
 
@@ -25,11 +26,12 @@ class TaskDocumentation < Tap::Task
25
26
  # c_multiline1
26
27
  config(:c_multiline, 'value' ) # c_multiline2
27
28
 
28
- config :c_with_attr, 'value', {:key => 'value'} # c_with_attr
29
-
30
29
  config :alt_c, 'value' # alt_c
31
- config :alt_c_with_attr, 'value', :key => 'value' # alt_c_with_attr
30
+ config :alt_c_validation, 'value' do |value| # alt_c_validation
31
+ end
32
32
  config :alt_c_without_value # alt_c_without_value
33
+ config :alt_c_validation_without_value do |value| # alt_c_validation_without_value
34
+ end
33
35
 
34
36
  # declare_config
35
37
  declare_config :declare_config
@@ -103,261 +105,266 @@ class TDocTest < Test::Unit::TestCase
103
105
  include Tap::Support
104
106
 
105
107
  TDoc.document(__FILE__)
106
-
107
- #
108
- # RDoc RubyLex and RubyToken redefinition test
109
- #
110
-
111
- def test_rubylex_and_rubytoken_redefinition
112
- filepath = __FILE__
113
- tl = RDoc::TopLevel.new(filepath)
114
- stats = RDoc::Stats.new
115
- options = Options.instance
116
- parser = RDoc::RubyParser.new(tl, filepath, File.read(filepath), options, stats)
117
-
118
- assert Tap::Support::TDoc::ConfigParser.included_modules.include?(RDoc::RubyToken)
119
- assert RDoc::RubyParser.included_modules.include?(RDoc::RubyToken)
120
- assert_equal RDoc::RubyLex, parser.instance_variable_get("@scanner").class
121
-
122
- if satisfied?(:irb_variant)
123
- assert_not_equal RubyToken, RDoc::RubyToken
124
- assert_not_equal RubyLex, RDoc::RubyLex
125
- assert RubyLex.included_modules.include?(RubyToken)
126
- assert !RubyLex.included_modules.include?(RDoc::RubyLex)
127
- else
128
- flunk unless !Object.const_defined?(:RubyToken) || RubyToken == RDoc::RubyToken
129
- flunk unless !Object.const_defined?(:RubyLex) || RubyLex == RDoc::RubyLex
130
- end
131
- end
132
-
133
- #
134
- # [] tests
135
- #
136
108
 
137
- def test_get_class_documentation
138
- c = TDoc[TaskDocumentation]
139
- assert_equal RDoc::NormalClass, c.class
140
- assert_equal "# = Section One\n# section one\n#\n# == Section Two\n# section two\n# line two\n", c.comment
141
-
142
-
143
- c = TDoc[Nested]
144
- assert_equal RDoc::NormalModule, c.class
145
- assert_equal "# nested doc\n", c.comment
146
-
147
- c = TDoc[Nested::Klass]
148
- assert_equal RDoc::NormalClass, c.class
149
- assert_equal "# class doc\n", c.comment
150
-
151
- c = TDoc[Nested::Mod]
152
- assert_equal RDoc::NormalModule, c.class
153
- assert_equal "# mod doc\n", c.comment
154
- end
155
-
156
- def test_get_documentation_works_for_strings_and_constants
157
- assert_equal RDoc::NormalClass, TDoc[Nested::Klass].class
158
- assert_equal TDoc["Nested::Klass"].object_id, TDoc[Nested::Klass].object_id
159
- end
109
+ #
110
+ # RDoc RubyLex and RubyToken redefinition test
111
+ #
112
+
113
+ def test_rubylex_and_rubytoken_redefinition
114
+ filepath = __FILE__
115
+ tl = RDoc::TopLevel.new(filepath)
116
+ stats = RDoc::Stats.new
117
+ options = Options.instance
118
+ parser = RDoc::RubyParser.new(tl, filepath, File.read(filepath), options, stats)
119
+
120
+ assert Tap::Support::TDoc::ConfigParser.included_modules.include?(RDoc::RubyToken)
121
+ assert RDoc::RubyParser.included_modules.include?(RDoc::RubyToken)
122
+ assert_equal RDoc::RubyLex, parser.instance_variable_get("@scanner").class
123
+
124
+ if satisfied?(:irb_variant)
125
+ assert_not_equal RubyToken, RDoc::RubyToken
126
+ assert_not_equal RubyLex, RDoc::RubyLex
127
+ assert RubyLex.included_modules.include?(RubyToken)
128
+ assert !RubyLex.included_modules.include?(RDoc::RubyLex)
129
+ else
130
+ flunk unless !Object.const_defined?(:RubyToken) || RubyToken == RDoc::RubyToken
131
+ flunk unless !Object.const_defined?(:RubyLex) || RubyLex == RDoc::RubyLex
132
+ end
133
+ end
160
134
 
161
- def test_configs_are_documented
162
- c = TDoc[TaskDocumentation]
163
-
164
- attributes = c.attributes.collect do |attribute|
165
- case attribute
166
- when TDoc::ConfigAttr
167
- {:comment => attribute.original_comment,
168
- :name => attribute.name,
169
- :rw => attribute.rw,
170
- :text => attribute.text}
171
- else
172
- {:comment => attribute.comment,
173
- :name => attribute.name,
174
- :rw => attribute.rw,
175
- :text => attribute.text}
176
- end
177
- end
178
-
179
- expected_attributes.each_with_index do |expected, i|
180
- assert_equal expected, attributes[i], "unequal attribute (index=#{i})"
181
- end
182
- assert_equal expected_attributes.length, attributes.length
183
- end
184
-
185
- #
186
- # accessor extensions
187
- #
188
-
189
- def test_comment_sections
190
- c = TDoc[TaskDocumentation]
191
-
192
- assert c.respond_to?(:comment_sections)
193
- assert_equal({
194
- "Section One" => "# section one\n#\n",
195
- "Section Two" => "# section two\n# line two\n"},
196
- c.comment_sections)
197
-
198
- assert_equal({
199
- "Section Two" => "# section two\n# line two\n"},
200
- c.comment_sections(/two/i))
201
-
202
- assert_equal({
203
- "Section Two" => "section two\nline two"},
204
- c.comment_sections(/two/i, true))
205
- end
206
-
207
- # def test_collect_configurations
208
- # c = TDoc.document(TaskDocumentation, __FILE__)
209
- # assert_equal expected_attributes[0..-5], TDoc.collect_configurations(c)
210
- # end
211
- #
212
- # def test_collect_attributes
213
- # c = TDoc.document(TaskDocumentation, __FILE__)
214
- # assert_equal expected_attributes[-4..-1], TDoc.collect_attributes(c)
215
- # end
216
-
217
- def expected_attributes
218
- @expected_attributes ||= [{
219
- :comment=>nil,
220
- :name=>"c_accessor",
221
- :rw=>"RW",
222
- :text=>"# c_accessor"},
223
- {
224
- :comment=>nil,
225
- :name=>"c_reader",
226
- :rw=>"R",
227
- :text=>"# c_reader"},
228
- {
229
- :comment=>nil,
230
- :name=>"c",
231
- :rw=>nil,
232
- :text=>"# c"},
233
- {
234
- :comment=>"# c_conventional\n",
235
- :name=>"c_conventional",
236
- :rw=>nil,
237
- :text=>""},
238
- {
239
- :comment=>nil,
240
- :name=>"c_without_doc",
241
- :rw=>nil,
242
- :text=>""},
243
- {
244
- :comment=>"# c_multiline1\n",
245
- :name=>"c_multiline",
246
- :rw=>nil,
247
- :text=>"# c_multiline2"},
248
- {
249
- :comment=>nil,
250
- :name=>"c_with_attr",
251
- :rw=>nil,
252
- :text=>"# c_with_attr"},
253
- {
254
- :comment=>nil,
255
- :name=>"alt_c",
256
- :rw=>nil,
257
- :text=>"# alt_c"},
258
- {
259
- :comment=>nil,
260
- :name=>"alt_c_with_attr",
261
- :rw=>nil,
262
- :text=>"# alt_c_with_attr"},
263
- {
264
- :comment=>nil,
265
- :name=>"alt_c_without_value",
266
- :rw=>nil,
267
- :text=>"# alt_c_without_value"},
268
- {
269
- :comment=>"# declare_config\n",
270
- :name=>"declare_config",
271
- :rw=>nil,
272
- :text=>""},
273
- {
274
- :comment=>"# confg_accessor\n",
275
- :name=>"config_accessor",
276
- :rw=>"RW",
277
- :text=>""},
278
- {
279
- :comment=>"# config_reader\n",
280
- :name=>"config_reader",
281
- :rw=>"R",
282
- :text=>""},
283
- {
284
- :comment=>"# config_writer\n",
285
- :name=>"config_writer",
286
- :rw=>"W",
287
- :text=>""},
288
- {
289
- :comment=>"# multi_config_accessor\n",
290
- :name=>"multi_config_accessor1",
291
- :rw=>"RW",
292
- :text=>""},
293
- {
294
- :comment=>"# multi_config_accessor\n",
295
- :name=>"multi_config_accessor2",
296
- :rw=>"RW",
297
- :text=>""},
298
- {
299
- :comment=>"# attr_accessor\n",
300
- :name=>"attr_accessor",
301
- :rw=>"RW",
302
- :text=>"# ignored"},
303
- {
304
- :comment=>nil,
305
- :name=>"attr_accessor_without_doc",
306
- :rw=>"RW",
307
- :text=>""},
308
- {
309
- :comment=>"# multi_attr_accessor\n",
310
- :name=>"multi_attr_accessor1",
311
- :rw=>"RW",
312
- :text=>""},
313
- {
314
- :comment=>"# multi_attr_accessor\n",
315
- :name=>"multi_attr_accessor2",
316
- :rw=>"RW",
317
- :text=>""}]
318
- end
319
-
320
- #
321
- # NotATask documentation
322
- #
323
-
324
- # def test_not_a_task_document
325
- # c = TDoc.document(NotATask, __FILE__)
326
- #
327
- # assert_equal RDoc::NormalClass, c.class
328
- # assert_equal "", c.comment
329
- #
330
- # attributes = c.attributes.collect do |attribute|
331
- # case attribute
332
- # when TDoc::ConfigAttr
333
- # {:comment => attribute.original_comment,
334
- # :name => attribute.name,
335
- # :rw => attribute.rw,
336
- # :text => attribute.text}
337
- # else
338
- # {:comment => attribute.comment,
339
- # :name => attribute.name,
340
- # :rw => attribute.rw,
341
- # :text => attribute.text}
342
- # end
343
- # end
344
- #
345
- # not_a_task_expected_attributes.each_with_index do |expected, i|
346
- # assert_equal expected, attributes[i], "unequal attribute (index=#{i})"
347
- # end
348
- # assert_equal not_a_task_expected_attributes.length, attributes.length
349
- # end
350
-
351
- def not_a_task_expected_attributes
352
- @not_a_task_expected_attributes ||= [{
353
- :comment=>nil,
354
- :name=>"is",
355
- :rw=>"RW",
356
- :text=>""},
357
- {
358
- :comment=>nil,
359
- :name=>"documented",
360
- :rw=>"RW",
361
- :text=>""}]
362
- end
135
+ #
136
+ # [] tests
137
+ #
138
+
139
+ def test_get_class_documentation
140
+ c = TDoc[TaskDocumentation]
141
+ assert_equal RDoc::NormalClass, c.class
142
+ assert_equal "# = Section One\n# section one\n#\n# == Section Two\n# section two\n# line two\n", c.comment
143
+
144
+
145
+ c = TDoc[Nested]
146
+ assert_equal RDoc::NormalModule, c.class
147
+ assert_equal "# nested doc\n", c.comment
148
+
149
+ c = TDoc[Nested::Klass]
150
+ assert_equal RDoc::NormalClass, c.class
151
+ assert_equal "# class doc\n", c.comment
152
+
153
+ c = TDoc[Nested::Mod]
154
+ assert_equal RDoc::NormalModule, c.class
155
+ assert_equal "# mod doc\n", c.comment
156
+ end
157
+
158
+ def test_get_documentation_works_for_strings_and_constants
159
+ assert_equal RDoc::NormalClass, TDoc[Nested::Klass].class
160
+ assert_equal TDoc["Nested::Klass"].object_id, TDoc[Nested::Klass].object_id
161
+ end
162
+
163
+ def test_configs_are_documented
164
+ c = TDoc[TaskDocumentation]
165
+
166
+ attributes = c.attributes.collect do |attribute|
167
+ case attribute
168
+ when TDoc::ConfigAttr
169
+ {:comment => attribute.original_comment,
170
+ :name => attribute.name,
171
+ :rw => attribute.rw,
172
+ :text => attribute.text}
173
+ else
174
+ {:comment => attribute.comment,
175
+ :name => attribute.name,
176
+ :rw => attribute.rw,
177
+ :text => attribute.text}
178
+ end
179
+ end
180
+
181
+ expected_attributes.each_with_index do |expected, i|
182
+ assert_equal expected, attributes[i], "unequal attribute (index=#{i})"
183
+ end
184
+ assert_equal expected_attributes.length, attributes.length
185
+ end
186
+
187
+ #
188
+ # accessor extensions
189
+ #
190
+
191
+ def test_comment_sections
192
+ c = TDoc[TaskDocumentation]
193
+
194
+ assert c.respond_to?(:comment_sections)
195
+ assert_equal({
196
+ "Section One" => "# section one\n#\n",
197
+ "Section Two" => "# section two\n# line two\n"},
198
+ c.comment_sections)
199
+
200
+ assert_equal({
201
+ "Section Two" => "# section two\n# line two\n"},
202
+ c.comment_sections(/two/i))
203
+
204
+ assert_equal({
205
+ "Section Two" => "section two\nline two"},
206
+ c.comment_sections(/two/i, true))
207
+ end
208
+
209
+ # def test_collect_configurations
210
+ # c = TDoc.document(TaskDocumentation, __FILE__)
211
+ # assert_equal expected_attributes[0..-5], TDoc.collect_configurations(c)
212
+ # end
213
+ #
214
+ # def test_collect_attributes
215
+ # c = TDoc.document(TaskDocumentation, __FILE__)
216
+ # assert_equal expected_attributes[-4..-1], TDoc.collect_attributes(c)
217
+ # end
218
+
219
+ def expected_attributes
220
+ @expected_attributes ||= [{
221
+ :comment=>nil,
222
+ :name=>"c_accessor",
223
+ :rw=>"RW",
224
+ :text=>"# c_accessor ('value')"},
225
+ {
226
+ :comment=>nil,
227
+ :name=>"c_validation",
228
+ :rw=>"RW",
229
+ :text=>"# c_validation ('value')"},
230
+ {
231
+ :comment=>nil,
232
+ :name=>"c_reader",
233
+ :rw=>"R",
234
+ :text=>"# c_reader ('value')"},
235
+ {
236
+ :comment=>nil,
237
+ :name=>"c",
238
+ :rw=>nil,
239
+ :text=>"# c ('value')"},
240
+ {
241
+ :comment=>"# c_conventional\n",
242
+ :name=>"c_conventional",
243
+ :rw=>nil,
244
+ :text=>" ('value')"},
245
+ {
246
+ :comment=>nil,
247
+ :name=>"c_without_doc",
248
+ :rw=>nil,
249
+ :text=>" ('value')"},
250
+ {
251
+ :comment=>"# c_multiline1\n",
252
+ :name=>"c_multiline",
253
+ :rw=>nil,
254
+ :text=>"# c_multiline2 ('value')"},
255
+ {
256
+ :comment=>nil,
257
+ :name=>"alt_c",
258
+ :rw=>nil,
259
+ :text=>"# alt_c ('value')"},
260
+ {
261
+ :comment=>nil,
262
+ :name=>"alt_c_validation",
263
+ :rw=>nil,
264
+ :text=>"# alt_c_validation ('value')"},
265
+ {
266
+ :comment=>nil,
267
+ :name=>"alt_c_without_value",
268
+ :rw=>nil,
269
+ :text=>"# alt_c_without_value"},
270
+ {
271
+ :comment=>nil,
272
+ :name=>"alt_c_validation_without_value",
273
+ :rw=>nil,
274
+ :text=>"# alt_c_validation_without_value"},
275
+ {
276
+ :comment=>"# declare_config\n",
277
+ :name=>"declare_config",
278
+ :rw=>nil,
279
+ :text=>""},
280
+ {
281
+ :comment=>"# confg_accessor\n",
282
+ :name=>"config_accessor",
283
+ :rw=>"RW",
284
+ :text=>""},
285
+ {
286
+ :comment=>"# config_reader\n",
287
+ :name=>"config_reader",
288
+ :rw=>"R",
289
+ :text=>""},
290
+ {
291
+ :comment=>"# config_writer\n",
292
+ :name=>"config_writer",
293
+ :rw=>"W",
294
+ :text=>""},
295
+ {
296
+ :comment=>"# multi_config_accessor\n",
297
+ :name=>"multi_config_accessor1",
298
+ :rw=>"RW",
299
+ :text=>""},
300
+ {
301
+ :comment=>"# multi_config_accessor\n",
302
+ :name=>"multi_config_accessor2",
303
+ :rw=>"RW",
304
+ :text=>""},
305
+ {
306
+ :comment=>"# attr_accessor\n",
307
+ :name=>"attr_accessor",
308
+ :rw=>"RW",
309
+ :text=>"# ignored"},
310
+ {
311
+ :comment=>nil,
312
+ :name=>"attr_accessor_without_doc",
313
+ :rw=>"RW",
314
+ :text=>""},
315
+ {
316
+ :comment=>"# multi_attr_accessor\n",
317
+ :name=>"multi_attr_accessor1",
318
+ :rw=>"RW",
319
+ :text=>""},
320
+ {
321
+ :comment=>"# multi_attr_accessor\n",
322
+ :name=>"multi_attr_accessor2",
323
+ :rw=>"RW",
324
+ :text=>""}]
325
+ end
326
+
327
+ #
328
+ # NotATask documentation
329
+ #
330
+
331
+ # def test_not_a_task_document
332
+ # c = TDoc.document(NotATask, __FILE__)
333
+ #
334
+ # assert_equal RDoc::NormalClass, c.class
335
+ # assert_equal "", c.comment
336
+ #
337
+ # attributes = c.attributes.collect do |attribute|
338
+ # case attribute
339
+ # when TDoc::ConfigAttr
340
+ # {:comment => attribute.original_comment,
341
+ # :name => attribute.name,
342
+ # :rw => attribute.rw,
343
+ # :text => attribute.text}
344
+ # else
345
+ # {:comment => attribute.comment,
346
+ # :name => attribute.name,
347
+ # :rw => attribute.rw,
348
+ # :text => attribute.text}
349
+ # end
350
+ # end
351
+ #
352
+ # not_a_task_expected_attributes.each_with_index do |expected, i|
353
+ # assert_equal expected, attributes[i], "unequal attribute (index=#{i})"
354
+ # end
355
+ # assert_equal not_a_task_expected_attributes.length, attributes.length
356
+ # end
357
+
358
+ def not_a_task_expected_attributes
359
+ @not_a_task_expected_attributes ||= [{
360
+ :comment=>nil,
361
+ :name=>"is",
362
+ :rw=>"RW",
363
+ :text=>""},
364
+ {
365
+ :comment=>nil,
366
+ :name=>"documented",
367
+ :rw=>"RW",
368
+ :text=>""}]
369
+ end
363
370
  end