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.
Files changed (59) hide show
  1. data/bin/rap +13 -5
  2. data/lib/tap.rb +0 -4
  3. data/lib/tap/app.rb +10 -138
  4. data/lib/tap/constants.rb +1 -1
  5. data/lib/tap/declarations.rb +201 -0
  6. data/lib/tap/env.rb +10 -2
  7. data/lib/tap/exe.rb +2 -2
  8. data/lib/tap/generator/generators/root/templates/Rakefile +1 -0
  9. data/lib/tap/generator/generators/root/templates/test/tap_test_suite.rb +1 -1
  10. data/lib/tap/spec.rb +38 -63
  11. data/lib/tap/spec/adapter.rb +8 -31
  12. data/lib/tap/spec/inheritable_class_test_root.rb +9 -0
  13. data/lib/tap/support/audit.rb +0 -2
  14. data/lib/tap/support/combinator.rb +83 -31
  15. data/lib/tap/support/configurable_class.rb +7 -7
  16. data/lib/tap/support/{dependable.rb → dependencies.rb} +9 -7
  17. data/lib/tap/support/executable.rb +226 -19
  18. data/lib/tap/support/gems/rake.rb +6 -3
  19. data/lib/tap/support/join.rb +87 -0
  20. data/lib/tap/support/joins.rb +13 -0
  21. data/lib/tap/support/joins/fork.rb +18 -0
  22. data/lib/tap/support/joins/merge.rb +20 -0
  23. data/lib/tap/support/joins/sequence.rb +21 -0
  24. data/lib/tap/support/joins/switch.rb +23 -0
  25. data/lib/tap/support/joins/sync_merge.rb +57 -0
  26. data/lib/tap/support/lazydoc/document.rb +10 -0
  27. data/lib/tap/support/node.rb +58 -0
  28. data/lib/tap/support/parser.rb +379 -0
  29. data/lib/tap/support/schema.rb +350 -0
  30. data/lib/tap/support/tdoc.rb +5 -0
  31. data/lib/tap/support/validation.rb +2 -0
  32. data/lib/tap/task.rb +26 -61
  33. data/lib/tap/test.rb +9 -82
  34. data/lib/tap/test/assertions.rb +38 -0
  35. data/lib/tap/test/extensions.rb +78 -0
  36. data/lib/tap/test/{file_methods.rb → file_test.rb} +64 -37
  37. data/lib/tap/test/{file_methods_class.rb → file_test_class.rb} +2 -2
  38. data/lib/tap/test/regexp_escape.rb +87 -0
  39. data/lib/tap/test/script_test.rb +46 -0
  40. data/lib/tap/test/script_tester.rb +109 -0
  41. data/lib/tap/test/{subset_methods.rb → subset_test.rb} +9 -9
  42. data/lib/tap/test/{subset_methods_class.rb → subset_test_class.rb} +22 -14
  43. data/lib/tap/test/{tap_methods.rb → tap_test.rb} +43 -6
  44. data/lib/tap/test/utils.rb +6 -3
  45. metadata +27 -24
  46. data/lib/tap/parser.rb +0 -619
  47. data/lib/tap/spec/file_methods.rb +0 -16
  48. data/lib/tap/spec/file_methods_class.rb +0 -13
  49. data/lib/tap/spec/subset_methods.rb +0 -14
  50. data/lib/tap/support/batchable.rb +0 -47
  51. data/lib/tap/support/batchable_class.rb +0 -107
  52. data/lib/tap/support/declarations.rb +0 -131
  53. data/lib/tap/support/lazydoc/declaration.rb +0 -20
  54. data/lib/tap/support/parsers/base.rb +0 -81
  55. data/lib/tap/support/parsers/server.rb +0 -113
  56. data/lib/tap/test/script_methods.rb +0 -75
  57. data/lib/tap/test/script_methods/regexp_escape.rb +0 -94
  58. data/lib/tap/test/script_methods/script_test.rb +0 -109
  59. data/lib/tap/workflow.rb +0 -161
@@ -0,0 +1,46 @@
1
+ require 'tap/test/assertions'
2
+ require 'tap/test/script_tester'
3
+ require 'tap/test/subset_test'
4
+
5
+ module Tap
6
+ module Test
7
+ module ScriptTest
8
+
9
+ def self.included(base)
10
+ super
11
+ base.send(:include, Tap::Test::SubsetTest)
12
+ base.send(:include, Tap::Test::Assertions)
13
+ end
14
+
15
+ def default_command_path
16
+ nil
17
+ end
18
+
19
+ def script_test(test_dir=method_root.root)
20
+ subset_test("SCRIPT", "s") do
21
+ Tap::Root.chdir(test_dir, true) do
22
+ Utils.with_argv do
23
+ puts "\n# == #{method_name}"
24
+
25
+ cmd = ScriptTester.new(default_command_path, env('stepwise')) do |expected, result, msg|
26
+ case expected
27
+ when String
28
+ assert_output_equal(expected, result, msg)
29
+ when Regexp
30
+ assert_alike(expected, result, msg)
31
+ end
32
+ end
33
+
34
+ yield(cmd)
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ end
41
+ end
42
+ end
43
+
44
+
45
+
46
+
@@ -0,0 +1,109 @@
1
+ require 'tap/support/shell_utils'
2
+ require 'tap/test/regexp_escape'
3
+
4
+ module Tap
5
+ module Test
6
+
7
+ class ScriptTester
8
+ include Tap::Support::ShellUtils
9
+
10
+ # The command path for self, returned by to_s
11
+ attr_accessor :command_path
12
+
13
+ # An array of (command, message, expected, validation)
14
+ # entries, representing the accumulated test commands.
15
+ attr_reader :commands
16
+
17
+ attr_reader :stepwise, :run_block
18
+
19
+ def initialize(command_path=nil, stepwise=false, &run_block)
20
+ @command_path = command_path
21
+ @commands = []
22
+ @stepwise = stepwise
23
+ @run_block = run_block
24
+ end
25
+
26
+ # Splits the input string, collecting single-line commands
27
+ # and expected results. Nil will be used as the expected
28
+ # result if the result is whitespace, or not present.
29
+ #
30
+ # cmd = ScriptTest.new
31
+ # cmd.split %Q{
32
+ # % command one
33
+ # expected text for command one
34
+ # % command two
35
+ # % command three
36
+ # expected text for command three
37
+ # }
38
+ # # => [
39
+ # # ["command one", "expected text for command one\n"],
40
+ # # ["command two", nil],
41
+ # # ["command three", "expected text for command three\n"]]
42
+ #
43
+ def split(str)
44
+ str.split(/^%\s*/).collect do |s|
45
+ next(nil) if s.strip.empty?
46
+ command, expected = s.split(/\n/, 2)
47
+ expected = nil if expected && expected.strip.empty?
48
+ [command.strip, expected]
49
+ end.compact
50
+ end
51
+
52
+ def time(msg, command)
53
+ run([command, msg, nil, nil])
54
+ end
55
+
56
+ def check(msg, command, use_regexp_escapes=true, &validation)
57
+ new_commands = split(command)
58
+ commands = new_commands.collect do |cmd, expected|
59
+ expected = RegexpEscape.new(expected) if expected && use_regexp_escapes
60
+ [cmd, msg, expected, validation]
61
+ end
62
+
63
+ run(*commands)
64
+ end
65
+
66
+ def match(msg, command, regexp=nil, &validation)
67
+ new_commands = split(command)
68
+ commands = new_commands.collect do |cmd, expected|
69
+ raise "expected text specified in match command" unless expected == nil
70
+ [cmd, msg, regexp, validation]
71
+ end
72
+
73
+ run(*commands)
74
+ end
75
+
76
+ def run(*commands)
77
+ commands.each_with_index do |(cmd, msg, expected, validation), i|
78
+ start = Time.now
79
+ result = capture_sh(cmd) {|ok, status, tempfile_path| }
80
+ elapsed = Time.now - start
81
+
82
+ cmd_msg = commands.length > 1 ? "#{msg} (#{i})" : msg
83
+ run_block.call(expected, result, %Q{#{cmd_msg}\n% #{cmd}}) if expected
84
+ validation.call(result) if validation
85
+
86
+ if stepwise
87
+ print %Q{
88
+ ------------------------------------
89
+ %s
90
+ > %s
91
+ %s
92
+ Time Elapsed: %.3fs} % [cmd_msg, cmd, result, elapsed]
93
+
94
+ print "\nContinue? (y/n): "
95
+ break if gets.strip =~ /^no?$/i
96
+ else
97
+ puts "%.3fs : %s" % [elapsed, cmd_msg]
98
+ end
99
+ end
100
+ end
101
+
102
+ # Returns the command path.
103
+ def to_s
104
+ command_path
105
+ end
106
+
107
+ end
108
+ end
109
+ end
@@ -1,10 +1,10 @@
1
1
  require 'benchmark'
2
- require 'tap/test/subset_methods_class'
2
+ require 'tap/test/subset_test_class'
3
3
 
4
4
  module Tap
5
5
  module Test
6
6
 
7
- # SubsetMethods provides methods to conditionally run tests, or to skip a
7
+ # SubsetTest provides methods to conditionally run tests, or to skip a
8
8
  # test suite entirely.
9
9
  #
10
10
  # require 'tap/test'
@@ -26,7 +26,7 @@ module Tap
26
26
  # to be skipped.
27
27
  #
28
28
  # class RunOnlyAFewTest < Test::Unit::TestCase
29
- # include SubsetMethods
29
+ # include SubsetTest
30
30
  #
31
31
  # def test_runs_all_the_time
32
32
  # assert true
@@ -64,7 +64,7 @@ module Tap
64
64
  # % tap run test EXTENDED=true
65
65
  # % rap test BENCHMARK=true
66
66
  #
67
- # In so far as SubsetMethods is concerned, the environment variables are
67
+ # In so far as SubsetTest is concerned, the environment variables are
68
68
  # case-insensitive. As in the example, additional ENV-based tests can be
69
69
  # defined using the subset_test method. To run all tests that get switched
70
70
  # using an ENV variable, set ALL=true.
@@ -76,13 +76,13 @@ module Tap
76
76
  # % rap test all=true
77
77
  #
78
78
  # See {Test::Unit::TestCase}[link:classes/Test/Unit/TestCase.html] and
79
- # SubsetMethodsClass for more information.
80
- module SubsetMethods
79
+ # SubsetTestClass for more information.
80
+ module SubsetTest
81
81
  include Tap::Test::EnvVars
82
82
 
83
83
  def self.included(base)
84
84
  super
85
- base.extend SubsetMethodsClass
85
+ base.extend SubsetTestClass
86
86
  end
87
87
 
88
88
  # Returns true if the specified conditions are satisfied.
@@ -113,7 +113,7 @@ module Tap
113
113
  # platform_test('mswin') { ... }
114
114
  # end
115
115
  #
116
- # See SubsetMethodsClass#match_platform? for matching details.
116
+ # See SubsetTestClass#match_platform? for matching details.
117
117
  def platform_test(*platforms)
118
118
  if self.class.match_platform?(*platforms)
119
119
  yield
@@ -137,7 +137,7 @@ module Tap
137
137
  # condition_test { # does not run }
138
138
  # end
139
139
  #
140
- # See SubsetMethodsClass#condition for more details.
140
+ # See SubsetTestClass#condition for more details.
141
141
  def condition_test(*condition_names)
142
142
  if self.class.unsatisfied_conditions(*condition_names).empty?
143
143
  yield
@@ -3,25 +3,25 @@ require 'tap/test/env_vars'
3
3
  module Tap
4
4
  module Test
5
5
 
6
- # Class methods extending tests which include SubsetMethods.
7
- module SubsetMethodsClass
6
+ # Class methods extending tests which include SubsetTest.
7
+ module SubsetTestClass
8
8
  include Tap::Test::EnvVars
9
9
 
10
10
  # Passes conditions to subclass
11
- def inherited(subclass) # :nodoc:
11
+ def inherited(child) # :nodoc:
12
12
  super
13
- subclass_conditions = conditions.inject({}) do |memo, (key, value)|
14
- memo.update(key => (value.dup rescue value))
15
- end
16
- subclass.instance_variable_set(:@conditions, subclass_conditions)
17
- subclass.instance_variable_set(:@run_test_suite, nil)
18
- subclass.instance_variable_set(:@skip_messages, [])
13
+ dup = {}
14
+ conditions.each_pair {|key, value| dup[key] = value.dup }
15
+ child.instance_variable_set(:@conditions, dup)
19
16
  end
20
17
 
21
- # A hash of [name, [msg, condition_block]] pairs defined by condition.
22
- def conditions
23
- @conditions ||= {}
18
+ # Initialize conditions.
19
+ def self.extended(base) # :nodoc:
20
+ base.instance_variable_set(:@conditions, {})
24
21
  end
22
+
23
+ # A hash of [name, [msg, condition_block]] pairs defined by condition.
24
+ attr_reader :conditions
25
25
 
26
26
  # Defines a condition block and associated message.
27
27
  # Raises an error if no condition block is given.
@@ -37,8 +37,16 @@ module Tap
37
37
  # satisfied?(:is_true) # => true
38
38
  # satisfied?(:is_true, :is_false) # => false
39
39
  #
40
- def satisfied?(*names)
41
- unsatisfied_conditions(*names).empty?
40
+ # Yields the name and message for each unsatisfied condition to the
41
+ # block, if given.
42
+ def satisfied?(*names) # :yields: name-of-unsatisfied-condition, msg
43
+ unsatisfied = unsatisfied_conditions(*names)
44
+
45
+ unsatisfied.each do |name|
46
+ yield(name, condition[name][0])
47
+ end if block_given?
48
+
49
+ unsatisfied.empty?
42
50
  end
43
51
 
44
52
  # Returns an array of the unsatified conditions. Raises
@@ -33,15 +33,15 @@ module Tap
33
33
  #
34
34
  # === Class Methods
35
35
  #
36
- # See {Test::Unit::TestCase}[link:classes/Test/Unit/TestCase.html] for documentation of the class methods added by TapMethods.
37
- module TapMethods
36
+ # See {Test::Unit::TestCase}[link:classes/Test/Unit/TestCase.html] for documentation of the class methods added by TapTest.
37
+ module TapTest
38
38
 
39
39
  # Returns the test-method-specific application.
40
40
  attr_reader :app
41
41
 
42
42
  # Setup creates a test-method-specific application that is initialized
43
43
  # to the method_root, and uses the directories and absolute paths from
44
- # trs (the test root structure, see Tap::Test::FileMethods).
44
+ # trs (the test root structure, see Tap::Test::FileTest).
45
45
  #
46
46
  # Also makes sure Tap::App.instance returns the test method app.
47
47
  def setup
@@ -54,18 +54,55 @@ module Tap
54
54
  # audit test methods
55
55
  #
56
56
 
57
- # Used to define expected audits in Tap::Test::TapMethods#assert_audit_equal
57
+ # Used to define expected audits in Tap::Test::TapTest#assert_audit_equal
58
58
  class ExpAudit < Array
59
59
  end
60
60
 
61
- # Used to define merged audit trails in Tap::Test::TapMethods#assert_audit_equal
61
+ # Used to define merged audit trails in Tap::Test::TapTest#assert_audit_equal
62
62
  class ExpMerge < Array
63
63
  end
64
64
 
65
+ class Tracer
66
+ include Tap::Support::Executable
67
+
68
+ class << self
69
+ def intern(n, app, runlist)
70
+ Array.new(n) { |index| new(index, app, runlist) }
71
+ end
72
+ end
73
+
74
+ def initialize(index, app, runlist)
75
+ @index = index
76
+ @runlist = runlist
77
+
78
+ @app = app
79
+ @_method_name = :trace
80
+ @on_complete_block =nil
81
+ @dependencies = []
82
+ @batch = [self]
83
+ end
84
+
85
+ def concat(str, id)
86
+ "#{str} #{id}".strip
87
+ end
88
+
89
+ def trace(trace)
90
+ id = "#{@index}.#{batch_index}"
91
+ @runlist << id
92
+
93
+ case trace
94
+ when Array then trace.collect {|str| concat(str, id) }
95
+ when String then concat(trace, id)
96
+ else raise "cannot utilize trace: #{trace}"
97
+ end
98
+ end
99
+ end
100
+
65
101
  # Asserts that an array of audits are all equal, basically feeding
66
102
  # each pair of audits to assert_audit_equal.
67
103
  def assert_audits_equal(expected, audits)
68
- Utils.each_pair_with_index(expected, audits) do |exp, audit, index|
104
+ error_msg = "expected <#{audits.length}> audits, but was <#{expected.length}>"
105
+ Utils.each_pair_with_index(expected, audits, error_msg) do |exp, audit, index|
69
106
  assert_audit_equal(exp, audit, [index])
70
107
  end
71
108
  end
@@ -164,11 +164,14 @@ module Tap
164
164
  end
165
165
 
166
166
  # Same as each_pair but yields the index of the entries as well.
167
- def each_pair_with_index(a, b, &block) # :yields: entry_a, entry_b, index
167
+ def each_pair_with_index(a, b, error_msg=nil, &block) # :yields: entry_a, entry_b, index
168
168
  a = [a] unless a.kind_of?(Array)
169
169
  b = [b] unless b.kind_of?(Array)
170
-
171
- raise ArgumentError, "The input arrays must have an equal number of entries." unless a.length == b.length
170
+
171
+ unless a.length == b.length
172
+ raise ArgumentError, (error_msg || "The input arrays must have an equal number of entries.")
173
+ end
174
+
172
175
  0.upto(a.length-1) do |index|
173
176
  yield(a[index], b[index], index)
174
177
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bahuvrihi-tap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.6
4
+ version: 0.10.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Simon Chiang
@@ -28,9 +28,6 @@ extra_rdoc_files:
28
28
  - doc/Class Reference
29
29
  - doc/Command Reference
30
30
  files:
31
- - README
32
- - MIT-LICENSE
33
- - History
34
31
  - cgi/run.rb
35
32
  - cmd/console.rb
36
33
  - cmd/destroy.rb
@@ -45,6 +42,7 @@ files:
45
42
  - bin/tap
46
43
  - lib/tap/app.rb
47
44
  - lib/tap/constants.rb
45
+ - lib/tap/declarations.rb
48
46
  - lib/tap/env.rb
49
47
  - lib/tap/exe.rb
50
48
  - lib/tap/file_task.rb
@@ -73,7 +71,6 @@ files:
73
71
  - lib/tap/generator/generators/task/templates/task.erb
74
72
  - lib/tap/generator/generators/task/templates/test.erb
75
73
  - lib/tap/generator/manifest.rb
76
- - lib/tap/parser.rb
77
74
  - lib/tap/patches/optparse/summarize.rb
78
75
  - lib/tap/patches/rake/rake_test_loader.rb
79
76
  - lib/tap/patches/rake/testtask.rb
@@ -82,14 +79,10 @@ files:
82
79
  - lib/tap/root.rb
83
80
  - lib/tap/spec.rb
84
81
  - lib/tap/spec/adapter.rb
85
- - lib/tap/spec/file_methods.rb
86
- - lib/tap/spec/file_methods_class.rb
87
- - lib/tap/spec/subset_methods.rb
82
+ - lib/tap/spec/inheritable_class_test_root.rb
88
83
  - lib/tap/support/aggregator.rb
89
84
  - lib/tap/support/assignments.rb
90
85
  - lib/tap/support/audit.rb
91
- - lib/tap/support/batchable.rb
92
- - lib/tap/support/batchable_class.rb
93
86
  - lib/tap/support/class_configuration.rb
94
87
  - lib/tap/support/combinator.rb
95
88
  - lib/tap/support/configurable.rb
@@ -97,24 +90,30 @@ files:
97
90
  - lib/tap/support/configuration.rb
98
91
  - lib/tap/support/constant.rb
99
92
  - lib/tap/support/constant_utils.rb
100
- - lib/tap/support/declarations.rb
101
- - lib/tap/support/dependable.rb
93
+ - lib/tap/support/dependencies.rb
102
94
  - lib/tap/support/executable.rb
103
95
  - lib/tap/support/executable_queue.rb
104
96
  - lib/tap/support/gems/rake.rb
105
97
  - lib/tap/support/gems/rack.rb
106
98
  - lib/tap/support/gems.rb
107
99
  - lib/tap/support/instance_configuration.rb
100
+ - lib/tap/support/join.rb
101
+ - lib/tap/support/joins.rb
102
+ - lib/tap/support/joins/fork.rb
103
+ - lib/tap/support/joins/merge.rb
104
+ - lib/tap/support/joins/sequence.rb
105
+ - lib/tap/support/joins/switch.rb
106
+ - lib/tap/support/joins/sync_merge.rb
108
107
  - lib/tap/support/lazy_attributes.rb
109
108
  - lib/tap/support/lazydoc.rb
110
109
  - lib/tap/support/lazydoc/comment.rb
111
110
  - lib/tap/support/lazydoc/config.rb
112
- - lib/tap/support/lazydoc/declaration.rb
113
111
  - lib/tap/support/lazydoc/document.rb
114
112
  - lib/tap/support/lazydoc/method.rb
115
113
  - lib/tap/support/manifest.rb
116
- - lib/tap/support/parsers/base.rb
117
- - lib/tap/support/parsers/server.rb
114
+ - lib/tap/support/node.rb
115
+ - lib/tap/support/parser.rb
116
+ - lib/tap/support/schema.rb
118
117
  - lib/tap/support/shell_utils.rb
119
118
  - lib/tap/support/tdoc.rb
120
119
  - lib/tap/support/tdoc/tdoc_html_generator.rb
@@ -127,22 +126,26 @@ files:
127
126
  - lib/tap/tasks/dump.rb
128
127
  - lib/tap/tasks/load.rb
129
128
  - lib/tap/tasks/rake.rb
129
+ - lib/tap/test/assertions.rb
130
130
  - lib/tap/test/env_vars.rb
131
- - lib/tap/test/file_methods.rb
132
- - lib/tap/test/file_methods_class.rb
133
- - lib/tap/test/script_methods.rb
134
- - lib/tap/test/script_methods/regexp_escape.rb
135
- - lib/tap/test/script_methods/script_test.rb
136
- - lib/tap/test/subset_methods.rb
137
- - lib/tap/test/subset_methods_class.rb
138
- - lib/tap/test/tap_methods.rb
131
+ - lib/tap/test/extensions.rb
132
+ - lib/tap/test/file_test.rb
133
+ - lib/tap/test/file_test_class.rb
134
+ - lib/tap/test/script_test.rb
135
+ - lib/tap/test/regexp_escape.rb
136
+ - lib/tap/test/script_tester.rb
137
+ - lib/tap/test/subset_test.rb
138
+ - lib/tap/test/subset_test_class.rb
139
+ - lib/tap/test/tap_test.rb
139
140
  - lib/tap/test/utils.rb
140
141
  - lib/tap/test.rb
141
- - lib/tap/workflow.rb
142
142
  - lib/tap.rb
143
143
  - template/404.erb
144
144
  - template/index.erb
145
145
  - vendor/url_encoded_pair_parser.rb
146
+ - README
147
+ - MIT-LICENSE
148
+ - History
146
149
  has_rdoc: true
147
150
  homepage: http://tap.rubyforge.org
148
151
  post_install_message: