...

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

Documentation: cmd/go/testdata/script

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

View as plain text