tap 0.11.1 → 0.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. data/History +35 -1
  2. data/MIT-LICENSE +1 -1
  3. data/README +16 -15
  4. data/bin/tap +1 -1
  5. data/cmd/console.rb +4 -3
  6. data/cmd/manifest.rb +2 -2
  7. data/cmd/run.rb +12 -15
  8. data/doc/Class Reference +120 -117
  9. data/doc/Command Reference +27 -27
  10. data/doc/Syntax Reference +55 -111
  11. data/doc/Tutorial +69 -26
  12. data/lib/tap.rb +3 -8
  13. data/lib/tap/app.rb +122 -146
  14. data/lib/tap/constants.rb +2 -2
  15. data/lib/tap/env.rb +178 -252
  16. data/lib/tap/exe.rb +67 -30
  17. data/lib/tap/file_task.rb +224 -411
  18. data/lib/tap/generator/arguments.rb +13 -0
  19. data/lib/tap/generator/base.rb +112 -30
  20. data/lib/tap/generator/destroy.rb +36 -13
  21. data/lib/tap/generator/generate.rb +69 -48
  22. data/lib/tap/generator/generators/command/templates/command.erb +3 -3
  23. data/lib/tap/generator/generators/config/config_generator.rb +82 -10
  24. data/lib/tap/generator/generators/generator/generator_generator.rb +16 -6
  25. data/lib/tap/generator/generators/generator/templates/task.erb +2 -2
  26. data/lib/tap/generator/generators/generator/templates/test.erb +26 -0
  27. data/lib/tap/generator/generators/root/root_generator.rb +24 -13
  28. data/lib/tap/generator/generators/root/templates/Rakefile +4 -4
  29. data/lib/tap/generator/generators/root/templates/{tapfile → Rapfile} +6 -6
  30. data/lib/tap/generator/generators/root/templates/gemspec +0 -1
  31. data/lib/tap/generator/generators/task/task_generator.rb +3 -3
  32. data/lib/tap/generator/generators/task/templates/test.erb +1 -1
  33. data/lib/tap/generator/manifest.rb +7 -1
  34. data/lib/tap/generator/preview.rb +76 -0
  35. data/lib/tap/root.rb +222 -156
  36. data/lib/tap/spec.rb +41 -0
  37. data/lib/tap/support/aggregator.rb +25 -28
  38. data/lib/tap/support/audit.rb +278 -357
  39. data/lib/tap/support/constant.rb +2 -1
  40. data/lib/tap/support/constant_manifest.rb +28 -25
  41. data/lib/tap/support/dependency.rb +1 -1
  42. data/lib/tap/support/executable.rb +52 -183
  43. data/lib/tap/support/executable_queue.rb +50 -20
  44. data/lib/tap/support/gems.rb +1 -1
  45. data/lib/tap/support/intern.rb +0 -6
  46. data/lib/tap/support/join.rb +49 -83
  47. data/lib/tap/support/joins.rb +0 -3
  48. data/lib/tap/support/joins/switch.rb +13 -11
  49. data/lib/tap/support/joins/sync_merge.rb +25 -50
  50. data/lib/tap/support/manifest.rb +1 -0
  51. data/lib/tap/support/node.rb +140 -20
  52. data/lib/tap/support/parser.rb +56 -42
  53. data/lib/tap/support/schema.rb +183 -157
  54. data/lib/tap/support/templater.rb +9 -1
  55. data/lib/tap/support/versions.rb +39 -0
  56. data/lib/tap/task.rb +150 -177
  57. data/lib/tap/tasks/dump.rb +4 -4
  58. data/lib/tap/tasks/load.rb +29 -29
  59. data/lib/tap/test.rb +66 -53
  60. data/lib/tap/test/env_vars.rb +3 -3
  61. data/lib/tap/test/extensions.rb +11 -17
  62. data/lib/tap/test/file_test.rb +74 -132
  63. data/lib/tap/test/file_test_class.rb +4 -1
  64. data/lib/tap/test/regexp_escape.rb +2 -2
  65. data/lib/tap/test/script_test.rb +2 -2
  66. data/lib/tap/test/subset_test.rb +6 -6
  67. data/lib/tap/test/tap_test.rb +28 -154
  68. metadata +30 -51
  69. data/bin/rap +0 -118
  70. data/cgi/run.rb +0 -97
  71. data/lib/tap/declarations.rb +0 -229
  72. data/lib/tap/generator/generators/config/templates/doc.erb +0 -12
  73. data/lib/tap/generator/generators/config/templates/nodoc.erb +0 -8
  74. data/lib/tap/generator/generators/file_task/file_task_generator.rb +0 -27
  75. data/lib/tap/generator/generators/file_task/templates/file.txt +0 -11
  76. data/lib/tap/generator/generators/file_task/templates/result.yml +0 -6
  77. data/lib/tap/generator/generators/file_task/templates/task.erb +0 -33
  78. data/lib/tap/generator/generators/file_task/templates/test.erb +0 -29
  79. data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +0 -5
  80. data/lib/tap/patches/optparse/summarize.rb +0 -62
  81. data/lib/tap/support/assignments.rb +0 -173
  82. data/lib/tap/support/class_configuration.rb +0 -182
  83. data/lib/tap/support/combinator.rb +0 -125
  84. data/lib/tap/support/configurable.rb +0 -113
  85. data/lib/tap/support/configurable_class.rb +0 -271
  86. data/lib/tap/support/configuration.rb +0 -170
  87. data/lib/tap/support/gems/rake.rb +0 -111
  88. data/lib/tap/support/instance_configuration.rb +0 -173
  89. data/lib/tap/support/joins/fork.rb +0 -19
  90. data/lib/tap/support/joins/merge.rb +0 -22
  91. data/lib/tap/support/joins/sequence.rb +0 -21
  92. data/lib/tap/support/lazy_attributes.rb +0 -45
  93. data/lib/tap/support/lazydoc.rb +0 -386
  94. data/lib/tap/support/lazydoc/comment.rb +0 -503
  95. data/lib/tap/support/lazydoc/config.rb +0 -17
  96. data/lib/tap/support/lazydoc/definition.rb +0 -36
  97. data/lib/tap/support/lazydoc/document.rb +0 -152
  98. data/lib/tap/support/lazydoc/method.rb +0 -24
  99. data/lib/tap/support/tdoc.rb +0 -409
  100. data/lib/tap/support/tdoc/tdoc_html_generator.rb +0 -38
  101. data/lib/tap/support/tdoc/tdoc_html_template.rb +0 -42
  102. data/lib/tap/support/validation.rb +0 -479
  103. data/lib/tap/tasks/rake.rb +0 -57
@@ -1,125 +0,0 @@
1
- require 'enumerator'
2
-
3
- module Tap
4
- module Support
5
-
6
- # Combinator provides a method for iterating over all combinations
7
- # of items in the input sets.
8
- #
9
- # c = Combinator.new [1,2], [3,4]
10
- # c.to_a # => [[1,3], [1,4], [2,3], [2,4]]
11
- #
12
- # Combinators can take any object that responds to each as an
13
- # input set; normally arrays are used.
14
- #
15
- # === Implementation
16
- #
17
- # Combinator iteratively combines each element from the first set (a)
18
- # with each element from the second set (b). When more than two sets
19
- # are given, the second and remaining sets are bundled into a
20
- # Combinator, which then acts as the second set.
21
- #
22
- # c = Combinator.new [1,2], [3,4], [5,6]
23
- # c.a # => [[1],[2]]
24
- # c.b.class # => Combinator
25
- # c.b.a # => [[3],[4]]
26
- # c.b.b # => [[5],[6]]
27
- #
28
- # Note that internally each item in a set is stored as a single-item
29
- # array; the arrays are added during combination. Thus when
30
- # iterating, the combinations are calculated like:
31
- #
32
- # ([1] + [3]) + [5] # => [1,3,5]
33
- #
34
- # This is probably not the fastest implementation, but it works.
35
- class Combinator
36
- include Enumerable
37
-
38
- # The first set
39
- attr_reader :a
40
-
41
- # The second set
42
- attr_reader :b
43
-
44
- # Creates a new Combinator. Each input must respond
45
- # to each, or be nil.
46
- def initialize(*sets)
47
- @a = make_set(sets.shift)
48
- @b = make_set(*sets)
49
- end
50
-
51
- # Returns the sets used to initialize the Combinator.
52
- def sets
53
- sets_in(a) + sets_in(b)
54
- end
55
-
56
- # True if length is zero.
57
- def empty?
58
- a.empty? && b.empty?
59
- end
60
-
61
- # Returns the number of combinations returned by each.
62
- def length
63
- case
64
- when !(@a.empty? || @b.empty?)
65
- @a.length * @b.length
66
- when @a.empty?
67
- @b.length
68
- when @b.empty?
69
- @a.length
70
- end
71
- end
72
-
73
- # Passes each combination as an array to the input block.
74
- def each # :yields: combination
75
- case
76
- when !(@a.empty? || @b.empty?)
77
- @a.each do |a|
78
- @b.each do |b|
79
- yield(a + b)
80
- end
81
- end
82
- when @a.empty?
83
- @b.each {|b| yield(b) }
84
- when @b.empty?
85
- @a.each {|a| yield(a) }
86
- end
87
- end
88
-
89
- private
90
-
91
- # makes a Combinator out of multiple sets or collects the
92
- # objects of a single set as arrays:
93
- #
94
- # make_set([1,2,3], [4,5,6]) # => Combinator.new([1,2,3], [4,5,6])
95
- # make_set([1,2,3]) # => [[1],[2],[3]]
96
- #
97
- def make_set(*sets) # :nodoc:
98
- # recieves an array of arrays or combinators
99
- return Combinator.new(*sets) if sets.length > 1
100
- return sets if sets.empty?
101
-
102
- set = sets[0]
103
- return [] if set == nil
104
-
105
- unless set.respond_to?(:each)
106
- raise ArgumentError, "does not respond to each: #{set}"
107
- end
108
-
109
- # recursively arrayifies each element
110
- arrayified_set = []
111
- set.each {|s| arrayified_set << [s]}
112
- arrayified_set
113
- end
114
-
115
- # basically the reverse of make_set
116
- def sets_in(set) # :nodoc:
117
- case set
118
- when Combinator then set.sets
119
- when Array then set.empty? ? [] : [set.collect {|s| s[0]}]
120
- end
121
- end
122
-
123
- end
124
- end
125
- end
@@ -1,113 +0,0 @@
1
- require 'tap/support/configurable_class'
2
-
3
- module Tap
4
- module Support
5
-
6
- # Configurable enables the specification of configurations within a class definition.
7
- #
8
- # class ConfigClass
9
- # include Configurable
10
- #
11
- # config :one, 'one'
12
- # config :two, 'two'
13
- # config :three, 'three'
14
- #
15
- # def initialize(overrides={})
16
- # initialize_config(overrides)
17
- # end
18
- # end
19
- #
20
- # c = ConfigClass.new
21
- # c.config.class # => InstanceConfiguration
22
- # c.config # => {:one => 'one', :two => 'two', :three => 'three'}
23
- #
24
- # The <tt>config</tt> object acts as a forwarding hash; declared configurations
25
- # map to accessors while undeclared configurations are stored internally:
26
- #
27
- # c.config[:one] = 'ONE'
28
- # c.one # => 'ONE'
29
- #
30
- # c.one = 1
31
- # c.config # => {:one => 1, :two => 'two', :three => 'three'}
32
- #
33
- # c.config[:undeclared] = 'value'
34
- # c.config.store # => {:undeclared => 'value'}
35
- #
36
- # The writer for a configuration can be defined by providing a block to config.
37
- # The Validation module provides a number of common validation/transform
38
- # blocks which can be accessed through the class method 'c':
39
- #
40
- # class SubClass < ConfigClass
41
- # config(:one, 'one') {|v| v.upcase }
42
- # config :two, 2, &c.integer
43
- # end
44
- #
45
- # s = SubClass.new
46
- # s.config # => {:one => 'ONE', :two => 2, :three => 'three'}
47
- #
48
- # s.one = 'aNothER'
49
- # s.one # => 'ANOTHER'
50
- #
51
- # s.two = -2
52
- # s.two # => -2
53
- # s.two = "3"
54
- # s.two # => 3
55
- # s.two = nil # !> ValidationError
56
- # s.two = 'str' # !> ValidationError
57
- #
58
- # As shown above, configurations are inherited from the parent and may be
59
- # overridden in subclasses. See ConfigurableClass for more details.
60
- #
61
- module Configurable
62
-
63
- # Extends including classes with ConfigurableClass
64
- def self.included(mod) # :nodoc:
65
- mod.extend Support::ConfigurableClass if mod.kind_of?(Class)
66
- end
67
-
68
- # An InstanceConfiguration with configurations for self
69
- attr_reader :config
70
-
71
- # Reconfigures self with the given overrides. Only the specified configs
72
- # are modified. Keys are symbolized.
73
- #
74
- # Returns self.
75
- def reconfigure(overrides={})
76
- keys = (config.class_config.ordered_keys + overrides.keys) & overrides.keys
77
- keys.each do |key|
78
- config[key.to_sym] = overrides[key]
79
- end
80
-
81
- self
82
- end
83
-
84
- # Reinitializes configurations in the copy such that
85
- # the new object has it's own set of configurations,
86
- # separate from the original object.
87
- def initialize_copy(orig)
88
- super
89
- initialize_config(orig.config)
90
- end
91
-
92
- protected
93
-
94
- # Initializes config to an InstanceConfiguration. Default config values
95
- # are overridden as specified by overrides. Keys are symbolized.
96
- def initialize_config(overrides={})
97
- class_config = self.class.configurations
98
- @config = class_config.instance_config
99
-
100
- overrides.each_pair do |key, value|
101
- config[key.to_sym] = value
102
- end
103
-
104
- class_config.each_pair do |key, value|
105
- next if config.has_key?(key)
106
- config[key] = value.default
107
- end
108
-
109
- config.bind(self)
110
- end
111
- end
112
- end
113
- end
@@ -1,271 +0,0 @@
1
- require 'tap/support/class_configuration'
2
- require 'tap/support/validation'
3
- require 'tap/support/lazy_attributes'
4
- require 'tap/support/lazydoc/config'
5
-
6
- module Tap
7
- module Support
8
- autoload(:Templater, 'tap/support/templater')
9
-
10
- # ConfigurableClass defines class methods used by a Configurable class to
11
- # declare configurations. In addition to registering key-value pairs,
12
- # these methods generate readers and writers, much like attr_accessor.
13
- #
14
- # class ConfigurableClass
15
- # extend ConfigurableClass
16
- # config :one, 'one'
17
- # end
18
- #
19
- # ConfigurableClass.configurations.to_hash # => {:one => 'one'}
20
- #
21
- # c = ConfigurableClass.new
22
- # c.respond_to?('one') # => true
23
- # c.respond_to?('one=') # => true
24
- #
25
- module ConfigurableClass
26
- include Tap::Support::LazyAttributes
27
-
28
- # A ClassConfiguration holding the class configurations.
29
- attr_reader :configurations
30
-
31
- # Sets the source_file for base and initializes base.configurations.
32
- def self.extended(base) # :nodoc:
33
- caller.each_with_index do |line, index|
34
- case line
35
- when /\/configurable.rb/ then next
36
- when Lazydoc::CALLER_REGEXP
37
- base.instance_variable_set(:@source_file, File.expand_path($1))
38
- break
39
- end
40
- end
41
-
42
- base.instance_variable_set(:@configurations, ClassConfiguration.new(base))
43
- end
44
-
45
- # When subclassed, the parent.configurations are duplicated and passed to
46
- # the child class where they can be extended/modified without affecting
47
- # the configurations of the parent class.
48
- def inherited(child) # :nodoc:
49
- unless child.instance_variable_defined?(:@source_file)
50
- caller.first =~ Lazydoc::CALLER_REGEXP
51
- child.instance_variable_set(:@source_file, File.expand_path($1))
52
- end
53
-
54
- child.instance_variable_set(:@configurations, ClassConfiguration.new(child, @configurations))
55
- super
56
- end
57
-
58
- # Returns the lazydoc for self.
59
- def lazydoc(resolve=true)
60
- Lazydoc.resolve_comments(configurations.code_comments) if resolve
61
- super
62
- end
63
-
64
- # Loads the contents of path as YAML. Returns an empty hash if the path
65
- # is empty, does not exist, or is not a file.
66
- def load_config(path)
67
- # the last check prevents YAML from auto-loading itself for empty files
68
- return {} if path == nil || !File.file?(path) || File.size(path) == 0
69
- YAML.load_file(path) || {}
70
- end
71
-
72
- protected
73
-
74
- # Declares a class configuration and generates the associated accessors.
75
- # If a block is given, the <tt>key=</tt> method will set <tt>@key</tt>
76
- # to the return of the block, which executes in class-context.
77
- # Configurations are inherited, and can be overridden in subclasses.
78
- #
79
- # class SampleClass
80
- # include Tap::Support::Configurable
81
- #
82
- # config :str, 'value'
83
- # config(:upcase, 'value') {|input| input.upcase }
84
- # end
85
- #
86
- # # An equivalent class to illustrate class-context
87
- # class EquivalentClass
88
- # attr_accessor :str
89
- # attr_reader :upcase
90
- #
91
- # UPCASE_BLOCK = lambda {|input| input.upcase }
92
- #
93
- # def upcase=(input)
94
- # @upcase = UPCASE_BLOCK.call(input)
95
- # end
96
- # end
97
- #
98
- def config(key, value=nil, options={}, &block)
99
- if block_given?
100
- # add arg_type implied by block, if necessary
101
- options[:arg_type] = arg_type(block) if options[:arg_type] == nil
102
- options[:arg_name] = arg_name(block) if options[:arg_name] == nil
103
-
104
- instance_variable = "@#{key}".to_sym
105
- config_attr(key, value, options) do |input|
106
- instance_variable_set(instance_variable, block.call(input))
107
- end
108
- else
109
- config_attr(key, value, options)
110
- end
111
- end
112
-
113
- # Declares a class configuration and generates the associated accessors.
114
- # If a block is given, the <tt>key=</tt> method will perform the block with
115
- # instance-context. Configurations are inherited, and can be overridden
116
- # in subclasses.
117
- #
118
- # class SampleClass
119
- # include Tap::Support::Configurable
120
- #
121
- # def initialize
122
- # initialize_config
123
- # end
124
- #
125
- # config_attr :str, 'value'
126
- # config_attr(:upcase, 'value') {|input| @upcase = input.upcase }
127
- # end
128
- #
129
- # # An equivalent class to illustrate instance-context
130
- # class EquivalentClass
131
- # attr_accessor :str
132
- # attr_reader :upcase
133
- #
134
- # def upcase=(input)
135
- # @upcase = input.upcase
136
- # end
137
- # end
138
- #
139
- # Instances of a Configurable class may set configurations through config.
140
- # The config object is an InstanceConfiguration which forwards read/write
141
- # operations to the configuration accessors. For example:
142
- #
143
- # s = SampleClass.new
144
- # s.config.class # => Tap::Support::InstanceConfiguration
145
- # s.str # => 'value'
146
- # s.config[:str] # => 'value'
147
- #
148
- # s.str = 'one'
149
- # s.config[:str] # => 'one'
150
- #
151
- # s.config[:str] = 'two'
152
- # s.str # => 'two'
153
- #
154
- # Alternative reader and writer methods may be specified as an option;
155
- # in this case config_attr assumes the methods are declared elsewhere
156
- # and will not define the associated accessors.
157
- #
158
- # class AlternativeClass
159
- # include Tap::Support::Configurable
160
- #
161
- # config_attr :sym, 'value', :reader => :get_sym, :writer => :set_sym
162
- #
163
- # def initialize
164
- # initialize_config
165
- # end
166
- #
167
- # def get_sym
168
- # @sym
169
- # end
170
- #
171
- # def set_sym(input)
172
- # @sym = input.to_sym
173
- # end
174
- # end
175
- #
176
- # alt = AlternativeClass.new
177
- # alt.respond_to?(:sym) # => false
178
- # alt.respond_to?(:sym=) # => false
179
- #
180
- # alt.config[:sym] = 'one'
181
- # alt.get_sym # => :one
182
- #
183
- # alt.set_sym('two')
184
- # alt.config[:sym] # => :two
185
- #
186
- # Idiosyncratically, true, false, and nil may also be provided as
187
- # reader/writer options. Specifying true is the same as using the
188
- # default. Specifying false or nil prevents config_attr from
189
- # defining accessors; false sets the configuration to use
190
- # the default reader/writer methods (ie <tt>key</tt> and <tt>key=</tt>,
191
- # which must be defined elsewhere) while nil prevents read/write
192
- # mapping of the config to a method.
193
- def config_attr(key, value=nil, options={}, &block)
194
-
195
- # add arg_type implied by block, if necessary
196
- options[:arg_type] = arg_type(block) if block_given? && options[:arg_type] == nil
197
- options[:arg_name] = arg_name(block) if block_given? && options[:arg_name] == nil
198
-
199
- # define the default public reader method
200
- if !options.has_key?(:reader) || options[:reader] == true
201
- attr_reader(key)
202
- public key
203
- end
204
-
205
- # define the public writer method
206
- case
207
- when options.has_key?(:writer) && options[:writer] != true
208
- raise(ArgumentError, "a block may not be specified with writer option") if block_given?
209
- when block_given?
210
- define_method("#{key}=", &block)
211
- public "#{key}="
212
- else
213
- attr_writer(key)
214
- public "#{key}="
215
- end
216
-
217
- # remove any true, false reader/writer declarations...
218
- # implicitly reverting the option to the default reader
219
- # and writer methods
220
- [:reader, :writer].each do |option|
221
- case options[option]
222
- when true, false then options.delete(option)
223
- end
224
- end
225
-
226
- # register with Lazydoc so that all extra documentation can be extracted
227
- caller.each do |line|
228
- case line
229
- when /in .config.$/ then next
230
- when Lazydoc::CALLER_REGEXP
231
- options[:desc] = Lazydoc.register($1, $3.to_i - 1, Lazydoc::Config)
232
- break
233
- end
234
- end if options[:desc] == nil
235
-
236
- configurations.add(key, value, options)
237
- end
238
-
239
- # Alias for Tap::Support::Validation
240
- def c
241
- Validation
242
- end
243
-
244
- private
245
-
246
- # Returns special argument types for standard validation
247
- # blocks, such as switch (Validation::SWITCH) and list
248
- # (Validation::LIST).
249
- def arg_type(block) # :nodoc:
250
- case
251
- when block == Validation::SWITCH then :switch
252
- when block == Validation::FLAG then :flag
253
- when block == Validation::LIST then :list
254
- else nil
255
- end
256
- end
257
-
258
- # Returns special argument names for standard validation
259
- # blocks, such as switch (Validation::ARRAY) and list
260
- # (Validation::HASH).
261
- def arg_name(block) # :nodoc:
262
- case
263
- when block == Validation::ARRAY then "'[a, b, c]'"
264
- when block == Validation::HASH then "'{one: 1, two: 2}'"
265
- else nil
266
- end
267
- end
268
-
269
- end
270
- end
271
- end