github.com/zxy12/go_duplicate_112_new@v0.0.0-20200807091221-747231827200/src/cmd/go/testdata/script/mod_internal.txt (about)

     1  env GO111MODULE=on
     2  
     3  # golang.org/x/internal should be importable from other golang.org/x modules.
     4  rm go.mod
     5  go mod init 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  rm go.mod
    23  go mod init golang.org/notx
    24  go build ./throughdep
    25  
    26  # ... but other modules should not, even if they have transitive dependencies.
    27  ! go build .
    28  stderr 'use of internal package golang.org/x/.* not allowed'
    29  
    30  # And transitive dependencies still should not leak.
    31  ! go build ./baddep
    32  stderr golang.org[/\\]notx[/\\]useinternal
    33  stderr 'use of internal package golang.org/x/.* not allowed'
    34  
    35  # Replacing an internal module should keep it internal to the same paths.
    36  rm go.mod
    37  go mod init golang.org/notx
    38  go mod edit -replace golang.org/x/internal=./replace/golang.org/notx/internal
    39  go build ./throughdep
    40  
    41  ! go build ./baddep
    42  stderr golang.org[/\\]notx[/\\]useinternal
    43  stderr 'use of internal package golang.org/x/.* not allowed'
    44  
    45  go mod edit -replace golang.org/x/internal=./vendor/golang.org/x/internal
    46  go build ./throughdep
    47  
    48  ! go build ./baddep
    49  stderr golang.org[/\\]notx[/\\]useinternal
    50  stderr 'use of internal package golang.org/x/.* not allowed'
    51  
    52  -- useinternal.go --
    53  package useinternal
    54  import _ "golang.org/x/internal/subtle"
    55  
    56  -- useinternal_test.go --
    57  package useinternal_test
    58  import (
    59  	"testing"
    60  	_ "golang.org/x/internal/subtle"
    61  )
    62  
    63  func Test(*testing.T) {}
    64  
    65  -- throughdep/useinternal.go --
    66  package throughdep
    67  import _ "golang.org/x/useinternal"
    68  
    69  -- baddep/useinternal.go --
    70  package baddep
    71  import _ "golang.org/notx/useinternal"
    72  
    73  -- fromstd/useinternal.go --
    74  package fromstd
    75  import _ "internal/testenv"
    76  
    77  -- replace/golang.org/notx/internal/go.mod --
    78  module golang.org/x/internal
    79  
    80  -- replace/golang.org/notx/internal/subtle/subtle.go --
    81  package subtle
    82  // Ha ha! Nothing here!
    83  
    84  -- vendor/golang.org/x/internal/go.mod --
    85  module golang.org/x/internal
    86  
    87  -- vendor/golang.org/x/internal/subtle/subtle.go --
    88  package subtle
    89  // Ha ha! Nothing here!