Parent

ParseTreeTestCase

Attributes

processor[RW]

Public Class Methods

add_test(name, data, klass = self.name[4..-1]) click to toggle source
    # File test/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 test/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 test/pt_testcase.rb, line 74
74:   def self.clone_same
75:     @@testcases.each do |node, data|
76:       data.each do |key, val|
77:         if val == :same then
78:           prev_key = self.previous(key)
79:           data[key] = data[prev_key].deep_clone
80:         end
81:       end
82:     end
83:   end
copy_test_case(nonverbose, klass) click to toggle source
    # File test/pt_testcase.rb, line 85
85:   def self.copy_test_case nonverbose, klass
86:     verbose = nonverbose + "_mri_verbose_flag"
87:     testcases[verbose][klass] = testcases[nonverbose][klass]
88:   end
generate_test(klass, node, data, input_name, output_name) click to toggle source
     # File test/pt_testcase.rb, line 90
 90:   def self.generate_test klass, node, data, input_name, output_name
 91:     klass.send(:define_method, "test_#{node}".to_sym) do
 92:       flunk "Processor is nil" if processor.nil?
 93: 
 94:       assert data.has_key?(input_name), "Unknown input data"
 95:       assert data.has_key?(output_name), "Missing test data"
 96: 
 97:       $missing[node] << output_name unless data.has_key? output_name
 98: 
 99:       input    = data[input_name].deep_clone
100:       expected = data[output_name].deep_clone
101: 
102:       case expected
103:       when :unsupported then
104:         assert_raises(UnsupportedNodeError) do
105:           processor.process(input)
106:         end
107:       else
108:         extra_expected = []
109:         extra_input = []
110: 
111:         _, expected, extra_expected = *expected if
112:           Array === expected and expected.first == :defx
113:         _, input, extra_input = *input if
114:           Array === input and input.first == :defx
115: 
116:         # OMG... I can't believe I have to do this this way.  these
117:         # hooks are here instead of refactoring this define_method
118:         # body into an assertion. It'll allow subclasses to hook in
119:         # and add behavior before or after the processor does it's
120:         # thing. If you go the body refactor route, some of the
121:         # RawParseTree test casese fail for completely bogus reasons.
122: 
123:         before_process_hook klass, node, data, input_name, output_name
124:         refute_nil data[input_name], "testcase does not exist?"
125:         @result = processor.process input
126:         assert_equal(expected, @result,
127:                      "failed on input: #{data[input_name].inspect}")
128:         after_process_hook klass, node, data, input_name, output_name
129: 
130:         extra_input.each do |extra|
131:           processor.process(extra)
132:         end
133:         extra = processor.extra_methods rescue []
134:         assert_equal extra_expected, extra
135:       end
136:     end
137:   end
generate_tests(klass) click to toggle source
     # File test/pt_testcase.rb, line 139
139:   def self.generate_tests klass
140:     install_missing_reporter
141:     clone_same
142: 
143:     output_name = klass.name.to_s.sub(/^Test/, '')
144: 
145:     input_name = self.previous(output_name)
146: 
147:     @@testcases.each do |node, data|
148:       next if [:skip, :unsupported].include? data[input_name]
149:       next if data[output_name] == :skip
150: 
151:       generate_test klass, node, data, input_name, output_name
152:     end
153:   end
inherited(klass) click to toggle source
     # File test/pt_testcase.rb, line 155
155:   def self.inherited klass
156:     super
157: 
158:     generate_tests klass unless klass.name =~ /TestCase/
159:   end
install_missing_reporter() click to toggle source
     # File test/pt_testcase.rb, line 161
161:   def self.install_missing_reporter
162:     unless defined? $missing then
163:       $missing = Hash.new { |h,k| h[k] = [] }
164:       at_exit {
165:         at_exit {
166:           warn ""
167:           $missing.sort.each do |name, klasses|
168:             warn "add_tests(#{name.inspect},"
169:             klasses.map! { |klass| "          #{klass.inspect} => :same" }
170:             warn klasses.join("\n") + ")"
171:           end
172:           warn ""
173:         }
174:       }
175:     end
176:   end
previous(key, extra=0) click to toggle source
     # File test/pt_testcase.rb, line 178
178:   def self.previous(key, extra=0) # FIX: remove R2C code
179:     idx = @@testcase_order.index(key)
180: 
181:     raise "Unknown class #{key} in @@testcase_order" if idx.nil?
182: 
183:     case key
184:     when "RubyToRubyC" then
185:       idx -= 1
186:     end
187:     @@testcase_order[idx - 1 - extra]
188:   end
testcase_order() click to toggle source
     # File test/pt_testcase.rb, line 190
190:   def self.testcase_order; @@testcase_order; end
testcases() click to toggle source
     # File test/pt_testcase.rb, line 191
191:   def self.testcases; @@testcases; end
unsupported_tests(*tests) click to toggle source
     # File test/pt_testcase.rb, line 193
193:   def self.unsupported_tests *tests
194:     tests.flatten.each do |name|
195:       add_test name, :unsupported
196:     end
197:   end

Public Instance Methods

after_process_hook(klass, node, data, input_name, output_name) click to toggle source
    # File test/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 test/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 test/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.