github.com/hikaru7719/go@v0.0.0-20181025140707-c8b2ac68906a/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  # Packages found via standard-library vendoring should not leak.
    22  ! go build ./fromstdvendor
    23  stderr 'use of vendored package golang_org/x/net/http/httpguts not allowed'
    24  
    25  env GO111MODULE=off
    26  ! go build ./fromstdvendor
    27  stderr 'cannot find package "golang_org/x/net/http/httpguts" in any of:'
    28  env GO111MODULE=on
    29  
    30  # Dependencies should be able to use their own internal modules...
    31  rm go.mod
    32  go mod init golang.org/notx
    33  go build ./throughdep
    34  
    35  # ... but other modules should not, even if they have transitive dependencies.
    36  ! go build .
    37  stderr 'use of internal package golang.org/x/.* not allowed'
    38  
    39  # And transitive dependencies still should not leak.
    40  ! go build ./baddep
    41  stderr golang.org[/\\]notx[/\\]useinternal
    42  stderr 'use of internal package golang.org/x/.* not allowed'
    43  
    44  # Replacing an internal module should keep it internal to the same paths.
    45  rm go.mod
    46  go mod init golang.org/notx
    47  go mod edit -replace golang.org/x/internal=./replace/golang.org/notx/internal
    48  go build ./throughdep
    49  
    50  ! go build ./baddep
    51  stderr golang.org[/\\]notx[/\\]useinternal
    52  stderr 'use of internal package golang.org/x/.* not allowed'
    53  
    54  go mod edit -replace golang.org/x/internal=./vendor/golang.org/x/internal
    55  go build ./throughdep
    56  
    57  ! go build ./baddep
    58  stderr golang.org[/\\]notx[/\\]useinternal
    59  stderr 'use of internal package golang.org/x/.* not allowed'
    60  
    61  -- useinternal.go --
    62  package useinternal
    63  import _ "golang.org/x/internal/subtle"
    64  
    65  -- useinternal_test.go --
    66  package useinternal_test
    67  import (
    68  	"testing"
    69  	_ "golang.org/x/internal/subtle"
    70  )
    71  
    72  func Test(*testing.T) {}
    73  
    74  -- throughdep/useinternal.go --
    75  package throughdep
    76  import _ "golang.org/x/useinternal"
    77  
    78  -- baddep/useinternal.go --
    79  package baddep
    80  import _ "golang.org/notx/useinternal"
    81  
    82  -- fromstd/useinternal.go --
    83  package fromstd
    84  import _ "internal/testenv"
    85  
    86  -- fromstdvendor/useinternal.go --
    87  package fromstdvendor
    88  import _ "golang_org/x/net/http/httpguts"
    89  
    90  -- replace/golang.org/notx/internal/go.mod --
    91  module golang.org/x/internal
    92  
    93  -- replace/golang.org/notx/internal/subtle/subtle.go --
    94  package subtle
    95  // Ha ha! Nothing here!
    96  
    97  -- vendor/golang.org/x/internal/go.mod --
    98  module golang.org/x/internal
    99  
   100  -- vendor/golang.org/x/internal/subtle/subtle.go --
   101  package subtle
   102  // Ha ha! Nothing here!