FormatTestCode formats the given Go code. The code must correspond to the content of a valid Go source file (i.e. start with "package")
(t *testing.T, code string)
| 64 | // FormatTestCode formats the given Go code. The code must correspond to the |
| 65 | // content of a valid Go source file (i.e. start with "package") |
| 66 | func FormatTestCode(t *testing.T, code string) string { |
| 67 | t.Helper() |
| 68 | // Process the code in memory without creating a temp file |
| 69 | formatted, err := finalizeGoSource("test.go", []byte(code)) |
| 70 | require.NoError(t, err) |
| 71 | return strings.Join(strings.Split(string(formatted), "\n")[2:], "\n") |
| 72 | } |
| 73 | |
| 74 | // CreateTempFile creates a temporary file and writes the given content. |
| 75 | // It is used only for testing. |