Sha256: dcbd4848055fb2a6d207a1a71e0d148ad0e9f7b3888f5821461097f147c1e1f2

Contents?: true

Size: 1.81 KB

Versions: 9

Compression:

Stored size: 1.81 KB

Contents

require File.expand_path(File.dirname(__FILE__) + '/../test/test.rb')

class UsersGuideTest < Test::Unit::TestCase

  DATA_DIR = 'data/users-guide'
  CURR_DIR = Dir.pwd
  for item in Dir.glob("#{DATA_DIR}/*.result").sort()
    filename = File.basename(item)
    name = (filename =~ /(.*)\.\w+$/) && $1.gsub(/[^\w]/, '_')
    s = <<-END
      def test_#{name}
        @name = #{name.inspect}
        @filename = #{filename.inspect}
        _test()
      end
    END
    eval s
  end

### BEGIN
  def test_address_book_ruby
    @command = 'kwalify -a genclass-ruby -tf address_book.schema.yaml'
    @result = File.read('address_book.rb')
    _test()
  end
  def test_example_address_book_ruby
    @command = 'ruby example_address_book.rb'
    @result = File.read('example_address_book_ruby.result')
    @testopts = { 'delete_object_id' => true }
    _test()
  end
### END

  def setup
    Dir.chdir DATA_DIR
  end

  def teardown
    Dir.chdir CURR_DIR
  end

  def _test
    #@name ||= (caller()[0] =~ /in `test_(.*?)'/) && $1
    @name = (self.name =~ /\Atest_(.*)\(.*\)\z/) && $1
    return if @name =~ /\_java$/
    @filename ||= @name + '.result'

    result = @result || File.read(@filename)
    tuples = result.split(/^(?=\$ )/).collect do |s|
      if s.sub!(/\A\$ (.*)\n/, '')
        command = $1
        while command =~ /\\\z/
          command.chop!
          s.sub!(/\A(.*)\n/, '')
          command << $1
        end
        [@command || command, @expected || s]
      else
        [@command, @expected || s]
      end
    end

    tuples.each do |command, expected|
      actual = @actual || `#{command}`
      #if @testopts && @testops['delete_object_id']
        rexp = /(\#<\w+(::\w+)*:)0x[0-9a-f]+/
        actual.gsub!(rexp, '\1')
        expected.gsub!(rexp, '\1')
      #end
      assert_text_equal(expected, actual)
    end

  end

end

Version data entries

9 entries across 7 versions & 4 rubygems

Version Path
dc-kwalify-0.7.2 test/test-users-guide.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/test/test-users-guide.rb
config_gems_initialization_aim-0.1.4 vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/test/test-users-guide.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/config_gems_initialization_aim-0.1.1/vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/test/test-users-guide.rb
config_gems_initialization_aim-0.1.3 vendor/bundle/ruby/2.5.0/gems/kwalify-0.7.2/test/test-users-guide.rb
kwalify-0.7.2 test/test-users-guide.rb
ddao-kwalify-0.7.1 test/test-users-guide.rb
kwalify-0.7.0 test/test-users-guide.rb
kwalify-0.7.1 test/test-users-guide.rb