Files
garble/testdata/script/tiny.txtar
Daniel Martí 65ffaa0efb stop ignoring GODEBUG when -tiny is used
GODEBUG started being used for configuring the behavior of the Go
toolchain and standard library, for the sake of smoother transitions
in terms of backwards and forwards compatibility.
See: https://go.dev/doc/godebug

As such, it is not right to have `garble build -tiny` ignore all
GODEBUG settings, because many GODEBUG keys nowadays do not actually
involve debugging what a Go binary is doing.

Moreover, the mechanism we were using broke with Go 1.25.2,
which refactored `func parsedebugvars()` into
`func parseRuntimeDebugVars(godebug string)`,
so our test started breaking as our runtime patching was broken.
2025-10-18 06:42:52 +02:00

72 lines
1.8 KiB
Plaintext

# Tiny mode
exec garble -tiny build
! binsubstr main$exe 'garble_main.go' 'fmt/print.go'
! exec ./main$exe
stderr '^\(0x[[:xdigit:]]+,0x[[:xdigit:]]+\)' # interfaces/pointers print correctly
# With -tiny, all line numbers are reset to 1.
# Unfortunately, line comment directives don't allow erasing line numbers entirely.
stderr '^caller: \?\? 1$' # position info is removed
stderr '^recovered: ya like jazz?'
! stderr 'panic: oh noes' # panics are hidden
stderr 'funcExported false funcUnexported true'
stderr 'funcStructExported false funcStructUnexported true'
[short] stop # no need to verify this with -short
# Default mode
exec garble build
! exec ./main$exe
stderr '^caller: [[:word:]]+\.go [1-9]'
stderr '^recovered: ya like jazz?'
stderr 'panic: oh noes'
stderr 'funcExported false funcUnexported false'
stderr 'funcStructExported false funcStructUnexported false'
-- go.mod --
module test/main
go 1.23
-- garble_main.go --
package main
import (
"reflect"
"runtime"
)
type testStruct struct{}
func (testStruct) unexportedFunc() { println("dummy") }
func (testStruct) ExportedFunc() { println("dummy") }
func ExportedFunc() { println("dummy") }
func unexportedFunc() { println("dummy") }
func isEmptyFuncName(i interface{}) bool {
name := runtime.FuncForPC(reflect.ValueOf(i).Pointer()).Name()
return len(name) == 0
}
func main() {
println("funcExported", isEmptyFuncName(ExportedFunc), "funcUnexported", isEmptyFuncName(unexportedFunc))
var s testStruct
println("funcStructExported", isEmptyFuncName(s.ExportedFunc), "funcStructUnexported", isEmptyFuncName(s.unexportedFunc))
var v any = "tada"
println(v)
defer func() {
if r := recover(); r != nil {
println("recovered:", r.(string))
panic("oh noes")
}
}()
_, file, line, _ := runtime.Caller(0)
println("caller:", file, line)
panic("ya like jazz?")
}