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