...

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

Documentation: cmd/go/testdata/script

     1env GO111MODULE=on
     2
     3cd foo
     4
     5# Testing an explicit source file should use the same import visibility as the
     6# package in the same directory.
     7go list -test -deps
     8go list -test -deps foo_test.go
     9
    10# If the file is inside the main module's vendor directory, it should have
    11# visibility based on the vendor-relative import path.
    12mkdir vendor/example.com/foo
    13cp foo_test.go vendor/example.com/foo
    14go list -test -deps vendor/example.com/foo/foo_test.go
    15
    16# If the file is outside the main module entirely, it should be treated as outside.
    17cp foo_test.go ../foo_test.go
    18! go list -test -deps ../foo_test.go
    19stderr 'use of internal package'
    20
    21-- foo/go.mod --
    22module example.com/foo
    23go 1.12
    24require example.com/internal v0.0.0
    25replace example.com/internal => ../internal
    26
    27-- foo/internal.go --
    28package foo
    29import _ "example.com/internal"
    30
    31-- foo/foo_test.go --
    32package foo_test
    33
    34import (
    35	"testing"
    36	"example.com/internal"
    37)
    38
    39func TestHacksEnabled(t *testing.T) {
    40	if !internal.Hacks {
    41		t.Fatal("hacks not enabled")
    42	}
    43}
    44
    45-- internal/go.mod --
    46module example.com/internal
    47
    48-- internal/internal.go --
    49package internal
    50const Hacks = true

View as plain text