diff options
| author | Paul Berry <paul@puppetlabs.com> | 2010-08-13 15:43:34 -0700 |
|---|---|---|
| committer | Paul Berry <paul@puppetlabs.com> | 2010-08-13 15:54:26 -0700 |
| commit | 4da88fb4cd57871f16649d50572240ac3f7420f0 (patch) | |
| tree | 1b0df4e444bc27f925aac293cf721fa7acee06f7 /spec/integration/parser | |
| parent | caca187dffbd6e628d7eda599c7f2939dd05fafc (diff) | |
[#4496]+[#4521]+[#4522] Add structures to the AST to represent type definitions (classes, definitions, and nodes).
Previously, type definitions were not represented directly in the AST.
Instead, the parser would instantiate types and insert them into
known_resource_types as soon as they were parsed. This made it
difficult to distinguish which types had come from the file that was
just parsed and which types had been loaded previously, which led to
bug 4496.
A side-effect of this change is that the user is no longer allowed to
define types inside of conditional constructs (such as if/else). This
was allowed before but had unexpected semantics (bugs 4521 and 4522).
It is still possible, however, to place an "include" statement inside
a conditional construct, and have that "include" statement trigger the
autoloading of a file that instantiates types.
Diffstat (limited to 'spec/integration/parser')
| -rwxr-xr-x | spec/integration/parser/collector_spec.rb | 2 | ||||
| -rwxr-xr-x | spec/integration/parser/compiler_spec.rb | 11 | ||||
| -rwxr-xr-x | spec/integration/parser/parser_spec.rb | 8 |
3 files changed, 17 insertions, 4 deletions
diff --git a/spec/integration/parser/collector_spec.rb b/spec/integration/parser/collector_spec.rb index 73273c909..b1cfc51c7 100755 --- a/spec/integration/parser/collector_spec.rb +++ b/spec/integration/parser/collector_spec.rb @@ -17,7 +17,7 @@ describe Puppet::Parser::Collector do def query(text) code = "File <| #{text} |>" parser = Puppet::Parser::Parser.new(@scope.compiler) - parser.parse(code).hostclass("").code[0].query + return parser.parse(code).code[0].query end {true => [%{title == "/tmp/testing"}, %{(title == "/tmp/testing")}, %{group == bin}, diff --git a/spec/integration/parser/compiler_spec.rb b/spec/integration/parser/compiler_spec.rb index 67e8e5e62..266347c60 100755 --- a/spec/integration/parser/compiler_spec.rb +++ b/spec/integration/parser/compiler_spec.rb @@ -80,4 +80,15 @@ describe Puppet::Parser::Compiler do Puppet::Resource::TypeCollection.any_instance.stubs(:stale?).returns(true).then.returns(false) # pretend change Puppet::Parser::Compiler.compile(node).version.should == 2 end + + it "should not allow classes inside conditional constructs" do + Puppet[:code] = <<-PP + if true { + class foo { + } + } + PP + + lambda { Puppet::Parser::Compiler.compile(Puppet::Node.new("mynode")) }.should raise_error(Puppet::Error) + end end diff --git a/spec/integration/parser/parser_spec.rb b/spec/integration/parser/parser_spec.rb index 7b85bcacb..0d9aa51e1 100755 --- a/spec/integration/parser/parser_spec.rb +++ b/spec/integration/parser/parser_spec.rb @@ -11,7 +11,7 @@ describe Puppet::Parser::Parser do end def result_instance - @result.hostclass("").code[0] + @result.code[0] end def matches?(string) @@ -44,7 +44,7 @@ describe Puppet::Parser::Parser do end def result_instance - @result.hostclass("").code[0] + @result.code[0] end def matches?(string) @@ -85,7 +85,9 @@ describe Puppet::Parser::Parser do class test {} """) - ast.hostclass("test").doc.should == "comment\n" + ast.code[0].should be_a(Puppet::Parser::AST::Hostclass) + ast.code[0].name.should == 'test' + ast.code[0].instantiate('')[0].doc.should == "comment\n" end end |
