summaryrefslogtreecommitdiffstats
path: root/test/parser/tc_parser.rb
blob: cb3cea0e9fbc2d2abd1074188896d974cf34c0ae (plain)
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
if __FILE__ == $0
    $:.unshift '../../lib'
    $:.unshift '..'
    $puppetbase = "../.."
end

require 'puppet'
require 'puppet/parser/parser'
require 'test/unit'
require 'puppettest'

# $Id$

class TestParser < Test::Unit::TestCase
    # hmmm
    # this is complicated, because we store references to the created
    # objects in a central store
    def setup
        Puppet[:loglevel] = :debug if __FILE__ == $0
        Puppet[:parseonly] = true
        #@lexer = Puppet::Parser::Lexer.new()
        @parser = Puppet::Parser::Parser.new()
        @@tmpfiles = []
    end

    def teardown
        @@tmpfiles.each { |file|
            if FileTest.exist?(file)
                system("rm -rf %s" % file)
            end
        }
    end

    def test_each_file
        textfiles { |file|
            Puppet.debug("parsing %s" % file) if __FILE__ == $0
            assert_nothing_raised() {
                @parser.file = file
                @parser.parse
            }

            Puppet::Type.eachtype { |type|
                type.each { |obj|
                    assert(obj.file)
                    assert(obj.name)
                    assert(obj.line)
                }
            }
            Puppet::Type.allclear
        }
    end

    def test_failers
        failers { |file|
            Puppet.debug("parsing failer %s" % file) if __FILE__ == $0
            assert_raise(Puppet::ParseError) {
                @parser.file = file
                @parser.parse
            }
            Puppet::Type.allclear
        }
    end

    def test_zzarrayrvalues
        parser = Puppet::Parser::Parser.new()
        ret = nil
        assert_nothing_raised {
            parser.string = 'file { "/tmp/testing": mode => [755, 640] }'
        }

        assert_nothing_raised {
            ret = parser.parse
        }
    end
end