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

     1  # Test support for declaring needed Go version in module.
     2  
     3  env GO111MODULE=on
     4  
     5  go list
     6  go build
     7  go build sub.1
     8  go build subver.1
     9  ! stderr 'module requires'
    10  ! go build badsub.1
    11  stderr '^note: module requires Go 1.11111$'
    12  
    13  go build versioned.1
    14  go mod edit -require versioned.1@v1.1.0
    15  ! go build versioned.1
    16  stderr '^note: module requires Go 1.99999$'
    17  
    18  [short] stop
    19  
    20  # The message should be printed even if the compiler emits no output.
    21  go build -o $WORK/nooutput.exe nooutput.go
    22  ! go build -toolexec=$WORK/nooutput.exe versioned.1
    23  stderr '^# versioned.1\nnote: module requires Go 1.99999$'
    24  
    25  -- go.mod --
    26  module m
    27  go 1.999
    28  require (
    29  	sub.1 v1.0.0
    30  	subver.1 v1.0.0
    31  	badsub.1 v1.0.0
    32  	versioned.1 v1.0.0
    33  )
    34  replace (
    35  	sub.1 => ./sub
    36  	subver.1 => ./subver
    37  	badsub.1 => ./badsub
    38  	versioned.1 v1.0.0 => ./versioned1
    39  	versioned.1 v1.1.0 => ./versioned2
    40  )
    41  
    42  -- x.go --
    43  package x
    44  
    45  -- sub/go.mod --
    46  module m
    47  go 1.11
    48  
    49  -- sub/x.go --
    50  package x
    51  
    52  -- subver/go.mod --
    53  module m
    54  go 1.11111
    55  
    56  -- subver/x.go --
    57  package x
    58  
    59  -- badsub/go.mod --
    60  module m
    61  go 1.11111
    62  
    63  -- badsub/x.go --
    64  package x
    65  invalid syntax
    66  
    67  -- versioned1/go.mod --
    68  module versioned
    69  go 1.0
    70  
    71  -- versioned1/x.go --
    72  package x
    73  
    74  -- versioned2/go.mod --
    75  module versioned
    76  go 1.99999
    77  
    78  -- versioned2/x.go --
    79  package x
    80  invalid syntax
    81  
    82  -- nooutput.go --
    83  // +build ignore
    84  
    85  package main
    86  
    87  import (
    88  	"bytes"
    89  	"os"
    90  	"os/exec"
    91  	"strings"
    92  )
    93  
    94  func main() {
    95  	stderr := new(bytes.Buffer)
    96  	stdout := new(bytes.Buffer)
    97  
    98  	cmd := exec.Command(os.Args[1], os.Args[2:]...)
    99  	cmd.Stderr = stderr
   100  	cmd.Stdout = stdout
   101  
   102  	err := cmd.Run()
   103  	if strings.HasPrefix(os.Args[2], "-V") {
   104  		os.Stderr.Write(stderr.Bytes())
   105  		os.Stdout.Write(stdout.Bytes())
   106  	}
   107  	if err != nil {
   108  		os.Exit(1)
   109  	}
   110  }
   111  

View as plain text