...

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

Documentation: cmd/go/testdata/script

     1! go work init doesnotexist
     2stderr 'go: directory doesnotexist does not exist'
     3go env GOWORK
     4! stdout .
     5
     6go work init ./a ./b
     7cmpenv go.work go.work.want
     8go env GOWORK
     9stdout '^'$WORK'(\\|/)gopath(\\|/)src(\\|/)go.work$'
    10
    11! go run  example.com/b
    12stderr 'a(\\|/)a.go:4:8: no required module provides package rsc.io/quote; to add it:\n\tcd '$WORK(\\|/)gopath(\\|/)src(\\|/)a'\n\tgo get rsc.io/quote'
    13cd a
    14go get rsc.io/quote
    15cat go.mod
    16go env GOMOD # go env GOMOD reports the module in a single module context
    17stdout $GOPATH(\\|/)src(\\|/)a(\\|/)go.mod
    18cd ..
    19go run example.com/b
    20stdout 'Hello, world.'
    21
    22# And try from a different directory
    23cd c
    24go run  example.com/b
    25stdout 'Hello, world.'
    26cd $GOPATH/src
    27
    28go list all # all includes both modules
    29stdout 'example.com/a'
    30stdout 'example.com/b'
    31
    32# -mod can only be set to readonly in workspace mode
    33go list -mod=readonly all
    34! go list -mod=mod all
    35stderr '^go: -mod may only be set to readonly or vendor when in workspace mode'
    36env GOWORK=off
    37go list -mod=mod all
    38env GOWORK=
    39
    40# Test that duplicates in the use list return an error
    41cp go.work go.work.backup
    42cp go.work.dup go.work
    43! go run example.com/b
    44stderr 'reading go.work: path .* appears multiple times in workspace'
    45cp go.work.backup go.work
    46
    47cp go.work.d go.work
    48go work use # update go version
    49go run example.com/d
    50
    51# Test that we don't run into "newRequirements called with unsorted roots"
    52# panic with unsorted main modules.
    53cp go.work.backwards go.work
    54go work use # update go version
    55go run example.com/d
    56
    57# Test that command-line-arguments work inside and outside modules.
    58# This exercises the code that determines which module command-line-arguments
    59# belongs to.
    60go list ./b/main.go
    61env GOWORK=off
    62go build -n -o foo foo.go
    63env GOWORK=
    64go build -n -o foo foo.go
    65
    66-- go.work.dup --
    67go 1.18
    68
    69use (
    70	a
    71	b
    72	../src/a
    73)
    74-- go.work.want --
    75go $goversion
    76
    77use (
    78	./a
    79	./b
    80)
    81-- go.work.d --
    82go 1.18
    83
    84use (
    85	a
    86	b
    87	d
    88)
    89-- a/go.mod --
    90
    91module example.com/a
    92
    93-- a/a.go --
    94package a
    95
    96import "fmt"
    97import "rsc.io/quote"
    98
    99func HelloFromA() {
   100	fmt.Println(quote.Hello())
   101}
   102
   103-- b/go.mod --
   104
   105module example.com/b
   106
   107-- b/main.go --
   108package main
   109
   110import "example.com/a"
   111
   112func main() {
   113	a.HelloFromA()
   114}
   115-- b/lib/hello.go --
   116package lib
   117
   118import "example.com/a"
   119
   120func Hello() {
   121	a.HelloFromA()
   122}
   123
   124-- c/README --
   125Create this directory so we can cd to
   126it and make sure paths are interpreted
   127relative to the go.work, not the cwd.
   128-- d/go.mod --
   129module example.com/d
   130
   131-- d/main.go --
   132package main
   133
   134import "example.com/b/lib"
   135
   136func main() {
   137	lib.Hello()
   138}
   139
   140-- go.work.backwards --
   141go 1.18
   142
   143use (
   144	d
   145	b
   146	a
   147)
   148
   149-- foo.go --
   150package main
   151import "fmt"
   152func main() {
   153	fmt.Println("Hello, World")
   154}

View as plain text