...

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

Documentation: cmd/go/testdata/script

     1env GO111MODULE=off
     2
     3# Test that you cannot import a main package.
     4# See golang.org/issue/4210 and golang.org/issue/17475.
     5
     6[short] skip
     7cd $WORK
     8
     9# Importing package main from that package main's test should work.
    10go build x
    11go test -c x
    12
    13# Importing package main from another package should fail.
    14! go build p1
    15stderr 'import "x" is a program, not an importable package'
    16
    17# ... even in that package's test.
    18go build p2
    19! go test -c p2
    20stderr 'import "x" is a program, not an importable package'
    21
    22# ... even if that package's test is an xtest.
    23go build p3
    24! go test p3
    25stderr 'import "x" is a program, not an importable package'
    26
    27# ... even if that package is a package main
    28go build p4
    29! go test -c p4
    30stderr 'import "x" is a program, not an importable package'
    31
    32# ... even if that package is a package main using an xtest.
    33go build p5
    34! go test -c p5
    35stderr 'import "x" is a program, not an importable package'
    36
    37-- x/main.go --
    38package main
    39
    40var X int
    41
    42func main() {}
    43-- x/main_test.go --
    44package main_test
    45
    46import (
    47	"testing"
    48	xmain "x"
    49)
    50
    51var _ = xmain.X
    52
    53func TestFoo(t *testing.T) {}
    54-- p1/p.go --
    55package p1
    56
    57import xmain "x"
    58
    59var _ = xmain.X
    60-- p2/p.go --
    61package p2
    62-- p2/p_test.go --
    63package p2
    64
    65import (
    66	"testing"
    67	xmain "x"
    68)
    69
    70var _ = xmain.X
    71
    72func TestFoo(t *testing.T) {}
    73-- p3/p.go --
    74package p
    75-- p3/p_test.go --
    76package p_test
    77
    78import (
    79	"testing"
    80	xmain "x"
    81)
    82
    83var _ = xmain.X
    84
    85func TestFoo(t *testing.T) {}
    86-- p4/p.go --
    87package main
    88
    89func main() {}
    90-- p4/p_test.go --
    91package main
    92
    93import (
    94	"testing"
    95	xmain "x"
    96)
    97
    98var _ = xmain.X
    99
   100func TestFoo(t *testing.T) {}
   101-- p5/p.go --
   102package main
   103func main() {}
   104-- p5/p_test.go --
   105package main_test
   106
   107import (
   108	"testing"
   109	xmain "x"
   110)
   111
   112var _ = xmain.X
   113
   114func TestFoo(t *testing.T) {}

View as plain text