Skip to content

Commit

Permalink
testdata: make pointer regexp less prone to flakes
Browse files Browse the repository at this point in the history
Pointers are of the form "0x" and a number of hex characters.
Those are all part of the obfuscated filename alphabet,
so if we're unlucky enough, we can get hits:

	> cmp stdout reverse.stdout
	--- stdout
	+++ reverse.stdout
	@@ -4,7 +4,7 @@
	 runtime/debug.Stack(...)
		runtime/debug/stack.go:24 +0x??
	 test/main/lib.printStackTrace(...)
	-	pv0x??mRa.go:1 +0x??
	+	test/main/lib/long_lib.go:32 +0x??
	 test/main/lib.(*ExportedLibType).ExportedLibMethod(...)
		test/main/lib/long_lib.go:19 +0x??
	 main.unexportedMainFunc.func1(...)

Include the plus sign in the regular expression,
which is used for showing pointers but isn't part of our alphabet.
  • Loading branch information
mvdan authored and lu4p committed Jan 12, 2022
1 parent d25e718 commit 716f007
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions testdata/scripts/reverse.txt
Expand Up @@ -110,13 +110,13 @@ func printStackTrace(w io.Writer) error {
// The format also changes depending on the ABI.
// Strip them out here, to have portable static stdout files.
rxCallArgs := regexp.MustCompile(`\(({|0x)[^)]+\)|\(\)`)
rxPointer := regexp.MustCompile(`0x[0-9a-f]+`)
rxPointer := regexp.MustCompile(`\+0x[0-9a-f]+`)

// Keep this comment here, because comments affect line numbers.

stack := debug.Stack()
stack = rxCallArgs.ReplaceAll(stack, []byte("(...)"))
stack = rxPointer.ReplaceAll(stack, []byte("0x??"))
stack = rxPointer.ReplaceAll(stack, []byte("+0x??"))
_, err := w.Write(stack)
return err
}
Expand Down

0 comments on commit 716f007

Please sign in to comment.