support garble test in main packages

A main package can be imported in one edge case we weren't testing:
when the same main package has any tests, which implicitly import main.

Before the fix, we would panic:

        > garble test -v ./...
        # test/bar/somemaintest.test
        panic: main packages should never need to obfuscate their import paths
This commit is contained in:
Daniel Martí
2022-11-08 13:35:00 +00:00
committed by lu4p
parent b6a0284f84
commit 416782340f
2 changed files with 16 additions and 2 deletions

View File

@@ -28,12 +28,14 @@ stdout 'package bar_test, func name:'
garble test -v ./...
stdout 'ok\s+test/bar\s'
stdout 'PASS.*TestFoo'
stdout 'PASS.*TestMain'
stdout 'PASS.*TestSeparateFoo'
stdout 'SKIP.*TestWithFlag'
stdout 'package bar, func name:'
stdout 'package bar_test, func name:'
! stdout 'OriginalFuncName'
stdout '\?\s+test/bar/somemain\s'
stdout 'ok\s+test/bar/somemaintest\s'
stdout 'ok\s+test/bar/sometest\s'
stdout 'ok\s+test/bar/exporttest\s'
@@ -120,6 +122,16 @@ func TestMain(m *testing.M) {
package main
func main() {}
-- somemaintest/main.go --
package main
func main() {}
-- somemaintest/main_test.go --
package main
import "testing"
func TestMain(t *testing.T) {}
-- sometest/foo_test.go --
package sometest