summaryrefslogtreecommitdiff
path: root/spec/unit/functions
AgeCommit message (Collapse)AuthorFilesLines
2014-09-08(PUP-3190) Don't assume puppet is in a lib dirAndrew Parker1-1/+0
The loaders previously assumed that any installation of puppet would be under a directory called lib. This holds true when running puppet from source (during development), or in some package cases, but is not generally true. This simplifying assumption was made so that the loading path for both puppet system extensions (built in functions) and module extensions could be loaded in the same manner: find the root of the extender and loading code from `lib/puppet/...`. This changes to loading to instead only assume that there is a `puppet` directory and not the name of the parent. This, however, forces the loader for modules to become specialized to only be able to find ruby extentions, because they are in the 'lib' directory, which is how the loader must now be configured.
2014-07-17Merge pull request #2874 from adrienthebo/maint/master/update-rspecAndrew Parker1-1/+1
Maint/master/update rspec
2014-07-15(maint) Remove deprecated `.to_not raise_error(args)` callsAdrien Thebo1-1/+1
From RSpec: DEPRECATION: `expect { }.not_to raise_error(SpecificErrorClass, message)` is deprecated. Use `expect { }.not_to raise_error` (with no args) instead. This commit removes all args from `.to_not raise_error` expectations.
2014-07-14(PUP-2883) Allow empty body in epp templatesHenrik Lindberg2-0/+20
This allows an epp body to be empty by making grammar accept an empty list of statements. This avoids getting a cryptic error message about "syntax error at end of file" when using parameters, but having no body that produces output, or when having a completely empty template.
2014-07-07Merge pull request #2821 from hlindberg/PUP-2794_callable_checkAndrew Parker6-110/+12
(PUP-2794) Change Callable to mean "can be called with"
2014-07-02(maint) Move the interative functions shared behavior to common dirHenrik Lindberg5-72/+4
This commit moves the shared behavior for iterative functions to shared_behaviours/iterative_functions.
2014-07-02(PUP-2794) Fix failing test after correction of has types > 0 checkHenrik Lindberg1-1/+1
2014-07-02(PUP-2794) Cleanup dead code and fix spacing in testsHenrik Lindberg2-22/+1
2014-07-02(PUP-2794) Modify the shared spec for iterative functionsHenrik Lindberg2-2/+28
This updates the shared tests for iterative functions to also be capable of handling reduce. This also adds missing tests that were part of one of the individual tests earlier. The test for reduce now also invokes the shared behavior for argument checking.
2014-07-02(PUP-2794) Change function reduce to use dispatchers for block arityHenrik Lindberg1-0/+1
This changes the reduce function to use the dispatchers to check the block arity.
2014-07-02(PUP-2794) Change function filter to use dispatch for block arityHenrik Lindberg1-18/+0
This changes the function filter to use the dispatchers instead of having a special arity check.
2014-07-02(PUP-2794) Change function filter to use dispatch for block arityHenrik Lindberg1-18/+0
This changes the function filter to use the dispatchers instead of having a special arity check.
2014-06-30(PUP-480) Put the nail in :undef's coffinHenrik Lindberg1-1/+1
This changes the evaluation of a LiteralUndef to nil from :undef. As a consequence, there were minor adjustments needed to the Closure's call_by_name support to get the correct semantics for "missing" parameters. Tests are also added to ensure that :undef does not sneak into arrays or hashes in the 4x function API. This commit contains a cheat for epp and inline_epp functions as they need to receive their arguments without transformation. When that is fixed (PUP-2845) the cheat in runtime3_support#call_function() should be removed. :undef is still used in the "puppet/pops" section of the code (mainly for reasons of transforming to 3x, and if :undef symbols leak from 3x.)
2014-06-30(PUP-2794) Change Callable to mean "can be called with"Henrik Lindberg1-4/+4
It is more meaningful to check that a Callable can be called with certain types (exact or more generic) than to check the reverse. This alters the meaning of Callable assignability so that a more generic Callable is accepted. While this seems counterintuitive from the perspective of the type system, it is the constraint that is expected as the constraint being expressed means "Must be callable with arguments of these types", and a more generic callable is just that. The current implementation got that wrong, and will actually accept callables that can in fact not be called. This also alters the assert_type function that declared that it would call a given block with Any, Any, when in fact it will call with Type, Type. Note, that a function that after this delares that it calls Callable[Any] will enforce that the given callable is Any. If the intent is to accept any callable, the type should be given as just Callable.
2014-06-27(PUP-2845) Move the inline_epp function to the new function API.Henrik Lindberg1-0/+87
This moves the function inline_epp to use the new function API. This also improves the argument checking since it is not not possible to leak non variable name compliant variables into the scope.
2014-06-27(PUP-2845) Move the epp function to the 4x function API.Henrik Lindberg1-0/+145
This moves the epp function to the new function API. The type checking is much approved as a consequence as the function is now protected against spilling non variable name compliant variables into the scope.
2014-06-19(PUP-2787) Rename Object Type to AnyHenrik Lindberg1-2/+2
This renames the top most type in the type system to Any from the name Object. This is done because the word Object carries connotations of "Object Oriented Programming" that simply adds confusion about how puppet works. This commit is basically a rename refactoring.
2014-06-14(PUP-2755) Move iterative functions to the new APIHenrik Lindberg6-0/+753
This moves all the iterative functions to the 4x function API. Functions are now simpler to read. A shared utility module was created for repeated asserts. While testing it was clear that it is difficult to use Puppet.lookup(:loaders), and the evaluator was changed to get the loaders via the compiler instead. The evaluator tests are changed to make use of the simplified handling of the loaders. The tests for the functions that have moved, were also moved, but are unchanged in what they test.
2014-06-12(maint) Remove optional_objectAndrew Parker1-2/+2
Object is now the top class and so there is no need to use Optional[Object] everywhere. This removes the type factory method optional_object and replaces all occurrances with just object. It also updates all of the uses of Optional[Object] to use just Object.
2014-06-12(PUP-514) Only check lambda args onceAndrew Parker1-1/+1
The previous implementation checked the argument types twice against the signature. This reduces it to a single check. The error for a missing argument is now caught in a place that used to be unreachable and so the error has been converted into an issue, which also provides the information about where the failure occurred.
2014-06-12(PUP-514) Ensure with() takes Type argumentsAndrew Parker1-1/+5
With hadn't been checked that it can take a Type as an argument. Normally this kind of check wouldn't be needed, but as the type system and calling conventions have been sorted out, this hasn't always worked as intended.
2014-06-12(PUP-514) Create "with" functionAndrew Parker1-0/+31
The with function is needed in order to easily try out invoking lambdas. Because this kind of thing can also be generally useful to anyone who wants to learn the puppet language (understand lambdas, for instance) or want to have a way of creating private scopes within a class, the with function is being added as a normal APIv4 function rather than something that is only available in tests.
2014-05-21(PUP-2314) Make assert_type handle lambda and user handlingHenrik Lindberg1-2/+21
This adds the ability to handle a Callable as the value, as well as supporting a lambda that takes over the built in raising of an error. This means that assert_type can be customized to fail with special message, or to issue a warning and use a default. assert_type(String, 1) |$expected, $actual| { warning("a $actual is not a $expected") "Free Beer, is the default" }
2014-05-06(PUP-957) Add checks for match against "any regular expression"Henrik Lindberg1-0/+4
2014-05-06(PUP-957) Add match function that returns matched result as array.Henrik Lindberg1-0/+53
The function handles matching of String, and Array[String] against: * regexp * string * Regexp type * Pattern type
2014-04-25(PUP-2344) Inject environment into loadersAndrew Parker1-1/+1
Having code depend on the "current environment" has lead to trouble in many instances. Having the loaders be given an explicit environment is a much safer way to proceed.
2014-04-25(PUP-2344) Fix issue with inter-module calls (visibility error)Henrik Lindberg1-2/+9
This fixes the problem where inter-module function calls could not be made. The main problem was that a function when loaded was given the public loader and thus had no visibility into its containing module's dependencies. The design is that module resolution should be on-demand, only when something actually needs the proviate loader should it be resolved. The resolution is triggered by asking for the private loader, but no such call was made on the call-path when a function was loaded. This commit adds the notion of private_loader to the loaders (those that do not have one respond with self). Those that do either provide the private loader explicitly (environment loader), or on demand (by obtaining the private loader from loaders). This change required tests to be modified since the logic now depends on :loaders being bound in the Puppet context logic that made this happen on demand was not implemented
2014-04-05(PUP-485) Add ability to give assert_type a type as a StringHenrik Lindberg1-3/+7
This adds the ability to also give the type as a String (it is parsed with the TypeParser). This is good when reading the type specification from an external source that cannot directly serialize a Puppet Type.
2014-04-05(PUP-485) Fix test after change to ParseError from ArgumentErrorHenrik Lindberg1-1/+1
2014-04-05(PUP-485) Add function assert_type(t, value)Henrik Lindberg1-0/+48
This function asserts that the value is an instance of the given type. The value is returned or an error is raised. This function use the new 4x function API.