Skip to content

Total coverage no longer easily regexable #284

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

Closed
desmondgc opened this issue Jan 4, 2019 · 9 comments
Closed

Total coverage no longer easily regexable #284

desmondgc opened this issue Jan 4, 2019 · 9 comments

Comments

@desmondgc
Copy link

In coverlet.msbuild v2.4.0, the total coverage output looks like this:

Total Line: 83.3%
Total Branch: 86.4%
Total Method: 83.9%

This functionality was added in #180 to support coverage badges in CI systems. In our GitLab config I can easily report on total branch coverage using the following: coverage: '/^Total Branch: \d+\.\d+/'

With the changes introduced in #271 / coverlet.msbuild v2.5.0, the output now looks like this:

+---------+--------+--------+--------+
|         | Line   | Branch | Method |
+---------+--------+--------+--------+
| Total   | 83.3%  | 86.4%  | 83.9%  |
+---------+--------+--------+--------+
| Average | 41.65% | 43.2%  | 41.95% |
+---------+--------+--------+--------+

This output format is much harder to work with. Can we eliminate the table?

@m4cx
Copy link

m4cx commented Jan 20, 2019

With this regex /\|\sTotal\s{1,}\|\s[^|]*\|\s\d+.\d+% I can find the string needed. But how exactly does gitlab handle the multiple numeric values? Does anyone know that?

I am not that used to regex. Is it possible with regex to remove the Line value from the string?

@desmondgc
Copy link
Author

GitLab's coverage regex will use a capture group, if present. So in this case, I can capture total branch coverage with the following regex: /^\|\s*Total\s*\|[^|]*\|\s*(\d+\.\d+)/

The point is, the output was originally added with an implicit requirement to be easily parsable. What used to be a simple and straightforward regex has become an ugly mess. Maybe we can add a switch for output format: table vs flat?

@m4cx
Copy link

m4cx commented Feb 2, 2019

Then I think the switch would be the appropriate solution. For humans this table view might quite appealing. But for parsing the simpe text output is perfekt

@anaether
Copy link

^\

The problem on your solution is that it dont works if you have full percent values.

This works:
18.00%
18.0%

This dont works:
18%

@anaether
Copy link

@desmondgc
My version works and fixes your bug (now it works also with integer values):
^|\sTotal\s|[^|]|\s(\d+.\d+ | [\d.]+)

If you want to use it, test it here:
https://rubular.com/

Sample Values:
+----------------------+-------+--------+--------+
| Module | Line | Branch | Method |
+----------------------+-------+--------+--------+
| Project | 6.3% | 18% | 11.6% |
+----------------------+-------+--------+--------+
| ProjectTest | 97.8% | 100% | 87.5% |
+----------------------+-------+--------+--------+

+---------+-------+--------+--------+
| | Line | Branch | Method |
+---------+-------+--------+--------+
| Total | 17% | 0% | 13.9% |
+---------+-------+--------+--------+
| Average | 3.95% | 9% | 6.95% |
+---------+-------+--------+--------+

@yauhenyaulampyeu
Copy link

| ?Total +| +(\d+.\d+|\d+)%
works fine

@gmarokov
Copy link

None of the above regex did the trick for me. What actually helped Total.*?(\d+(?:\.\d+)?)%

@joan-grau
Copy link

In my case, what separates the decimals from integers is a comma, so What actually helped me si Total.*?(\d+(?:\,\d+)?)%

@MarcoRossignoli
Copy link
Collaborator

Close for stale, related feature issue to avoid regex usage #542

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

No branches or pull requests

7 participants