...

Text file src/cmd/go/testdata/script/test_buildinfo.txt

Documentation: cmd/go/testdata/script

     1# Ensure buildinfo is populated on test binaries even if they
     2# are not tests for package main. See issue #33976.
     3
     4[short] skip 'invokes go test'
     5
     6go mod init foo
     7go get example.com/version@v1.0.0
     8
     9go test -v
    10stdout '(devel)'
    11stdout 'example.com/version v1.0.0'
    12
    13-- foo_test.go --
    14package foo
    15
    16import (
    17        "runtime/debug"
    18        "testing"
    19
    20        _ "example.com/version"
    21)
    22
    23func TestBuildInfo(t *testing.T) {
    24        info, ok := debug.ReadBuildInfo()
    25        if !ok {
    26                t.Fatal("no debug info")
    27        }
    28        t.Log(info.Main.Version)
    29
    30        for _, d := range info.Deps {
    31                t.Log(d.Path, d.Version)
    32        }
    33}

View as plain text