CreateTempFile creates a temporary file and writes the given content. It is used only for testing.
(t *testing.T, content string)
| 50 | // CreateTempFile creates a temporary file and writes the given content. |
| 51 | // It is used only for testing. |
| 52 | func CreateTempFile(t *testing.T, content string) string { |
| 53 | t.Helper() |
| 54 | f, err := os.CreateTemp("", "") |
| 55 | if err != nil { |
| 56 | t.Fatal(err) |
| 57 | } |
| 58 | _, err = f.WriteString(content) |
| 59 | if err != nil { |
| 60 | _ = os.Remove(f.Name()) |
| 61 | t.Fatal(err) |
| 62 | } |
| 63 | if err := f.Close(); err != nil { |
| 64 | t.Fatal(err) |
| 65 | } |
| 66 | return f.Name() |
| 67 | } |
| 68 | |
| 69 | // ResetDSL resets the global expression state for testing and initializes |
| 70 | // a default API. This function should be called before running any DSL that |