MCPcopy Create free account
hub / github.com/php/frankenphp / TestGoFileGenerator_ErrorHandling

Function TestGoFileGenerator_ErrorHandling

internal/extgen/gofile_test.go:319–359  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

317}
318
319func TestGoFileGenerator_ErrorHandling(t *testing.T) {
320 tests := []struct {
321 name string
322 sourceFile string
323 expectErr bool
324 }{
325 {
326 name: "nonexistent file",
327 sourceFile: "/nonexistent/file.go",
328 expectErr: true,
329 },
330 {
331 name: "invalid Go syntax",
332 sourceFile: createTempSourceFile(t, "invalid go syntax here"),
333 expectErr: true,
334 },
335 {
336 name: "valid file",
337 sourceFile: createTempSourceFile(t, "package main\nfunc test() {}"),
338 expectErr: false,
339 },
340 }
341
342 for _, tt := range tests {
343 t.Run(tt.name, func(t *testing.T) {
344 generator := &Generator{
345 BaseName: "test",
346 SourceFile: tt.sourceFile,
347 }
348
349 goGen := GoFileGenerator{generator}
350 _, err := goGen.buildContent()
351
352 if tt.expectErr {
353 assert.Error(t, err, "Expected error but got none")
354 } else {
355 assert.NoError(t, err, "Unexpected error")
356 }
357 })
358 }
359}
360
361func TestGoFileGenerator_ComplexScenario(t *testing.T) {
362 sourceContent := `package example

Callers

nothing calls this directly

Calls 3

buildContentMethod · 0.95
createTempSourceFileFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected