From 1178255f8596ea503daf30c84c7c1039f755e7f0 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Thu, 3 Feb 2022 11:50:45 -0500 Subject: all: untab /* */ doc comments A long time ago, gofmt insisted on inserting tabs in /* */ comments at the top level of the file, like this: /* Package doc comment. */ package p Gofmt still insists on the tab for comments not at top level, but it has relaxed the rules about top-level comments. A few very old doc comments are indented, left over from the old rule. We are considering formatting doc comments, and so to make everything consistent, standardize on unindented doc comments by removing tabs in the few doc comments that are still indented this way. Also update some cmd/gofmt testdata to match. Change-Id: I293742e39b52f8a48ec41f72ca4acdafa7ce43bc Reviewed-on: https://go-review.googlesource.com/c/go/+/384261 Trust: Russ Cox Run-TryBot: Russ Cox TryBot-Result: Gopher Robot Reviewed-by: Ian Lance Taylor --- src/runtime/debug/stack_test.go | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src/runtime/debug/stack_test.go') diff --git a/src/runtime/debug/stack_test.go b/src/runtime/debug/stack_test.go index 9376e82b84..4cab8864df 100644 --- a/src/runtime/debug/stack_test.go +++ b/src/runtime/debug/stack_test.go @@ -20,22 +20,22 @@ func (t T) method() []byte { } /* - The traceback should look something like this, modulo line numbers and hex constants. - Don't worry much about the base levels, but check the ones in our own package. +The traceback should look something like this, modulo line numbers and hex constants. +Don't worry much about the base levels, but check the ones in our own package. - goroutine 10 [running]: - runtime/debug.Stack(0x0, 0x0, 0x0) - /Users/r/go/src/runtime/debug/stack.go:28 +0x80 - runtime/debug.(*T).ptrmethod(0xc82005ee70, 0x0, 0x0, 0x0) - /Users/r/go/src/runtime/debug/stack_test.go:15 +0x29 - runtime/debug.T.method(0x0, 0x0, 0x0, 0x0) - /Users/r/go/src/runtime/debug/stack_test.go:18 +0x32 - runtime/debug.TestStack(0xc8201ce000) - /Users/r/go/src/runtime/debug/stack_test.go:37 +0x38 - testing.tRunner(0xc8201ce000, 0x664b58) - /Users/r/go/src/testing/testing.go:456 +0x98 - created by testing.RunTests - /Users/r/go/src/testing/testing.go:561 +0x86d + goroutine 10 [running]: + runtime/debug.Stack(0x0, 0x0, 0x0) + /Users/r/go/src/runtime/debug/stack.go:28 +0x80 + runtime/debug.(*T).ptrmethod(0xc82005ee70, 0x0, 0x0, 0x0) + /Users/r/go/src/runtime/debug/stack_test.go:15 +0x29 + runtime/debug.T.method(0x0, 0x0, 0x0, 0x0) + /Users/r/go/src/runtime/debug/stack_test.go:18 +0x32 + runtime/debug.TestStack(0xc8201ce000) + /Users/r/go/src/runtime/debug/stack_test.go:37 +0x38 + testing.tRunner(0xc8201ce000, 0x664b58) + /Users/r/go/src/testing/testing.go:456 +0x98 + created by testing.RunTests + /Users/r/go/src/testing/testing.go:561 +0x86d */ func TestStack(t *testing.T) { b := T(0).method() -- cgit v1.3 From c6244b59095a74b77c977d250708ba1858ae2388 Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Thu, 10 Mar 2022 23:57:57 -0500 Subject: runtime/debug: do not require a GOROOT/src prefix in TestStack When paths are trimmed, the reported file locations begin with the package import path (not GOROOT/src). Updates #51461. Change-Id: Ia6814f970aee11f3d933e75c75136d679d19e220 Reviewed-on: https://go-review.googlesource.com/c/go/+/391815 Trust: Bryan Mills Run-TryBot: Bryan Mills Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot --- src/runtime/debug/stack_test.go | 82 ++++++++++++++++++++++++++++++++++------- 1 file changed, 69 insertions(+), 13 deletions(-) (limited to 'src/runtime/debug/stack_test.go') diff --git a/src/runtime/debug/stack_test.go b/src/runtime/debug/stack_test.go index 4cab8864df..671057c3a0 100644 --- a/src/runtime/debug/stack_test.go +++ b/src/runtime/debug/stack_test.go @@ -5,11 +5,26 @@ package debug_test import ( + "bytes" + "fmt" + "internal/testenv" + "os" + "os/exec" + "path/filepath" + "runtime" . "runtime/debug" "strings" "testing" ) +func TestMain(m *testing.M) { + if os.Getenv("GO_RUNTIME_DEBUG_TEST_DUMP_GOROOT") != "" { + fmt.Println(runtime.GOROOT()) + os.Exit(0) + } + os.Exit(m.Run()) +} + type T int func (t *T) ptrmethod() []byte { @@ -43,23 +58,64 @@ func TestStack(t *testing.T) { if len(lines) < 6 { t.Fatal("too few lines") } + + // If built with -trimpath, file locations should start with package paths. + // Otherwise, file locations should start with a GOROOT/src prefix + // (for whatever value of GOROOT is baked into the binary, not the one + // that may be set in the environment). + fileGoroot := "" + if envGoroot := os.Getenv("GOROOT"); envGoroot != "" { + // Since GOROOT is set explicitly in the environment, we can't be certain + // that it is the same GOROOT value baked into the binary, and we can't + // change the value in-process because runtime.GOROOT uses the value from + // initial (not current) environment. Spawn a subprocess to determine the + // real baked-in GOROOT. + t.Logf("found GOROOT %q from environment; checking embedded GOROOT value", envGoroot) + testenv.MustHaveExec(t) + exe, err := os.Executable() + if err != nil { + t.Fatal(err) + } + cmd := exec.Command(exe) + cmd.Env = append(os.Environ(), "GOROOT=", "GO_RUNTIME_DEBUG_TEST_DUMP_GOROOT=1") + out, err := cmd.Output() + if err != nil { + t.Fatal(err) + } + fileGoroot = string(bytes.TrimSpace(out)) + } else { + // Since GOROOT is not set in the environment, its value (if any) must come + // from the path embedded in the binary. + fileGoroot = runtime.GOROOT() + } + filePrefix := "" + if fileGoroot != "" { + filePrefix = filepath.ToSlash(fileGoroot) + "/src/" + } + n := 0 - frame := func(line, code string) { - check(t, lines[n], code) + frame := func(file, code string) { + t.Helper() + + line := lines[n] + if !strings.Contains(line, code) { + t.Errorf("expected %q in %q", code, line) + } n++ - check(t, lines[n], line) + + line = lines[n] + + wantPrefix := "\t" + filePrefix + file + if !strings.HasPrefix(line, wantPrefix) { + t.Errorf("in line %q, expected prefix %q", line, wantPrefix) + } n++ } n++ - frame("src/runtime/debug/stack.go", "runtime/debug.Stack") - frame("src/runtime/debug/stack_test.go", "runtime/debug_test.(*T).ptrmethod") - frame("src/runtime/debug/stack_test.go", "runtime/debug_test.T.method") - frame("src/runtime/debug/stack_test.go", "runtime/debug_test.TestStack") - frame("src/testing/testing.go", "") -} -func check(t *testing.T, line, has string) { - if !strings.Contains(line, has) { - t.Errorf("expected %q in %q", has, line) - } + frame("runtime/debug/stack.go", "runtime/debug.Stack") + frame("runtime/debug/stack_test.go", "runtime/debug_test.(*T).ptrmethod") + frame("runtime/debug/stack_test.go", "runtime/debug_test.T.method") + frame("runtime/debug/stack_test.go", "runtime/debug_test.TestStack") + frame("testing/testing.go", "") } -- cgit v1.3