summaryrefslogtreecommitdiff
path: root/spec/unit/parser/ast/leaf_spec.rb
AgeCommit message (Collapse)AuthorFilesLines
2013-12-16(PUP-864) Add deprecation warning for mutation of array/hashHenrik Lindberg1-0/+2
This adds a deprecation warning to operations that mutates array and hash - i.e. $a = [1,2,4] $a[3] = 5, and equivalent for hash. The warning message has a URL that leads to PUP-864. Existing tests that test that mutation is possible now also checks that a warning is issued.
2013-08-05(#22079) Fix HashArrayAccess produces :undef when value is falseHenrik Lindberg1-0/+8
It should naturally have produced false. The test for "having value" was wrong and equated nil with false.
2013-06-07(#21164) Add tests for useful hash access errorsAndy Brody1-0/+31
Make sure we get ParseErrors that contain "not a hash or array" so it's clear what has happened.
2013-04-23spelling/grammatical fixesRichard Soderberg1-6/+6
2012-09-26(Maint) Remove rspec from shebang lineJeff McCune1-1/+1
Without this patch Ruby 1.9 is still complaining loudly about trying to parse the spec files. The previous attempt to clean up this problem in edc3ddf works for Ruby 1.8 but not 1.9. I'd prefer to remove the shebang lines entirely, but doing so will cause encoding errors in Ruby 1.9. This patch strives for a happy middle ground of convincing Ruby it is actually working with Ruby while not confusing it to think it should exec() to rspec. This patch is the result of the following command run against the source tree: find spec -type f -print0 | \ xargs -0 perl -pl -i -e 's,^\#\!\s?/(.*)rspec,\#! /usr/bin/env ruby,'
2012-07-15ast: code cleanup for HostName nodes.Daniel Pittman1-2/+2
This eliminates a to_s that duplicates the parent class. It also avoids depending on matching a regular expression object against a regular expression object - something that apparently works, but I can only imagine does so by pure accident. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-07-15ast: correctly quote strings in {Flat,}String nodes.Daniel Pittman1-4/+13
A string that contained an embedded double-quote wouldn't be correctly escaped when the AST rendered the node to a flat string - it quoted around the outside, but didn't escape the content. This fixes that, and adds testing that embedded double-quotes are correctly handled on output. Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-07-15Drop the hash prefix when passing compiler to scope.Daniel Pittman1-9/+9
Now that the compiler is always required by the scope we can save a few keystrokes by making the non-optional argument a regular value, not a name prefixed option. (...even if I love Objective-C as much as the next developer, having the same text in every call just to name the argument doesn't make much sense in such an internal context.) Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-07-15A scope always has a compiler.Daniel Pittman1-10/+31
The scope object contained some internal code to substitute an external environment when the compiler was not supplied. This was used only in testing, not in any production capacity. In light of that, we can eliminate the dynamic decision making inside the scope and simply demand that a compiler instance (or a fake equivalent) is always supplied. This reduces the complexity of the code and makes clearer the object relationships involved. (The small cost is a lot of testing that depended on this had to change to use a real compiler. Most of the change derives from that.) Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2012-05-01Merge branch '2.7.x'Patrick Carlisle1-2/+2
* 2.7.x: Revert "Fix incorrect argument handling for expire in NodeExpirer" Fix #14123 for Windows Fix incorrect argument handling for expire in NodeExpirer Fix filebucket specs on Windows (#8778) Make '' == undef commutative in the DSL (#14173) Enforce that filebucket paths must be absolute (#14127) Add integration tests for ssh_authorized_key maint: refactor integration specs for ssh_authorized_key (#14127) ssh_authorized_keys grammer fails on blank lines. (#14123) Puppet shouldn't explode if PATH contains ~nonexistent_user Conflicts: lib/puppet/provider/ssh_authorized_key/parsed.rb lib/puppet/util.rb
2012-04-30(#8778) Make '' == undef commutative in the DSLJeff McCune1-2/+2
Without this patch applied the Puppet DSL treats undef == '' as true but '' == undef as false. This is undesirable because the equality operator should be commutative. This patch fixes the problem by adding an explicit check for '' == undef in the AST. Without this patch applied, Puppet already has an explicit check for undef == '' but not for '' == undef. The spec tests are also updated by this patch to reflect the change.
2012-03-27Merge branch '2.7.x'cprice1-0/+15
Conflicts: lib/puppet/daemon.rb spec/unit/daemon_spec.rb spec/unit/parser/ast/leaf_spec.rb spec/unit/provider/package/dpkg_spec.rb spec/unit/util/settings_spec.rb
2012-02-07(#12479) Don't make undef regexp match as the string undef.Daniel Pittman1-1/+16
As part of commit 53869e99 we did work to make the behaviour of variables that were explicitly `undef` at least somewhat saner. One unintended side-effect of this was that we started matching `undef` as the literal string `undef`, not as the empty string, and not "not matching". Either of the later would have been sane things to do; this fixes that by picking "match undef as empty string". That is for consistency: we already match the *literal* empty string as equal to undef, so it makes sense to treat it the same way for a regular expression. (Debate on that point is welcome elsewhere, but we should change literal and regexp matching the same, consistent way if we change it anywhere.) Signed-off-by: Daniel Pittman <daniel@puppetlabs.com>
2011-12-16Merge branch '2.7.x'Nick Lewis1-0/+16
2011-12-12(#6412) Return :undef when accessing non-existing hash/array elementsBrice Figureau1-0/+16
The truethiness test done in P::P::Scope.true? doesn't handle nil values, because it is not valid as result of a puppet expression. Unfortunately ruby hash['invalid'] or array[inexistant_index] returns nil which then was considered as true in an if expression. This patch makes sure :undef is returned in those cases. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
2011-07-15Adding []/[]= support to ScopeLuke Kanies1-28/+25
The interface to scope is much clearer this way anyway, but this is needed to integrate Puppet with Hiera[1]. It just provides hash-like behavior to Scope, which Hiera and others can now easily rely on. I also went through all of the code that used Scope#lookupvar and Scope#setvar and changed it if possible, and at the same time cleaned up a lot of tests that were unnecessarily stubbing (and thus making it difficult to tell if I had actually broken anything). 1 - https://github.com/ripienaar/hiera Signed-off-by: Luke Kanies <luke@puppetlabs.com> Reviewed-by: Nick Lewis <nick@puppetlabs.com>
2011-04-13maint: clean up the spec test headers in bulk.Daniel Pittman1-2/+1
We now use a shebang of: #!/usr/bin/env rspec This enables the direct execution of spec tests again, which was lost earlier during the transition to more directly using the rspec2 runtime environment.
2011-04-12Fix for #5027 -- generate a deprication warning for dynamic lookupMarkus Roberts1-6/+6
This fix implements the same logic as Nick & Paul's patch in a different way. There aren't any tests yet and I'm still working out if I agree with the handling of some edge cases, so this should be considered premliminary.
2011-04-12Towards 5027 -- add options hash to lookupvar as with setvarMarkus Roberts1-10/+15
This patch adds an options hash to lookupvar analogous to the one taken by setvar and uses it to pass in source location for error reporting. It also fixes the mechanism used by setvar (file was not being passed correctly), adds line and file information to errors in templates, and extends/corrects tests. As presently written it does not gather userful line numbers from inline templates and there are no tests for the template line number generation.
2011-04-12Refactor en route to #5027 -- remove usestring parameter from lookupvarMarkus Roberts1-2/+2
The usestring parameter to lookupvar was objectionable for several reasons; first, it performed a function orthogonal to the main purpose of the method, second its default was the least common value, and third it was causing other code to work for reasons that were not obvious (extlookup). This refactor breaks the value-transforming function out into a seperate method which allows the user to specify the value to be used in lieu of :undef and removes the parameter. The function, Scope#undef_as(default,exp) is written so that it can be used in user code (templates, functions, etc.) if needed. This refactor will introduce a user-visible behaviour change in the case where users were counting on lookupvar to return "" for undefined variables. The best solution is to have them use undef_as, replacing: lookupvar('myvar') with undef_as('',lookupvar('myvar')) (with the option to specify another default value if desired). If this is too objectionable, we could rename the existing lookupvar as raw_lookupvar and define def lookupvar(v) undef_as('',raw_lookupvar(v)) end to restore the present behaviour.
2011-04-08maint: just require 'spec_helper', thanks rspec2Daniel Pittman1-1/+1
rspec2 automatically sets a bunch of load-path stuff we were by hand, so we can just stop. As a side-effect we can now avoid a whole pile of stupid things to try and include the spec_helper.rb file... ...and then we can stop protecting spec_helper from evaluating twice, since we now require it with a consistent name. Yay. Reviewed-By: Pieter van de Bruggen <pieter@puppetlabs.com>
2010-12-06maint: Use expand_path when requiring spec_helper or puppettestMatt Robinson1-1/+1
Doing a require to a relative path can cause files to be required more than once when they're required from different relative paths. If you expand the path fully, this won't happen. Ruby 1.9 also requires that you use expand_path when doing these requires. Paired-with: Jesse Wolfe
2010-11-16Fixed #5296 - test warnings messagesJames Turnbull1-1/+1
2010-11-10Fix #5127 - error when accessing array elementsBrice Figureau1-0/+42
Accesing an array with an integer index (ie $array[1]) is producing a ruby error: can't convert String into Integer This is because the array index is not properly converted to an number before the array element lookup is performed. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
2010-08-03[#4370] Fixes extlookup precedence getting overwritten between runsMatt Robinson1-0/+4
We found the gsub! in extlookup was actually modifying the value for extlookup_precedence, so the next node to call it just got the interpolated value from the first run. We did two things in the code to prevent this: 1. We returned a dup of the ast string object so that modifying it wouldn’t change puppet’s state. We didn’t do this for all possible return values because we depend on using the original ast array object to do array concatenation 2. We fixed extlookup to not do a destructive gsub Reviewed by: Jesse Wolfe
2010-07-19[#4269] Undef variables interpolate to empty stringNick Lewis1-0/+31
This fixes double-quoted strings to interpolate undef variables as an empty string. This is the behavior present in 0.25.x.
2010-07-19[#4287] Fix the undefined evaluate_match error when comparing functionsMatt Robinson1-57/+0
Ticket #4238 introduced a problem that a function couldn't compare to another value until after it was evaluated, and AST::Function didn't have the evaluate_match method. This change moves that method from AST::Leaf to AST. The special casing necessary for doing comparisons between AST objects feels messy and could probably be encapsulated better. I've created ticket #4291 to remind us to refactor this at some point. Paired with: Nick Lewis Signed-off-by: Matt Robinson <matt@puppetlabs.com>
2010-07-18Fix #4238 - if should match undef as ''Brice Figureau1-0/+21
The comparisons operator (and more particularly == and !=) were not treating the undef value as '', like case and selector did since #2818. This patch makes sure comparison operator uses AST leaf matching. Unfortunately, doing this introduces a behavior change compared to the previous versions: Numbers embedded in strings will now be matched as numbers in case and selector statements instead of string matching. Signed-off-by: Brice Figureau <brice-puppet@daysofwonder.com>
2010-07-09Code smell: Two space indentationMarkus Roberts1-261/+261
Replaced 106806 occurances of ^( +)(.*$) with The ruby community almost universally (i.e. everyone but Luke, Markus, and the other eleven people who learned ruby in the 1900s) uses two-space indentation. 3 Examples: The code: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") becomes: end # Tell getopt which arguments are valid def test_get_getopt_args element = Setting.new :name => "foo", :desc => "anything", :settings => Puppet::Util::Settings.new assert_equal([["--foo", GetoptLong::REQUIRED_ARGUMENT]], element.getopt_args, "Did not produce appropriate getopt args") The code: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object becomes: assert_equal(str, val) assert_instance_of(Float, result) end # Now test it with a passed object The code: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end becomes: end assert_nothing_raised do klass[:Yay] = "boo" klass["Cool"] = :yayness end
2010-06-28[#3994-part 3] rename spec tests from *_spec_spec to *_spec.rbMarkus Roberts1-0/+367
Part 2 re-did the change on the spec files, which it shouldn't have.
2010-06-28[#3994-part 2] rename integration tests to *_spec.rbMarkus Roberts1-367/+0
Some spec files like active_record.rb had names that would confuse the load path and get loaded instead of the intended implentation when the spec was run from the same directory as the file. Author: Matt Robinson <matt@puppetlabs.com> Date: Fri Jun 11 15:29:33 2010 -0700
2010-06-23[#3994] rename the specs to have _spec.rb at the endMarkus Roberts1-0/+367
Some spec files like active_record.rb had names that would confuse the load path and get loaded instead of the intended implentation when the spec was run from the same directory as the file. Author: Matt Robinson <matt@puppetlabs.com> Date: Fri Jun 11 15:29:33 2010 -0700