Changeset 1006

Show
Ignore:
Timestamp:
2008-05-23 13:04:05 (8 months ago)
Author:
gaspard
Message:

Created a 'Zena' bundle to ease yaml testing. You can now run the focused yaml test (from the yaml file) with CMD+SHIFT+R. If there is a failure, the last link points to the place in the yaml file. Running CMD+R runs all tests for the current file group.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/parser/test/parser/zazen.yml

    r1004 r1006  
    141141textile_link: 
    142142  src: "See \"trac\":http://dev.zenadmin.org/report/3." 
    143   res: "<
     143  res: "<p>See <a href=\"http://dev.zenadmin.org/report/3\">trac</a>.</p>
    144144 
    145145wiki_link: 
  • trunk/lib/parser/test/parser_test.rb

    r886 r1006  
    1 require File.join(File.dirname(__FILE__) , 'testhelp.rb') 
     1require 'test/unit' 
     2require 'yaml' 
     3require File.join(File.dirname(__FILE__) , '..', 'lib', 'parser') 
     4require File.join(File.dirname(__FILE__), '..','..','yaml_test') 
    25require 'ruby-debug' 
    36Debugger.start 
     
    6366 
    6467class ParserTest < Test::Unit::TestCase 
    65   testfile :zafu => {}, :zafu_asset => {}, :zafu_insight => {}, :zazen => {} #, :latex => {:module => :zazen, :output => 'latex'} 
     68  yaml_test :zafu => {}, :zafu_asset => {}, :zafu_insight => {}, :zazen => {} #, :latex => {:module => :zazen, :output => 'latex'} 
     69  @@test_parsers = {} 
     70  @@test_options = {} 
     71   
     72  @@file_list.each do |file, opts| 
     73    file = file.to_s 
     74    mod_name = opts.delete(:module) || file 
     75    mod_name = mod_name.to_s.split("_").first.capitalize 
     76    @@test_parsers[file] = Parser.parser_with_rules(eval("#{mod_name}::Rules"), eval("#{mod_name}::Tags")) 
     77    @@test_options[file] = opts 
     78  end 
     79   
     80  def do_test(file, test) 
     81    res = @@test_parsers[file].new_with_url("/#{test.gsub('_', '/')}", :helper=>ParserModule::DummyHelper.new(@@test_strings[file])).render(@@test_options[file]) 
     82    if @@test_strings[file][test]['res'] 
     83      assert_yaml_test @@test_strings[file][test]['res'], res 
     84    end 
     85  end 
     86   
    6687  def test_single 
    6788    do_test('zafu', 'only_hello') 
  • trunk/lib/query_builder/test/query_builder_test.rb

    r970 r1006  
    9898 
    9999class QueryTest < Test::Unit::TestCase 
    100   yaml_dir File.dirname(__FILE__) 
    101100  yaml_test :basic, :joins, :filters, :errors 
    102101   
  • trunk/lib/yaml_test.rb

    r980 r1006  
    1919      # We need to do a class_eval so that the class variables 'test_strings, test_methods, ...' are scoped 
    2020      # in the final class and are not global to all tests using the YamlTest helper. 
     21      if files[0].kind_of?(Hash) 
     22        file_list = files[0] 
     23      else 
     24        file_list = Hash[*(files.map{|f| [f,{}]}.flatten)] 
     25      end 
     26       
    2127      class_eval %Q{ 
    2228        @@test_strings = {} 
     
    2430        @@test_options = {} 
    2531        @@test_files = [] 
    26         #{files.inspect}.each do |file| 
     32        @@file_list  = #{file_list.inspect} 
     33        @@file_directory ||= begin 
     34          if #{caller[0].inspect}.split('/').last =~ /^(.*)_test.rb/ 
     35            File.join(File.dirname(#{caller[0].inspect}), $1) 
     36          else 
     37            puts "Bad file name for yaml_tests '#{caller[0]}'. Should be '..._test.rb'. Trying main directory." 
     38            File.dirname(#{caller[0].inspect}) 
     39          end 
     40        end 
     41         
     42        @@file_list.each do |file, opts| 
    2743          file = file.to_s 
    2844          strings = {} 
     
    4258          @@test_methods[file] = test_methods 
    4359          @@test_files << file 
     60        end 
    4461         
     62        # Override this in your test class 
     63        def parse(value) 
     64          value 
     65        end 
    4566         
    46           # Override this in your test class 
    47           def parse(value) 
    48             value 
     67        def do_test(file, test) 
     68          context = @@test_strings[file][test]['context'] || {} 
     69          default_context = (@@test_strings[file]['default'] || {})['context'] || {} 
     70          context = Hash[*default_context.merge(context).map{|k,v| [k.to_sym,v]}.flatten] 
     71          res = parse(@@test_strings[file][test]['src'] || test.gsub('_',' '), context) 
     72          if test_res = @@test_strings[file][test]['res'] 
     73            assert_yaml_test test_res, res 
    4974          end 
    50  
    51           def do_test(file, test) 
    52             context = @@test_strings[file][test]['context'] || {} 
    53             default_context = (@@test_strings[file]['default'] || {})['context'] || {} 
    54             context = Hash[*default_context.merge(context).map{|k,v| [k.to_sym,v]}.flatten] 
    55             res = parse(@@test_strings[file][test]['src'] || test.gsub('_',' '), context) 
    56             if test_res = @@test_strings[file][test]['res'] 
    57               assert_yaml_test test_res, res 
     75        end 
     76         
     77        protected 
     78          def assert_yaml_test(test_res, res) 
     79            if test_res[0..1] == '!/' 
     80              assert_no_match %r{\#{test_res[2..-2]}}m, res 
     81            elsif test_res[0..0] == '/' 
     82              assert_match %r{\#{test_res[1..-2]}}m, res 
     83            else 
     84              assert_equal test_res, res 
    5885            end 
    5986          end 
    60            
    61           protected 
    62             def assert_yaml_test(test_res, res) 
    63               if test_res[0..1] == '!/' 
    64                 assert_no_match %r{\#{test_res[2..-2]}}m, res 
    65               elsif test_res[0..0] == '/' 
    66                 assert_match %r{\#{test_res[1..-2]}}m, res 
    67               else 
    68                 assert_equal test_res, res 
    69               end 
    70             end 
    71         end 
    7287      } 
    7388    end 
  • trunk/test/helpers/node_query_test.rb

    r984 r1006  
    22 
    33class NodeQueryTest < ZenaTestUnit 
    4   yaml_dir  File.join(File.dirname(__FILE__), 'node_query') 
    54  yaml_test :basic, :filters, :relations 
    65 
  • trunk/test/helpers/zena_parser/data.yml

    r1005 r1006  
    2121  res: "150.000" 
    2222 
     23stat_count: 
     24  src: "<r:data do='stat' find='count'/>" 
     25  res: "5" 
     26   
    2327stat_min: 
    2428  src: "<r:data do='stat' find='min'/>"