File: test-users-guide.rb

package info (click to toggle)
kwalify 0.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,852 kB
  • ctags: 1,188
  • sloc: ruby: 8,446; xml: 172; makefile: 36; java: 36
file content (75 lines) | stat: -rw-r--r-- 1,858 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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