MCPcopy Create free account
hub / github.com/bracesdev/errtrace / TestShouldFormat

Function TestShouldFormat

cmd/errtrace/main_test.go:365–394  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

363}
364
365func TestShouldFormat(t *testing.T) {
366 tests := []struct {
367 name string
368 give mainParams
369 want bool
370 }{
371 {"auto/no write", mainParams{Format: formatAuto}, false},
372 {"auto/write", mainParams{Format: formatAuto, Write: true}, true},
373 {"always", mainParams{Format: formatAlways}, true},
374 {"never", mainParams{Format: formatNever}, false},
375 }
376
377 for _, tt := range tests {
378 t.Run(tt.name, func(t *testing.T) {
379 if want, got := tt.want, tt.give.shouldFormat(); got != want {
380 t.Errorf("got %v, want %v", got, want)
381 }
382 })
383 }
384
385 t.Run("unknown", func(t *testing.T) {
386 defer func() {
387 if err := recover(); err == nil {
388 t.Fatal("no panic")
389 }
390 }()
391
392 (&mainParams{Format: format(999)}).shouldFormat()
393 })
394}
395
396// -format=auto should format the file if used with -w,
397// and not format the file if used without -w.

Callers

nothing calls this directly

Calls 3

formatTypeAlias · 0.85
RunMethod · 0.80
shouldFormatMethod · 0.80

Tested by

no test coverage detected