{"id":15035419,"url":"https://github.com/yudai/go_cover","last_synced_at":"2025-04-10T00:21:31.235Z","repository":{"id":57643176,"uuid":"86122802","full_name":"yudai/go_cover","owner":"yudai","description":"How -coverpkg works when you calculate test coverage","archived":false,"fork":false,"pushed_at":"2017-03-25T01:20:28.000Z","size":1,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-24T02:05:18.043Z","etag":null,"topics":["coverage","golang","testing"],"latest_commit_sha":null,"homepage":null,"language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yudai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-03-25T01:00:44.000Z","updated_at":"2024-12-15T12:54:28.000Z","dependencies_parsed_at":"2022-08-27T23:22:50.223Z","dependency_job_id":null,"html_url":"https://github.com/yudai/go_cover","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudai%2Fgo_cover","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudai%2Fgo_cover/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudai%2Fgo_cover/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yudai%2Fgo_cover/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yudai","download_url":"https://codeload.github.com/yudai/go_cover/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248132122,"owners_count":21052977,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["coverage","golang","testing"],"created_at":"2024-09-24T20:28:37.246Z","updated_at":"2025-04-10T00:21:31.198Z","avatar_url":"https://github.com/yudai.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Go coverage with -coverpkg\n\nThis repository demonstrates how the `-coverpkg` option works when you get test coverage of your projects.\n\nThis project has two packages, one is pkg1 and the other is pkg2. The pkg1 has enough tests, it's actually 100%. On the other hand, the pkg2 has no tests.\n\n`without_coverpkg.sh` calculates the \"total\" coverage using `go test` commands without `-coverpkg`. `with_coverpkg.sh` does the same thing with the `-coverpkg` option. The script lists up dependency packages in the project and pass that to the `-coverpkg` option.\n\n# Outputs\n\n```shell\nyudai@yudai01% ./without_coverpkg.sh\n?       github.com/yudai/go_cover       [no test files]\n=== RUN   TestPkg1\n--- PASS: TestPkg1 (0.00s)\nPASS\ncoverage: 100.0% of statements\nok      github.com/yudai/go_cover/pkg1  1.014s\n?       github.com/yudai/go_cover/pkg2  [no test files]\ngithub.com/yudai/go_cover/pkg1/pkg1.go:7:       DoSomething     100.0%\ngithub.com/yudai/go_cover/pkg1/pkg1.go:15:      DoSomethingElse 100.0%\ngithub.com/yudai/go_cover/pkg1/pkg1.go:23:      CallPkg2        100.0%\ntotal:                                          (statements)    100.0%\n```\n\nWe don't have any tests for `pkg2`, but the shown coverage is 100%.\n\n\n```shell\nyudai@yudai01% ./with_coverpkg.sh\nwarning: no packages being tested depend on github.com/yudai/go_cover/pkg1\nwarning: no packages being tested depend on github.com/yudai/go_cover/pkg2\n?       github.com/yudai/go_cover       [no test files]\nwarning: no packages being tested depend on github.com/yudai/go_cover\n=== RUN   TestPkg1\n--- PASS: TestPkg1 (0.00s)\nPASS\ncoverage: 51.9% of statements in github.com/yudai/go_cover, github.com/yudai/go_cover/pkg1, github.com/yudai/go_cover/pkg2\nok      github.com/yudai/go_cover/pkg1  1.019s\nwarning: no packages being tested depend on github.com/yudai/go_cover\nwarning: no packages being tested depend on github.com/yudai/go_cover/pkg1\n?       github.com/yudai/go_cover/pkg2  [no test files]\ngithub.com/yudai/go_cover/main.go:3:            main            0.0%\ngithub.com/yudai/go_cover/pkg1/pkg1.go:7:       DoSomething     100.0%\ngithub.com/yudai/go_cover/pkg1/pkg1.go:15:      DoSomethingElse 100.0%\ngithub.com/yudai/go_cover/pkg1/pkg1.go:23:      CallPkg2        100.0%\ngithub.com/yudai/go_cover/pkg2/pkg2.go:3:       DoSomething     30.0%\ngithub.com/yudai/go_cover/pkg2/pkg2.go:18:      DoSomethingElse 0.0%\ntotal:                                          (statements)    51.9%\n```\n\nNow you see the real total coverage.\n\n# Conclusion\n\nIt's good to have `-coverpkg` option in the script to calculate the project-wide test coverage. It can revial hidden untested packages.\n\nHowever, when you want to see if each package has enough unit tests, you don't want to use the `-coverpkg` option, becasue it makes the test comand output \"integrated\" coverages.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyudai%2Fgo_cover","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyudai%2Fgo_cover","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyudai%2Fgo_cover/lists"}