mirror of
https://github.com/burrowers/garble.git
synced 2025-12-24 12:58:05 +08:00
basic.txt just builds main.go without a module. Similarly, we leave imports.txt without a GOPRIVATE, to test the 'go list -m' fallback. For all other tests, explicitly set GOPRIVATE, to avoid two exec calls - both 'go env GOPRIVATE' as well as 'go list -m'. Each of those calls takes in the order of 10ms, so saving ~26 exec calls should easily add to 200-300ms saved from 'go test -short'.
60 lines
1.1 KiB
Plaintext
60 lines
1.1 KiB
Plaintext
env GOPRIVATE=test/main
|
|
|
|
garble build
|
|
exec ./main
|
|
cmp stderr main.stderr
|
|
|
|
! binsubstr main$exe 'unexportedMethod' 'privateIface'
|
|
|
|
-- go.mod --
|
|
module test/main
|
|
-- main.go --
|
|
package main
|
|
|
|
import "test/main/tinyfmt"
|
|
|
|
type T string
|
|
|
|
func (t T) String() string {
|
|
return "String method for " + string(t)
|
|
}
|
|
|
|
func (t T) unexportedMethod() string {
|
|
return "unexported method for " + string(t)
|
|
}
|
|
|
|
type privateInterface interface {
|
|
privateIface()
|
|
}
|
|
|
|
func (T) privateIface() {}
|
|
|
|
var _ privateInterface = T("")
|
|
|
|
func main() {
|
|
tinyfmt.Println(T("foo"))
|
|
tinyfmt.Println(T("foo").unexportedMethod())
|
|
}
|
|
-- tinyfmt/fmt.go --
|
|
package tinyfmt
|
|
|
|
// Println emulates fmt.Println, and allows the main package to indirectly use
|
|
// T.String in a realistic way. We don't want to import fmt to avoid compiling
|
|
// too many packages, since we don't have build caching yet.
|
|
func Println(args ...interface{}) {
|
|
for _, arg := range args {
|
|
switch arg := arg.(type) {
|
|
case interface{String() string}:
|
|
print(arg.String())
|
|
case string:
|
|
print(arg)
|
|
default:
|
|
panic("unsupported type")
|
|
}
|
|
}
|
|
println()
|
|
}
|
|
-- main.stderr --
|
|
String method for foo
|
|
unexported method for foo
|