@@ -39,6 +39,15 @@ def load_constant(typed_name)
39
39
40
40
let ( :loader ) { FunctionAPISpecModule ::TestFunctionLoader . new }
41
41
42
+ def parse_eval ( code , here )
43
+ if here . respond_to? ( :source_location )
44
+ eval ( code , here , here . source_location [ 0 ] , here . source_location [ 1 ] )
45
+ else
46
+ # this can be removed when ruby < 2.6 is dropped
47
+ eval ( code , here )
48
+ end
49
+ end
50
+
42
51
it 'allows a simple function to be created without dispatch declaration' do
43
52
f = Puppet ::Functions . create_function ( 'min' ) do
44
53
def min ( x , y )
@@ -484,7 +493,7 @@ def test(x)
484
493
the_loader = loader ( )
485
494
here = get_binding ( the_loader )
486
495
expect do
487
- eval ( <<-CODE , here )
496
+ parse_eval ( <<-CODE , here )
488
497
Puppet::Functions.create_function('testing::test') do
489
498
local_types do
490
499
type 'MyType += Array[Integer]'
@@ -505,7 +514,7 @@ def test(x)
505
514
the_loader = loader ( )
506
515
here = get_binding ( the_loader )
507
516
expect do
508
- eval ( <<-CODE , here )
517
+ parse_eval ( <<-CODE , here )
509
518
Puppet::Functions.create_function('testing::test') do
510
519
dispatch :test do
511
520
param 'Array[1+=1]', :x
@@ -525,7 +534,7 @@ def test(x)
525
534
it 'uses return_type to validate returned value' do
526
535
the_loader = loader ( )
527
536
here = get_binding ( the_loader )
528
- fc = eval ( <<-CODE , here )
537
+ fc = parse_eval ( <<-CODE , here )
529
538
Puppet::Functions.create_function('testing::test') do
530
539
dispatch :test do
531
540
param 'Integer', :x
@@ -547,7 +556,7 @@ def test(x)
547
556
the_loader = loader ( )
548
557
the_loader . add_type ( 'myalias' , type_alias_t ( 'MyAlias' , 'Integer' ) )
549
558
here = get_binding ( the_loader )
550
- fc = eval ( <<-CODE , here )
559
+ fc = parse_eval ( <<-CODE , here )
551
560
Puppet::Functions.create_function('testing::test') do
552
561
dispatch :test do
553
562
param 'MyAlias', :x
@@ -567,7 +576,7 @@ def test(x)
567
576
it 'reports a reference to an unresolved type' do
568
577
the_loader = loader ( )
569
578
here = get_binding ( the_loader )
570
- fc = eval ( <<-CODE , here )
579
+ fc = parse_eval ( <<-CODE , here )
571
580
Puppet::Functions.create_function('testing::test') do
572
581
dispatch :test do
573
582
param 'MyAlias', :x
@@ -586,7 +595,7 @@ def test(x)
586
595
it 'create local Type aliases' do
587
596
the_loader = loader ( )
588
597
here = get_binding ( the_loader )
589
- fc = eval ( <<-CODE , here )
598
+ fc = parse_eval ( <<-CODE , here )
590
599
Puppet::Functions.create_function('testing::test') do
591
600
local_types do
592
601
type 'MyType = Array[Integer]'
@@ -608,7 +617,7 @@ def test(x)
608
617
it 'create nested local Type aliases' do
609
618
the_loader = loader ( )
610
619
here = get_binding ( the_loader )
611
- fc = eval ( <<-CODE , here )
620
+ fc = parse_eval ( <<-CODE , here )
612
621
Puppet::Functions.create_function('testing::test') do
613
622
local_types do
614
623
type 'InnerType = Array[Integer]'
@@ -631,7 +640,7 @@ def test(x)
631
640
it 'create self referencing local Type aliases' do
632
641
the_loader = loader ( )
633
642
here = get_binding ( the_loader )
634
- fc = eval ( <<-CODE , here )
643
+ fc = parse_eval ( <<-CODE , here )
635
644
Puppet::Functions.create_function('testing::test') do
636
645
local_types do
637
646
type 'Tree = Hash[String,Variant[String,Tree]]'
0 commit comments