@@ -34,6 +34,47 @@ def validate(factory)
34
34
expect ( validate ( parse ( 'function ::aaa() {}' ) ) ) . to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_NAME )
35
35
end
36
36
37
+ it 'should raise error for illegal class locations' do
38
+ expect ( validate ( parse ( 'function aaa::ccc() {}' , 'aaa/manifests/bbb.pp' ) ) ) . to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
39
+ expect ( validate ( parse ( 'class bbb() {}' , 'aaa/manifests/init.pp' ) ) ) . to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
40
+ expect ( validate ( parse ( 'define aaa::bbb::ccc::eee() {}' , 'aaa/manifests/bbb/ddd.pp' ) ) ) . to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
41
+ end
42
+
43
+ it 'should not raise error for legal definition locations' do
44
+ expect ( validate ( parse ( 'function aaa::bbb() {}' , 'aaa/manifests/bbb.pp' ) ) ) . not_to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
45
+ expect ( validate ( parse ( 'define bbb() {}' , 'aaa/manifests/site.pp' ) ) ) . not_to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
46
+ expect ( validate ( parse ( 'class aaa() {}' , 'aaa/manifests/init.pp' ) ) ) . not_to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
47
+ expect ( validate ( parse ( 'class aaa() {}' , 'manifests/site.pp' ) ) ) . not_to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
48
+ expect ( validate ( parse ( 'function aaa::bbB::ccc() {}' , 'aaa/manifests/bBb.pp' ) ) ) . not_to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
49
+ expect ( validate ( parse ( 'function aaa::bbb::ccc() {}' , 'aaa/manifests/bbb/CCC.pp' ) ) ) . not_to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
50
+ end
51
+
52
+ it 'should not raise error for class locations when not parsing a file' do
53
+ #nil file means eval or some other way to get puppet language source code into the catalog
54
+ expect ( validate ( parse ( 'function aaa::ccc() {}' , nil ) ) ) . not_to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
55
+ end
56
+
57
+ it 'should not raise error for definitions inside initial --manifest' do
58
+ Puppet [ :manifest ] = 'a/manifest/file.pp'
59
+ expect ( validate ( parse ( 'class aaa() {}' , 'a/manifest/file.pp' ) ) ) . not_to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
60
+ end
61
+
62
+ it 'should not raise error for definitions inside initial --manifest' do
63
+ Puppet [ :manifest ] = 'a/manifest/dir'
64
+ expect ( validate ( parse ( 'class aaa() {}' , 'a/manifest/dir/file1.pp' ) ) ) . not_to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
65
+ expect ( validate ( parse ( 'class bbb::ccc::ddd() {}' , 'a/manifest/dir/and/more/stuff.pp' ) ) ) . not_to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
66
+ end
67
+
68
+ it 'should raise error for definitions not inside initial --manifest' do
69
+ Puppet [ :manifest ] = 'a/manifest/somewhere/else'
70
+ expect ( validate ( parse ( 'class aaa() {}' , 'a/manifest/dir/file1.pp' ) ) ) . to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
71
+ end
72
+
73
+ it 'should raise error if the manifest file does not come from a well formed module path' do
74
+ skip ( "This test path won't work on windows." ) if Puppet ::Util ::Platform . windows?
75
+ expect ( validate ( parse ( 'class aaa() {}' , '/manifest/dir/file1.pp' ) ) ) . to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
76
+ end
77
+
37
78
it 'should raise error for illegal type names' do
38
79
expect ( validate ( parse ( 'type ::Aaa = Any' ) ) ) . to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_NAME )
39
80
end
@@ -56,6 +97,13 @@ def validate(factory)
56
97
expect ( acceptor . error_count ) . to eql ( 0 )
57
98
expect ( acceptor ) . to have_issue ( Puppet ::Pops ::Issues ::DUPLICATE_KEY )
58
99
end
100
+
101
+ it 'produces a warning for illegal function locations' do
102
+ acceptor = validate ( parse ( 'function aaa::ccc() {}' , 'aaa/manifests/bbb.pp' ) )
103
+ expect ( acceptor . warning_count ) . to eql ( 1 )
104
+ expect ( acceptor . error_count ) . to eql ( 0 )
105
+ expect ( acceptor ) . to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
106
+ end
59
107
end
60
108
61
109
context 'with --strict set to warning' do
@@ -80,6 +128,13 @@ def validate(factory)
80
128
expect ( acceptor . error_count ) . to eql ( 0 )
81
129
expect ( acceptor ) . to have_issue ( Puppet ::Pops ::Issues ::CLASS_NOT_VIRTUALIZABLE )
82
130
end
131
+
132
+ it 'produces a warning for illegal function locations' do
133
+ acceptor = validate ( parse ( 'function aaa::ccc() {}' , 'aaa/manifests/bbb.pp' ) )
134
+ expect ( acceptor . warning_count ) . to eql ( 1 )
135
+ expect ( acceptor . error_count ) . to eql ( 0 )
136
+ expect ( acceptor ) . to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
137
+ end
83
138
end
84
139
85
140
context 'with --strict set to error' do
@@ -111,6 +166,13 @@ def validate(factory)
111
166
expect ( acceptor . error_count ) . to eql ( 1 )
112
167
expect ( acceptor ) . to have_issue ( Puppet ::Pops ::Issues ::CLASS_NOT_VIRTUALIZABLE )
113
168
end
169
+
170
+ it 'produces an error for illegal function locations' do
171
+ acceptor = validate ( parse ( 'function aaa::ccc() {}' , 'aaa/manifests/bbb.pp' ) )
172
+ expect ( acceptor . warning_count ) . to eql ( 0 )
173
+ expect ( acceptor . error_count ) . to eql ( 1 )
174
+ expect ( acceptor ) . to have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
175
+ end
114
176
end
115
177
116
178
context 'with --strict set to off' do
@@ -121,6 +183,13 @@ def validate(factory)
121
183
expect ( acceptor . error_count ) . to eql ( 0 )
122
184
expect ( acceptor ) . to_not have_issue ( Puppet ::Pops ::Issues ::DUPLICATE_KEY )
123
185
end
186
+
187
+ it 'does not produce an error or warning for illegal function locations' do
188
+ acceptor = validate ( parse ( 'function aaa::ccc() {}' , 'aaa/manifests/bbb.pp' ) )
189
+ expect ( acceptor . warning_count ) . to eql ( 0 )
190
+ expect ( acceptor . error_count ) . to eql ( 0 )
191
+ expect ( acceptor ) . to_not have_issue ( Puppet ::Pops ::Issues ::ILLEGAL_DEFINITION_LOCATION )
192
+ end
124
193
end
125
194
126
195
context 'irrespective of --strict' do
@@ -145,7 +214,7 @@ def validate(factory)
145
214
expect ( acceptor ) . to have_issue ( Puppet ::Pops ::Issues ::CLASS_NOT_VIRTUALIZABLE )
146
215
end
147
216
148
- it 'produces a warning for exported class resource' do
217
+ it 'produces a warning for exported class resource' do
149
218
acceptor = validate ( parse ( '@@class { test: }' ) )
150
219
expect ( acceptor . warning_count ) . to eql ( 1 )
151
220
expect ( acceptor . error_count ) . to eql ( 0 )
@@ -662,7 +731,7 @@ def issue(at_top)
662
731
end
663
732
end
664
733
665
- def parse ( source )
666
- Puppet ::Pops ::Parser ::Parser . new . parse_string ( source )
734
+ def parse ( source , path = nil )
735
+ Puppet ::Pops ::Parser ::Parser . new . parse_string ( source , path )
667
736
end
668
737
end
0 commit comments