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

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

View as plain text