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

Function TestToolExec

cmd/errtrace/toolexec_test.go:22–182  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

20)
21
22func TestToolExec(t *testing.T) {
23 const testProgDir = "./testdata/toolexec-test"
24 const testProgPkg = "braces.dev/errtrace/cmd/errtrace/testdata/toolexec-test/"
25
26 errTraceCmd := filepath.Join(t.TempDir(), "errtrace")
27 if runtime.GOOS == "windows" {
28 errTraceCmd += ".exe" // can't run binaries on Windows otherwise.
29 }
30 _, stderr, err := runGo(t, ".", "build", "-o", errTraceCmd, ".")
31 if err != nil {
32 t.Fatalf("compile errtrace failed: %v\nstderr: %s", err, stderr)
33 }
34
35 var wantTraces []string
36 err = filepath.Walk(testProgDir, func(path string, info fs.FileInfo, err error) error {
37 if err != nil {
38 return errtrace.Wrap(err)
39 }
40 if info.IsDir() {
41 return nil
42 }
43
44 for _, line := range findTraceLines(t, path) {
45 absPath, err := filepath.Abs(path)
46 if err != nil {
47 t.Fatalf("abspath: %v", err)
48 }
49 if runtime.GOOS == "windows" {
50 // On Windows, absPath uses windows path separators, e.g., "c:\foo"
51 // but the paths reported in traces contain '/'.
52 absPath = filepath.ToSlash(absPath)
53 }
54
55 wantTraces = append(wantTraces, fmt.Sprintf("%v:%v", absPath, line))
56 }
57 return nil
58 })
59 if err != nil {
60 t.Fatal("Walk failed", err)
61 }
62 sort.Strings(wantTraces)
63
64 tests := []struct {
65 name string
66 goArgs func(t testing.TB) []string
67 wantTraces []string
68 wantErr string
69 }{
70 {
71 name: "no toolexec",
72 goArgs: func(t testing.TB) []string {
73 return []string{"."}
74 },
75 wantTraces: nil,
76 },
77 {
78 name: "toolexec with pkg",
79 goArgs: func(t testing.TB) []string {

Callers

nothing calls this directly

Calls 7

WrapFunction · 0.92
DiffFunction · 0.92
runGoFunction · 0.85
findTraceLinesFunction · 0.85
goListFilesFunction · 0.85
fileLinesFunction · 0.85
RunMethod · 0.80

Tested by

no test coverage detected