bahuvrihi-tap 0.10.6 → 0.10.7
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/rap +13 -5
- data/lib/tap.rb +0 -4
- data/lib/tap/app.rb +10 -138
- data/lib/tap/constants.rb +1 -1
- data/lib/tap/declarations.rb +201 -0
- data/lib/tap/env.rb +10 -2
- data/lib/tap/exe.rb +2 -2
- data/lib/tap/generator/generators/root/templates/Rakefile +1 -0
- data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +1 -1
- data/lib/tap/spec.rb +38 -63
- data/lib/tap/spec/adapter.rb +8 -31
- data/lib/tap/spec/inheritable_class_test_root.rb +9 -0
- data/lib/tap/support/audit.rb +0 -2
- data/lib/tap/support/combinator.rb +83 -31
- data/lib/tap/support/configurable_class.rb +7 -7
- data/lib/tap/support/{dependable.rb → dependencies.rb} +9 -7
- data/lib/tap/support/executable.rb +226 -19
- data/lib/tap/support/gems/rake.rb +6 -3
- data/lib/tap/support/join.rb +87 -0
- data/lib/tap/support/joins.rb +13 -0
- data/lib/tap/support/joins/fork.rb +18 -0
- data/lib/tap/support/joins/merge.rb +20 -0
- data/lib/tap/support/joins/sequence.rb +21 -0
- data/lib/tap/support/joins/switch.rb +23 -0
- data/lib/tap/support/joins/sync_merge.rb +57 -0
- data/lib/tap/support/lazydoc/document.rb +10 -0
- data/lib/tap/support/node.rb +58 -0
- data/lib/tap/support/parser.rb +379 -0
- data/lib/tap/support/schema.rb +350 -0
- data/lib/tap/support/tdoc.rb +5 -0
- data/lib/tap/support/validation.rb +2 -0
- data/lib/tap/task.rb +26 -61
- data/lib/tap/test.rb +9 -82
- data/lib/tap/test/assertions.rb +38 -0
- data/lib/tap/test/extensions.rb +78 -0
- data/lib/tap/test/{file_methods.rb → file_test.rb} +64 -37
- data/lib/tap/test/{file_methods_class.rb → file_test_class.rb} +2 -2
- data/lib/tap/test/regexp_escape.rb +87 -0
- data/lib/tap/test/script_test.rb +46 -0
- data/lib/tap/test/script_tester.rb +109 -0
- data/lib/tap/test/{subset_methods.rb → subset_test.rb} +9 -9
- data/lib/tap/test/{subset_methods_class.rb → subset_test_class.rb} +22 -14
- data/lib/tap/test/{tap_methods.rb → tap_test.rb} +43 -6
- data/lib/tap/test/utils.rb +6 -3
- metadata +27 -24
- data/lib/tap/parser.rb +0 -619
- data/lib/tap/spec/file_methods.rb +0 -16
- data/lib/tap/spec/file_methods_class.rb +0 -13
- data/lib/tap/spec/subset_methods.rb +0 -14
- data/lib/tap/support/batchable.rb +0 -47
- data/lib/tap/support/batchable_class.rb +0 -107
- data/lib/tap/support/declarations.rb +0 -131
- data/lib/tap/support/lazydoc/declaration.rb +0 -20
- data/lib/tap/support/parsers/base.rb +0 -81
- data/lib/tap/support/parsers/server.rb +0 -113
- data/lib/tap/test/script_methods.rb +0 -75
- data/lib/tap/test/script_methods/regexp_escape.rb +0 -94
- data/lib/tap/test/script_methods/script_test.rb +0 -109
- data/lib/tap/workflow.rb +0 -161
data/lib/tap/env.rb
CHANGED
@@ -190,6 +190,9 @@ module Tap
|
|
190
190
|
# Specify files to require when self is activated.
|
191
191
|
config :requires, [], &c.array_or_nil
|
192
192
|
|
193
|
+
# Specify files to load when self is activated.
|
194
|
+
config :loads, [], &c.array_or_nil
|
195
|
+
|
193
196
|
# Specify gems to load as nested Envs. Gems may be specified
|
194
197
|
# by name and/or version, like 'gemname >= 1.2'; by default the
|
195
198
|
# latest version of the gem is selected.
|
@@ -245,7 +248,7 @@ module Tap
|
|
245
248
|
next unless File.file?(path) && document = Support::Lazydoc.scan_doc(path, 'manifest')
|
246
249
|
|
247
250
|
document.default_const_name = env.root.relative_filepath(load_path, path).chomp('.rb').camelize
|
248
|
-
document.
|
251
|
+
document.const_names.collect do |const_name|
|
249
252
|
[const_name.underscore, Support::Constant.new(const_name, path)]
|
250
253
|
end
|
251
254
|
end
|
@@ -260,7 +263,7 @@ module Tap
|
|
260
263
|
|
261
264
|
next unless document = Support::Lazydoc.scan_doc(path, 'generator')
|
262
265
|
document.default_const_name = "#{env.root.relative_filepath(generator_path, dirname)}_generator".camelize
|
263
|
-
document.
|
266
|
+
document.const_names.collect do |const_name|
|
264
267
|
[const_name.underscore.chomp('_generator'), Support::Constant.new(const_name, path)]
|
265
268
|
end
|
266
269
|
end
|
@@ -458,6 +461,11 @@ module Tap
|
|
458
461
|
require path
|
459
462
|
end
|
460
463
|
|
464
|
+
# perform loads
|
465
|
+
loads.each do |path|
|
466
|
+
load path
|
467
|
+
end
|
468
|
+
|
461
469
|
true
|
462
470
|
end
|
463
471
|
|
data/lib/tap/exe.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'tap/env'
|
2
2
|
require 'tap/app'
|
3
|
-
require 'tap/
|
3
|
+
require 'tap/support/schema'
|
4
4
|
|
5
5
|
module Tap
|
6
6
|
class Exe < Env
|
@@ -74,7 +74,7 @@ module Tap
|
|
74
74
|
end
|
75
75
|
|
76
76
|
def build(argv=ARGV)
|
77
|
-
|
77
|
+
Support::Schema.parse(argv).compact.build(app) do |args|
|
78
78
|
task = args.shift
|
79
79
|
const = search(:tasks, task)
|
80
80
|
|
@@ -58,6 +58,7 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
58
58
|
|
59
59
|
rdoc.rdoc_dir = 'rdoc'
|
60
60
|
rdoc.title = '<%= project_name %>'
|
61
|
+
rdoc.main = 'README'
|
61
62
|
rdoc.options << '--line-numbers' << '--inline-source'
|
62
63
|
rdoc.rdoc_files.include( spec.extra_rdoc_files )
|
63
64
|
rdoc.rdoc_files.include( spec.files.select {|file| file =~ /^lib.*\.rb$/} )
|
data/lib/tap/spec.rb
CHANGED
@@ -1,67 +1,42 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
def self.included(base)
|
5
|
-
super
|
6
|
-
base.send(:include, Tap::Spec::Adapter)
|
7
|
-
end
|
8
|
-
|
9
|
-
# Causes a TestCase to act as a file test, by instantiating a class Tap::Root
|
10
|
-
# (trs), and including FileMethods. The root and directories used to
|
11
|
-
# instantiate trs can be specified as options. By default file_test_root
|
12
|
-
# and the directories {:input => 'input', :output => 'output', :expected => 'expected'}
|
13
|
-
# will be used.
|
14
|
-
#
|
15
|
-
# Note: file_test_root determines a root directory <em>based on the calling file</em>.
|
16
|
-
# Be sure to specify the root directory explicitly if you call acts_as_file_test
|
17
|
-
# from a file that is NOT meant to be test file.
|
18
|
-
def acts_as_file_spec(options={})
|
19
|
-
include Tap::Spec::FileMethods
|
20
|
-
|
21
|
-
options = {
|
22
|
-
:root => file_test_root,
|
23
|
-
:directories => {:input => 'input', :output => 'output', :expected => 'expected'}
|
24
|
-
}.merge(options)
|
25
|
-
self.trs = Tap::Root.new(options[:root], options[:directories])
|
26
|
-
end
|
27
|
-
|
28
|
-
# Causes a unit test to act as a tap test -- resulting in the following:
|
29
|
-
# - setup using acts_as_file_test
|
30
|
-
# - inclusion of Tap::Test::SubsetMethods
|
31
|
-
# - inclusion of Tap::Test::InstanceMethods
|
32
|
-
#
|
33
|
-
# Note: Unless otherwise specified, <tt>acts_as_tap_test</tt> infers a root directory
|
34
|
-
# based on the calling file. Be sure to specify the root directory explicitly
|
35
|
-
# if you call acts_as_file_test from a file that is NOT meant to be test file.
|
36
|
-
# def acts_as_tap_spec(options={})
|
37
|
-
# include Tap::Test::SubsetMethods
|
38
|
-
# include Tap::Test::FileMethods
|
39
|
-
# include Tap::Test::TapMethods
|
40
|
-
#
|
41
|
-
# acts_as_file_test({:root => file_test_root}.merge(options))
|
42
|
-
# end
|
43
|
-
#
|
44
|
-
# def acts_as_script_spec(options={})
|
45
|
-
# include Tap::Test::FileMethods
|
46
|
-
# include Tap::Test::ScriptMethods
|
47
|
-
#
|
48
|
-
# acts_as_file_test({:root => file_test_root}.merge(options))
|
49
|
-
# end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
module Tap
|
54
|
-
|
55
|
-
# Modules facilitating testing. TapMethods are specific to
|
56
|
-
# Tap, but SubsetMethods and FileMethods are more general in
|
57
|
-
# their utility.
|
58
|
-
module Spec
|
59
|
-
autoload(:SubsetMethods, 'tap/spec/subset_methods')
|
60
|
-
autoload(:FileMethods, 'tap/spec/file_methods')
|
61
|
-
autoload(:TapMethods, 'tap/spec/tap_methods')
|
62
|
-
end
|
63
|
-
end
|
1
|
+
require 'tap/test/extensions'
|
2
|
+
require 'tap/spec/adapter'
|
3
|
+
require 'tap/spec/inheritable_class_test_root'
|
64
4
|
|
5
|
+
module Spec
|
6
|
+
module Example
|
7
|
+
class ExampleGroup
|
8
|
+
extend Tap::Test::Extensions
|
9
|
+
include Tap::Spec::Adapter
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def acts_as_file_test(*args)
|
13
|
+
super
|
14
|
+
extend Tap::Spec::InheritableClassTestRoot
|
15
|
+
end
|
65
16
|
|
17
|
+
private
|
66
18
|
|
19
|
+
# Infers the test root directory from the calling file.
|
20
|
+
# 'some_class.rb' => 'some_class'
|
21
|
+
# 'some_class_test.rb' => 'some_class'
|
22
|
+
def test_root_dir # :nodoc:
|
23
|
+
# caller[2] is considered the calling file (which should be the test case)
|
24
|
+
# note that caller entries are like this:
|
25
|
+
# ./path/to/file.rb:10
|
26
|
+
# ./path/to/file.rb:10:in 'method'
|
67
27
|
|
28
|
+
calling_file = caller[2].gsub(/:\d+(:in .*)?$/, "")
|
29
|
+
calling_file.chomp(File.extname(calling_file)).chomp("_spec")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
before(:each) do
|
34
|
+
setup
|
35
|
+
end
|
36
|
+
|
37
|
+
after(:each) do
|
38
|
+
teardown
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/lib/tap/spec/adapter.rb
CHANGED
@@ -1,37 +1,14 @@
|
|
1
1
|
module Tap
|
2
2
|
module Spec
|
3
3
|
module Adapter
|
4
|
-
def
|
5
|
-
|
4
|
+
def setup
|
5
|
+
end
|
6
|
+
|
7
|
+
def teardown
|
6
8
|
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
# warning. Useful if you're running tests with -w.
|
11
|
-
#
|
12
|
-
# check 1.should == 1
|
13
|
-
#
|
14
|
-
# Check will validate that the line calling check contains a
|
15
|
-
# should/should_not statement; the check fails if it does not.
|
16
|
-
def check(return_value)
|
17
|
-
return false unless SCRIPT_LINES__
|
18
|
-
|
19
|
-
caller[0] =~ /^(([A-z]:)?[^:]+):(\d+)/
|
20
|
-
|
21
|
-
check_file = SCRIPT_LINES__[$1]
|
22
|
-
violated("could not validate check: #{$1} (#{$3})") unless check_file
|
23
|
-
|
24
|
-
# note the line number in caller
|
25
|
-
# starts at 1, not 0
|
26
|
-
line = check_file[$3.to_i - 1]
|
27
|
-
case line
|
28
|
-
when /\.should(_not)?[^\w]/
|
29
|
-
true # pass
|
30
|
-
when /^\s+check/
|
31
|
-
violated("check used without should/should_not statement: #{line} (#{caller[0]})")
|
32
|
-
else
|
33
|
-
violated("multiline check statements are not allowed: #{caller[0]}")
|
34
|
-
end
|
10
|
+
def method_name
|
11
|
+
self.description.strip.gsub(/\s+/, "_")
|
35
12
|
end
|
36
13
|
|
37
14
|
# Maps flunk to violated.
|
@@ -39,9 +16,9 @@ module Tap
|
|
39
16
|
violated(msg)
|
40
17
|
end
|
41
18
|
|
42
|
-
# Maps assert_equal to actual.should
|
19
|
+
# Maps assert_equal to actual.should.equal expected.
|
43
20
|
def assert_equal(expected, actual, msg=nil)
|
44
|
-
|
21
|
+
actual.should == expected
|
45
22
|
end
|
46
23
|
end
|
47
24
|
end
|
data/lib/tap/support/audit.rb
CHANGED
@@ -1,21 +1,64 @@
|
|
1
|
-
|
1
|
+
require 'enumerator'
|
2
|
+
|
3
|
+
module Tap
|
2
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 Combinator bundles all but the first set into a new
|
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.
|
3
35
|
class Combinator
|
4
|
-
|
36
|
+
include Enumerable
|
37
|
+
|
38
|
+
# The first set.
|
39
|
+
attr_reader :a
|
40
|
+
|
41
|
+
# The second set.
|
42
|
+
attr_reader :b
|
5
43
|
|
44
|
+
# Creates a new Combinator. Input sets must be an Array, or nil.
|
45
|
+
# Within the Array any objects are allowed for combination.
|
6
46
|
def initialize(*sets)
|
7
47
|
@a = make_set(sets.shift)
|
8
48
|
@b = make_set(*sets)
|
9
49
|
end
|
10
50
|
|
51
|
+
# Returns the sets used to initialize the Combinator.
|
11
52
|
def sets
|
12
|
-
sets_in(
|
53
|
+
sets_in(a) + sets_in(b)
|
13
54
|
end
|
14
55
|
|
56
|
+
# True if length is zero.
|
15
57
|
def empty?
|
16
|
-
|
58
|
+
a.empty? && b.empty?
|
17
59
|
end
|
18
60
|
|
61
|
+
# Returns the number of combinations returned by each.
|
19
62
|
def length
|
20
63
|
case
|
21
64
|
when !(@a.empty? || @b.empty?)
|
@@ -27,47 +70,56 @@ module Tap
|
|
27
70
|
end
|
28
71
|
end
|
29
72
|
|
73
|
+
# Passes each combination as an array to the input block.
|
30
74
|
def each
|
31
75
|
case
|
32
76
|
when !(@a.empty? || @b.empty?)
|
33
|
-
@a.each do
|
34
|
-
@b.each do
|
35
|
-
yield(
|
77
|
+
@a.each do |a|
|
78
|
+
@b.each do |b|
|
79
|
+
yield(a + b)
|
36
80
|
end
|
37
81
|
end
|
38
82
|
when @a.empty?
|
39
|
-
@b.each {
|
83
|
+
@b.each {|b| yield(b) }
|
40
84
|
when @b.empty?
|
41
|
-
@a.each {
|
85
|
+
@a.each {|a| yield(a) }
|
42
86
|
end
|
43
87
|
end
|
44
88
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
def sets_in(set)
|
56
|
-
set.kind_of?(Array) ? (set.empty? ? [] : [set]) : set.sets
|
57
|
-
end
|
58
|
-
|
59
|
-
def make_set(*sets)
|
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
|
60
99
|
return Combinator.new(*sets) if sets.length > 1
|
61
|
-
return
|
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
|
62
114
|
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
when
|
67
|
-
when
|
68
|
-
else [set]
|
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]}]
|
69
120
|
end
|
70
121
|
end
|
122
|
+
|
71
123
|
end
|
72
124
|
end
|
73
125
|
end
|
@@ -271,10 +271,10 @@ module Tap
|
|
271
271
|
# blocks, such as switch (Validation::SWITCH) and list
|
272
272
|
# (Validation::LIST).
|
273
273
|
def arg_type(block) # :nodoc:
|
274
|
-
case
|
275
|
-
when Validation::SWITCH then :switch
|
276
|
-
when Validation::FLAG then :flag
|
277
|
-
when Validation::LIST then :list
|
274
|
+
case
|
275
|
+
when block == Validation::SWITCH then :switch
|
276
|
+
when block == Validation::FLAG then :flag
|
277
|
+
when block == Validation::LIST then :list
|
278
278
|
else nil
|
279
279
|
end
|
280
280
|
end
|
@@ -283,9 +283,9 @@ module Tap
|
|
283
283
|
# blocks, such as switch (Validation::ARRAY) and list
|
284
284
|
# (Validation::HASH).
|
285
285
|
def arg_name(block) # :nodoc:
|
286
|
-
case
|
287
|
-
when Validation::ARRAY then "'[a, b, c]'"
|
288
|
-
when Validation::HASH then "'{one: 1, two: 2}'"
|
286
|
+
case
|
287
|
+
when block == Validation::ARRAY then "'[a, b, c]'"
|
288
|
+
when block == Validation::HASH then "'{one: 1, two: 2}'"
|
289
289
|
else nil
|
290
290
|
end
|
291
291
|
end
|
@@ -3,9 +3,11 @@ module Tap
|
|
3
3
|
|
4
4
|
# Dependable encapsulates the module-level methods facilitating
|
5
5
|
# dependencies in Executable.
|
6
|
-
|
7
|
-
def
|
8
|
-
|
6
|
+
class Dependencies
|
7
|
+
def initialize
|
8
|
+
@registry = []
|
9
|
+
@results = []
|
10
|
+
@resolve_stack = []
|
9
11
|
end
|
10
12
|
|
11
13
|
# An array of registered [instance, argv] pairs.
|
@@ -16,10 +18,10 @@ module Tap
|
|
16
18
|
attr_reader :results
|
17
19
|
|
18
20
|
# Clears all registered dependencies and results.
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
@resolve_stack
|
21
|
+
def clear
|
22
|
+
registry.clear
|
23
|
+
results.clear
|
24
|
+
@resolve_stack.clear
|
23
25
|
end
|
24
26
|
|
25
27
|
# Returns the index of the [instance, argv] pair in self,
|