summaryrefslogtreecommitdiff
path: root/spec/unit/parser
AgeCommit message (Collapse)AuthorFilesLines
2013-07-13(#21409) Ensure that create_resources acts the same as a resource declAndrew Parker1-18/+6
The previous implementation of create_resources duplicated most of the logic of Puppet::Parser::AST::Resource, but had variations which meant that it didn't actually behave the same. This lead to the possibility that what should have been equivalent statements in the language did not always result in the same catalog. This re-implements create_resources to construct the AST that is needed to create the requested resources and evaluate the resulting structure. This should only be able to differ from actual resource declarations in the language if the constructed AST is wrong.
2013-07-13(#21508) Make local variables available to templates as instance varsHenrik Lindberg1-0/+43
The problem was that templates reference scope variables using instance variables e.g. @myvar, these were configured from the hash returned by Scope#to_hash. That method did not consider ephemeral scopes. The solution was to add collection of the emphmeral scopes' (that represent local scopes) variables and include them in the hash. As before, the match scopes (i.e. for $0 - $n) are not included in the result.
2013-07-12Merge pull request #1753 from pcarlisle/rspec-deprecationsAndrew Parker4-22/+22
(maint) Fix rspec warnings
2013-07-11Merge branch 'stable'Andrew Parker1-184/+166
* stable: (maint) Refactor type_loader, mostly specs (#21653) Skip modules with no manifest directory when loading resource types
2013-07-11(maint) Fix rspec warningsPatrick Carlisle4-22/+22
Running specs with rspec 2.13 caused a lot of warnings. Many of them actually exposed preexisting bugs, the most common being a syntax error when expecting an Exception. These are worth fixing even if we don't bump to rspec 2.13.
2013-07-10(maint) Refactor type_loader, mostly specsPatrick Carlisle1-189/+165
This cleans up the specs for type_loader a lot and slightly refactors a few methods in type_loader.
2013-07-09(#21653) Skip modules with no manifest directory when loading resource typesPatrick Carlisle1-0/+6
The resource_type face tries to parse all manifests from modules, but was failing if a module didn't have a manifest directory. This is not an error condition so we just skip those modules.
2013-06-24Merge branch 'stable'Patrick Carlisle1-42/+22
* stable: (#21043) Use ruby.exe instead of rubyw.exe (#21264) Update rgen dependency to 0.6.5 (Maint) Cleanup specs (#21320) Use sleep in the daemon loop instead of select
2013-06-24(Maint) Cleanup specsAndrew Parker1-42/+22
This cleans up the specs to make them a little more expressive of the behavior of the fqdn_rand function's real functionality. One surprising result that came out of this was that the tests tried to assert that the fqdn_rand function was callable without any arguments. However the test for this passed simply because it asserted that a particular error was *not* raised, when in fact a different exception that expressed what it was trying to catch (ArgumentError vs. Puppet::ParserError). The docs indicate that calling with no arguments is not actually supported and so that test has been removed.
2013-06-21Merge branch 'stable'Andrew Parker1-0/+67
* stable: (#21376) Sequence BlockExpressions without nesting
2013-06-20(#21376) Sequence BlockExpressions without nestingPatrick Carlisle1-0/+67
When merging Puppet::Resource::Type instances the code attribute was merged in a way that caused a deep tree of BlockExpressions. This could cause stack overflows when evaluating this tree, since evaluation is recursive. This changes the merge method so that they are sequenced as a flat array.
2013-06-12Merge pull request #1694 from ab/fix/master/improve_string_parse_errorsAdrien Thebo2-2/+33
Improve error messages for non-string variable names
2013-06-07(#21164) Check for correct exception messageAndy Brody1-2/+2
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-06-07(#21164) Raise ParseError for non-string var namesAndy Brody1-2/+2
Raise ParseError rather than DevError for non-string variable names. This is more consistent with the other validation, and also means that we get a file and line number when hitting this error rather than just the rather opaque message. Also inspect the variable name for good measure.
2013-06-07Merge pull request #1665 from lollipopman/hiera_include_arityAdrien Thebo1-0/+12
commit 9ed6fcea48591cda58db1379b58cd39dfbdca684 which added arity checks
2013-05-31Change hiera_include to properly call include with an array of argumentsJesse Hathaway1-0/+12
Before this change hiera includes which looked up an empty array resulted in this error: ArgumentError: include(): Wrong number of arguments given (0 for minimum 1) Now hiera includes properly allow for a lookup that results in an empty array This regression was caused by the arity checks committed in 9ed6fcea48591cda58db1379b58cd39dfbdca684
2013-05-30Merge branch 'stable'Adrien Thebo1-1/+6
2013-05-28(#20302) Windows ruby 1.8 workarounds are not necessary in 1.9Josh Cooper1-1/+6
Previously, the sprintf spec failed, because ruby outputted the exponent with a leading zero, despite a precision of 2. The zaml spec failed, because ruby didn't recognize the Europe/London timezone. Ruby 1.9 fixes these issues, so the workaround in sprintf_spec is no longer necessary, and the zaml_spec issue is no longer pending.
2013-04-23spelling/grammatical fixesRichard Soderberg8-17/+17
2013-04-15(maint) Make select and reject produce result of same class as receiver.Henrik Lindberg2-0/+50
The return type of select and reject where unspecified and tests did not check for type (not caring because all tests applied more iteration to the result and that evened out the differences). Now both select and reject produce a result of the same class as the receiver. This is now noted in the documentation. Tests have been added.
2013-04-11(Maint) Ensure that activerecord tests are isolatedAndrew Parker1-4/+4
The activerecord based tests would setup activerecord and rails in a manner that included stubbing. This made some things behave as you might want, but caused some manner of getting them to behave the wrong way. By removing the stubbing, the test cases all work from a clean database. Another issue occured when one of the tests assumed that no other code that used its indirection had been run prior to it. The test itself was very questionable and ended up breaking when the tests were run in a particular order. The test in question tried to assert that the code would setup activerecord when it was initialized. Since all of the other tests relied on this, and that particular behavior did not appear to be important to the external contract of the class, the test has been removed.
2013-04-11(Maint) Ensure that 'hiera-puppet' is loaded correctlyAndrew Parker2-4/+0
The test for the hiera_* functions showed an interesting error. If the hiera_hash or hiera_array tests were run in isolation they would complain that Hiera was not defined and then fail. If the hiera_include tests were run beforehand, then the tests for hash and array worked as expected. The issues seems to have been that the require that brought in hiera was being delayed until too late. By making sure that hiera-puppet is loaded as soon as the function is defined, rather than called, we are certain that hiera will be around when we need it.
2013-04-09(Maint) Cleanup trailing whitespaceJosh Cooper2-6/+6
Removed trailing whitespace only.
2013-04-10(maint) Fix iteration functions not behaving to spec for hashHenrik Lindberg6-112/+143
When calling iteration functions collect, reject, and select with a hash there were cases where only hash key was passed to the given lambda. This commit corrects this by ensuring that it is always a key/value tuple that is passed. This commit also includes improved tests for these cases as well as argument checking.
2013-04-09(maint) remove lines with only spacesHenrik Lindberg1-9/+9
2013-04-05Fix test for future parser in arithmetic operatorsPatrick Carlisle1-5/+14
When checking whether concatenation is supported the check for the Puppet[:parser] setting was wrong (checking for a symbol instead of array). This caused concatenation to not be supported even with the future parser enabled.
2013-04-05(#11331) Clean up trailing spaces and bad formatting.Henrik Lindberg3-58/+58
This cleans up source formatting (spaces/tabs), dead todo, blank lines, ending without a linebreak, and corrects indentation.
2013-04-05(#11331) Revert the classic grammar and lexer to master.Henrik Lindberg3-93/+2
This makes two small changes to the classic grammar since BlockExpression should be used instead of ASTArray for sequences of expressions to make AST comply with both grammars. Reverts test of parser and lexer to master version.
2013-04-05(#11331) Change array/hash concat/merge to only be available for --parser ↵Henrik Lindberg1-0/+8
future. This adds an assertion that + is only allowed when --parser future is in effect. Tests uppdated.
2013-04-05(#11331) Change name of EParserAdapter's file to e_parser_adapter.rbHenrik Lindberg2-2/+2
2013-04-05(#11331) Remove a 'require debugger' since this fails on Ruby 1.8.7Henrik Lindberg1-1/+0
(and should not be there in the first place).
2013-04-05(#11331) Restore initialization of AST constant in test.Henrik Lindberg1-1/+1
The earlier required fix of using AST ||= is no longer required to get rid of redefinition errors. Instead the ||= is not possible to use in 1.8.7 since the constant is not defined).
2013-04-05(#11331) Forbid assignment to numeric variables (unless option is :ephemeral)Henrik Lindberg1-13/+13
This is an internal protection against assignment to numeric variables - as they royally screw things up wrt being overwritten by ephemeral scopes (or causing imutability errors).
2013-04-05(#11331) Fix issues with recording origin (result may be nil).Henrik Lindberg1-1/+1
Also fixes tests of issues. Relabels Object and String as Ruby Object, and Ruby String.
2013-04-05(#11331) Make tests run for both current and future parser.Henrik Lindberg8-241/+437
Tests were hardwired to run for only future/eparser. Now all tests where parser is involved runs for both current/classic and future/eparser (except when testing methods; where parsing is only done in order to construct a call; it is the function that is tested, not the parsing). The collect method testing includes testing the various ways a call can be made to it, but this is the only place; this because it is more work to unwire all the others when the final style for lambdas gets picked.
2013-04-05(#11331) Add eparser unit test.Henrik Lindberg1-0/+408
Eparser was unit tested by the parser unit test, but did not work as intended. This adds a separat test This is basically a copy of the parser unit test, but with removal of tests that only check the parser implementation (internal calls to "self" from the old parser). There are also minor adjustments as the egrammar parser has better information (e.g. the result contains "file" instead of "File" as type is already detected and type internally has already done a downcase).
2013-04-05(#11331) Refactor ParserFactory and PopsParserAdapterHenrik Lindberg1-4/+4
This separates the PopsParserAdapter from the ParserFactory and renames it to EParserAdapter.
2013-04-05(#18764) Modify design of enumerables. Fix doc of all.Henrik Lindberg3-104/+43
Rework each_slice/slice and fix doc of all enumerable f's The idea that each/foreach/each_slice should produce the last produced value from the lambda was bad. This makes it difficult to chain these calls. These functions now produce the receiver. Modify the return value of each_slice to the receiver. Rename each_slice to slice and make block optional to produce array. It was a bad idea to implement each_slice as the only way to get slices from an array. The renamed function works as before when given an optional lambda. When called without a lambda it produces the collected result of all slices. Thus making it possible to iterate over it. The alternative was to equip all other iteration methods with slicing functionality, or to implement a separate slicing function. Corrects documentation in all enumerable functions.
2013-04-05(#18764) Add each_slice iteration function.Henrik Lindberg1-0/+70
2013-04-05(#18764) Modifies picking 'each' to be consistent for Array and Hash.Henrik Lindberg2-8/+144
One argument, pick each entry (Array = value, Hash = array with key,value). Two arguments, pick each entry (Array = index, value; Hash = key, value). Additional arguments for array (picking pairs etc.) support removed.
2013-04-05(#18764) Add concat, append operations (+, <<) for array, and merge (+) hash.Henrik Lindberg1-0/+79
This is good because it is otherwise very difficult to perform typical data transformations (without these operations you can filter, map, and reduce to one - or jump through hoops trying to write a reduction that appends. Although not strictly part of #18764, this is the same category.
2013-04-05(#11331) Add todo note for change of transformer's ast method.Henrik Lindberg1-2/+5
Describes the intent for adding source positions to produces AST objects. (maint) Add read accessor for importer. This to help debugging. Adjust tests to not include spec helper at rspec config time. Fix type_loader_spec test mocking the wrong object. (The mocking in type_loader_spec still does not clean up ok. If executed before spec/unit/pops/impl/transform/transform_conditionals.rb, the second fail due to getting wrong instance of AstTransformer !!??) Update yardoc for Utils.find_adapter Fix utils method that was not a module method (find_adapter). Cleanup tests (comments, blank lines, debugger). (refactor) Make AstTransformer use Utils class to find adapter. Finding an adapter should be in one place only.
2013-04-05(#11331) Change specs to use ParserFactory instead of (classic) Parser.Henrik Lindberg6-18/+24
2013-04-05(#11331) Remove warnings about re-initialized constants when running tests.Henrik Lindberg1-1/+1
2013-04-05(#11331) Make lambdas optionally available on all function calls.Henrik Lindberg1-0/+12
This makes it possible to invoke foreach as: foreach($a) {|$x| ... } The only caveat is that a parentheses-less call must have at least one argument. This is not allowed: foo {|$x| } If someone implements a function that takes only a lambda that call would need to be written as: foo() {|$x| } This since it is not allowed to pass a lambda as an argument (since this would require implementing real closures).
2013-04-05(#11331) Make implementation of lambda call work under Ruby 1.8.7Henrik Lindberg1-0/+1
Under some conditions, array zip in ruby 1.8.7 produces a single value instead of an array. The result was that the integer value of the first char was produced as the result instead of the expected string. This fix checks if the name value is just a string name, or an array with [name, value].
2013-04-05(#11331) Add support to end a lambda with = expression.Henrik Lindberg1-1/+40
This relaxes the constraint that a = expr must be the only statement in a lambda (or be a sequence of statements). Is is now instead possible to place this statement last after a sequence of statements. This commit also fixes an issue where the last value of the lambda and foreach function did not produce a value. There was an inspect in a rescue that was only there for debugging. Now removed.
2013-04-05(#11331) Add support for foreach.Henrik Lindberg1-41/+1
This adds support for "foreach" for arrays and hashes. The implementation adds support for MethodCall and Lambda expressions to the lexer and parser. A method call is simply a variant of function call that supports an optional parameterized block (i.e. a lambda). The foreach method is simply implemented as a function that accepts a "receiver" and a lambda. The foreach function operates on arrays and hashes. The implementation does not alter any existing syntax and does not introduce any additional keywords or constraints on any lexer literals. Since racc only has one token lookahead it was necessary to add such lookahead in the lexer for LBRACE, which now produces a LAMBDA token if LBRACE is followed by PIPE. DOT token was reintroduced, and a PIPE token added. To allow a lambda to return the result of a single expression, the syntax: {|...| = expr } may be used. Unfortunately, a major rewrite of the grammar is required to allow this without a syntactic marker. Also unfortunate is the fact that all functions invokable as statements does not produce an rvalue and an rvalue function may not be used as a statement. (To change that would also be a major rewrite). Hence, a syntactic marker (in a lambda only), that allows a single expression to be turned into a "rvalue" statment seems to be the best approach). If the grammar is improved in the future, the = could be made optional.
2013-04-05(#18764) Add methods for enumerable functions.Henrik Lindberg4-0/+180
This adds support for the functions/methods collect, reject, select, and reduce. This implementation depends on support for lambdas being added in puppet as described in issue #11331). Which probably will be released in puppet 3.2.