Skip to content

Commit

Permalink
fix test flake in reverse.txt
Browse files Browse the repository at this point in the history
Just ran into this failure while fixing a different bug:

	> ! grep 'ExportedLib(Type|Field)|unexportedMainFunc|test/main|main\.go|lib\.go' main.stderr
	[main.stderr]
	lib filename: A4Spnz0u.go

	goroutine 1 [running]:
	runtime/debug.Stack(...)
		runtime/debug/stack.go:24 +0x??
	kso0S_A6.at6JKzwa(...)
		p8_ovZPW.go:1 +0x??
	kso0S_A6.(*JKArRn6w).ExportedLibMethod(...)
		h4JncykI.go:1 +0x??
	main.cQXA3D6d.func1(...)
		FaQ2WcAJ.go:1
	main.cQXA3D6d(...)
		T7Ztgy1Q.go:1 +0x??
	main.main(...)
		OHzKYhm3.go:1 +0x??

	main filename: Myi8glib.go

	FAIL: testdata/scripts/reverse.txt:16: unexpected match for `ExportedLib(Type|Field)|unexportedMainFunc|test/main|main\.go|lib\.go` found in main.stderr: lib.go

Note that "main.go" ended up obfuscated as "Myi8glib.go",
which just so happens to match against "lib.go".

Use longer filenames, so that the chances of collisions are near-zero.
  • Loading branch information
mvdan authored and capnspacehook committed Jan 10, 2022
1 parent ff80300 commit d8e5351
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions testdata/scripts/reverse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ cp stderr main.stderr
# so we can't use a static golden file.
grep 'goroutine 1 \[running\]' main.stderr
# Note that ExportedLibMethod isn't obfuscated.
! grep 'ExportedLib(Type|Field)|unexportedMainFunc|test/main|main\.go|lib\.go' main.stderr
# Note that we use long names like "long_lib.go",
# because an obfuscated filename could realistically end with "lib".
! grep 'ExportedLib(Type|Field)|unexportedMainFunc|test/main|long_main\.go|long_lib\.go' main.stderr

stdin main.stderr
garble reverse .
Expand Down Expand Up @@ -53,7 +55,7 @@ cmp stdout main-literals.stderr
module test/main

go 1.17
-- main.go --
-- long_main.go --
package main

import (
Expand All @@ -80,7 +82,7 @@ func unexportedMainFunc() {
}
anonFunc()
}
-- lib/lib.go --
-- lib/long_lib.go --
package lib

import (
Expand Down Expand Up @@ -138,23 +140,23 @@ var _ = reflect.TypeOf(UnobfuscatedStruct{})

var _ = struct{SomeField int}(UnobfuscatedStruct{})
-- reverse.stdout --
lib filename: test/main/lib/lib.go
lib filename: test/main/lib/long_lib.go

goroutine 1 [running]:
runtime/debug.Stack(...)
runtime/debug/stack.go:24 +0x??
test/main/lib.printStackTrace(...)
test/main/lib/lib.go:32 +0x??
test/main/lib/long_lib.go:32 +0x??
test/main/lib.(*ExportedLibType).ExportedLibMethod(...)
test/main/lib/lib.go:19 +0x??
test/main/lib/long_lib.go:19 +0x??
main.unexportedMainFunc.func1(...)
test/main/main.go:21
test/main/long_main.go:21
main.unexportedMainFunc(...)
test/main/main.go:25 +0x??
test/main/long_main.go:25 +0x??
main.main(...)
test/main/main.go:11 +0x??
test/main/long_main.go:11 +0x??

main filename: test/main/main.go
main filename: test/main/long_main.go
-- build-error-reverse.stdout-go1.17 --
# test/main/build-error
test/main/build-error/error.go:18: cannot convert UnobfuscatedStruct{} (type UnobfuscatedStruct) to type struct { SomeField int }
Expand Down

0 comments on commit d8e5351

Please sign in to comment.