~bkerensa/ubuntu/raring/puppet/new-upstream-release

« back to all changes in this revision

Viewing changes to test/language/parser.rb

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-07-25 01:00:37 UTC
  • mfrom: (1.1.24 upstream) (3.1.25 sid)
  • Revision ID: james.westby@ubuntu.com-20110725010037-875vuxs10eboqgw3
Tags: 2.7.1-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - debian/puppetmaster-passenger.postinst: Use cacrl instead of hostcrl to
    set the location of the CRL in apache2 configuration. Fix apache2
    configuration on upgrade as well (LP: #641001)
  - move all puppet dependencies to puppet-common since all the code
    actually located in puppet-common.
  - move libagueas from a recommend to a dependency.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env ruby
2
2
 
3
 
require File.dirname(__FILE__) + '/../lib/puppettest'
 
3
require File.expand_path(File.dirname(__FILE__) + '/../lib/puppettest')
4
4
 
5
5
require 'mocha'
6
6
require 'puppet'
14
14
  include PuppetTest::Support::Utils
15
15
  def setup
16
16
    super
17
 
    Puppet[:parseonly] = true
18
17
    #@lexer = Puppet::Parser::Lexer.new
19
18
  end
20
19
 
39
38
    failers { |file|
40
39
      parser = mkparser
41
40
      Puppet.debug("parsing failer #{file}") if __FILE__ == $0
42
 
      assert_raise(Puppet::ParseError, "Did not fail while parsing #{file}") {
43
 
        parser.file = file
44
 
        ast = parser.parse
 
41
      assert_raise(Puppet::ParseError, Puppet::Error, "Did not fail while parsing #{file}") {
 
42
        Puppet[:manifest] = file
45
43
        config = mkcompiler(parser)
46
44
        config.compile
47
45
        #ast.hostclass("").evaluate config.topscope
288
286
      ret = parser.parse
289
287
    }
290
288
 
291
 
    ret.hostclass("").code.each do |obj|
 
289
    ret.code.each do |obj|
292
290
      assert_instance_of(AST::Collection, obj)
293
291
    end
294
292
  end
362
360
 
363
361
 
364
362
    assert_raise(Puppet::ParseError) {
365
 
      parser.parse %{define mydef($schedule) {}}
 
363
      parser.known_resource_types.import_ast(parser.parse(%{define mydef($schedule) {}}), '')
366
364
    }
367
365
 
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) {}}), '')
371
369
    }
372
370
  end
373
371
 
379
377
    str1 = %{if true { #{exec.call("true")} }}
380
378
    ret = nil
381
379
    assert_nothing_raised {
382
 
      ret = parser.parse(str1).hostclass("").code[0]
 
380
      ret = parser.parse(str1).code[0]
383
381
    }
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)
390
388
  end
393
391
    parser = mkparser
394
392
 
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 {} }}), '')
397
395
    }
398
396
    assert(parser.hostclass("myclass"), "Could not find myclass")
399
397
    assert(parser.hostclass("myclass::other"), "Could not find myclass::other")
400
398
 
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 {}
405
 
      }"
 
403
      }"), '')
406
404
    }
407
405
    sub = parser.hostclass("container::deep::sub")
408
406
    assert(sub, "Could not find sub")
409
407
 
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 {}"), '')
413
411
    }
414
412
    sub = parser.hostclass("container::one")
415
413
    assert(sub, "Could not find one")
417
415
 
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"), '')
421
419
    }
422
420
  end
423
421
 
426
424
 
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 ""
431
 
 
432
 
      assert_instance_of(Puppet::Resource::TypeCollection, out)
433
 
      assert_nil(parser.hostclass(""), "Got a 'main' class when we had no code")
434
 
    end
435
 
 
436
 
    # Now try something a touch more complicated
437
427
    parser.initvars
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)
443
432
    end
444
433
  end
445
434
 
482
471
 
483
472
      ret = nil
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
486
476
      end
487
477
 
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")
494
486
 
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
498
491
      end
499
492
 
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")
503
496
      end
506
499
  ensure
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
512
505
    end
513
506
  end
514
507
 
537
530
        ret = parser.parse("File #{arrow}")
538
531
      end
539
532
 
540
 
      coll = ret.hostclass("").code[0]
 
533
      coll = ret.code[0]
541
534
      assert_instance_of(AST::Collection, coll)
542
535
      assert_equal(form, coll.form)
543
536
    end
545
538
  ensure
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
551
544
    end
552
545
  end
553
546
 
560
553
 
561
554
      res = nil
562
555
      assert_nothing_raised do
563
 
        res = parser.parse(str).hostclass("").code[0]
 
556
        res = parser.parse(str).code[0]
564
557
      end
565
558
 
566
559
      assert_instance_of(AST::Collection, res)
583
576
 
584
577
      res = nil
585
578
      assert_nothing_raised do
586
 
        res = parser.parse(str).hostclass("").code[0]
 
579
        res = parser.parse(str).code[0]
587
580
      end
588
581
 
589
582
      assert_instance_of(AST::Collection, res)
607
600
 
608
601
      res = nil
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]
611
604
      end
612
605
 
613
606
      assert_instance_of(AST::Collection, res)
624
617
  def test_fully_qualified_definitions
625
618
    parser = mkparser
626
619
 
 
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 { }}), '')
629
623
    }
630
624
    assert(parser.definition("one::two"), "Could not find one::two with no namespace")
631
 
 
632
 
    # Now try using the definition
633
 
    assert_nothing_raised("Could not parse fully-qualified definition usage") {
634
 
      parser.parse %{one::two { yayness: }}
635
 
    }
636
625
  end
637
626
 
638
627
  # #524
691
680
      result = parser.parse %{$variable = undef}
692
681
    }
693
682
 
694
 
    main = result.hostclass("").code
 
683
    main = result.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"
705
694
    result = nil
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
708
698
    end
709
699
    assert_instance_of(Puppet::Resource::TypeCollection, result, "Did not get a ASTSet back from parsing")
710
700
 
734
724
 
735
725
    result = nil
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')
738
729
    end
739
730
    assert_equal(result, parser.find_hostclass("", "yayNess"))
740
731
 
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')
743
735
    end
744
736
    assert_equal(result, parser.find_definition("", "fUntEst"), "#{"fUntEst"} was not matched")
745
737
  end