Luke Kanies wrote:
> On Sep 15, 2008, at 3:29 AM, Brice Figureau wrote:
> 
>> Brice Figureau wrote:
>>> Hi,
>>>
>>> Here is an attempt to provide an append variable operator (see below
>>> for an example). My minimal testing show that it seems to work fine
>>> in simple manifests.
>>>
>>> My aim is to gather comments/reactions from the community regarding
>>> this feature which was previously asked (and that I wanted myself).
>>> Let me know if that's something that _shouldn't_ be done: I know
>>> puppet vars are write-only by design, so changing their values might
>>> open a pandora box I'm not aware of.
>> I meant write-once of course, and not write-only.
>> Note that it is possible to allow the append operator only in a new
>> scope and raise and error otherwise.
>> Ie allow sth like:
>>
>> $var = 'puppet'
>> class klass {
>>  $var += ' is great'
>> }
>>
>> but not:
>> $var = 'puppet'
>> $var += ' is great'
>>
>> It is just a matter of checking that the scope doesn't yet contain the
>> variable.
> 
> 
> I'm not opposed to this, and can see why people are interested in this.
> 
> Just to be clear, this works by basically making a new variable in the  
> current scope that is a concatenation of the specified variable and  
> the new text/array, right?

Not a new variable, it adds in the current scope a variable with the 
same name as the upper scope variable but whose value is concatenated 
with the current rvalue.

The implementation in the patch above allows to append _in the same 
scope_, but I don't think this is right, hence my aforementioned comment 
that I can easily explicitely allow append operator only on new 
descendant context.

> If so, then that seems perfectly reasonable to me, since it's very  
> similar to just using something like:
> 
> $othervar = "$var new text"
> 
> It only affects lower scopes, rather than modifying the original  
> value, so it should work great.

Yes.

> As to tests, there should be sufficient lexer tests, but I agree that  
> we don't have parser tests to speak of; all I've got are integration  
> tests in the form of snippets, like you already have done.  It might  
> be a good time to create that parser unit test file and add tests for  
> this code. :)

My problem is that I don't even know how to start a parser unit rspec :-(

The only thing I can think of is: parse some puppet snippets (or should 
I feed lexer results?), then mock the AST::XYZ object to check that they 
are called fine. Is that the right thing to do?

Right now, I have a rspec append test, that is more an integration test, 
as it feeds puppet snippets to a parser, then compile the AST tree, then 
finally checks that the scope contains the right value, or that right 
scope function setvar is called. Is that something you might include?

> I think the major changes, though, are in the scope class, and it's  
> also only tested in test/ rather than spec/.

OK, so I can also start a rspec scope that at least check the setvar method.

On a different side, there are demand for more complex if test (ie 
including or, and, ==, !=, etc ala collection expressions). I'm 
volunteer to implement this (and even already started). Is this 
something that you can include, or should I use my spare time for 
something else?

Thanks,
-- 
Brice Figureau
Days of Wonder
http://www.daysofwonder.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Puppet Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/puppet-dev?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to