• Caleb Spare's avatar
    cmd/go: move automatic testing.Init call into generated test code · 49a1a01b
    Caleb Spare authored
    In CL 173722, we moved the flag registration in the testing package into
    an Init function. In order to avoid needing changes to user code, we
    called Init automatically as part of testing.MainStart.
    
    However, that isn't early enough if flag.Parse is called before the
    tests run, as part of package initialization.
    
    Fix this by injecting a bit of code to call testing.Init into test
    packages. This runs before any other initialization code in the user's
    test package, so testing.Init will be called before any user code can
    call flag.Parse.
    
    Fixes #31859
    
    Change-Id: Ib42cd8d3819150c49a3cecf7eef2472319d0c7e9
    Reviewed-on: https://go-review.googlesource.com/c/go/+/176098
    Run-TryBot: Caleb Spare <cespare@gmail.com>
    TryBot-Result: Gobot Gobot <gobot@golang.org>
    Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
    49a1a01b
testing.go 44.5 KB