Class: ParseTreeTestCase
- Defined in:
- lib/pt_testcase.rb
Constant Summary collapse
- TEST_SUFFIX =
"_#{most_versions.join "_"}"
- VER_RE =
/(#{Regexp.union(*all_versions)})/
- @@testcase_order =
Shared TestCases:
%w(Ruby ParseTree)
- @@testcases =
Hash.new { |h,k| h[k] = {} }
Instance Attribute Summary collapse
-
#processor ⇒ Object
to be defined by subclass.
Class Method Summary collapse
- .add_18tests(name, hash) ⇒ Object
- .add_19edgecases(ruby, sexp, cases) ⇒ Object
- .add_19tests(name, hash) ⇒ Object
- .add_test(name, data, klass = self.name[4..-1]) ⇒ Object
- .add_tests(name, hash) ⇒ Object
- .clone_same ⇒ Object
- .copy_test_case(nonverbose, klass) ⇒ Object
- .generate_test(klass, node, data, input_name, output_name) ⇒ Object
- .generate_tests(klass) ⇒ Object
- .inherited(klass) ⇒ Object
- .install_missing_reporter ⇒ Object
-
.previous(key, extra = 0) ⇒ Object
FIX: remove R2C code.
- .testcase_order ⇒ Object
- .testcases ⇒ Object
- .unsupported_tests(*tests) ⇒ Object
Instance Method Summary collapse
- #after_process_hook(klass, node, data, input_name, output_name) ⇒ Object
- #before_process_hook(klass, node, data, input_name, output_name) ⇒ Object
- #setup ⇒ Object
Instance Attribute Details
#processor ⇒ Object
to be defined by subclass
43 44 45 |
# File 'lib/pt_testcase.rb', line 43 def processor @processor end |
Class Method Details
.add_18tests(name, hash) ⇒ Object
81 82 83 |
# File 'lib/pt_testcase.rb', line 81 def self.add_18tests name, hash add_tests "#{name}__18", hash end |
.add_19edgecases(ruby, sexp, cases) ⇒ Object
89 90 91 92 93 |
# File 'lib/pt_testcase.rb', line 89 def self.add_19edgecases ruby, sexp, cases cases.each do |name, code| add_19tests name, "Ruby" => code, "ParseTree" => sexp, "Ruby2Ruby" => ruby end end |
.add_19tests(name, hash) ⇒ Object
85 86 87 |
# File 'lib/pt_testcase.rb', line 85 def self.add_19tests name, hash add_tests "#{name}_#{TEST_SUFFIX}", hash # HACK? end |
.add_test(name, data, klass = self.name[4..-1]) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/pt_testcase.rb', line 56 def self.add_test name, data, klass = self.name[4..-1] name = name.to_s klass = klass.to_s if testcases.has_key? name then if testcases[name].has_key? klass then warn "testcase #{klass}##{name} already has data" else testcases[name][klass] = data end else warn "testcase #{name} does not exist" end end |
.add_tests(name, hash) ⇒ Object
71 72 73 74 75 76 77 78 79 |
# File 'lib/pt_testcase.rb', line 71 def self.add_tests name, hash name = name.to_s hash.each do |klass, data| warn "testcase #{klass}##{name} already has data" if testcases[name].has_key? klass testcases[name][klass] = data end end |
.clone_same ⇒ Object
95 96 97 98 99 100 101 102 103 104 |
# File 'lib/pt_testcase.rb', line 95 def self.clone_same @@testcases.each do |node, data| data.each do |key, val| if val == :same then prev_key = self.previous(key) data[key] = data[prev_key].deep_clone end end end end |
.copy_test_case(nonverbose, klass) ⇒ Object
106 107 108 109 |
# File 'lib/pt_testcase.rb', line 106 def self.copy_test_case nonverbose, klass verbose = nonverbose + "_mri_verbose_flag" testcases[verbose][klass] = testcases[nonverbose][klass] end |
.generate_test(klass, node, data, input_name, output_name) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/pt_testcase.rb', line 111 def self.generate_test klass, node, data, input_name, output_name klass.send :define_method, "test_#{node}" do flunk "Processor is nil" if processor.nil? tversions = node[/(?:_#{VER_RE})+$/] if tversions then cversion = self.class.name[/#{VER_RE}/] assert true # shut up prove_it! # can't push this up because it may be generating into an # abstract test class and the actual subclass is versioned. return "version specific test" unless tversions.include? cversion if cversion end assert data.has_key?(input_name), "Unknown input data" assert data.has_key?(output_name), "Missing test data" $missing[node] << output_name unless data.has_key? output_name input = data[input_name].deep_clone expected = data[output_name].deep_clone case expected when :unsupported then assert_raises(UnsupportedNodeError) do processor.process(input) end else extra_expected = [] extra_input = [] _, expected, extra_expected = *expected if Array === expected and expected.sexp_type == :defx _, input, extra_input = *input if Array === input and input.sexp_type == :defx # OMG... I can't believe I have to do this this way. these # hooks are here instead of refactoring this define_method # body into an assertion. It'll allow subclasses to hook in # and add behavior before or after the processor does it's # thing. If you go the body refactor route, some of the # RawParseTree test cases fail for completely bogus reasons. before_process_hook klass, node, data, input_name, output_name refute_nil data[input_name], "testcase does not exist?" timeout = (ENV["RP_TIMEOUT"] || 10).to_i @result = processor.process input, "(string)", timeout assert_equal(expected, @result, "failed on input: #{data[input_name].inspect}") after_process_hook klass, node, data, input_name, output_name extra_input.each do |extra| processor.process(extra) end extra = if processor.respond_to?(:extra_methods) then processor.extra_methods else [] end assert_equal extra_expected, extra end end end |
.generate_tests(klass) ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/pt_testcase.rb', line 176 def self.generate_tests klass install_missing_reporter clone_same output_name = klass.name.to_s.sub(/^Test/, "") input_name = self.previous(output_name) @@testcases.each do |node, data| next if [:skip, :unsupported].include? data[input_name] next if data[output_name] == :skip generate_test klass, node, data, input_name, output_name end end |
.inherited(klass) ⇒ Object
192 193 194 195 196 |
# File 'lib/pt_testcase.rb', line 192 def self.inherited klass super generate_tests klass unless klass.name =~ /TestCase/ end |
.install_missing_reporter ⇒ Object
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/pt_testcase.rb', line 198 def self.install_missing_reporter unless defined? $missing then $missing = Hash.new { |h,k| h[k] = [] } at_exit { at_exit { warn "" $missing.sort.each do |name, klasses| warn "add_tests(#{name.inspect}," klasses.map! { |klass| " #{klass.inspect} => :same" } warn klasses.join("\n") + ")" end warn "" } } end end |
.previous(key, extra = 0) ⇒ Object
FIX: remove R2C code
215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/pt_testcase.rb', line 215 def self.previous key, extra=0 # FIX: remove R2C code idx = @@testcase_order.index(key) raise "Unknown class #{key} in @@testcase_order" if idx.nil? case key when "RubyToRubyC" then idx -= 1 end @@testcase_order[idx - 1 - extra] end |
.testcase_order ⇒ Object
227 |
# File 'lib/pt_testcase.rb', line 227 def self.testcase_order; @@testcase_order; end |
.testcases ⇒ Object
228 |
# File 'lib/pt_testcase.rb', line 228 def self.testcases; @@testcases; end |
.unsupported_tests(*tests) ⇒ Object
230 231 232 233 234 |
# File 'lib/pt_testcase.rb', line 230 def self.unsupported_tests *tests tests.flatten.each do |name| add_test name, :unsupported end end |
Instance Method Details
#after_process_hook(klass, node, data, input_name, output_name) ⇒ Object
50 51 |
# File 'lib/pt_testcase.rb', line 50 def after_process_hook klass, node, data, input_name, output_name end |
#before_process_hook(klass, node, data, input_name, output_name) ⇒ Object
53 54 |
# File 'lib/pt_testcase.rb', line 53 def before_process_hook klass, node, data, input_name, output_name end |
#setup ⇒ Object
45 46 47 48 |
# File 'lib/pt_testcase.rb', line 45 def setup super @processor = nil end |