41
40
Puppet.debug("parsing failer #{file}") if __FILE__ == $0
42
assert_raise(Puppet::ParseError, "Did not fail while parsing #{file}") {
41
assert_raise(Puppet::ParseError, Puppet::Error, "Did not fail while parsing #{file}") {
42
Puppet[:manifest] = file
45
43
config = mkcompiler(parser)
47
45
#ast.hostclass("").evaluate config.topscope
364
362
assert_raise(Puppet::ParseError) {
365
parser.parse %{define mydef($schedule) {}}
363
parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule) {}}), '')
368
366
assert_nothing_raised {
369
parser.parse %{define adef($schedule = false) {}}
370
parser.parse %{define mydef($schedule = daily) {}}
367
parser.known_resource_types.import_ast(parser.parse(%{define adef($schedule = false) {}}), '')
368
parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule = daily) {}}), '')
379
377
str1 = %{if true { #{exec.call("true")} }}
381
379
assert_nothing_raised {
382
ret = parser.parse(str1).hostclass("").code[0]
380
ret = parser.parse(str1).code[0]
384
382
assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
385
383
parser = mkparser
386
384
str2 = %{if true { #{exec.call("true")} } else { #{exec.call("false")} }}
387
ret = parser.parse(str2).hostclass("").code[0]
385
ret = parser.parse(str2).code[0]
388
386
assert_instance_of(Puppet::Parser::AST::IfStatement, ret)
389
387
assert_instance_of(Puppet::Parser::AST::Else, ret.else)
393
391
parser = mkparser
395
393
assert_nothing_raised {
396
parser.parse %{class myclass { class other {} }}
394
parser.known_resource_types.import_ast(parser.parse(%{class myclass { class other {} }}), '')
398
396
assert(parser.hostclass("myclass"), "Could not find myclass")
399
397
assert(parser.hostclass("myclass::other"), "Could not find myclass::other")
401
399
assert_nothing_raised {
402
parser.parse "class base {}
400
parser.known_resource_types.import_ast(parser.parse("class base {}
403
401
class container {
404
402
class deep::sub inherits base {}
407
405
sub = parser.hostclass("container::deep::sub")
408
406
assert(sub, "Could not find sub")
410
408
# Now try it with a parent class being a fq class
411
409
assert_nothing_raised {
412
parser.parse "class container::one inherits container::deep::sub {}"
410
parser.known_resource_types.import_ast(parser.parse("class container::one inherits container::deep::sub {}"), '')
414
412
sub = parser.hostclass("container::one")
415
413
assert(sub, "Could not find one")
418
416
# Finally, try including a qualified class
419
417
assert_nothing_raised("Could not include fully qualified class") {
420
parser.parse "include container::deep::sub"
418
parser.known_resource_types.import_ast(parser.parse("include container::deep::sub"), '')
427
425
# Make sure we put the top-level code into a class called "" in
428
426
# the "" namespace
429
assert_nothing_raised do
430
out = parser.parse ""
432
assert_instance_of(Puppet::Resource::TypeCollection, out)
433
assert_nil(parser.hostclass(""), "Got a 'main' class when we had no code")
436
# Now try something a touch more complicated
438
428
assert_nothing_raised do
439
out = parser.parse "Exec { path => '/usr/bin:/usr/sbin' }"
440
assert_instance_of(Puppet::Resource::TypeCollection, out)
441
assert_equal("", parser.hostclass("").name)
442
assert_equal("", parser.hostclass("").namespace)
429
parser.known_resource_types.import_ast(parser.parse("Exec { path => '/usr/bin:/usr/sbin' }"), '')
430
assert_equal("", parser.known_resource_types.hostclass("").name)
431
assert_equal("", parser.known_resource_types.hostclass("").namespace)
484
473
assert_nothing_raised do
485
ret = parser.parse("#{at}file { '/tmp/testing': owner => root }")
474
parser.known_resource_types.import_ast(parser.parse("#{at}file { '/tmp/testing': owner => root }"), '')
475
ret = parser.known_resource_types
488
478
assert_instance_of(AST::ASTArray, ret.hostclass("").code)
489
479
resdef = ret.hostclass("").code[0]
490
480
assert_instance_of(AST::Resource, resdef)
491
assert_equal("/tmp/testing", resdef.title.value)
481
assert_instance_of(AST::ASTArray, resdef.instances)
482
assert_equal(1, resdef.instances.children.length)
483
assert_equal("/tmp/testing", resdef.instances[0].title.value)
492
484
# We always get an astarray back, so...
493
485
check.call(resdef, "simple resource")
495
487
# Now let's try it with multiple resources in the same spec
496
488
assert_nothing_raised do
497
ret = parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }")
489
parser.known_resource_types.import_ast(parser.parse("#{at}file { ['/tmp/1', '/tmp/2']: owner => root }"), '')
490
ret = parser.known_resource_types
500
ret.hostclass("").code.each do |res|
493
ret.hostclass("").code[0].each do |res|
501
494
assert_instance_of(AST::Resource, res)
502
495
check.call(res, "multiresource")
507
500
if Puppet.features.rails?
508
501
Puppet[:storeconfigs] = false
509
Puppet::Resource::Catalog.cache_class = catalog_cache_class
510
Puppet::Node::Facts.cache_class = facts_cache_class
511
Puppet::Node.cache_class = node_cache_class
502
Puppet::Resource::Catalog.indirection.cache_class = catalog_cache_class
503
Puppet::Node::Facts.indirection.cache_class = facts_cache_class
504
Puppet::Node.indirection.cache_class = node_cache_class
537
530
ret = parser.parse("File #{arrow}")
540
coll = ret.hostclass("").code[0]
541
534
assert_instance_of(AST::Collection, coll)
542
535
assert_equal(form, coll.form)
546
539
if Puppet.features.rails?
547
540
Puppet[:storeconfigs] = false
548
Puppet::Resource::Catalog.cache_class = catalog_cache_class
549
Puppet::Node::Facts.cache_class = facts_cache_class
550
Puppet::Node.cache_class = node_cache_class
541
Puppet::Resource::Catalog.indirection.cache_class = catalog_cache_class
542
Puppet::Node::Facts.indirection.cache_class = facts_cache_class
543
Puppet::Node.indirection.cache_class = node_cache_class
609
602
assert_nothing_raised("Could not parse '#{test}'") do
610
res = parser.parse(str).hostclass("").code[0]
603
res = parser.parse(str).code[0]
613
606
assert_instance_of(AST::Collection, res)
624
617
def test_fully_qualified_definitions
625
618
parser = mkparser
620
types = parser.known_resource_types
627
621
assert_nothing_raised("Could not parse fully-qualified definition") {
628
parser.parse %{define one::two { }}
622
types.import_ast(parser.parse(%{define one::two { }}), '')
630
624
assert(parser.definition("one::two"), "Could not find one::two with no namespace")
632
# Now try using the definition
633
assert_nothing_raised("Could not parse fully-qualified definition usage") {
634
parser.parse %{one::two { yayness: }}
691
680
result = parser.parse %{$variable = undef}
694
main = result.hostclass("").code
695
684
children = main.children
696
685
assert_instance_of(AST::VarDef, main.children[0])
697
686
assert_instance_of(AST::Undef, main.children[0].value)
704
693
str = "file { '/tmp/yay': ensure => file }\nclass yay {}\nnode foo {}\ndefine bar {}\n"
706
695
assert_nothing_raised("Could not parse") do
707
result = parser.parse(str)
696
parser.known_resource_types.import_ast(parser.parse(str), '')
697
result = parser.known_resource_types
709
699
assert_instance_of(Puppet::Resource::TypeCollection, result, "Did not get a ASTSet back from parsing")
736
726
assert_nothing_raised do
737
result = parser.newclass "Yayness"
727
parser.known_resource_types.import_ast(parser.parse("class yayness { }"), '')
728
result = parser.known_resource_types.hostclass('yayness')
739
730
assert_equal(result, parser.find_hostclass("", "yayNess"))
741
732
assert_nothing_raised do
742
result = parser.newdefine "FunTest"
733
parser.known_resource_types.import_ast(parser.parse("define funtest { }"), '')
734
result = parser.known_resource_types.definition('funtest')
744
736
assert_equal(result, parser.find_definition("", "fUntEst"), "#{"fUntEst"} was not matched")