@@ -232,6 +232,85 @@ func TestExtractGoFunction(t *testing.T) {
232232 }
233233}
234234
235+ func TestModuleParserErrors (t * testing.T ) {
236+ tests := []struct {
237+ name string
238+ input string
239+ expectedErr string
240+ }{
241+ {
242+ name : "duplicate init directives" ,
243+ input : `package main
244+
245+ //export_php:module init
246+ func firstInit() {
247+ // First init function
248+ }
249+
250+ //export_php:module init
251+ func secondInit() {
252+ // Second init function - should error
253+ }` ,
254+ expectedErr : "duplicate init directive" ,
255+ },
256+ {
257+ name : "duplicate shutdown directives" ,
258+ input : `package main
259+
260+ //export_php:module shutdown
261+ func firstShutdown() {
262+ // First shutdown function
263+ }
264+
265+ //export_php:module shutdown
266+ func secondShutdown() {
267+ // Second shutdown function - should error
268+ }` ,
269+ expectedErr : "duplicate shutdown directive" ,
270+ },
271+ {
272+ name : "multiple duplicates" ,
273+ input : `package main
274+
275+ //export_php:module init
276+ func firstInit() {
277+ // First init function
278+ }
279+
280+ //export_php:module init
281+ func secondInit() {
282+ // Duplicate init - should error
283+ }
284+
285+ //export_php:module shutdown
286+ func firstShutdown() {
287+ // First shutdown function
288+ }
289+
290+ //export_php:module shutdown
291+ func secondShutdown() {
292+ // Duplicate shutdown - should error
293+ }` ,
294+ expectedErr : "duplicate init directive" ,
295+ },
296+ }
297+
298+ for _ , tt := range tests {
299+ t .Run (tt .name , func (t * testing.T ) {
300+ tmpDir := t .TempDir ()
301+ fileName := filepath .Join (tmpDir , tt .name + ".go" )
302+ require .NoError (t , os .WriteFile (fileName , []byte (tt .input ), 0644 ))
303+
304+ parser := & ModuleParser {}
305+ module , err := parser .parse (fileName )
306+
307+ assert .Error (t , err , "parse() should return error for duplicate directives" )
308+ assert .Contains (t , err .Error (), tt .expectedErr , "error message should contain expected text" )
309+ assert .Nil (t , module , "parse() should return nil when there's an error" )
310+ })
311+ }
312+ }
313+
235314func TestModuleParserFileErrors (t * testing.T ) {
236315 parser := & ModuleParser {}
237316
0 commit comments