mirror of
https://github.com/burrowers/garble.git
synced 2025-12-24 12:58:05 +08:00
The first makes our test scripts more consistent, as all external program executions happen via "exec" and are not as easily confused with custom builtin commands like our "generate-literals". The second catches mistakes if any of our txtar files have duplicate files, where all but one of the contents would be ignored before.
96 lines
1.3 KiB
Plaintext
96 lines
1.3 KiB
Plaintext
exec garble build
|
|
exec ./main
|
|
cmp stdout main.stdout
|
|
|
|
! binsubstr main$exe 'unexportedMethod' 'privateIface'
|
|
|
|
[short] stop # no need to verify this with -short
|
|
|
|
# Check that the program works as expected without garble.
|
|
go build
|
|
exec ./main
|
|
cmp stdout main.stdout
|
|
-- go.mod --
|
|
module test/main
|
|
|
|
go 1.20
|
|
-- main.go --
|
|
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"test/main/lib1"
|
|
"test/main/lib2"
|
|
"test/main/lib3"
|
|
)
|
|
|
|
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("")
|
|
|
|
type StructUnnamed = struct {
|
|
Foo int
|
|
Bar struct {
|
|
Nested *[]string
|
|
}
|
|
lib3.StructEmbed
|
|
}
|
|
|
|
var _ = lib1.Struct1(lib2.Struct2{})
|
|
|
|
var _ = StructUnnamed(lib2.Struct2{})
|
|
|
|
func main() {
|
|
fmt.Println(T("foo"))
|
|
fmt.Println(T("foo").unexportedMethod())
|
|
}
|
|
-- lib1/lib1.go --
|
|
package lib1
|
|
|
|
import "test/main/lib3"
|
|
|
|
type Struct1 struct {
|
|
Foo int
|
|
Bar struct {
|
|
Nested *[]string
|
|
}
|
|
lib3.StructEmbed
|
|
}
|
|
|
|
-- lib2/lib2.go --
|
|
package lib2
|
|
|
|
import "test/main/lib3"
|
|
|
|
type Struct2 struct {
|
|
Foo int
|
|
Bar struct {
|
|
Nested *[]string
|
|
}
|
|
lib3.StructEmbed
|
|
}
|
|
-- lib3/lib3.go --
|
|
package lib3
|
|
|
|
type StructEmbed struct {
|
|
Baz any
|
|
}
|
|
-- main.stdout --
|
|
String method for foo
|
|
unexported method for foo
|