MCPcopy Create free account
hub / github.com/google/pprof / TestOpenSourceFile

Function TestOpenSourceFile

internal/report/source_test.go:123–216  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

121}
122
123func TestOpenSourceFile(t *testing.T) {
124 tempdir, err := os.MkdirTemp("", "")
125 if err != nil {
126 t.Fatalf("failed to create temp dir: %v", err)
127 }
128 const lsep = string(filepath.ListSeparator)
129 for _, tc := range []struct {
130 desc string
131 searchPath string
132 trimPath string
133 fs []string
134 path string
135 wantPath string // If empty, error is wanted.
136 }{
137 {
138 desc: "exact absolute path is found",
139 fs: []string{"foo/bar.cc"},
140 path: "$dir/foo/bar.cc",
141 wantPath: "$dir/foo/bar.cc",
142 },
143 {
144 desc: "exact relative path is found",
145 searchPath: "$dir",
146 fs: []string{"foo/bar.cc"},
147 path: "foo/bar.cc",
148 wantPath: "$dir/foo/bar.cc",
149 },
150 {
151 desc: "multiple search path",
152 searchPath: "some/path" + lsep + "$dir",
153 fs: []string{"foo/bar.cc"},
154 path: "foo/bar.cc",
155 wantPath: "$dir/foo/bar.cc",
156 },
157 {
158 desc: "relative path is found in parent dir",
159 searchPath: "$dir/foo/bar",
160 fs: []string{"bar.cc", "foo/bar/baz.cc"},
161 path: "bar.cc",
162 wantPath: "$dir/bar.cc",
163 },
164 {
165 desc: "trims configured prefix",
166 searchPath: "$dir",
167 trimPath: "some-path" + lsep + "/some/remote/path",
168 fs: []string{"my-project/foo/bar.cc"},
169 path: "/some/remote/path/my-project/foo/bar.cc",
170 wantPath: "$dir/my-project/foo/bar.cc",
171 },
172 {
173 desc: "trims heuristically",
174 searchPath: "$dir/my-project",
175 fs: []string{"my-project/foo/bar.cc"},
176 path: "/some/remote/path/my-project/foo/bar.cc",
177 wantPath: "$dir/my-project/foo/bar.cc",
178 },
179 {
180 desc: "error when not found",

Callers

nothing calls this directly

Calls 3

openSourceFileFunction · 0.85
CloseMethod · 0.65
NameMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…