...

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

Documentation: cmd/go/testdata/script

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

View as plain text