{"action":"created","issue":{"url":"https://api.github.com/repos/bazelbuild/rules_go/issues/1451","repository_url":"https://api.github.com/repos/bazelbuild/rules_go","labels_url":"https://api.github.com/repos/bazelbuild/rules_go/issues/1451/labels{/name}","comments_url":"https://api.github.com/repos/bazelbuild/rules_go/issues/1451/comments","events_url":"https://api.github.com/repos/bazelbuild/rules_go/issues/1451/events","html_url":"https://github.com/bazelbuild/rules_go/issues/1451","id":315542695,"number":1451,"title":"A file with a TestMain() and no Test() results in a compilation error.","user":{"login":"liztio","id":33235082,"avatar_url":"https://avatars0.githubusercontent.com/u/33235082?v=4","gravatar_id":"","url":"https://api.github.com/users/liztio","html_url":"https://github.com/liztio","followers_url":"https://api.github.com/users/liztio/followers","following_url":"https://api.github.com/users/liztio/following{/other_user}","gists_url":"https://api.github.com/users/liztio/gists{/gist_id}","starred_url":"https://api.github.com/users/liztio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/liztio/subscriptions","organizations_url":"https://api.github.com/users/liztio/orgs","repos_url":"https://api.github.com/users/liztio/repos","events_url":"https://api.github.com/users/liztio/events{/privacy}","received_events_url":"https://api.github.com/users/liztio/received_events","type":"User","site_admin":false},"labels":[{"id":342021202,"url":"https://api.github.com/repos/bazelbuild/rules_go/labels/bug","name":"bug","color":"fc2929","default":true},{"id":668667257,"url":"https://api.github.com/repos/bazelbuild/rules_go/labels/rules","name":"rules","color":"0e8a16","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-18T15:58:54Z","updated_at":"2018-04-18T17:50:55Z","closed_at":null,"author_association":"NONE","body":"I had a file that looked like this: \r\n\r\n```go\r\npackage e2e_kubeadm\r\n\r\nimport (\r\n\t\"flag\"\r\n\t\"os\"\r\n\t\"testing\"\r\n\r\n\t\"github.com/spf13/pflag\"\r\n\t\"k8s.io/kubernetes/test/e2e/framework\"\r\n)\r\n\r\nfunc init() {\r\n\tframework.RegisterCommonFlags()\r\n\r\n\tpflag.CommandLine.AddGoFlagSet(flag.CommandLine)\r\n}\r\n\r\nfunc TestMain(m *testing.M) {\r\n\tpflag.Parse()\r\n\tframework.AfterReadingAllFlags(&framework.TestContext)\r\n\tos.Exit(m.Run())\r\n}\r\n```\r\n\r\nBut if failed to compile: \r\n```\r\n/private/var/tmp/_bazel_liz/aaf126f19606a5dec6111ea1f19477ba/bazel-sandbox/3918368524966085086/execroot/__main__/bazel-out/darwin-fastbuild/bin/test/e2e_kubeadm/darwin_amd64_stripped/go_default_test~/testmain.go:109:2: undefined: l\r\n```\r\n\r\nThat file looks like \r\n```go\r\npackage main\r\nimport (\r\n\t\"flag\"\r\n\t\"log\"\r\n\t\"os\"\r\n\t\"fmt\"\r\n\t\"strconv\"\r\n\t\"testing\"\r\n\t\"testing/internal/testdeps\"\r\n\r\n\r\n\r\n\r\n)\r\n\r\nvar allTests = []testing.InternalTest{\r\n\r\n}\r\n\r\nvar benchmarks = []testing.InternalBenchmark{\r\n\r\n}\r\n\r\nvar examples = []testing.InternalExample{\r\n\r\n}\r\n\r\nfunc testsInShard() []testing.InternalTest {\r\n\ttotalShards, err := strconv.Atoi(os.Getenv(\"TEST_TOTAL_SHARDS\"))\r\n\tif err != nil || totalShards <= 1 {\r\n\t\treturn allTests\r\n\t}\r\n\tshardIndex, err := strconv.Atoi(os.Getenv(\"TEST_SHARD_INDEX\"))\r\n\tif err != nil || shardIndex < 0 {\r\n\t\treturn allTests\r\n\t}\r\n\ttests := []testing.InternalTest{}\r\n\tfor i, t := range allTests {\r\n\t\tif i % totalShards == shardIndex {\r\n\t\t\ttests = append(tests, t)\r\n\t\t}\r\n\t}\r\n\treturn tests\r\n}\r\n\r\nfunc coverRegisterAll() testing.Cover {\r\n\tcoverage := testing.Cover{\r\n\t\tMode: \"set\",\r\n\t\tCoveredPackages: \"\",\r\n\t\tCounters: map[string][]uint32{},\r\n\t\tBlocks: map[string][]testing.CoverBlock{},\r\n\t}\r\n\r\n\treturn coverage\r\n}\r\n\r\nfunc coverRegisterFile(coverage *testing.Cover, fileName string, counter []uint32, pos []uint32, numStmts []uint16) {\r\n\tif 3*len(counter) != len(pos) || len(counter) != len(numStmts) {\r\n\t\tpanic(\"coverage: mismatched sizes\")\r\n\t}\r\n\tif coverage.Counters[fileName] != nil {\r\n\t\t// Already registered.\r\n\t\tfmt.Printf(\"Already covered %s\\n\", fileName)\r\n\t\treturn\r\n\t}\r\n\tcoverage.Counters[fileName] = counter\r\n\tblock := make([]testing.CoverBlock, len(counter))\r\n\tfor i := range counter {\r\n\t\tblock[i] = testing.CoverBlock{\r\n\t\t\tLine0: pos[3*i+0],\r\n\t\t\tCol0: uint16(pos[3*i+2]),\r\n\t\t\tLine1: pos[3*i+1],\r\n\t\t\tCol1: uint16(pos[3*i+2]>>16),\r\n\t\t\tStmts: numStmts[i],\r\n\t\t}\r\n\t}\r\n\tcoverage.Blocks[fileName] = block\r\n}\r\n\r\nfunc main() {\r\n\t// Check if we're being run by Bazel and change directories if so.\r\n\t// TEST_SRCDIR is set by the Bazel test runner, so that makes a decent proxy.\r\n\tif _, ok := os.LookupEnv(\"TEST_SRCDIR\"); ok {\r\n\t\tif err := os.Chdir(\"test/e2e_kubeadm\"); err != nil {\r\n\t\t\tlog.Fatalf(\"could not change to test directory: %v\", err)\r\n\t\t}\r\n\t}\r\n\r\n\tif filter := os.Getenv(\"TESTBRIDGE_TEST_ONLY\"); filter != \"\" {\r\n\t\tif f := flag.Lookup(\"test.run\"); f != nil {\r\n\t\t\tf.Value.Set(filter)\r\n\t\t}\r\n\t}\r\n\r\n\tcoverage := coverRegisterAll()\r\n\tif len(coverage.Counters) > 0 {\r\n\t\ttesting.RegisterCover(coverage)\r\n\t}\r\n\r\n\tif coverageDat, ok := os.LookupEnv(\"COVERAGE_OUTPUT_FILE\"); ok {\r\n\t\tif testing.CoverMode() != \"\" {\r\n\t\t\tflag.Lookup(\"test.coverprofile\").Value.Set(coverageDat)\r\n\t\t}\r\n\t}\r\n\r\n\tm := testing.MainStart(testdeps.TestDeps{}, testsInShard(), benchmarks, examples)\r\n\t\r\n\tl.TestMain(m)\r\n\t\r\n}\r\n```\r\n\r\nThe `l` in `l.TestMain` should be imported by generate_test_main, but the file is never included unless it also has a regular Test* case."},"comment":{"url":"https://api.github.com/repos/bazelbuild/rules_go/issues/comments/382472836","html_url":"https://github.com/bazelbuild/rules_go/issues/1451#issuecomment-382472836","issue_url":"https://api.github.com/repos/bazelbuild/rules_go/issues/1451","id":382472836,"user":{"login":"jayconrod","id":164791,"avatar_url":"https://avatars3.githubusercontent.com/u/164791?v=4","gravatar_id":"","url":"https://api.github.com/users/jayconrod","html_url":"https://github.com/jayconrod","followers_url":"https://api.github.com/users/jayconrod/followers","following_url":"https://api.github.com/users/jayconrod/following{/other_user}","gists_url":"https://api.github.com/users/jayconrod/gists{/gist_id}","starred_url":"https://api.github.com/users/jayconrod/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jayconrod/subscriptions","organizations_url":"https://api.github.com/users/jayconrod/orgs","repos_url":"https://api.github.com/users/jayconrod/repos","events_url":"https://api.github.com/users/jayconrod/events{/privacy}","received_events_url":"https://api.github.com/users/jayconrod/received_events","type":"User","site_admin":false},"created_at":"2018-04-18T17:50:55Z","updated_at":"2018-04-18T17:50:55Z","author_association":"CONTRIBUTOR","body":"Thanks for reporting! #1452 should fix this."}}
{"actor":{"display_login":"jayconrod"}}