Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cover displays as 0% when -cover is not provided #62

Closed
leighmcculloch opened this issue May 26, 2022 · 6 comments · Fixed by #68
Closed

Cover displays as 0% when -cover is not provided #62

leighmcculloch opened this issue May 26, 2022 · 6 comments · Fixed by #68

Comments

@leighmcculloch
Copy link

I noticed that when I forget to include the -cover option on the go test command, the COVER column is displayed with a 0.0% value.

┌─────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │      PACKAGE      │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼───────────────────┼───────┼──────┼──────┼───────│
│  PASS   │ 0.11s   │ 4d63.com/optional │ 0.0%  │   21 │    0 │    0  │
└─────────────────────────────────────────────────────────────────────┘

tparse could hide that column when go test has not provided any coverage information.

From best I can tell the go test -json output omits the coverage outputs when -cover isn't used, and explicitly states 0.0% when -cover is used but no coverage exists. So it should be possible to distinguish between these situations.

@leighmcculloch
Copy link
Author

I'd be happy to contribute this if you're open to contributions.

@mfridman
Copy link
Owner

Good catch, let's fix this!

If you're up for it, contributions welcome. Otherwise I can fix this up fairly quickly. Need to improve the parsing between these 2 lines:

with -cover

{"Time":"2022-05-26T00:46:03.790079-04:00","Action":"output","Package":"fmt","Output":"ok  \tfmt\t0.159s\tcoverage: 95.2% of statements\n"}

no -cover

{"Time":"2022-05-26T00:46:12.520973-04:00","Action":"output","Package":"fmt","Output":"ok  \tfmt\t0.161s\n"}

@mfridman
Copy link
Owner

Oh, I think it already returns a pkg.Cover .. so can probably modify the default coverage string here:

coverage := fmt.Sprintf("%.1f%%", pkg.Coverage)
if pkg.Summary.Action != parse.ActionFail {
switch cover := pkg.Coverage; {
case cover > 0.0 && cover <= 50.0:
coverage = c.red(coverage, false)
case pkg.Coverage > 50.0 && pkg.Coverage < 80.0:
coverage = c.yellow(coverage, false)
case pkg.Coverage >= 80.0:
coverage = c.green(coverage, false)
}
}

@leighmcculloch
Copy link
Author

leighmcculloch commented Jun 4, 2022

I'd be happy to contribute this if you're open to contributions.

Sorry, I was too eager and can't take this now. Still loving the tool 🎉. Thank you!

@mfridman
Copy link
Owner

mfridman commented Jun 4, 2022

Haha, no worries. I'll fix this up today!

@mfridman
Copy link
Owner

mfridman commented Jun 4, 2022

Jotting this down for brevity.

Previously

┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │ 0.10s   │ github.com/mfridman/tparse/parse │ 0.0%  │   42 │    0 │    0  │
│  PASS   │ 0.16s   │ github.com/mfridman/tparse/tests │ 0.0%  │   85 │    0 │    0  │
└────────────────────────────────────────────────────────────────────────────────────┘

But, as pointed out there were not coverage statements, so let's display -- instead of 0.0%. Notably:

coverage: [no statements]
ok      github.com/mfridman/tparse/tests        0.151s  coverage: [no statements]

Expected without coverage

┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  0.17s  │ github.com/mfridman/tparse/parse │  --   │  42  │  0   │  0    │
│  PASS   │  0.24s  │ github.com/mfridman/tparse/tests │  --   │  85  │  0   │  0    │
└────────────────────────────────────────────────────────────────────────────────────┘

Expected with coverage

┌────────────────────────────────────────────────────────────────────────────────────┐
│  STATUS │ ELAPSED │             PACKAGE              │ COVER │ PASS │ FAIL │ SKIP  │
│─────────┼─────────┼──────────────────────────────────┼───────┼──────┼──────┼───────│
│  PASS   │  0.12s  │ github.com/mfridman/tparse/parse │ 14.0% │  42  │  0   │  0    │
│  PASS   │  0.19s  │ github.com/mfridman/tparse/tests │ 89.8% │  85  │  0   │  0    │
└────────────────────────────────────────────────────────────────────────────────────┘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants