}
}
+const mainPkgPath = "prog"
+
func buildProg(t *testing.T, prog string, dir string, tag string, flags []string) (string, string) {
// Create subdirs.
subdir := filepath.Join(dir, prog+"dir"+tag)
// Emit go.mod.
mod := filepath.Join(subdir, "go.mod")
- modsrc := "\nmodule prog\n\ngo 1.19\n"
+ modsrc := "\nmodule " + mainPkgPath + "\n\ngo 1.19\n"
if err := os.WriteFile(mod, []byte(modsrc), 0666); err != nil {
t.Fatal(err)
}
func testDump(t *testing.T, s state) {
// Run the dumper on the two dirs we generated.
- dargs := []string{"-pkg=main", "-live", "-i=" + s.outdirs[0] + "," + s.outdirs[1]}
+ dargs := []string{"-pkg=" + mainPkgPath, "-live", "-i=" + s.outdirs[0] + "," + s.outdirs[1]}
lines := runToolOp(t, s, "debugdump", dargs)
// Sift through the output to make sure it has some key elements.
},
{
"main package",
- regexp.MustCompile(`^Package path: main\s*$`),
+ regexp.MustCompile(`^Package path: ` + mainPkgPath + `\s*$`),
},
{
"main function",
}
}
if !found {
- t.Errorf("dump output regexp match failed for %s", testpoint.tag)
+ t.Errorf("dump output regexp match failed for %q", testpoint.tag)
bad = true
}
}
func testPercent(t *testing.T, s state) {
// Run the dumper on the two dirs we generated.
- dargs := []string{"-pkg=main", "-i=" + s.outdirs[0] + "," + s.outdirs[1]}
+ dargs := []string{"-pkg=" + mainPkgPath, "-i=" + s.outdirs[0] + "," + s.outdirs[1]}
lines := runToolOp(t, s, "percent", dargs)
// Sift through the output to make sure it has the needful.
dumplines(lines)
}
}
+
func testPkgList(t *testing.T, s state) {
dargs := []string{"-i=" + s.outdirs[0] + "," + s.outdirs[1]}
lines := runToolOp(t, s, "pkglist", dargs)
- want := []string{"main", "prog/dep"}
+ want := []string{mainPkgPath, mainPkgPath + "/dep"}
bad := false
if len(lines) != 2 {
t.Errorf("expect pkglist to return two lines")
func testTextfmt(t *testing.T, s state) {
outf := s.dir + "/" + "t.txt"
- dargs := []string{"-pkg=main", "-i=" + s.outdirs[0] + "," + s.outdirs[1],
+ dargs := []string{"-pkg=" + mainPkgPath, "-i=" + s.outdirs[0] + "," + s.outdirs[1],
"-o", outf}
lines := runToolOp(t, s, "textfmt", dargs)
dumplines(lines[0:10])
t.Errorf("textfmt: want %s got %s", want0, lines[0])
}
- want1 := "prog/prog1.go:13.14,15.2 1 1"
+ want1 := mainPkgPath + "/prog1.go:13.14,15.2 1 1"
if lines[1] != want1 {
dumplines(lines[0:10])
t.Errorf("textfmt: want %s got %s", want1, lines[1])
nonzero: true,
},
}
- flags := []string{"-live", "-pkg=main"}
+ flags := []string{"-live", "-pkg=" + mainPkgPath}
runDumpChecks(t, s, outdir, flags, testpoints)
}
// based on package.
ins := fmt.Sprintf("-i=%s,%s", indir1, indir2)
out := fmt.Sprintf("-o=%s", outdir)
- margs := []string{"-pkg=prog/dep", ins, out}
+ margs := []string{"-pkg=" + mainPkgPath + "/dep", ins, out}
lines := runToolOp(t, s, "merge", margs)
if len(lines) != 0 {
t.Errorf("merge run produced %d lines of unexpected output", len(lines))
t.Fatalf("dump run produced no output")
}
want := map[string]int{
- "Package path: prog/dep": 0,
- "Func: Dep1": 0,
- "Func: PDep": 0,
+ "Package path: " + mainPkgPath + "/dep": 0,
+ "Func: Dep1": 0,
+ "Func: PDep": 0,
}
bad := false
for _, line := range lines {
},
}
- flags := []string{"-live", "-pkg=main"}
+ flags := []string{"-live", "-pkg=" + mainPkgPath}
runDumpChecks(t, s, moutdir, flags, testpoints)
}
}
// Dump the files in the subtract output dir and examine the result.
- dargs := []string{"-pkg=main", "-live", "-i=" + soutdir}
+ dargs := []string{"-pkg=" + mainPkgPath, "-live", "-i=" + soutdir}
lines = runToolOp(t, s, "debugdump", dargs)
if len(lines) == 0 {
t.Errorf("dump run produced no output")
}
// Dump the files in the subtract output dir and examine the result.
- dargs := []string{"-pkg=main", "-live", "-i=" + ioutdir}
+ dargs := []string{"-pkg=" + mainPkgPath, "-live", "-i=" + ioutdir}
lines = runToolOp(t, s, "debugdump", dargs)
if len(lines) == 0 {
t.Errorf("dump run produced no output")
func testForSpecificFunctions(t *testing.T, dir string, want []string, avoid []string) string {
args := []string{"tool", "covdata", "debugdump",
- "-live", "-pkg=main", "-i=" + dir}
+ "-live", "-pkg=command-line-arguments", "-i=" + dir}
t.Logf("running: go %v\n", args)
cmd := exec.Command(testenv.GoToolPath(t), args...)
b, err := cmd.CombinedOutput()
output := string(b)
rval := ""
for _, f := range want {
- wf := "Func: " + f
+ wf := "Func: " + f + "\n"
if strings.Contains(output, wf) {
continue
}
rval += fmt.Sprintf("error: output should contain %q but does not\n", wf)
}
for _, f := range avoid {
- wf := "Func: " + f
+ wf := "Func: " + f + "\n"
if strings.Contains(output, wf) {
rval += fmt.Sprintf("error: output should not contain %q but does\n", wf)
}
}
+ if rval != "" {
+ t.Logf("=-= begin output:\n" + output + "\n=-= end output\n")
+ }
return rval
}