MCPcopy Index your code
hub / github.com/php/frankenphp / TestGoFileGenerator_MalformedSource

Function TestGoFileGenerator_MalformedSource

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

Source from the content-addressed store, hash-verified

993}
994
995func TestGoFileGenerator_MalformedSource(t *testing.T) {
996 tests := []struct {
997 name string
998 sourceContent string
999 expectError bool
1000 }{
1001 {
1002 name: "missing package declaration",
1003 sourceContent: "func test() {}",
1004 expectError: true,
1005 },
1006 {
1007 name: "syntax error",
1008 sourceContent: "package main\nfunc test( {}",
1009 expectError: true,
1010 },
1011 {
1012 name: "incomplete function",
1013 sourceContent: "package main\nfunc test() {",
1014 expectError: true,
1015 },
1016 {
1017 name: "valid minimal source",
1018 sourceContent: "package main\nfunc test() {}",
1019 expectError: false,
1020 },
1021 }
1022
1023 for _, tt := range tests {
1024 t.Run(tt.name, func(t *testing.T) {
1025 tmpDir := t.TempDir()
1026 sourceFile := filepath.Join(tmpDir, "test.go")
1027 require.NoError(t, os.WriteFile(sourceFile, []byte(tt.sourceContent), 0644))
1028
1029 generator := &Generator{
1030 BaseName: "test",
1031 SourceFile: sourceFile,
1032 BuildDir: tmpDir,
1033 }
1034
1035 goGen := GoFileGenerator{generator}
1036 _, err := goGen.buildContent()
1037
1038 if tt.expectError {
1039 assert.Error(t, err, "Expected error for malformed source")
1040 } else {
1041 assert.NoError(t, err, "Should not error for valid source")
1042 }
1043
1044 contentAfter, readErr := os.ReadFile(sourceFile)
1045 require.NoError(t, readErr)
1046 assert.Equal(t, tt.sourceContent, string(contentAfter), "Source file should remain unchanged even on error")
1047 })
1048 }
1049}
1050
1051func TestGoFileGenerator_MethodWrapperWithNullableArrayParams(t *testing.T) {
1052 tmpDir := t.TempDir()

Callers

nothing calls this directly

Calls 2

buildContentMethod · 0.95
ErrorMethod · 0.45

Tested by

no test coverage detected