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

     1  # Elementary test of each analyzer in the "go fix" suite.
     2  # This is simply to prove that they are running at all;
     3  # detailed behavior is tested in x/tools.
     4  #
     5  # Each assertion matches the expected diff.
     6  #
     7  # Tip: to see the actual stdout,
     8  # temporarily prefix the go command with "! ".
     9  
    10  go fix -diff example.com/x
    11  
    12  # buildtag
    13  stdout '-// \+build go1.26'
    14  
    15  # hostport
    16  stdout 'net.Dial.*net.JoinHostPort'
    17  
    18  # inline
    19  stdout 'var three = 1 \+ 2'
    20  
    21  # newexpr (proxy for whole modernize suite)
    22  stdout 'var _ = new\(123\)'
    23  
    24  -- go.mod --
    25  module example.com/x
    26  go 1.26
    27  
    28  -- x.go --
    29  //go:build go1.26
    30  // +build go1.26
    31  
    32  // ↑ buildtag
    33  
    34  package x
    35  
    36  import (
    37  	"fmt"
    38  	"net"
    39  )
    40  
    41  // hostport
    42  var s string
    43  var _, _ = net.Dial("tcp", fmt.Sprintf("%s:%d", s, 80))
    44  
    45  //go:fix inline
    46  func add(x, y int) int { return x + y }
    47  
    48  // inline
    49  var three = add(1, 2)
    50  
    51  // newexpr
    52  func varOf(x int) *int { return &x }
    53  var _ = varOf(123)
    54  

View as plain text