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

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

View as plain text