Parent

ParseTreeTestCase

Attributes

processor[RW]

Public Class Methods

add19_edgecases(ruby, sexp, cases) click to toggle source

REFACTOR: we’ve got 4 sets of edge cases w/ the same output

      # File lib/pt_testcase.rb, line 3252
3252:   def self.add19_edgecases ruby, sexp, cases
3253:     cases.each do |name, code|
3254:       add_19tests name, "Ruby" => code, "ParseTree" => sexp, "Ruby2Ruby" => ruby
3255:     end
3256:   end
add_18tests(name, hash) click to toggle source
    # File lib/pt_testcase.rb, line 74
74:   def self.add_18tests name, hash
75:     add_tests "#{name}__18", hash
76:   end
add_19tests(name, hash) click to toggle source
    # File lib/pt_testcase.rb, line 78
78:   def self.add_19tests name, hash
79:     add_tests "#{name}__19", hash
80:   end
add_test(name, data, klass = self.name[4..-1]) click to toggle source
    # File lib/pt_testcase.rb, line 49
49:   def self.add_test name, data, klass = self.name[4..1]
50:     name = name.to_s
51:     klass = klass.to_s
52: 
53:     if testcases.has_key? name then
54:       if testcases[name].has_key? klass then
55:         warn "testcase #{klass}##{name} already has data"
56:       else
57:         testcases[name][klass] = data
58:       end
59:     else
60:       warn "testcase #{name} does not exist"
61:     end
62:   end
add_tests(name, hash) click to toggle source
    # File lib/pt_testcase.rb, line 64
64:   def self.add_tests name, hash
65:     name = name.to_s
66: 
67:     hash.each do |klass, data|
68:       warn "testcase #{klass}##{name} already has data" if
69:         testcases[name].has_key? klass
70:       testcases[name][klass] = data
71:     end
72:   end
clone_same() click to toggle source
    # File lib/pt_testcase.rb, line 82
82:   def self.clone_same
83:     @@testcases.each do |node, data|
84:       data.each do |key, val|
85:         if val == :same then
86:           prev_key = self.previous(key)
87:           data[key] = data[prev_key].deep_clone
88:         end
89:       end
90:     end
91:   end
copy_test_case(nonverbose, klass) click to toggle source
    # File lib/pt_testcase.rb, line 93
93:   def self.copy_test_case nonverbose, klass
94:     verbose = nonverbose + "_mri_verbose_flag"
95:     testcases[verbose][klass] = testcases[nonverbose][klass]
96:   end
generate_test(klass, node, data, input_name, output_name) click to toggle source
     # File lib/pt_testcase.rb, line 98
 98:   def self.generate_test klass, node, data, input_name, output_name
 99:     klass.send :define_method, "test_#{node}" do
100:       flunk "Processor is nil" if processor.nil?
101: 
102:       if node =~ /(1[89])$/ then
103:         version = $1
104:         skip "version specific test" unless self.class.name =~ /#{version}/
105:       end
106: 
107:       assert data.has_key?(input_name), "Unknown input data"
108:       assert data.has_key?(output_name), "Missing test data"
109: 
110:       $missing[node] << output_name unless data.has_key? output_name
111: 
112:       input    = data[input_name].deep_clone
113:       expected = data[output_name].deep_clone
114: 
115:       case expected
116:       when :unsupported then
117:         assert_raises(UnsupportedNodeError) do
118:           processor.process(input)
119:         end
120:       else
121:         extra_expected = []
122:         extra_input = []
123: 
124:         _, expected, extra_expected = *expected if
125:           Array === expected and expected.first == :defx
126:         _, input, extra_input = *input if
127:           Array === input and input.first == :defx
128: 
129:         # OMG... I can't believe I have to do this this way.  these
130:         # hooks are here instead of refactoring this define_method
131:         # body into an assertion. It'll allow subclasses to hook in
132:         # and add behavior before or after the processor does it's
133:         # thing. If you go the body refactor route, some of the
134:         # RawParseTree test cases fail for completely bogus reasons.
135: 
136:         before_process_hook klass, node, data, input_name, output_name
137:         refute_nil data[input_name], "testcase does not exist?"
138:         @result = processor.process input
139:         assert_equal(expected, @result,
140:                      "failed on input: #{data[input_name].inspect}")
141:         after_process_hook klass, node, data, input_name, output_name
142: 
143:         extra_input.each do |extra|
144:           processor.process(extra)
145:         end
146:         extra = processor.extra_methods rescue []
147:         assert_equal extra_expected, extra
148:       end
149:     end
150:   end
generate_tests(klass) click to toggle source
     # File lib/pt_testcase.rb, line 152
152:   def self.generate_tests klass
153:     install_missing_reporter
154:     clone_same
155: 
156:     output_name = klass.name.to_s.sub(/^Test/, '')
157: 
158:     input_name = self.previous(output_name)
159: 
160:     @@testcases.each do |node, data|
161:       next if [:skip, :unsupported].include? data[input_name]
162:       next if data[output_name] == :skip
163: 
164:       generate_test klass, node, data, input_name, output_name
165:     end
166:   end
inherited(klass) click to toggle source
     # File lib/pt_testcase.rb, line 168
168:   def self.inherited klass
169:     super
170: 
171:     generate_tests klass unless klass.name =~ /TestCase/
172:   end
install_missing_reporter() click to toggle source
     # File lib/pt_testcase.rb, line 174
174:   def self.install_missing_reporter
175:     unless defined? $missing then
176:       $missing = Hash.new { |h,k| h[k] = [] }
177:       at_exit {
178:         at_exit {
179:           warn ""
180:           $missing.sort.each do |name, klasses|
181:             warn "add_tests(#{name.inspect},"
182:             klasses.map! { |klass| "          #{klass.inspect} => :same" }
183:             warn klasses.join("\n") + ")"
184:           end
185:           warn ""
186:         }
187:       }
188:     end
189:   end
previous(key, extra=0) click to toggle source
     # File lib/pt_testcase.rb, line 191
191:   def self.previous(key, extra=0) # FIX: remove R2C code
192:     idx = @@testcase_order.index(key)
193: 
194:     raise "Unknown class #{key} in @@testcase_order" if idx.nil?
195: 
196:     case key
197:     when "RubyToRubyC" then
198:       idx -= 1
199:     end
200:     @@testcase_order[idx - 1 - extra]
201:   end
testcase_order() click to toggle source
     # File lib/pt_testcase.rb, line 203
203:   def self.testcase_order; @@testcase_order; end
testcases() click to toggle source
     # File lib/pt_testcase.rb, line 204
204:   def self.testcases; @@testcases; end
unsupported_tests(*tests) click to toggle source
     # File lib/pt_testcase.rb, line 206
206:   def self.unsupported_tests *tests
207:     tests.flatten.each do |name|
208:       add_test name, :unsupported
209:     end
210:   end

Public Instance Methods

after_process_hook(klass, node, data, input_name, output_name) click to toggle source
    # File lib/pt_testcase.rb, line 43
43:   def after_process_hook klass, node, data, input_name, output_name
44:   end
before_process_hook(klass, node, data, input_name, output_name) click to toggle source
    # File lib/pt_testcase.rb, line 46
46:   def before_process_hook klass, node, data, input_name, output_name
47:   end
setup() click to toggle source
    # File lib/pt_testcase.rb, line 38
38:   def setup
39:     super
40:     @processor = nil
41:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.