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

Function TestListFlag

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

Source from the content-addressed store, hash-verified

506}
507
508func TestListFlag(t *testing.T) {
509 uninstrumentedSource := strings.Join([]string{
510 "package foo",
511 `import "errors"`,
512 "func foo() error {",
513 ` return errors.New("foo")`,
514 "}",
515 }, "\n")
516
517 instrumentedSource := strings.Join([]string{
518 "package foo",
519 `import "errors"; import "braces.dev/errtrace"`,
520 "func foo() error {",
521 ` return errtrace.Wrap(errors.New("foo"))`,
522 "}",
523 }, "\n")
524
525 dir := t.TempDir()
526
527 instrumented := filepath.Join(dir, "instrumented.go")
528 if err := os.WriteFile(instrumented, []byte(instrumentedSource), 0o600); err != nil {
529 t.Fatal(err)
530 }
531
532 uninstrumented := filepath.Join(dir, "uninstrumented.go")
533 if err := os.WriteFile(uninstrumented, []byte(uninstrumentedSource), 0o600); err != nil {
534 t.Fatal(err)
535 }
536
537 var out bytes.Buffer
538 exitCode := (&mainCmd{
539 Stdout: &out,
540 Stderr: testWriter{t},
541 }).Run([]string{"-l", uninstrumented, instrumented})
542 if want := 0; exitCode != want {
543 t.Errorf("exit code = %d, want %d", exitCode, want)
544 }
545
546 // Only the uninstrumented file should be listed.
547 if want, got := uninstrumented+"\n", out.String(); got != want {
548 t.Errorf("got:\n%s\nwant:\n%s\ndiff:\n%s", indent(got), indent(want), indent(diff.Lines(want, got)))
549 }
550}
551
552func TestOptoutLines(t *testing.T) {
553 fset := token.NewFileSet()

Callers

nothing calls this directly

Calls 4

LinesFunction · 0.92
indentFunction · 0.85
RunMethod · 0.80
StringMethod · 0.65

Tested by

no test coverage detected