MCPcopy Create free account
hub / github.com/charmbracelet/bubbletea / TestLogToFile

Function TestLogToFile

logging_test.go:11–30  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

9)
10
11func TestLogToFile(t *testing.T) {
12 path := filepath.Join(t.TempDir(), "log.txt")
13 prefix := "logprefix"
14 f, err := LogToFile(path, prefix)
15 if err != nil {
16 t.Error(err)
17 }
18 log.SetFlags(log.Lmsgprefix)
19 log.Println("some test log")
20 if closeErr := f.Close(); closeErr != nil {
21 t.Error(closeErr)
22 }
23 out, err := os.ReadFile(path)
24 if err != nil {
25 t.Error(err)
26 }
27 if string(out) != prefix+" some test log\n" {
28 t.Fatalf("wrong log msg: %q", string(out))
29 }
30}
31
32func TestLogToFileWithPrefixSpacing(t *testing.T) {
33 tests := []struct {

Callers

nothing calls this directly

Calls 4

LogToFileFunction · 0.85
PrintlnMethod · 0.80
CloseMethod · 0.80
ErrorMethod · 0.45

Tested by

no test coverage detected