summaryrefslogtreecommitdiffstats
path: root/spec/integration/parser
diff options
context:
space:
mode:
authorLuke Kanies <luke@puppetlabs.com>2010-05-10 23:50:05 -0700
committertest branch <puppet-dev@googlegroups.com>2010-02-17 06:50:53 -0800
commit2c153b12921d67354ea0968ad81590a124ac8b75 (patch)
treee1667858786446a5a56306823663960c2ec4905b /spec/integration/parser
parent052f98fdac20af4593372ecedaa13af97664a482 (diff)
downloadpuppet-2c153b12921d67354ea0968ad81590a124ac8b75.tar.gz
puppet-2c153b12921d67354ea0968ad81590a124ac8b75.tar.xz
puppet-2c153b12921d67354ea0968ad81590a124ac8b75.zip
Fixing #448 - relationships have their own syntax
You can now specify relationships directly in the language: File[/foo] -> Service[bar] Specifies a normal dependency while: File[/foo] ~> Service[bar] Specifies a subscription. You can also do relationship chaining, specifying multiple relationships on a single line: File[/foo] -> Package[baz] -> Service[bar] Note that while it's confusing, you don't have to have all of the arrows be the same direction: File[/foo] -> Service[bar] <~ Package[baz] This can provide some succinctness at the cost of readability. You can also specify full resources, rather than just resource refs: file { "/foo": ensure => present } -> package { bar: ensure => installed } But wait! There's more! You can also specify a subscription on either side of the relationship marker: yumrepo { foo: .... } package { bar: provider => yum, ... } Yumrepo <| |> -> Package <| provider == yum |> This, finally, provides easy many to many relationships in Puppet, but it also opens the door to massive dependency cycles. This last feature is a very powerful stick, and you can considerably hurt yourself with it. Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'spec/integration/parser')
-rwxr-xr-xspec/integration/parser/parser.rb92
1 files changed, 92 insertions, 0 deletions
diff --git a/spec/integration/parser/parser.rb b/spec/integration/parser/parser.rb
index 5a30f066e..ee476c02f 100755
--- a/spec/integration/parser/parser.rb
+++ b/spec/integration/parser/parser.rb
@@ -3,6 +3,76 @@
require File.dirname(__FILE__) + '/../../spec_helper'
describe Puppet::Parser::Parser do
+ module ParseMatcher
+ class ParseAs
+ def initialize(klass)
+ @parser = Puppet::Parser::Parser.new "development"
+ @class = klass
+ end
+
+ def result_instance
+ @result.hostclass("").code[0]
+ end
+
+ def matches?(string)
+ @string = string
+ @result = @parser.parse(string)
+ return result_instance.instance_of?(@class)
+ end
+
+ def description
+ "parse as a #{@class}"
+ end
+
+ def failure_message
+ " expected #{@string} to parse as #{@class} but was #{result_instance.class}"
+ end
+
+ def negative_failure_message
+ " expected #{@string} not to parse as #{@class}"
+ end
+ end
+
+ def parse_as(klass)
+ ParseAs.new(klass)
+ end
+
+ class ParseWith
+ def initialize(block)
+ @parser = Puppet::Parser::Parser.new "development"
+ @block = block
+ end
+
+ def result_instance
+ @result.hostclass("").code[0]
+ end
+
+ def matches?(string)
+ @string = string
+ @result = @parser.parse(string)
+ return @block.call(result_instance)
+ end
+
+ def description
+ "parse with the block evaluating to true"
+ end
+
+ def failure_message
+ " expected #{@string} to parse with a true result in the block"
+ end
+
+ def negative_failure_message
+ " expected #{@string} not to parse with a true result in the block"
+ end
+ end
+
+ def parse_with(&block)
+ ParseWith.new(block)
+ end
+ end
+
+ include ParseMatcher
+
before :each do
@resource_type_collection = Puppet::Resource::TypeCollection.new("env")
@parser = Puppet::Parser::Parser.new "development"
@@ -18,4 +88,26 @@ describe Puppet::Parser::Parser do
ast.hostclass("test").doc.should == "comment\n"
end
end
+
+ describe "when parsing" do
+ it "should be able to parse normal left to right relationships" do
+ "Notify[foo] -> Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
+ end
+
+ it "should be able to parse right to left relationships" do
+ "Notify[foo] <- Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
+ end
+
+ it "should be able to parse normal left to right subscriptions" do
+ "Notify[foo] ~> Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
+ end
+
+ it "should be able to parse right to left subscriptions" do
+ "Notify[foo] <~ Notify[bar]".should parse_as(Puppet::Parser::AST::Relationship)
+ end
+
+ it "should correctly set the arrow type of a relationship" do
+ "Notify[foo] <~ Notify[bar]".should parse_with { |rel| rel.arrow == "<~" }
+ end
+ end
end