github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/testdata/script/mod_internal.txt (about)

     1  env GO111MODULE=on
     2  [short] skip
     3  
     4  # golang.org/x/internal should be importable from other golang.org/x modules.
     5  go mod edit -module=golang.org/x/anything
     6  go build .
     7  
     8  # ...and their tests...
     9  go test
    10  stdout PASS
    11  
    12  # ...but that should not leak into other modules.
    13  ! go build ./baddep
    14  stderr golang.org[/\\]notx[/\\]useinternal
    15  stderr 'use of internal package golang.org/x/.* not allowed'
    16  
    17  # Internal packages in the standard library should not leak into modules.
    18  ! go build ./fromstd
    19  stderr 'use of internal package internal/testenv not allowed'
    20  
    21  # Dependencies should be able to use their own internal modules...
    22  go mod edit -module=golang.org/notx
    23  go build ./throughdep
    24  
    25  # ... but other modules should not, even if they have transitive dependencies.
    26  ! go build .
    27  stderr 'use of internal package golang.org/x/.* not allowed'
    28  
    29  # And transitive dependencies still should not leak.
    30  ! go build ./baddep
    31  stderr golang.org[/\\]notx[/\\]useinternal
    32  stderr 'use of internal package golang.org/x/.* not allowed'
    33  
    34  # Replacing an internal module should keep it internal to the same paths.
    35  go mod edit -module=golang.org/notx
    36  go mod edit -replace golang.org/x/internal=./replace/golang.org/notx/internal
    37  go build ./throughdep
    38  
    39  ! go build ./baddep
    40  stderr golang.org[/\\]notx[/\\]useinternal
    41  stderr 'use of internal package golang.org/x/.* not allowed'
    42  
    43  go mod edit -replace golang.org/x/internal=./vendor/golang.org/x/internal
    44  go build ./throughdep
    45  
    46  ! go build ./baddep
    47  stderr golang.org[/\\]notx[/\\]useinternal
    48  stderr 'use of internal package golang.org/x/.* not allowed'
    49  
    50  -- go.mod --
    51  module TBD
    52  go 1.12
    53  -- useinternal.go --
    54  package useinternal
    55  import _ "golang.org/x/internal/subtle"
    56  
    57  -- useinternal_test.go --
    58  package useinternal_test
    59  import (
    60  	"testing"
    61  	_ "golang.org/x/internal/subtle"
    62  )
    63  
    64  func Test(*testing.T) {}
    65  
    66  -- throughdep/useinternal.go --
    67  package throughdep
    68  import _ "golang.org/x/useinternal"
    69  
    70  -- baddep/useinternal.go --
    71  package baddep
    72  import _ "golang.org/notx/useinternal"
    73  
    74  -- fromstd/useinternal.go --
    75  package fromstd
    76  import _ "internal/testenv"
    77  
    78  -- replace/golang.org/notx/internal/go.mod --
    79  module golang.org/x/internal
    80  
    81  -- replace/golang.org/notx/internal/subtle/subtle.go --
    82  package subtle
    83  // Ha ha! Nothing here!
    84  
    85  -- vendor/golang.org/x/internal/go.mod --
    86  module golang.org/x/internal
    87  
    88  -- vendor/golang.org/x/internal/subtle/subtle.go --
    89  package subtle
    90  // Ha ha! Nothing here!