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

     1  # This test verifies that issue 56293 has been fixed, and that the
     2  # insertion of coverage instrumentation doesn't perturb package
     3  # initialization order.
     4  
     5  [short] skip
     6  
     7  # Skip if new coverage is turned off.
     8  [!GOEXPERIMENT:coverageredesign] skip
     9  
    10  go test -cover example
    11  
    12  -- go.mod --
    13  module example
    14  
    15  go 1.20
    16  
    17  -- m.go --
    18  
    19  package main
    20  
    21  import (
    22  	"flag"
    23  )
    24  
    25  var (
    26  	fooFlag = flag.String("foo", "", "this should be ok")
    27  	foo     = flag.Lookup("foo")
    28  
    29  	barFlag = flag.String("bar", "", "this should be also ok, but is "+notOK()+".")
    30  	bar     = flag.Lookup("bar")
    31  )
    32  
    33  func notOK() string {
    34  	return "not OK"
    35  }
    36  
    37  -- m_test.go --
    38  
    39  package main
    40  
    41  import (
    42  	"testing"
    43  )
    44  
    45  func TestFoo(t *testing.T) {
    46  	if foo == nil {
    47  		t.Fatal()
    48  	}
    49  }
    50  
    51  func TestBar(t *testing.T) {
    52  	if bar == nil {
    53  		t.Fatal()
    54  	}
    55  }
    56  

View as plain text